]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdcrc.c
984815d98a9377876dafc12e21c13ec0c7c1d0a7
[proxmark3-svn] / client / cmdcrc.c
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>
13 //#include <stdlib.h>
14 //#include <ctype.h>
15 #include "cmdmain.h"
16 #include "cmdcrc.h"
17 #include "reveng/reveng.h"
18 #include "ui.h"
19 #include "util.h"
20
21 #define MAX_ARGS 20
22
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;
28
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;
49 }
50
51 int CmdCrc(const char *Cmd)
52 {
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 }
65
66 return 0;
67 }
68
Impressum, Datenschutz