]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdcrc.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2015 iceman <iceman at iuse.se>
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
7 //-----------------------------------------------------------------------------
8 // CRC Calculations from the software reveng commands
9 //-----------------------------------------------------------------------------
16 # define STDIN_FILENO 0
17 # endif /* STDIN_FILENO */
26 #include "reveng/reveng.h"
32 int split(char *str
, char *arr
[MAX_ARGS
]){
35 int maxWords
= MAX_ARGS
;
39 while(isspace(str
[beginIndex
])){
42 if(str
[beginIndex
] == '\0')
44 endIndex
= beginIndex
;
45 while (str
[endIndex
] && !isspace(str
[endIndex
])){
48 int len
= endIndex
- beginIndex
;
49 char *tmp
= calloc(len
+ 1, sizeof(char));
50 memcpy(tmp
, &str
[beginIndex
], len
);
52 //PrintAndLog("cnt: %d, %s",wordCnt-1, arr[wordCnt-1]);
53 beginIndex
= endIndex
;
54 if (wordCnt
== maxWords
)
60 int CmdCrc(const char *Cmd
)
62 char name
[] = {"reveng "};
64 memcpy(Cmd2
, name
, 7);
65 memcpy(Cmd2
+ 7, Cmd
, 50);
67 int argc
= split(Cmd2
, argv
);
68 //PrintAndLog("argc: %d, %s %s Cmd: %s",argc, argv[0], Cmd2, Cmd);
69 reveng_main(argc
, argv
);
70 for(int i
= 0; i
< argc
; ++i
){
78 int GetModels(char *Models
[], int *count
, uint32_t *width
){
80 static model_t model
= {
81 PZERO
, /* no CRC polynomial, user must specify */
83 P_BE
, /* RefIn = false, RefOut = false, plus P_RTJUST setting in reveng.h */
84 PZERO
, /* XorOut = 0 */
85 PZERO
, /* check value unused */
86 NULL
/* no model name */
88 //int ibperhx = 8, obperhx = 8;
89 //int rflags = 0, uflags = 0; /* search and UI flags */
91 //unsigned long width = 0UL;
92 //int c, mode = 0, args, psets, pass;
93 //poly_t apoly, crc, qpoly = PZERO, *apolys, *pptr = NULL, *qptr = NULL;
94 //model_t pset = model, *candmods, *mptr;
99 /* stdin must be binary */
101 _setmode(STDIN_FILENO
, _O_BINARY
);
109 if (*width
== 0) { //reveng -D
111 //PrintAndLog("Count: %d",*count);
113 PrintAndLog("no preset models available");
116 for(int mode
= 0; mode
< *count
; ++mode
) {
117 mbynum(&model
, mode
);
119 size_t size
= (model
.name
&& *model
.name
) ? strlen(model
.name
) : 6;
120 //PrintAndLog("Size: %d, %s",size,model.name);
121 char *tmp
= calloc(size
+1, sizeof(char));
123 PrintAndLog("out of memory?");
126 memcpy(tmp
, model
.name
, size
);
133 //PrintAndLog("DONE");
137 //test call to GetModels
138 int CmdrevengTest(const char *Cmd
){
142 int ans
= GetModels(Models
, &count
, &width
);
145 PrintAndLog("Count: %d",count
);
146 for (int i
= 0; i
< count
; i
++){
147 PrintAndLog("Model %d: %s",i
,Models
[i
]);