]>
Commit | Line | Data |
---|---|---|
fe81b478 | 1 | //----------------------------------------------------------------------------- |
2 | // Copyright (C) 2015 iceman <iceman at iuse.se> | |
3 | // | |
4 | // This code is licensed to you under the terms of the GNU GPL, version 2 or, | |
5 | // at your option, any later version. See the LICENSE.txt file for the text of | |
6 | // the license. | |
7 | //----------------------------------------------------------------------------- | |
8 | // CRC Calculations from the software reveng commands | |
9 | //----------------------------------------------------------------------------- | |
10 | ||
11 | #include <stdio.h> | |
12 | #include <string.h> | |
f46c3663 | 13 | //#include <stdlib.h> |
14 | //#include <ctype.h> | |
fe81b478 | 15 | #include "cmdmain.h" |
fe81b478 | 16 | #include "cmdcrc.h" |
17 | #include "reveng/reveng.h" | |
f46c3663 | 18 | #include "ui.h" |
19 | #include "util.h" | |
fe81b478 | 20 | |
f46c3663 | 21 | #define MAX_ARGS 20 |
fe81b478 | 22 | |
f46c3663 | 23 | int split(char *str, char *arr[MAX_ARGS]){ |
24 | int beginIndex = 0; | |
25 | int endIndex; | |
26 | int maxWords = MAX_ARGS; | |
27 | int wordCnt = 0; | |
fe81b478 | 28 | |
f46c3663 | 29 | while(1){ |
30 | while(isspace(str[beginIndex])){ | |
31 | ++beginIndex; | |
32 | } | |
33 | if(str[beginIndex] == '\0') | |
34 | break; | |
35 | endIndex = beginIndex; | |
36 | while (str[endIndex] && !isspace(str[endIndex])){ | |
37 | ++endIndex; | |
38 | } | |
39 | int len = endIndex - beginIndex; | |
40 | char *tmp = calloc(len + 1, sizeof(char)); | |
41 | memcpy(tmp, &str[beginIndex], len); | |
42 | arr[wordCnt++] = tmp; | |
43 | //PrintAndLog("cnt: %d, %s",wordCnt-1, arr[wordCnt-1]); | |
44 | beginIndex = endIndex; | |
45 | if (wordCnt == maxWords) | |
46 | break; | |
47 | } | |
48 | return wordCnt; | |
fe81b478 | 49 | } |
50 | ||
fe81b478 | 51 | int CmdCrc(const char *Cmd) |
52 | { | |
f46c3663 | 53 | char name[] = {"reveng "}; |
54 | char Cmd2[50 + 7]; | |
55 | memcpy(Cmd2, name, 7); | |
56 | memcpy(Cmd2 + 7, Cmd, 50); | |
57 | char *argv[MAX_ARGS]; | |
58 | int argc = split(Cmd2, argv); | |
59 | //PrintAndLog("argc: %d, %s %s Cmd: %s",argc, argv[0], Cmd2, Cmd); | |
60 | reveng_main(argc, argv); | |
61 | for(int i = 0; i < argc; ++i){ | |
62 | //puts(arr[i]); | |
63 | free(argv[i]); | |
64 | } | |
fe81b478 | 65 | |
f46c3663 | 66 | return 0; |
fe81b478 | 67 | } |
f46c3663 | 68 |