]>
Commit | Line | Data |
---|---|---|
9ca155ba | 1 | //-----------------------------------------------------------------------------\r |
b62a5a84 | 2 | // Copyright (C) 2011,2012 Merlok\r |
9ca155ba M |
3 | //\r |
4 | // This code is licensed to you under the terms of the GNU GPL, version 2 or,\r | |
5 | // at your option, any later version. See the LICENSE.txt file for the text of\r | |
6 | // the license.\r | |
7 | //-----------------------------------------------------------------------------\r | |
8 | // High frequency MIFARE commands\r | |
9 | //-----------------------------------------------------------------------------\r | |
10 | \r | |
11 | #include "cmdhfmf.h"\r | |
12 | \r | |
13 | static int CmdHelp(const char *Cmd);\r | |
14 | \r | |
9ca155ba M |
15 | int CmdHF14AMifare(const char *Cmd)\r |
16 | {\r | |
17 | uint32_t uid = 0;\r | |
1c611bbd | 18 | uint32_t nt = 0, nr = 0;\r |
9ca155ba M |
19 | uint64_t par_list = 0, ks_list = 0, r_key = 0;\r |
20 | uint8_t isOK = 0;\r | |
ac14bee3 | 21 | uint8_t keyBlock[8] = {0};\r |
aea4d766 | 22 | \r |
1c611bbd | 23 | UsbCommand c = {CMD_READER_MIFARE, {true, 0, 0}};\r |
24 | \r | |
25 | // message\r | |
26 | printf("-------------------------------------------------------------------------\n");\r | |
27 | printf("Executing command. Expected execution time: 25sec on average :-)\n");\r | |
28 | printf("Press the key on the proxmark3 device to abort both proxmark3 and client.\n");\r | |
29 | printf("-------------------------------------------------------------------------\n");\r | |
aea4d766 | 30 | \r |
9ca155ba | 31 | \r |
aea4d766 | 32 | start:\r |
e772353f | 33 | clearCommandBuffer();\r |
34 | SendCommand(&c);\r | |
9ca155ba M |
35 | \r |
36 | //flush queue\r | |
37 | while (ukbhit()) getchar();\r | |
38 | \r | |
9ca155ba M |
39 | \r |
40 | // wait cycle\r | |
41 | while (true) {\r | |
1c611bbd | 42 | printf(".");\r |
aea4d766 | 43 | fflush(stdout);\r |
9ca155ba M |
44 | if (ukbhit()) {\r |
45 | getchar();\r | |
46 | printf("\naborted via keyboard!\n");\r | |
47 | break;\r | |
48 | }\r | |
49 | \r | |
902cb3c0 | 50 | UsbCommand resp;\r |
1c611bbd | 51 | if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {\r |
902cb3c0 | 52 | isOK = resp.arg[0] & 0xff;\r |
902cb3c0 | 53 | uid = (uint32_t)bytes_to_num(resp.d.asBytes + 0, 4);\r |
54 | nt = (uint32_t)bytes_to_num(resp.d.asBytes + 4, 4);\r | |
55 | par_list = bytes_to_num(resp.d.asBytes + 8, 8);\r | |
56 | ks_list = bytes_to_num(resp.d.asBytes + 16, 8);\r | |
1c611bbd | 57 | nr = bytes_to_num(resp.d.asBytes + 24, 4);\r |
9ca155ba | 58 | printf("\n\n");\r |
9ca155ba M |
59 | if (!isOK) PrintAndLog("Proxmark can't get statistic info. Execution aborted.\n");\r |
60 | break;\r | |
61 | }\r | |
62 | } \r | |
1c611bbd | 63 | \r |
9ca155ba M |
64 | printf("\n");\r |
65 | \r | |
66 | // error\r | |
67 | if (isOK != 1) return 1;\r | |
68 | \r | |
69 | // execute original function from util nonce2key\r | |
1c611bbd | 70 | if (nonce2key(uid, nt, nr, par_list, ks_list, &r_key))\r |
bfaecce6 M |
71 | {\r |
72 | isOK = 2;\r | |
73 | PrintAndLog("Key not found (lfsr_common_prefix list is null). Nt=%08x", nt); \r | |
74 | } else {\r | |
75 | printf("------------------------------------------------------------------\n");\r | |
125a98a1 | 76 | PrintAndLog("Key found:%012"llx" \n", r_key);\r |
9ca155ba | 77 | \r |
bfaecce6 M |
78 | num_to_bytes(r_key, 6, keyBlock);\r |
79 | isOK = mfCheckKeys(0, 0, 1, keyBlock, &r_key);\r | |
80 | }\r | |
9ca155ba | 81 | if (!isOK) \r |
125a98a1 | 82 | PrintAndLog("Found valid key:%012"llx, r_key);\r |
9ca155ba | 83 | else\r |
aea4d766 | 84 | {\r |
1c611bbd | 85 | if (isOK != 2) PrintAndLog("Found invalid key. "); \r |
86 | PrintAndLog("Failing is expected to happen in 25%% of all cases. Trying again with a different reader nonce...");\r | |
87 | c.arg[0] = false;\r | |
aea4d766 | 88 | goto start;\r |
89 | }\r | |
9ca155ba M |
90 | \r |
91 | return 0;\r | |
92 | }\r | |
93 | \r | |
94 | int CmdHF14AMfWrBl(const char *Cmd)\r | |
95 | {\r | |
96 | uint8_t blockNo = 0;\r | |
97 | uint8_t keyType = 0;\r | |
98 | uint8_t key[6] = {0, 0, 0, 0, 0, 0};\r | |
99 | uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};\r | |
100 | \r | |
101 | char cmdp = 0x00;\r | |
102 | \r | |
103 | if (strlen(Cmd)<3) {\r | |
104 | PrintAndLog("Usage: hf mf wrbl <block number> <key A/B> <key (12 hex symbols)> <block data (32 hex symbols)>");\r | |
105 | PrintAndLog(" sample: hf mf wrbl 0 A FFFFFFFFFFFF 000102030405060708090A0B0C0D0E0F");\r | |
106 | return 0;\r | |
107 | } \r | |
108 | \r | |
109 | blockNo = param_get8(Cmd, 0);\r | |
110 | cmdp = param_getchar(Cmd, 1);\r | |
111 | if (cmdp == 0x00) {\r | |
112 | PrintAndLog("Key type must be A or B");\r | |
113 | return 1;\r | |
114 | }\r | |
115 | if (cmdp != 'A' && cmdp != 'a') keyType = 1;\r | |
116 | if (param_gethex(Cmd, 2, key, 12)) {\r | |
117 | PrintAndLog("Key must include 12 HEX symbols");\r | |
118 | return 1;\r | |
119 | }\r | |
120 | if (param_gethex(Cmd, 3, bldata, 32)) {\r | |
121 | PrintAndLog("Block data must include 32 HEX symbols");\r | |
122 | return 1;\r | |
123 | }\r | |
124 | PrintAndLog("--block no:%02x key type:%02x key:%s", blockNo, keyType, sprint_hex(key, 6));\r | |
125 | PrintAndLog("--data: %s", sprint_hex(bldata, 16));\r | |
126 | \r | |
127 | UsbCommand c = {CMD_MIFARE_WRITEBL, {blockNo, keyType, 0}};\r | |
128 | memcpy(c.d.asBytes, key, 6);\r | |
129 | memcpy(c.d.asBytes + 10, bldata, 16);\r | |
130 | SendCommand(&c);\r | |
9ca155ba | 131 | \r |
902cb3c0 | 132 | UsbCommand resp;\r |
133 | if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r | |
134 | uint8_t isOK = resp.arg[0] & 0xff;\r | |
9ca155ba M |
135 | PrintAndLog("isOk:%02x", isOK);\r |
136 | } else {\r | |
137 | PrintAndLog("Command execute timeout");\r | |
138 | }\r | |
139 | \r | |
d2f487af | 140 | return 0;\r |
141 | }\r | |
142 | \r | |
d2f487af | 143 | int CmdHF14AMfRdBl(const char *Cmd)\r |
144 | {\r | |
145 | uint8_t blockNo = 0;\r | |
9ca155ba M |
146 | uint8_t keyType = 0;\r |
147 | uint8_t key[6] = {0, 0, 0, 0, 0, 0};\r | |
148 | \r | |
149 | char cmdp = 0x00;\r | |
150 | \r | |
151 | \r | |
152 | if (strlen(Cmd)<3) {\r | |
153 | PrintAndLog("Usage: hf mf rdbl <block number> <key A/B> <key (12 hex symbols)>");\r | |
154 | PrintAndLog(" sample: hf mf rdbl 0 A FFFFFFFFFFFF ");\r | |
155 | return 0;\r | |
156 | } \r | |
157 | \r | |
158 | blockNo = param_get8(Cmd, 0);\r | |
159 | cmdp = param_getchar(Cmd, 1);\r | |
160 | if (cmdp == 0x00) {\r | |
161 | PrintAndLog("Key type must be A or B");\r | |
162 | return 1;\r | |
163 | }\r | |
164 | if (cmdp != 'A' && cmdp != 'a') keyType = 1;\r | |
165 | if (param_gethex(Cmd, 2, key, 12)) {\r | |
166 | PrintAndLog("Key must include 12 HEX symbols");\r | |
167 | return 1;\r | |
168 | }\r | |
169 | PrintAndLog("--block no:%02x key type:%02x key:%s ", blockNo, keyType, sprint_hex(key, 6));\r | |
170 | \r | |
171 | UsbCommand c = {CMD_MIFARE_READBL, {blockNo, keyType, 0}};\r | |
172 | memcpy(c.d.asBytes, key, 6);\r | |
173 | SendCommand(&c);\r | |
9ca155ba | 174 | \r |
902cb3c0 | 175 | UsbCommand resp;\r |
176 | if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r | |
177 | uint8_t isOK = resp.arg[0] & 0xff;\r | |
178 | uint8_t * data = resp.d.asBytes;\r | |
9ca155ba M |
179 | \r |
180 | if (isOK)\r | |
181 | PrintAndLog("isOk:%02x data:%s", isOK, sprint_hex(data, 16));\r | |
182 | else\r | |
183 | PrintAndLog("isOk:%02x", isOK);\r | |
184 | } else {\r | |
185 | PrintAndLog("Command execute timeout");\r | |
186 | }\r | |
187 | \r | |
d2f487af | 188 | return 0;\r |
189 | }\r | |
190 | \r | |
d2f487af | 191 | int CmdHF14AMfRdSc(const char *Cmd)\r |
192 | {\r | |
193 | int i;\r | |
9ca155ba M |
194 | uint8_t sectorNo = 0;\r |
195 | uint8_t keyType = 0;\r | |
196 | uint8_t key[6] = {0, 0, 0, 0, 0, 0};\r | |
197 | \r | |
198 | uint8_t isOK = 0;\r | |
199 | uint8_t * data = NULL;\r | |
200 | \r | |
201 | char cmdp = 0x00;\r | |
202 | \r | |
203 | if (strlen(Cmd)<3) {\r | |
204 | PrintAndLog("Usage: hf mf rdsc <sector number> <key A/B> <key (12 hex symbols)>");\r | |
205 | PrintAndLog(" sample: hf mf rdsc 0 A FFFFFFFFFFFF ");\r | |
206 | return 0;\r | |
207 | } \r | |
208 | \r | |
209 | sectorNo = param_get8(Cmd, 0);\r | |
210 | if (sectorNo > 63) {\r | |
211 | PrintAndLog("Sector number must be less than 64");\r | |
212 | return 1;\r | |
213 | }\r | |
214 | cmdp = param_getchar(Cmd, 1);\r | |
215 | if (cmdp == 0x00) {\r | |
216 | PrintAndLog("Key type must be A or B");\r | |
217 | return 1;\r | |
218 | }\r | |
219 | if (cmdp != 'A' && cmdp != 'a') keyType = 1;\r | |
220 | if (param_gethex(Cmd, 2, key, 12)) {\r | |
221 | PrintAndLog("Key must include 12 HEX symbols");\r | |
222 | return 1;\r | |
223 | }\r | |
224 | PrintAndLog("--sector no:%02x key type:%02x key:%s ", sectorNo, keyType, sprint_hex(key, 6));\r | |
225 | \r | |
226 | UsbCommand c = {CMD_MIFARE_READSC, {sectorNo, keyType, 0}};\r | |
227 | memcpy(c.d.asBytes, key, 6);\r | |
228 | SendCommand(&c);\r | |
9ca155ba M |
229 | PrintAndLog(" ");\r |
230 | \r | |
902cb3c0 | 231 | UsbCommand resp;\r |
232 | if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r | |
233 | isOK = resp.arg[0] & 0xff;\r | |
234 | data = resp.d.asBytes;\r | |
9ca155ba M |
235 | \r |
236 | PrintAndLog("isOk:%02x", isOK);\r | |
237 | if (isOK) \r | |
238 | for (i = 0; i < 2; i++) {\r | |
239 | PrintAndLog("data:%s", sprint_hex(data + i * 16, 16));\r | |
240 | }\r | |
241 | } else {\r | |
242 | PrintAndLog("Command1 execute timeout");\r | |
243 | }\r | |
244 | \r | |
902cb3c0 | 245 | // response2\r |
9ca155ba | 246 | PrintAndLog(" ");\r |
902cb3c0 | 247 | if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r |
248 | isOK = resp.arg[0] & 0xff;\r | |
249 | data = resp.d.asBytes;\r | |
9ca155ba M |
250 | \r |
251 | if (isOK) \r | |
252 | for (i = 0; i < 2; i++) {\r | |
253 | PrintAndLog("data:%s", sprint_hex(data + i * 16, 16));\r | |
254 | }\r | |
255 | } else {\r | |
256 | PrintAndLog("Command2 execute timeout");\r | |
257 | }\r | |
258 | \r | |
259 | return 0;\r | |
260 | }\r | |
261 | \r | |
aea4d766 | 262 | int CmdHF14AMfDump(const char *Cmd)\r |
26fdb4ab | 263 | {\r |
264 | int i, j;\r | |
265 | \r | |
aea4d766 | 266 | uint8_t keyA[40][6];\r |
267 | uint8_t keyB[40][6];\r | |
268 | uint8_t rights[40][4];\r | |
26fdb4ab | 269 | \r |
26fdb4ab | 270 | FILE *fin;\r |
271 | FILE *fout;\r | |
272 | \r | |
902cb3c0 | 273 | UsbCommand resp;\r |
26fdb4ab | 274 | \r |
275 | if ((fin = fopen("dumpkeys.bin","rb")) == NULL) {\r | |
aea4d766 | 276 | PrintAndLog("Could not find file dumpkeys.bin");\r |
26fdb4ab | 277 | return 1;\r |
278 | }\r | |
279 | \r | |
280 | if ((fout = fopen("dumpdata.bin","wb")) == NULL) { \r | |
aea4d766 | 281 | PrintAndLog("Could not create file name dumpdata.bin");\r |
26fdb4ab | 282 | return 1;\r |
283 | }\r | |
284 | \r | |
285 | // Read key file\r | |
286 | \r | |
287 | for (i=0 ; i<16 ; i++) {\r | |
759c16b3 | 288 | if (fread( keyA[i], 1, 6, fin ) == 0) {\r |
289 | PrintAndLog("File reading error.");\r | |
290 | return 2;\r | |
291 | }\r | |
26fdb4ab | 292 | }\r |
293 | for (i=0 ; i<16 ; i++) {\r | |
759c16b3 | 294 | if (fread( keyB[i], 1, 6, fin ) == 0) {\r |
295 | PrintAndLog("File reading error.");\r | |
296 | return 2;\r | |
297 | }\r | |
26fdb4ab | 298 | }\r |
299 | \r | |
300 | // Read access rights to sectors\r | |
301 | \r | |
302 | PrintAndLog("|-----------------------------------------|");\r | |
303 | PrintAndLog("|------ Reading sector access bits...-----|");\r | |
304 | PrintAndLog("|-----------------------------------------|");\r | |
305 | \r | |
306 | for (i = 0 ; i < 16 ; i++) {\r | |
307 | UsbCommand c = {CMD_MIFARE_READBL, {4*i + 3, 0, 0}};\r | |
308 | memcpy(c.d.asBytes, keyA[i], 6);\r | |
309 | SendCommand(&c);\r | |
26fdb4ab | 310 | \r |
902cb3c0 | 311 | if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r |
312 | uint8_t isOK = resp.arg[0] & 0xff;\r | |
313 | uint8_t *data = resp.d.asBytes;\r | |
26fdb4ab | 314 | if (isOK){\r |
315 | rights[i][0] = ((data[7] & 0x10)>>4) | ((data[8] & 0x1)<<1) | ((data[8] & 0x10)>>2);\r | |
316 | rights[i][1] = ((data[7] & 0x20)>>5) | ((data[8] & 0x2)<<0) | ((data[8] & 0x20)>>3);\r | |
317 | rights[i][2] = ((data[7] & 0x40)>>6) | ((data[8] & 0x4)>>1) | ((data[8] & 0x40)>>4);\r | |
318 | rights[i][3] = ((data[7] & 0x80)>>7) | ((data[8] & 0x8)>>2) | ((data[8] & 0x80)>>5);\r | |
319 | }\r | |
320 | else{\r | |
321 | PrintAndLog("Could not get access rights for block %d", i);\r | |
322 | }\r | |
323 | }\r | |
324 | else {\r | |
325 | PrintAndLog("Command execute timeout");\r | |
326 | }\r | |
327 | }\r | |
328 | \r | |
329 | // Read blocks and print to file\r | |
330 | \r | |
331 | PrintAndLog("|-----------------------------------------|");\r | |
332 | PrintAndLog("|----- Dumping all blocks to file... -----|");\r | |
333 | PrintAndLog("|-----------------------------------------|");\r | |
334 | \r | |
902cb3c0 | 335 | \r |
26fdb4ab | 336 | for (i=0 ; i<16 ; i++) {\r |
337 | for (j=0 ; j<4 ; j++) {\r | |
902cb3c0 | 338 | bool received = false;\r |
339 | \r | |
340 | if (j == 3){\r | |
26fdb4ab | 341 | UsbCommand c = {CMD_MIFARE_READBL, {i*4 + j, 0, 0}};\r |
342 | memcpy(c.d.asBytes, keyA[i], 6);\r | |
343 | SendCommand(&c);\r | |
902cb3c0 | 344 | received = WaitForResponseTimeout(CMD_ACK,&resp,1500);\r |
26fdb4ab | 345 | }\r |
346 | else{\r | |
347 | if ((rights[i][j] == 6) | (rights[i][j] == 5)) {\r | |
348 | UsbCommand c = {CMD_MIFARE_READBL, {i*4+j, 1, 0}};\r | |
349 | memcpy(c.d.asBytes, keyB[i], 6);\r | |
350 | SendCommand(&c);\r | |
902cb3c0 | 351 | received = WaitForResponseTimeout(CMD_ACK,&resp,1500);\r |
26fdb4ab | 352 | }\r |
353 | else if (rights[i][j] == 7) {\r | |
354 | PrintAndLog("Access rights do not allow reading of sector %d block %d",i,j);\r | |
355 | }\r | |
356 | else {\r | |
357 | UsbCommand c = {CMD_MIFARE_READBL, {i*4+j, 0, 0}};\r | |
358 | memcpy(c.d.asBytes, keyA[i], 6);\r | |
359 | SendCommand(&c);\r | |
902cb3c0 | 360 | received = WaitForResponseTimeout(CMD_ACK,&resp,1500);\r |
26fdb4ab | 361 | }\r |
362 | }\r | |
363 | \r | |
902cb3c0 | 364 | if (received) {\r |
365 | uint8_t isOK = resp.arg[0] & 0xff;\r | |
366 | uint8_t *data = resp.d.asBytes;\r | |
3d77fdfa | 367 | if (j == 3) {\r |
368 | data[0] = (keyA[i][0]);\r | |
369 | data[1] = (keyA[i][1]);\r | |
370 | data[2] = (keyA[i][2]);\r | |
371 | data[3] = (keyA[i][3]);\r | |
372 | data[4] = (keyA[i][4]);\r | |
373 | data[5] = (keyA[i][5]);\r | |
374 | data[10] = (keyB[i][0]);\r | |
375 | data[11] = (keyB[i][1]);\r | |
376 | data[12] = (keyB[i][2]);\r | |
377 | data[13] = (keyB[i][3]);\r | |
378 | data[14] = (keyB[i][4]);\r | |
379 | data[15] = (keyB[i][5]);\r | |
380 | }\r | |
26fdb4ab | 381 | if (isOK) {\r |
382 | fwrite ( data, 1, 16, fout );\r | |
6a2c1d8e | 383 | PrintAndLog("Dumped card data into 'dumpdata.bin'");\r |
05ed5c49 | 384 | \r |
26fdb4ab | 385 | }\r |
386 | else {\r | |
387 | PrintAndLog("Could not get access rights for block %d", i);\r | |
388 | }\r | |
389 | }\r | |
390 | else {\r | |
391 | PrintAndLog("Command execute timeout");\r | |
392 | }\r | |
393 | }\r | |
394 | }\r | |
395 | \r | |
396 | fclose(fin);\r | |
397 | fclose(fout);\r | |
26fdb4ab | 398 | return 0;\r |
399 | }\r | |
400 | \r | |
aea4d766 | 401 | int CmdHF14AMfRestore(const char *Cmd)\r |
26fdb4ab | 402 | {\r |
403 | \r | |
404 | int i,j;\r | |
26fdb4ab | 405 | uint8_t keyType = 0;\r |
406 | uint8_t key[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};\r | |
407 | uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};\r | |
408 | uint8_t keyA[16][6];\r | |
409 | uint8_t keyB[16][6];\r | |
410 | \r | |
26fdb4ab | 411 | FILE *fdump;\r |
412 | FILE *fkeys;\r | |
413 | \r | |
26fdb4ab | 414 | if ((fdump = fopen("dumpdata.bin","rb")) == NULL) {\r |
aea4d766 | 415 | PrintAndLog("Could not find file dumpdata.bin");\r |
26fdb4ab | 416 | return 1;\r |
417 | }\r | |
418 | if ((fkeys = fopen("dumpkeys.bin","rb")) == NULL) {\r | |
aea4d766 | 419 | PrintAndLog("Could not find file dumpkeys.bin");\r |
26fdb4ab | 420 | return 1;\r |
421 | }\r | |
422 | \r | |
423 | for (i=0 ; i<16 ; i++) {\r | |
759c16b3 | 424 | if (fread(keyA[i], 1, 6, fkeys) == 0) {\r |
8720c8f5 | 425 | PrintAndLog("File reading error.");\r |
759c16b3 | 426 | return 2;\r |
427 | }\r | |
26fdb4ab | 428 | }\r |
429 | for (i=0 ; i<16 ; i++) {\r | |
759c16b3 | 430 | if (fread(keyB[i], 1, 6, fkeys) == 0) {\r |
8720c8f5 | 431 | PrintAndLog("File reading error.");\r |
759c16b3 | 432 | return 2;\r |
433 | }\r | |
26fdb4ab | 434 | }\r |
435 | \r | |
9d710943 | 436 | PrintAndLog("Restoring dumpdata.bin to card");\r |
26fdb4ab | 437 | \r |
438 | for (i=0 ; i<16 ; i++) {\r | |
439 | for( j=0 ; j<4 ; j++) {\r | |
440 | UsbCommand c = {CMD_MIFARE_WRITEBL, {i*4 + j, keyType, 0}};\r | |
441 | memcpy(c.d.asBytes, key, 6);\r | |
442 | \r | |
759c16b3 | 443 | if (fread(bldata, 1, 16, fdump) == 0) {\r |
8720c8f5 | 444 | PrintAndLog("File reading error.");\r |
445 | return 2;\r | |
759c16b3 | 446 | }\r |
26fdb4ab | 447 | \r |
448 | if (j == 3) {\r | |
449 | bldata[0] = (keyA[i][0]);\r | |
450 | bldata[1] = (keyA[i][1]);\r | |
451 | bldata[2] = (keyA[i][2]);\r | |
452 | bldata[3] = (keyA[i][3]);\r | |
453 | bldata[4] = (keyA[i][4]);\r | |
454 | bldata[5] = (keyA[i][5]);\r | |
455 | bldata[10] = (keyB[i][0]);\r | |
456 | bldata[11] = (keyB[i][1]);\r | |
457 | bldata[12] = (keyB[i][2]);\r | |
458 | bldata[13] = (keyB[i][3]);\r | |
459 | bldata[14] = (keyB[i][4]);\r | |
460 | bldata[15] = (keyB[i][5]);\r | |
461 | } \r | |
462 | \r | |
6c064e16 | 463 | PrintAndLog("Writing to block %2d: %s", i*4+j, sprint_hex(bldata, 16));\r |
464 | \r | |
465 | /*\r | |
9d710943 | 466 | PrintAndLog("Writing to block %2d: %s Confirm? [Y,N]", i*4+j, sprint_hex(bldata, 16));\r |
467 | \r | |
0f7f9edc | 468 | scanf("%c",&ch);\r |
6c064e16 | 469 | if ((ch != 'y') && (ch != 'Y')){\r |
9d710943 | 470 | PrintAndLog("Aborting !");\r |
471 | return 1;\r | |
472 | }\r | |
6c064e16 | 473 | */\r |
26fdb4ab | 474 | \r |
475 | memcpy(c.d.asBytes + 10, bldata, 16);\r | |
476 | SendCommand(&c);\r | |
26fdb4ab | 477 | \r |
902cb3c0 | 478 | UsbCommand resp;\r |
8720c8f5 | 479 | if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r |
902cb3c0 | 480 | uint8_t isOK = resp.arg[0] & 0xff;\r |
26fdb4ab | 481 | PrintAndLog("isOk:%02x", isOK);\r |
482 | } else {\r | |
483 | PrintAndLog("Command execute timeout");\r | |
484 | }\r | |
485 | }\r | |
486 | }\r | |
487 | \r | |
488 | fclose(fdump);\r | |
489 | fclose(fkeys);\r | |
490 | return 0;\r | |
491 | }\r | |
492 | \r | |
9ca155ba M |
493 | int CmdHF14AMfNested(const char *Cmd)\r |
494 | {\r | |
495 | int i, j, res, iterations;\r | |
496 | sector * e_sector = NULL;\r | |
497 | uint8_t blockNo = 0;\r | |
498 | uint8_t keyType = 0;\r | |
499 | uint8_t trgBlockNo = 0;\r | |
500 | uint8_t trgKeyType = 0;\r | |
501 | uint8_t blDiff = 0;\r | |
502 | int SectorsCnt = 0;\r | |
503 | uint8_t key[6] = {0, 0, 0, 0, 0, 0};\r | |
9492e0b0 | 504 | uint8_t keyBlock[6*6];\r |
9ca155ba | 505 | uint64_t key64 = 0;\r |
8556b852 | 506 | int transferToEml = 0;\r |
9ca155ba | 507 | \r |
26fdb4ab | 508 | int createDumpFile = 0;\r |
509 | FILE *fkeys;\r | |
21156267 | 510 | uint8_t standart[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};\r |
511 | uint8_t tempkey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};\r | |
26fdb4ab | 512 | \r |
9ca155ba M |
513 | char cmdp, ctmp;\r |
514 | \r | |
515 | if (strlen(Cmd)<3) {\r | |
516 | PrintAndLog("Usage:");\r | |
26fdb4ab | 517 | PrintAndLog(" all sectors: hf mf nested <card memory> <block number> <key A/B> <key (12 hex symbols)> [t,d]");\r |
0014cb46 M |
518 | PrintAndLog(" one sector: hf mf nested o <block number> <key A/B> <key (12 hex symbols)>");\r |
519 | PrintAndLog(" <target block number> <target key A/B> [t]");\r | |
9ca155ba | 520 | PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");\r |
8556b852 | 521 | PrintAndLog("t - transfer keys into emulator memory");\r |
26fdb4ab | 522 | PrintAndLog("d - write keys to binary file");\r |
9ca155ba M |
523 | PrintAndLog(" ");\r |
524 | PrintAndLog(" sample1: hf mf nested 1 0 A FFFFFFFFFFFF ");\r | |
8556b852 | 525 | PrintAndLog(" sample1: hf mf nested 1 0 A FFFFFFFFFFFF t ");\r |
26fdb4ab | 526 | PrintAndLog(" sample1: hf mf nested 1 0 A FFFFFFFFFFFF d ");\r |
9ca155ba M |
527 | PrintAndLog(" sample2: hf mf nested o 0 A FFFFFFFFFFFF 4 A");\r |
528 | return 0;\r | |
529 | } \r | |
530 | \r | |
531 | cmdp = param_getchar(Cmd, 0);\r | |
532 | blockNo = param_get8(Cmd, 1);\r | |
533 | ctmp = param_getchar(Cmd, 2);\r | |
534 | if (ctmp == 0x00) {\r | |
535 | PrintAndLog("Key type must be A or B");\r | |
536 | return 1;\r | |
537 | }\r | |
538 | if (ctmp != 'A' && ctmp != 'a') keyType = 1;\r | |
539 | if (param_gethex(Cmd, 3, key, 12)) {\r | |
540 | PrintAndLog("Key must include 12 HEX symbols");\r | |
541 | return 1;\r | |
542 | }\r | |
543 | \r | |
8556b852 | 544 | if (cmdp == 'o' || cmdp == 'O') {\r |
9ca155ba M |
545 | cmdp = 'o';\r |
546 | trgBlockNo = param_get8(Cmd, 4);\r | |
547 | ctmp = param_getchar(Cmd, 5);\r | |
548 | if (ctmp == 0x00) {\r | |
549 | PrintAndLog("Target key type must be A or B");\r | |
550 | return 1;\r | |
551 | }\r | |
552 | if (ctmp != 'A' && ctmp != 'a') trgKeyType = 1;\r | |
553 | } else {\r | |
554 | switch (cmdp) {\r | |
555 | case '0': SectorsCnt = 05; break;\r | |
556 | case '1': SectorsCnt = 16; break;\r | |
557 | case '2': SectorsCnt = 32; break;\r | |
558 | case '4': SectorsCnt = 64; break;\r | |
559 | default: SectorsCnt = 16;\r | |
560 | }\r | |
561 | }\r | |
8556b852 M |
562 | \r |
563 | ctmp = param_getchar(Cmd, 4);\r | |
21156267 | 564 | if (ctmp == 't' || ctmp == 'T') transferToEml = 1;\r |
565 | else if (ctmp == 'd' || ctmp == 'D') createDumpFile = 1;\r | |
566 | \r | |
8556b852 M |
567 | ctmp = param_getchar(Cmd, 6);\r |
568 | transferToEml |= (ctmp == 't' || ctmp == 'T');\r | |
21156267 | 569 | transferToEml |= (ctmp == 'd' || ctmp == 'D');\r |
9ca155ba | 570 | \r |
8556b852 | 571 | PrintAndLog("--block no:%02x key type:%02x key:%s etrans:%d", blockNo, keyType, sprint_hex(key, 6), transferToEml);\r |
9ca155ba M |
572 | if (cmdp == 'o')\r |
573 | PrintAndLog("--target block no:%02x target key type:%02x ", trgBlockNo, trgKeyType);\r | |
574 | \r | |
575 | if (cmdp == 'o') {\r | |
9492e0b0 | 576 | if (mfnested(blockNo, keyType, key, trgBlockNo, trgKeyType, keyBlock, true)) {\r |
9ca155ba M |
577 | PrintAndLog("Nested error.");\r |
578 | return 2;\r | |
579 | }\r | |
9492e0b0 | 580 | key64 = bytes_to_num(keyBlock, 6);\r |
581 | if (key64) {\r | |
125a98a1 | 582 | PrintAndLog("Found valid key:%012"llx, key64);\r |
8556b852 M |
583 | \r |
584 | // transfer key to the emulator\r | |
585 | if (transferToEml) {\r | |
586 | mfEmlGetMem(keyBlock, (trgBlockNo / 4) * 4 + 3, 1);\r | |
587 | \r | |
588 | if (!trgKeyType)\r | |
589 | num_to_bytes(key64, 6, keyBlock);\r | |
590 | else\r | |
591 | num_to_bytes(key64, 6, &keyBlock[10]);\r | |
592 | mfEmlSetMem(keyBlock, (trgBlockNo / 4) * 4 + 3, 1); \r | |
593 | }\r | |
594 | } else {\r | |
9ca155ba | 595 | PrintAndLog("No valid key found");\r |
8556b852 | 596 | }\r |
21156267 | 597 | }\r |
598 | else { // ------------------------------------ multiple sectors working\r | |
9492e0b0 | 599 | clock_t time1;\r |
600 | time1 = clock();\r | |
601 | \r | |
9ca155ba M |
602 | blDiff = blockNo % 4;\r |
603 | PrintAndLog("Block shift=%d", blDiff);\r | |
604 | e_sector = calloc(SectorsCnt, sizeof(sector));\r | |
605 | if (e_sector == NULL) return 1;\r | |
606 | \r | |
607 | //test current key 4 sectors\r | |
608 | memcpy(keyBlock, key, 6);\r | |
9492e0b0 | 609 | num_to_bytes(0xffffffffffff, 6, (uint8_t*)(keyBlock + 1 * 6));\r |
610 | num_to_bytes(0x000000000000, 6, (uint8_t*)(keyBlock + 2 * 6));\r | |
611 | num_to_bytes(0xa0a1a2a3a4a5, 6, (uint8_t*)(keyBlock + 3 * 6));\r | |
612 | num_to_bytes(0xb0b1b2b3b4b5, 6, (uint8_t*)(keyBlock + 4 * 6));\r | |
9ca155ba M |
613 | num_to_bytes(0xaabbccddeeff, 6, (uint8_t*)(keyBlock + 5 * 6));\r |
614 | \r | |
615 | PrintAndLog("Testing known keys. Sector count=%d", SectorsCnt);\r | |
616 | for (i = 0; i < SectorsCnt; i++) {\r | |
617 | for (j = 0; j < 2; j++) {\r | |
618 | if (e_sector[i].foundKey[j]) continue;\r | |
619 | \r | |
620 | res = mfCheckKeys(i * 4 + blDiff, j, 6, keyBlock, &key64);\r | |
621 | \r | |
622 | if (!res) {\r | |
623 | e_sector[i].Key[j] = key64;\r | |
624 | e_sector[i].foundKey[j] = 1;\r | |
625 | }\r | |
626 | }\r | |
9492e0b0 | 627 | }\r |
628 | \r | |
9ca155ba | 629 | \r |
9ca155ba M |
630 | // nested sectors\r |
631 | iterations = 0;\r | |
632 | PrintAndLog("nested...");\r | |
9492e0b0 | 633 | bool calibrate = true;\r |
9ca155ba | 634 | for (i = 0; i < NESTED_SECTOR_RETRY; i++) {\r |
9492e0b0 | 635 | for (trgBlockNo = blDiff; trgBlockNo < SectorsCnt * 4; trgBlockNo = trgBlockNo + 4) {\r |
9ca155ba M |
636 | for (trgKeyType = 0; trgKeyType < 2; trgKeyType++) { \r |
637 | if (e_sector[trgBlockNo / 4].foundKey[trgKeyType]) continue;\r | |
9492e0b0 | 638 | PrintAndLog("-----------------------------------------------");\r |
639 | if(mfnested(blockNo, keyType, key, trgBlockNo, trgKeyType, keyBlock, calibrate)) {\r | |
640 | PrintAndLog("Nested error.\n");\r | |
641 | return 2;\r | |
642 | }\r | |
643 | else {\r | |
644 | calibrate = false;\r | |
645 | }\r | |
9ca155ba M |
646 | \r |
647 | iterations++;\r | |
9492e0b0 | 648 | \r |
649 | key64 = bytes_to_num(keyBlock, 6);\r | |
650 | if (key64) {\r | |
125a98a1 | 651 | PrintAndLog("Found valid key:%012"llx, key64);\r |
9ca155ba M |
652 | e_sector[trgBlockNo / 4].foundKey[trgKeyType] = 1;\r |
653 | e_sector[trgBlockNo / 4].Key[trgKeyType] = key64;\r | |
654 | }\r | |
655 | }\r | |
9492e0b0 | 656 | }\r |
9ca155ba M |
657 | }\r |
658 | \r | |
a0041115 | 659 | printf("Time in nested: %1.3f (%1.3f sec per key)\n\n", ((float)clock() - time1)/CLOCKS_PER_SEC, ((float)clock() - time1)/iterations/CLOCKS_PER_SEC);\r |
9492e0b0 | 660 | \r |
661 | PrintAndLog("-----------------------------------------------\nIterations count: %d\n\n", iterations);\r | |
9ca155ba M |
662 | //print them\r |
663 | PrintAndLog("|---|----------------|---|----------------|---|");\r | |
664 | PrintAndLog("|sec|key A |res|key B |res|");\r | |
665 | PrintAndLog("|---|----------------|---|----------------|---|");\r | |
666 | for (i = 0; i < SectorsCnt; i++) {\r | |
125a98a1 | 667 | PrintAndLog("|%03d| %012"llx" | %d | %012"llx" | %d |", i,\r |
9ca155ba M |
668 | e_sector[i].Key[0], e_sector[i].foundKey[0], e_sector[i].Key[1], e_sector[i].foundKey[1]);\r |
669 | }\r | |
670 | PrintAndLog("|---|----------------|---|----------------|---|");\r | |
671 | \r | |
8556b852 M |
672 | // transfer them to the emulator\r |
673 | if (transferToEml) {\r | |
674 | for (i = 0; i < SectorsCnt; i++) {\r | |
675 | mfEmlGetMem(keyBlock, i * 4 + 3, 1);\r | |
676 | if (e_sector[i].foundKey[0])\r | |
ab8b654e | 677 | num_to_bytes(e_sector[i].Key[0], 6, keyBlock);\r |
8556b852 M |
678 | if (e_sector[i].foundKey[1])\r |
679 | num_to_bytes(e_sector[i].Key[1], 6, &keyBlock[10]);\r | |
680 | mfEmlSetMem(keyBlock, i * 4 + 3, 1);\r | |
681 | } \r | |
682 | }\r | |
683 | \r | |
21156267 | 684 | // Create dump file\r |
26fdb4ab | 685 | if (createDumpFile) {\r |
686 | if ((fkeys = fopen("dumpkeys.bin","wb")) == NULL) { \r | |
aea4d766 | 687 | PrintAndLog("Could not create file dumpkeys.bin");\r |
26fdb4ab | 688 | free(e_sector);\r |
689 | return 1;\r | |
690 | }\r | |
21156267 | 691 | PrintAndLog("Printing keys to bynary file dumpkeys.bin...");\r |
26fdb4ab | 692 | for(i=0; i<16; i++) {\r |
21156267 | 693 | if (e_sector[i].foundKey[0]){\r |
694 | num_to_bytes(e_sector[i].Key[0], 6, tempkey);\r | |
695 | fwrite ( tempkey, 1, 6, fkeys );\r | |
696 | }\r | |
697 | else{\r | |
698 | fwrite ( &standart, 1, 6, fkeys );\r | |
699 | }\r | |
26fdb4ab | 700 | }\r |
701 | for(i=0; i<16; i++) {\r | |
21156267 | 702 | if (e_sector[i].foundKey[1]){\r |
703 | num_to_bytes(e_sector[i].Key[1], 6, tempkey);\r | |
704 | fwrite ( tempkey, 1, 6, fkeys );\r | |
705 | }\r | |
706 | else{\r | |
707 | fwrite ( &standart, 1, 6, fkeys );\r | |
708 | }\r | |
26fdb4ab | 709 | }\r |
710 | fclose(fkeys);\r | |
711 | }\r | |
712 | \r | |
9ca155ba M |
713 | free(e_sector);\r |
714 | }\r | |
715 | \r | |
716 | return 0;\r | |
717 | }\r | |
718 | \r | |
aea4d766 | 719 | static uint32_t\r |
720 | get_trailer_block (uint32_t uiBlock)\r | |
721 | {\r | |
722 | // Test if we are in the small or big sectors\r | |
723 | uint32_t trailer_block = 0;\r | |
724 | if (uiBlock < 128) {\r | |
725 | trailer_block = uiBlock + (3 - (uiBlock % 4));\r | |
726 | } else {\r | |
727 | trailer_block = uiBlock + (15 - (uiBlock % 16));\r | |
728 | }\r | |
729 | return trailer_block;\r | |
730 | }\r | |
9ca155ba M |
731 | int CmdHF14AMfChk(const char *Cmd)\r |
732 | {\r | |
aea4d766 | 733 | FILE * f;\r |
734 | char filename[256]={0};\r | |
83613803 | 735 | char buf[13];\r |
aea4d766 | 736 | uint8_t *keyBlock = NULL, *p;\r |
737 | uint8_t stKeyBlock = 20;\r | |
738 | \r | |
9ca155ba M |
739 | int i, res;\r |
740 | int keycnt = 0;\r | |
741 | char ctmp = 0x00;\r | |
742 | uint8_t blockNo = 0;\r | |
aea4d766 | 743 | uint8_t SectorsCnt = 1;\r |
9ca155ba | 744 | uint8_t keyType = 0;\r |
9ca155ba | 745 | uint64_t key64 = 0;\r |
aea4d766 | 746 | \r |
747 | int transferToEml = 0;\r | |
748 | int createDumpFile = 0;\r | |
9ca155ba | 749 | \r |
aea4d766 | 750 | keyBlock = calloc(stKeyBlock, 6);\r |
751 | if (keyBlock == NULL) return 1;\r | |
752 | \r | |
0c12504a | 753 | uint64_t defaultKeys[] =\r |
754 | {\r | |
755 | 0xffffffffffff, // Default key (first key used by program if no user defined key)\r | |
756 | 0x000000000000, // Blank key\r | |
757 | 0xa0a1a2a3a4a5, // NFCForum MAD key\r | |
758 | 0xb0b1b2b3b4b5,\r | |
759 | 0xaabbccddeeff,\r | |
760 | 0x4d3a99c351dd,\r | |
761 | 0x1a982c7e459a,\r | |
762 | 0xd3f7d3f7d3f7,\r | |
763 | 0x714c5c886e97,\r | |
764 | 0x587ee5f9350f,\r | |
765 | 0xa0478cc39091,\r | |
766 | 0x533cb6c723f6,\r | |
767 | 0x8fd0a4f256e9\r | |
768 | };\r | |
769 | int defaultKeysSize = (sizeof(defaultKeys) / 7) - 1;\r | |
770 | \r | |
771 | for (int defaultKeyCounter = 0; defaultKeyCounter < defaultKeysSize; defaultKeyCounter++)\r | |
772 | {\r | |
773 | num_to_bytes(defaultKeys[defaultKeyCounter], 6, (uint8_t*)(keyBlock + defaultKeyCounter * 6));\r | |
774 | }\r | |
aea4d766 | 775 | \r |
9ca155ba | 776 | if (strlen(Cmd)<3) {\r |
aea4d766 | 777 | PrintAndLog("Usage: hf mf chk <block number>/<*card memory> <key type (A/B/?)> [t] [<key (12 hex symbols)>] [<dic (*.dic)>]");\r |
778 | PrintAndLog(" * - all sectors");\r | |
779 | PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");\r | |
780 | // PrintAndLog("d - write keys to binary file\n");\r | |
781 | \r | |
782 | PrintAndLog(" sample: hf mf chk 0 A 1234567890ab keys.dic");\r | |
783 | PrintAndLog(" hf mf chk *1 ? t");\r | |
9ca155ba M |
784 | return 0;\r |
785 | } \r | |
786 | \r | |
aea4d766 | 787 | if (param_getchar(Cmd, 0)=='*') {\r |
788 | blockNo = 3;\r | |
789 | switch(param_getchar(Cmd+1, 0)) {\r | |
790 | case '0': SectorsCnt = 5; break;\r | |
791 | case '1': SectorsCnt = 16; break;\r | |
792 | case '2': SectorsCnt = 32; break;\r | |
793 | case '4': SectorsCnt = 40; break;\r | |
794 | default: SectorsCnt = 16;\r | |
795 | }\r | |
796 | }\r | |
797 | else\r | |
798 | blockNo = param_get8(Cmd, 0);\r | |
799 | \r | |
9ca155ba | 800 | ctmp = param_getchar(Cmd, 1);\r |
aea4d766 | 801 | switch (ctmp) { \r |
802 | case 'a': case 'A':\r | |
803 | keyType = !0;\r | |
804 | break;\r | |
805 | case 'b': case 'B':\r | |
806 | keyType = !1;\r | |
807 | break;\r | |
808 | case '?':\r | |
809 | keyType = 2;\r | |
810 | break;\r | |
811 | default:\r | |
812 | PrintAndLog("Key type must be A , B or ?");\r | |
9ca155ba | 813 | return 1;\r |
aea4d766 | 814 | };\r |
9ca155ba | 815 | \r |
aea4d766 | 816 | ctmp = param_getchar(Cmd, 2);\r |
817 | if (ctmp == 't' || ctmp == 'T') transferToEml = 1;\r | |
818 | else if (ctmp == 'd' || ctmp == 'D') createDumpFile = 1;\r | |
819 | \r | |
820 | for (i = transferToEml || createDumpFile; param_getchar(Cmd, 2 + i); i++) {\r | |
821 | if (!param_gethex(Cmd, 2 + i, keyBlock + 6 * keycnt, 12)) {\r | |
822 | if ( stKeyBlock - keycnt < 2) {\r | |
823 | p = realloc(keyBlock, 6*(stKeyBlock+=10));\r | |
824 | if (!p) {\r | |
825 | PrintAndLog("Cannot allocate memory for Keys");\r | |
826 | free(keyBlock);\r | |
827 | return 2;\r | |
828 | }\r | |
829 | keyBlock = p;\r | |
830 | }\r | |
831 | PrintAndLog("chk key[%d] %02x%02x%02x%02x%02x%02x", keycnt,\r | |
832 | (keyBlock + 6*keycnt)[0],(keyBlock + 6*keycnt)[1], (keyBlock + 6*keycnt)[2],\r | |
833 | (keyBlock + 6*keycnt)[3], (keyBlock + 6*keycnt)[4], (keyBlock + 6*keycnt)[5], 6);\r | |
834 | keycnt++;\r | |
835 | } else {\r | |
836 | // May be a dic file\r | |
837 | if ( param_getstr(Cmd, 2 + i,filename) > 255 ) {\r | |
838 | PrintAndLog("File name too long");\r | |
839 | free(keyBlock);\r | |
840 | return 2;\r | |
841 | }\r | |
842 | \r | |
aea4d766 | 843 | if ( (f = fopen( filename , "r")) ) {\r |
0c12504a | 844 | while( fgets(buf, sizeof(buf), f) ){\r |
99a71a0d | 845 | if (strlen(buf) < 12 || buf[11] == '\n')\r |
846 | continue;\r | |
aea4d766 | 847 | \r |
99a71a0d | 848 | while (fgetc(f) != '\n' && !feof(f)) ; //goto next line\r |
849 | \r | |
9492e0b0 | 850 | if( buf[0]=='#' ) continue; //The line start with # is comment, skip\r |
9ca155ba | 851 | \r |
99a71a0d | 852 | if (!isxdigit(buf[0])){\r |
853 | PrintAndLog("File content error. '%s' must include 12 HEX symbols",buf);\r | |
aea4d766 | 854 | continue;\r |
855 | }\r | |
856 | \r | |
99a71a0d | 857 | buf[12] = 0;\r |
aea4d766 | 858 | \r |
859 | if ( stKeyBlock - keycnt < 2) {\r | |
860 | p = realloc(keyBlock, 6*(stKeyBlock+=10));\r | |
861 | if (!p) {\r | |
862 | PrintAndLog("Cannot allocate memory for defKeys");\r | |
863 | free(keyBlock);\r | |
864 | return 2;\r | |
865 | }\r | |
866 | keyBlock = p;\r | |
867 | }\r | |
868 | memset(keyBlock + 6 * keycnt, 0, 6);\r | |
99a71a0d | 869 | num_to_bytes(strtoll(buf, NULL, 16), 6, keyBlock + 6*keycnt);\r |
125a98a1 | 870 | PrintAndLog("chk custom key[%d] %012"llx, keycnt, bytes_to_num(keyBlock + 6*keycnt, 6));\r |
aea4d766 | 871 | keycnt++;\r |
0c12504a | 872 | memset(buf, 0, sizeof(buf));\r |
aea4d766 | 873 | }\r |
aea4d766 | 874 | } else {\r |
875 | PrintAndLog("File: %s: not found or locked.", filename);\r | |
876 | free(keyBlock);\r | |
877 | return 1;\r | |
878 | fclose(f);\r | |
879 | }\r | |
9ca155ba | 880 | }\r |
9ca155ba M |
881 | }\r |
882 | \r | |
883 | if (keycnt == 0) {\r | |
aea4d766 | 884 | PrintAndLog("No key specified,try default keys");\r |
0c12504a | 885 | for (;keycnt < defaultKeysSize; keycnt++)\r |
aea4d766 | 886 | PrintAndLog("chk default key[%d] %02x%02x%02x%02x%02x%02x", keycnt,\r |
887 | (keyBlock + 6*keycnt)[0],(keyBlock + 6*keycnt)[1], (keyBlock + 6*keycnt)[2],\r | |
888 | (keyBlock + 6*keycnt)[3], (keyBlock + 6*keycnt)[4], (keyBlock + 6*keycnt)[5], 6);\r | |
9ca155ba | 889 | }\r |
9ca155ba | 890 | \r |
aea4d766 | 891 | for ( int t = !keyType ; t < 2 ; keyType==2?(t++):(t=2) ) {\r |
892 | int b=blockNo;\r | |
893 | for (int i=0; i<SectorsCnt; ++i) {\r | |
894 | PrintAndLog("--SectorsCnt:%d block no:0x%02x key type:%C key count:%d ", i, b, t?'B':'A', keycnt);\r | |
9492e0b0 | 895 | uint32_t max_keys = keycnt>USB_CMD_DATA_SIZE/6?USB_CMD_DATA_SIZE/6:keycnt;\r |
896 | for (uint32_t c = 0; c < keycnt; c+=max_keys) {\r | |
897 | uint32_t size = keycnt-c>max_keys?max_keys:keycnt-c;\r | |
898 | res = mfCheckKeys(b, t, size, &keyBlock[6*c], &key64);\r | |
aea4d766 | 899 | if (res !=1) {\r |
900 | if (!res) {\r | |
125a98a1 | 901 | PrintAndLog("Found valid key:[%012"llx"]",key64);\r |
aea4d766 | 902 | if (transferToEml) {\r |
903 | uint8_t block[16];\r | |
904 | mfEmlGetMem(block, get_trailer_block(b), 1);\r | |
905 | num_to_bytes(key64, 6, block + t*10);\r | |
906 | mfEmlSetMem(block, get_trailer_block(b), 1);\r | |
907 | }\r | |
aea4d766 | 908 | }\r |
909 | } else {\r | |
910 | PrintAndLog("Command execute timeout");\r | |
911 | }\r | |
912 | }\r | |
913 | b<127?(b+=4):(b+=16); \r | |
914 | }\r | |
9ca155ba | 915 | }\r |
aea4d766 | 916 | \r |
917 | free(keyBlock);\r | |
9ca155ba | 918 | \r |
aea4d766 | 919 | /*\r |
920 | // Create dump file\r | |
921 | if (createDumpFile) {\r | |
922 | if ((fkeys = fopen("dumpkeys.bin","wb")) == NULL) { \r | |
923 | PrintAndLog("Could not create file dumpkeys.bin");\r | |
924 | free(e_sector);\r | |
925 | return 1;\r | |
926 | }\r | |
927 | PrintAndLog("Printing keys to bynary file dumpkeys.bin...");\r | |
928 | for(i=0; i<16; i++) {\r | |
929 | if (e_sector[i].foundKey[0]){\r | |
930 | num_to_bytes(e_sector[i].Key[0], 6, tempkey);\r | |
931 | fwrite ( tempkey, 1, 6, fkeys );\r | |
932 | }\r | |
933 | else{\r | |
934 | fwrite ( &standart, 1, 6, fkeys );\r | |
935 | }\r | |
936 | }\r | |
937 | for(i=0; i<16; i++) {\r | |
938 | if (e_sector[i].foundKey[1]){\r | |
939 | num_to_bytes(e_sector[i].Key[1], 6, tempkey);\r | |
940 | fwrite ( tempkey, 1, 6, fkeys );\r | |
941 | }\r | |
942 | else{\r | |
943 | fwrite ( &standart, 1, 6, fkeys );\r | |
944 | }\r | |
945 | }\r | |
946 | fclose(fkeys);\r | |
947 | }\r | |
948 | */\r | |
9ca155ba M |
949 | return 0;\r |
950 | }\r | |
951 | \r | |
952 | int CmdHF14AMf1kSim(const char *Cmd)\r | |
953 | {\r | |
7bc95e2e | 954 | uint8_t uid[7] = {0, 0, 0, 0, 0, 0, 0};\r |
d2f487af | 955 | uint8_t exitAfterNReads = 0;\r |
956 | uint8_t flags = 0;\r | |
957 | \r | |
9ca155ba | 958 | if (param_getchar(Cmd, 0) == 'h') {\r |
d2f487af | 959 | PrintAndLog("Usage: hf mf sim u <uid (8 hex symbols)> n <numreads> i x");\r |
960 | PrintAndLog(" u (Optional) UID. If not specified, the UID from emulator memory will be used");\r | |
961 | PrintAndLog(" n (Optional) Automatically exit simulation after <numreads> blocks have been read by reader. 0 = infinite");\r | |
962 | PrintAndLog(" i (Optional) Interactive, means that console will not be returned until simulation finishes or is aborted");\r | |
963 | PrintAndLog(" x (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)");\r | |
9ca155ba M |
964 | PrintAndLog(" sample: hf mf sim 0a0a0a0a ");\r |
965 | return 0;\r | |
9ca155ba | 966 | }\r |
d2f487af | 967 | uint8_t pnr = 0;\r |
968 | if (param_getchar(Cmd, pnr) == 'u') {\r | |
969 | if(param_gethex(Cmd, pnr+1, uid, 8) == 0)\r | |
970 | {\r | |
971 | flags |=FLAG_4B_UID_IN_DATA; // UID from packet\r | |
972 | }else if(param_gethex(Cmd,pnr+1,uid,14) == 0)\r | |
973 | {\r | |
974 | flags |= FLAG_7B_UID_IN_DATA;// UID from packet\r | |
975 | }else\r | |
976 | {\r | |
977 | PrintAndLog("UID, if specified, must include 8 or 14 HEX symbols");\r | |
978 | return 1;\r | |
979 | }\r | |
980 | pnr +=2;\r | |
981 | }\r | |
982 | if (param_getchar(Cmd, pnr) == 'n') {\r | |
983 | exitAfterNReads = param_get8(Cmd,pnr+1);\r | |
984 | pnr += 2;\r | |
985 | }\r | |
986 | if (param_getchar(Cmd, pnr) == 'i' ) {\r | |
987 | //Using a flag to signal interactiveness, least significant bit\r | |
988 | flags |= FLAG_INTERACTIVE;\r | |
989 | pnr++;\r | |
990 | }\r | |
991 | \r | |
992 | if (param_getchar(Cmd, pnr) == 'x' ) {\r | |
993 | //Using a flag to signal interactiveness, least significant bit\r | |
994 | flags |= FLAG_NR_AR_ATTACK;\r | |
995 | }\r | |
996 | PrintAndLog(" uid:%s, numreads:%d, flags:%d (0x%02x) ",\r | |
997 | flags & FLAG_4B_UID_IN_DATA ? sprint_hex(uid,4):\r | |
998 | flags & FLAG_7B_UID_IN_DATA ? sprint_hex(uid,7): "N/A"\r | |
999 | , exitAfterNReads, flags,flags);\r | |
1000 | \r | |
1001 | \r | |
1002 | UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {flags, exitAfterNReads,0}};\r | |
1003 | memcpy(c.d.asBytes, uid, sizeof(uid));\r | |
9ca155ba M |
1004 | SendCommand(&c);\r |
1005 | \r | |
7bc95e2e | 1006 | if(flags & FLAG_INTERACTIVE)\r |
d2f487af | 1007 | {\r |
1008 | UsbCommand resp;\r | |
1009 | PrintAndLog("Press pm3-button to abort simulation");\r | |
1010 | while(! WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r | |
1011 | //We're waiting only 1.5 s at a time, otherwise we get the\r | |
1012 | // annoying message about "Waiting for a response... "\r | |
1013 | }\r | |
1014 | }\r | |
1015 | \r | |
9ca155ba M |
1016 | return 0;\r |
1017 | }\r | |
1018 | \r | |
1019 | int CmdHF14AMfDbg(const char *Cmd)\r | |
1020 | {\r | |
8556b852 M |
1021 | int dbgMode = param_get32ex(Cmd, 0, 0, 10);\r |
1022 | if (dbgMode > 4) {\r | |
1023 | PrintAndLog("Max debud mode parameter is 4 \n");\r | |
1024 | }\r | |
1025 | \r | |
1026 | if (strlen(Cmd) < 1 || !param_getchar(Cmd, 0) || dbgMode > 4) {\r | |
9ca155ba M |
1027 | PrintAndLog("Usage: hf mf dbg <debug level>");\r |
1028 | PrintAndLog(" 0 - no debug messages");\r | |
1029 | PrintAndLog(" 1 - error messages");\r | |
1030 | PrintAndLog(" 2 - all messages");\r | |
1031 | PrintAndLog(" 4 - extended debug mode");\r | |
1032 | return 0;\r | |
1033 | } \r | |
1034 | \r | |
8556b852 M |
1035 | UsbCommand c = {CMD_MIFARE_SET_DBGMODE, {dbgMode, 0, 0}};\r |
1036 | SendCommand(&c);\r | |
1037 | \r | |
9ca155ba M |
1038 | return 0;\r |
1039 | }\r | |
1040 | \r | |
1041 | int CmdHF14AMfEGet(const char *Cmd)\r | |
1042 | {\r | |
8556b852 M |
1043 | uint8_t blockNo = 0;\r |
1044 | uint8_t data[3 * 16];\r | |
1045 | int i;\r | |
1046 | \r | |
1047 | if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r | |
1048 | PrintAndLog("Usage: hf mf eget <block number>");\r | |
1049 | PrintAndLog(" sample: hf mf eget 0 ");\r | |
1050 | return 0;\r | |
1051 | } \r | |
1052 | \r | |
1053 | blockNo = param_get8(Cmd, 0);\r | |
8556b852 M |
1054 | \r |
1055 | PrintAndLog(" ");\r | |
1056 | if (!mfEmlGetMem(data, blockNo, 3)) {\r | |
1057 | for (i = 0; i < 3; i++) {\r | |
1058 | PrintAndLog("data[%d]:%s", blockNo + i, sprint_hex(data + i * 16, 16));\r | |
1059 | }\r | |
1060 | } else {\r | |
1061 | PrintAndLog("Command execute timeout");\r | |
1062 | }\r | |
1063 | \r | |
1064 | return 0;\r | |
1065 | }\r | |
1066 | \r | |
1067 | int CmdHF14AMfEClear(const char *Cmd)\r | |
1068 | {\r | |
1069 | if (param_getchar(Cmd, 0) == 'h') {\r | |
1070 | PrintAndLog("Usage: hf mf eclr");\r | |
1071 | PrintAndLog("It set card emulator memory to empty data blocks and key A/B FFFFFFFFFFFF \n");\r | |
1072 | return 0;\r | |
1073 | } \r | |
1074 | \r | |
1075 | UsbCommand c = {CMD_MIFARE_EML_MEMCLR, {0, 0, 0}};\r | |
1076 | SendCommand(&c);\r | |
9ca155ba M |
1077 | return 0;\r |
1078 | }\r | |
1079 | \r | |
1080 | int CmdHF14AMfESet(const char *Cmd)\r | |
1081 | {\r | |
8556b852 M |
1082 | uint8_t memBlock[16];\r |
1083 | uint8_t blockNo = 0;\r | |
1084 | \r | |
1085 | memset(memBlock, 0x00, sizeof(memBlock));\r | |
1086 | \r | |
1087 | if (strlen(Cmd) < 3 || param_getchar(Cmd, 0) == 'h') {\r | |
1088 | PrintAndLog("Usage: hf mf eset <block number> <block data (32 hex symbols)>");\r | |
1089 | PrintAndLog(" sample: hf mf eset 1 000102030405060708090a0b0c0d0e0f ");\r | |
1090 | return 0;\r | |
1091 | } \r | |
1092 | \r | |
1093 | blockNo = param_get8(Cmd, 0);\r | |
8556b852 M |
1094 | \r |
1095 | if (param_gethex(Cmd, 1, memBlock, 32)) {\r | |
1096 | PrintAndLog("block data must include 32 HEX symbols");\r | |
1097 | return 1;\r | |
1098 | }\r | |
1099 | \r | |
1100 | // 1 - blocks count\r | |
1101 | UsbCommand c = {CMD_MIFARE_EML_MEMSET, {blockNo, 1, 0}};\r | |
1102 | memcpy(c.d.asBytes, memBlock, 16);\r | |
1103 | SendCommand(&c);\r | |
9ca155ba M |
1104 | return 0;\r |
1105 | }\r | |
1106 | \r | |
1107 | int CmdHF14AMfELoad(const char *Cmd)\r | |
1108 | {\r | |
ab8b654e | 1109 | FILE * f;\r |
8720c8f5 | 1110 | char filename[255];\r |
ab8b654e M |
1111 | char * fnameptr = filename;\r |
1112 | char buf[64];\r | |
1113 | uint8_t buf8[64];\r | |
1114 | int i, len, blockNum;\r | |
8720c8f5 | 1115 | bool 4kcard = 0;\r |
ab8b654e M |
1116 | \r |
1117 | memset(filename, 0, sizeof(filename));\r | |
1118 | memset(buf, 0, sizeof(buf));\r | |
1119 | \r | |
aea4d766 | 1120 | if (param_getchar(Cmd, 0) == 'h' || param_getchar(Cmd, 0)== 0x00) {\r |
ab8b654e | 1121 | PrintAndLog("It loads emul dump from the file `filename.eml`");\r |
8720c8f5 | 1122 | PrintAndLog("Usage: hf mf eload <file name w/o `.eml`> <4 - 4kcard>");\r |
1123 | PrintAndLog(" sample: hf mf eload filename [4]");\r | |
ab8b654e M |
1124 | return 0;\r |
1125 | } \r | |
1126 | \r | |
8720c8f5 | 1127 | size = param_getchar(Cmd, 1);\r |
1128 | if (size == '4') 4kcard = 1;\r | |
1129 | \r | |
ab8b654e | 1130 | len = strlen(Cmd);\r |
8720c8f5 | 1131 | if (len > 254) len = 254;\r |
ab8b654e M |
1132 | \r |
1133 | memcpy(filename, Cmd, len);\r | |
1134 | fnameptr += len;\r | |
1135 | \r | |
1136 | sprintf(fnameptr, ".eml"); \r | |
1137 | \r | |
1138 | // open file\r | |
1139 | f = fopen(filename, "r");\r | |
1140 | if (f == NULL) {\r | |
1141 | PrintAndLog("File not found or locked.");\r | |
1142 | return 1;\r | |
1143 | }\r | |
1144 | \r | |
1145 | blockNum = 0;\r | |
1146 | while(!feof(f)){\r | |
1147 | memset(buf, 0, sizeof(buf));\r | |
759c16b3 | 1148 | if (fgets(buf, sizeof(buf), f) == NULL) {\r |
d2f487af | 1149 | if(blockNum == 16 * 4)\r |
1150 | {\r | |
1151 | break;\r | |
1152 | }\r | |
1153 | PrintAndLog("File reading error.");\r | |
759c16b3 | 1154 | return 2;\r |
1155 | }\r | |
aea4d766 | 1156 | \r |
ab8b654e | 1157 | if (strlen(buf) < 32){\r |
aea4d766 | 1158 | if(strlen(buf) && feof(f))\r |
1159 | break;\r | |
ab8b654e M |
1160 | PrintAndLog("File content error. Block data must include 32 HEX symbols");\r |
1161 | return 2;\r | |
1162 | }\r | |
1163 | for (i = 0; i < 32; i += 2)\r | |
1164 | sscanf(&buf[i], "%02x", (unsigned int *)&buf8[i / 2]);\r | |
1165 | // PrintAndLog("data[%02d]:%s", blockNum, sprint_hex(buf8, 16));\r | |
1166 | \r | |
1167 | if (mfEmlSetMem(buf8, blockNum, 1)) {\r | |
1168 | PrintAndLog("Cant set emul block: %d", blockNum);\r | |
1169 | return 3;\r | |
1170 | }\r | |
1171 | blockNum++;\r | |
1172 | \r | |
aea4d766 | 1173 | if (blockNum >= 32 * 4 + 8 * 16) break;\r |
ab8b654e M |
1174 | }\r |
1175 | fclose(f);\r | |
1176 | \r | |
8720c8f5 | 1177 | if(4kcard){\r |
1178 | if (blockNum != 32 * 4 + 8 * 16){\r | |
1179 | PrintAndLog("File content error. There must be 64 blocks");\r | |
1180 | return 4;\r | |
1181 | }\r | |
1182 | }else{\r | |
1183 | if (blockNum != 16 * 4 && blockNum != 32 * 4 + 8 * 16){\r | |
1184 | PrintAndLog("File content error. There must be 64 blocks");\r | |
1185 | return 4;\r | |
1186 | }\r | |
ab8b654e | 1187 | }\r |
d2f487af | 1188 | PrintAndLog("Loaded %d blocks from file: %s", blockNum, filename);\r |
9ca155ba M |
1189 | return 0;\r |
1190 | }\r | |
1191 | \r | |
1192 | int CmdHF14AMfESave(const char *Cmd)\r | |
1193 | {\r | |
ab8b654e | 1194 | FILE * f;\r |
8720c8f5 | 1195 | char filename[255];\r |
ab8b654e M |
1196 | char * fnameptr = filename;\r |
1197 | uint8_t buf[64];\r | |
1198 | int i, j, len;\r | |
1199 | \r | |
1200 | memset(filename, 0, sizeof(filename));\r | |
1201 | memset(buf, 0, sizeof(buf));\r | |
1202 | \r | |
1203 | if (param_getchar(Cmd, 0) == 'h') {\r | |
1204 | PrintAndLog("It saves emul dump into the file `filename.eml` or `cardID.eml`");\r | |
1205 | PrintAndLog("Usage: hf mf esave [file name w/o `.eml`]");\r | |
1206 | PrintAndLog(" sample: hf mf esave ");\r | |
1207 | PrintAndLog(" hf mf esave filename");\r | |
1208 | return 0;\r | |
1209 | } \r | |
1210 | \r | |
1211 | len = strlen(Cmd);\r | |
8720c8f5 | 1212 | if (len > 254) len = 254;\r |
ab8b654e M |
1213 | \r |
1214 | if (len < 1) {\r | |
1215 | // get filename\r | |
1216 | if (mfEmlGetMem(buf, 0, 1)) {\r | |
1217 | PrintAndLog("Cant get block: %d", 0);\r | |
1218 | return 1;\r | |
1219 | }\r | |
1220 | for (j = 0; j < 7; j++, fnameptr += 2)\r | |
1221 | sprintf(fnameptr, "%02x", buf[j]); \r | |
1222 | } else {\r | |
1223 | memcpy(filename, Cmd, len);\r | |
1224 | fnameptr += len;\r | |
1225 | }\r | |
1226 | \r | |
1227 | sprintf(fnameptr, ".eml"); \r | |
1228 | \r | |
1229 | // open file\r | |
1230 | f = fopen(filename, "w+");\r | |
1231 | \r | |
1232 | // put hex\r | |
aea4d766 | 1233 | for (i = 0; i < 32 * 4 + 8 * 16; i++) {\r |
ab8b654e M |
1234 | if (mfEmlGetMem(buf, i, 1)) {\r |
1235 | PrintAndLog("Cant get block: %d", i);\r | |
1236 | break;\r | |
1237 | }\r | |
1238 | for (j = 0; j < 16; j++)\r | |
1239 | fprintf(f, "%02x", buf[j]); \r | |
1240 | fprintf(f,"\n");\r | |
1241 | }\r | |
1242 | fclose(f);\r | |
1243 | \r | |
1244 | PrintAndLog("Saved to file: %s", filename);\r | |
1245 | \r | |
9ca155ba M |
1246 | return 0;\r |
1247 | }\r | |
1248 | \r | |
26fdb4ab | 1249 | int CmdHF14AMfECFill(const char *Cmd)\r |
1250 | {\r | |
8556b852 M |
1251 | uint8_t keyType = 0;\r |
1252 | \r | |
1253 | if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r | |
1254 | PrintAndLog("Usage: hf mf efill <key A/B>");\r | |
1255 | PrintAndLog("sample: hf mf efill A");\r | |
1256 | PrintAndLog("Card data blocks transfers to card emulator memory.");\r | |
1257 | PrintAndLog("Keys must be laid in the simulator memory. \n");\r | |
1258 | return 0;\r | |
1259 | } \r | |
1260 | \r | |
1261 | char ctmp = param_getchar(Cmd, 0);\r | |
1262 | if (ctmp == 0x00) {\r | |
1263 | PrintAndLog("Key type must be A or B");\r | |
1264 | return 1;\r | |
1265 | }\r | |
1266 | if (ctmp != 'A' && ctmp != 'a') keyType = 1;\r | |
1267 | \r | |
1268 | UsbCommand c = {CMD_MIFARE_EML_CARDLOAD, {0, keyType, 0}};\r | |
1269 | SendCommand(&c);\r | |
1270 | return 0;\r | |
1271 | }\r | |
1272 | \r | |
26fdb4ab | 1273 | int CmdHF14AMfEKeyPrn(const char *Cmd)\r |
1274 | {\r | |
aea4d766 | 1275 | int i,b=-1;\r |
8556b852 M |
1276 | uint8_t data[16];\r |
1277 | uint64_t keyA, keyB;\r | |
1278 | \r | |
1279 | PrintAndLog("|---|----------------|----------------|");\r | |
1280 | PrintAndLog("|sec|key A |key B |");\r | |
1281 | PrintAndLog("|---|----------------|----------------|");\r | |
aea4d766 | 1282 | for (i = 0; i < 40; i++) {\r |
1283 | b<127?(b+=4):(b+=16);\r | |
1284 | if (mfEmlGetMem(data, b, 1)) {\r | |
1285 | PrintAndLog("error get block %d", b);\r | |
8556b852 M |
1286 | break;\r |
1287 | }\r | |
1288 | keyA = bytes_to_num(data, 6);\r | |
1289 | keyB = bytes_to_num(data + 10, 6);\r | |
125a98a1 | 1290 | PrintAndLog("|%03d| %012"llx" | %012"llx" |", i, keyA, keyB);\r |
8556b852 M |
1291 | }\r |
1292 | PrintAndLog("|---|----------------|----------------|");\r | |
1293 | \r | |
1294 | return 0;\r | |
1295 | }\r | |
1296 | \r | |
0675f200 M |
1297 | int CmdHF14AMfCSetUID(const char *Cmd)\r |
1298 | {\r | |
1299 | uint8_t wipeCard = 0;\r | |
1300 | uint8_t uid[8];\r | |
1301 | uint8_t oldUid[8];\r | |
1302 | int res;\r | |
1303 | \r | |
1304 | if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r | |
1305 | PrintAndLog("Usage: hf mf csetuid <UID 8 hex symbols> <w>");\r | |
1306 | PrintAndLog("sample: hf mf csetuid 01020304 w");\r | |
1307 | PrintAndLog("Set UID for magic Chinese card (only works with!!!)");\r | |
1308 | PrintAndLog("If you want wipe card then add 'w' into command line. \n");\r | |
1309 | return 0;\r | |
1310 | } \r | |
1311 | \r | |
1312 | if (param_getchar(Cmd, 0) && param_gethex(Cmd, 0, uid, 8)) {\r | |
1313 | PrintAndLog("UID must include 8 HEX symbols");\r | |
1314 | return 1;\r | |
1315 | }\r | |
1316 | \r | |
1317 | char ctmp = param_getchar(Cmd, 1);\r | |
1318 | if (ctmp == 'w' || ctmp == 'W') wipeCard = 1;\r | |
1319 | \r | |
1320 | PrintAndLog("--wipe card:%02x uid:%s", wipeCard, sprint_hex(uid, 4));\r | |
1321 | \r | |
1322 | res = mfCSetUID(uid, oldUid, wipeCard);\r | |
1323 | if (res) {\r | |
1324 | PrintAndLog("Can't set UID. error=%d", res);\r | |
1325 | return 1;\r | |
1326 | }\r | |
1327 | \r | |
1328 | PrintAndLog("old UID:%s", sprint_hex(oldUid, 4));\r | |
1329 | return 0;\r | |
1330 | }\r | |
1331 | \r | |
1332 | int CmdHF14AMfCSetBlk(const char *Cmd)\r | |
1333 | {\r | |
f774db95 M |
1334 | uint8_t uid[8];\r |
1335 | uint8_t memBlock[16];\r | |
1336 | uint8_t blockNo = 0;\r | |
1337 | int res;\r | |
1338 | memset(memBlock, 0x00, sizeof(memBlock));\r | |
1339 | \r | |
1340 | if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r | |
1341 | PrintAndLog("Usage: hf mf csetblk <block number> <block data (32 hex symbols)>");\r | |
1342 | PrintAndLog("sample: hf mf csetblk 1 01020304050607080910111213141516");\r | |
1343 | PrintAndLog("Set block data for magic Chinese card (only works with!!!)");\r | |
1344 | PrintAndLog("If you want wipe card then add 'w' into command line. \n");\r | |
1345 | return 0;\r | |
1346 | } \r | |
1347 | \r | |
1348 | blockNo = param_get8(Cmd, 0);\r | |
f774db95 M |
1349 | \r |
1350 | if (param_gethex(Cmd, 1, memBlock, 32)) {\r | |
1351 | PrintAndLog("block data must include 32 HEX symbols");\r | |
1352 | return 1;\r | |
1353 | }\r | |
1354 | \r | |
1355 | PrintAndLog("--block number:%02x data:%s", blockNo, sprint_hex(memBlock, 16));\r | |
1356 | \r | |
208a0166 | 1357 | res = mfCSetBlock(blockNo, memBlock, uid, 0, CSETBLOCK_SINGLE_OPER);\r |
f774db95 M |
1358 | if (res) {\r |
1359 | PrintAndLog("Can't write block. error=%d", res);\r | |
1360 | return 1;\r | |
1361 | }\r | |
1362 | \r | |
1363 | PrintAndLog("UID:%s", sprint_hex(uid, 4));\r | |
0675f200 M |
1364 | return 0;\r |
1365 | }\r | |
1366 | \r | |
1367 | int CmdHF14AMfCLoad(const char *Cmd)\r | |
1368 | {\r | |
208a0166 M |
1369 | FILE * f;\r |
1370 | char filename[20];\r | |
1371 | char * fnameptr = filename;\r | |
1372 | char buf[64];\r | |
1373 | uint8_t buf8[64];\r | |
1374 | uint8_t fillFromEmulator = 0;\r | |
1375 | int i, len, blockNum, flags;\r | |
1376 | \r | |
1377 | memset(filename, 0, sizeof(filename));\r | |
1378 | memset(buf, 0, sizeof(buf));\r | |
1379 | \r | |
1380 | if (param_getchar(Cmd, 0) == 'h' || param_getchar(Cmd, 0)== 0x00) {\r | |
1381 | PrintAndLog("It loads magic Chinese card (only works with!!!) from the file `filename.eml`");\r | |
1382 | PrintAndLog("or from emulator memory (option `e`)");\r | |
1383 | PrintAndLog("Usage: hf mf cload <file name w/o `.eml`>");\r | |
1384 | PrintAndLog(" or: hf mf cload e ");\r | |
1385 | PrintAndLog(" sample: hf mf cload filename");\r | |
1386 | return 0;\r | |
1387 | } \r | |
1388 | \r | |
1389 | char ctmp = param_getchar(Cmd, 0);\r | |
1390 | if (ctmp == 'e' || ctmp == 'E') fillFromEmulator = 1;\r | |
1391 | \r | |
1392 | if (fillFromEmulator) {\r | |
1393 | flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;\r | |
1394 | for (blockNum = 0; blockNum < 16 * 4; blockNum += 1) {\r | |
1395 | if (mfEmlGetMem(buf8, blockNum, 1)) {\r | |
1396 | PrintAndLog("Cant get block: %d", blockNum);\r | |
1397 | return 2;\r | |
1398 | }\r | |
1399 | \r | |
1400 | if (blockNum == 2) flags = 0;\r | |
1401 | if (blockNum == 16 * 4 - 1) flags = CSETBLOCK_HALT + CSETBLOCK_RESET_FIELD;\r | |
1402 | \r | |
1403 | if (mfCSetBlock(blockNum, buf8, NULL, 0, flags)) {\r | |
1404 | PrintAndLog("Cant set magic card block: %d", blockNum);\r | |
1405 | return 3;\r | |
1406 | }\r | |
1407 | }\r | |
1408 | return 0;\r | |
1409 | } else {\r | |
1410 | len = strlen(Cmd);\r | |
1411 | if (len > 14) len = 14;\r | |
1412 | \r | |
1413 | memcpy(filename, Cmd, len);\r | |
1414 | fnameptr += len;\r | |
1415 | \r | |
1416 | sprintf(fnameptr, ".eml"); \r | |
1417 | \r | |
1418 | // open file\r | |
1419 | f = fopen(filename, "r");\r | |
1420 | if (f == NULL) {\r | |
1421 | PrintAndLog("File not found or locked.");\r | |
1422 | return 1;\r | |
1423 | }\r | |
1424 | \r | |
1425 | blockNum = 0;\r | |
1426 | flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;\r | |
1427 | while(!feof(f)){\r | |
1428 | memset(buf, 0, sizeof(buf));\r | |
759c16b3 | 1429 | if (fgets(buf, sizeof(buf), f) == NULL) {\r |
1430 | PrintAndLog("File reading error.");\r | |
1431 | return 2;\r | |
1432 | }\r | |
208a0166 M |
1433 | \r |
1434 | if (strlen(buf) < 32){\r | |
1435 | if(strlen(buf) && feof(f))\r | |
1436 | break;\r | |
1437 | PrintAndLog("File content error. Block data must include 32 HEX symbols");\r | |
1438 | return 2;\r | |
1439 | }\r | |
1440 | for (i = 0; i < 32; i += 2)\r | |
1441 | sscanf(&buf[i], "%02x", (unsigned int *)&buf8[i / 2]);\r | |
1442 | \r | |
1443 | if (blockNum == 2) flags = 0;\r | |
1444 | if (blockNum == 16 * 4 - 1) flags = CSETBLOCK_HALT + CSETBLOCK_RESET_FIELD;\r | |
1445 | \r | |
1446 | if (mfCSetBlock(blockNum, buf8, NULL, 0, flags)) {\r | |
1447 | PrintAndLog("Cant set magic card block: %d", blockNum);\r | |
1448 | return 3;\r | |
1449 | }\r | |
1450 | blockNum++;\r | |
1451 | \r | |
1452 | if (blockNum >= 16 * 4) break; // magic card type - mifare 1K\r | |
1453 | }\r | |
1454 | fclose(f);\r | |
1455 | \r | |
1456 | if (blockNum != 16 * 4 && blockNum != 32 * 4 + 8 * 16){\r | |
1457 | PrintAndLog("File content error. There must be 64 blocks");\r | |
1458 | return 4;\r | |
1459 | }\r | |
1460 | PrintAndLog("Loaded from file: %s", filename);\r | |
1461 | return 0;\r | |
1462 | }\r | |
0675f200 M |
1463 | }\r |
1464 | \r | |
545a1f38 M |
1465 | int CmdHF14AMfCGetBlk(const char *Cmd) {\r |
1466 | uint8_t memBlock[16];\r | |
1467 | uint8_t blockNo = 0;\r | |
1468 | int res;\r | |
1469 | memset(memBlock, 0x00, sizeof(memBlock));\r | |
1470 | \r | |
1471 | if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r | |
1472 | PrintAndLog("Usage: hf mf cgetblk <block number>");\r | |
1473 | PrintAndLog("sample: hf mf cgetblk 1");\r | |
1474 | PrintAndLog("Get block data from magic Chinese card (only works with!!!)\n");\r | |
1475 | return 0;\r | |
1476 | } \r | |
1477 | \r | |
1478 | blockNo = param_get8(Cmd, 0);\r | |
545a1f38 M |
1479 | \r |
1480 | PrintAndLog("--block number:%02x ", blockNo);\r | |
1481 | \r | |
1482 | res = mfCGetBlock(blockNo, memBlock, CSETBLOCK_SINGLE_OPER);\r | |
1483 | if (res) {\r | |
1484 | PrintAndLog("Can't read block. error=%d", res);\r | |
1485 | return 1;\r | |
1486 | }\r | |
1487 | \r | |
1488 | PrintAndLog("block data:%s", sprint_hex(memBlock, 16));\r | |
1489 | return 0;\r | |
1490 | }\r | |
1491 | \r | |
1492 | int CmdHF14AMfCGetSc(const char *Cmd) {\r | |
1493 | uint8_t memBlock[16];\r | |
1494 | uint8_t sectorNo = 0;\r | |
1495 | int i, res, flags;\r | |
1496 | memset(memBlock, 0x00, sizeof(memBlock));\r | |
1497 | \r | |
1498 | if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r | |
1499 | PrintAndLog("Usage: hf mf cgetsc <sector number>");\r | |
1500 | PrintAndLog("sample: hf mf cgetsc 0");\r | |
1501 | PrintAndLog("Get sector data from magic Chinese card (only works with!!!)\n");\r | |
1502 | return 0;\r | |
1503 | } \r | |
1504 | \r | |
1505 | sectorNo = param_get8(Cmd, 0);\r | |
1506 | if (sectorNo > 15) {\r | |
1507 | PrintAndLog("Sector number must be in [0..15] as in MIFARE classic.");\r | |
1508 | return 1;\r | |
1509 | }\r | |
1510 | \r | |
1511 | PrintAndLog("--sector number:%02x ", sectorNo);\r | |
1512 | \r | |
1513 | flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;\r | |
1514 | for (i = 0; i < 4; i++) {\r | |
1515 | if (i == 1) flags = 0;\r | |
1516 | if (i == 3) flags = CSETBLOCK_HALT + CSETBLOCK_RESET_FIELD;\r | |
1517 | \r | |
1518 | res = mfCGetBlock(sectorNo * 4 + i, memBlock, flags);\r | |
1519 | if (res) {\r | |
1520 | PrintAndLog("Can't read block. %02x error=%d", sectorNo * 4 + i, res);\r | |
1521 | return 1;\r | |
1522 | }\r | |
1523 | \r | |
1524 | PrintAndLog("block %02x data:%s", sectorNo * 4 + i, sprint_hex(memBlock, 16));\r | |
1525 | }\r | |
1526 | return 0;\r | |
1527 | }\r | |
1528 | \r | |
1529 | int CmdHF14AMfCSave(const char *Cmd) {\r | |
1530 | \r | |
1531 | FILE * f;\r | |
1532 | char filename[20];\r | |
1533 | char * fnameptr = filename;\r | |
1534 | uint8_t fillFromEmulator = 0;\r | |
1535 | uint8_t buf[64];\r | |
1536 | int i, j, len, flags;\r | |
1537 | \r | |
1538 | memset(filename, 0, sizeof(filename));\r | |
1539 | memset(buf, 0, sizeof(buf));\r | |
1540 | \r | |
1541 | if (param_getchar(Cmd, 0) == 'h') {\r | |
1542 | PrintAndLog("It saves `magic Chinese` card dump into the file `filename.eml` or `cardID.eml`");\r | |
1543 | PrintAndLog("or into emulator memory (option `e`)");\r | |
1544 | PrintAndLog("Usage: hf mf esave [file name w/o `.eml`][e]");\r | |
1545 | PrintAndLog(" sample: hf mf esave ");\r | |
1546 | PrintAndLog(" hf mf esave filename");\r | |
1547 | PrintAndLog(" hf mf esave e \n");\r | |
1548 | return 0;\r | |
1549 | } \r | |
1550 | \r | |
1551 | char ctmp = param_getchar(Cmd, 0);\r | |
1552 | if (ctmp == 'e' || ctmp == 'E') fillFromEmulator = 1;\r | |
1553 | \r | |
1554 | if (fillFromEmulator) {\r | |
1555 | // put into emulator\r | |
1556 | flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;\r | |
1557 | for (i = 0; i < 16 * 4; i++) {\r | |
1558 | if (i == 1) flags = 0;\r | |
1559 | if (i == 16 * 4 - 1) flags = CSETBLOCK_HALT + CSETBLOCK_RESET_FIELD;\r | |
1560 | \r | |
1561 | if (mfCGetBlock(i, buf, flags)) {\r | |
1562 | PrintAndLog("Cant get block: %d", i);\r | |
1563 | break;\r | |
1564 | }\r | |
1565 | \r | |
1566 | if (mfEmlSetMem(buf, i, 1)) {\r | |
1567 | PrintAndLog("Cant set emul block: %d", i);\r | |
1568 | return 3;\r | |
1569 | }\r | |
1570 | }\r | |
1571 | return 0;\r | |
1572 | } else {\r | |
1573 | len = strlen(Cmd);\r | |
1574 | if (len > 14) len = 14;\r | |
1575 | \r | |
1576 | if (len < 1) {\r | |
1577 | // get filename\r | |
1578 | if (mfCGetBlock(0, buf, CSETBLOCK_SINGLE_OPER)) {\r | |
1579 | PrintAndLog("Cant get block: %d", 0);\r | |
1580 | return 1;\r | |
1581 | }\r | |
1582 | for (j = 0; j < 7; j++, fnameptr += 2)\r | |
1583 | sprintf(fnameptr, "%02x", buf[j]); \r | |
1584 | } else {\r | |
1585 | memcpy(filename, Cmd, len);\r | |
1586 | fnameptr += len;\r | |
1587 | }\r | |
1588 | \r | |
1589 | sprintf(fnameptr, ".eml"); \r | |
1590 | \r | |
1591 | // open file\r | |
1592 | f = fopen(filename, "w+");\r | |
1593 | \r | |
1594 | // put hex\r | |
1595 | flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;\r | |
1596 | for (i = 0; i < 16 * 4; i++) {\r | |
1597 | if (i == 1) flags = 0;\r | |
1598 | if (i == 16 * 4 - 1) flags = CSETBLOCK_HALT + CSETBLOCK_RESET_FIELD;\r | |
1599 | \r | |
1600 | if (mfCGetBlock(i, buf, flags)) {\r | |
1601 | PrintAndLog("Cant get block: %d", i);\r | |
1602 | break;\r | |
1603 | }\r | |
1604 | for (j = 0; j < 16; j++)\r | |
1605 | fprintf(f, "%02x", buf[j]); \r | |
1606 | fprintf(f,"\n");\r | |
1607 | }\r | |
1608 | fclose(f);\r | |
1609 | \r | |
1610 | PrintAndLog("Saved to file: %s", filename);\r | |
1611 | \r | |
1612 | return 0;\r | |
1613 | }\r | |
1614 | }\r | |
1615 | \r | |
b62a5a84 | 1616 | int CmdHF14AMfSniff(const char *Cmd){\r |
55acbb2a | 1617 | // params\r |
c948cbde M |
1618 | bool wantLogToFile = 0;\r |
1619 | bool wantDecrypt = 0;\r | |
eede7162 | 1620 | //bool wantSaveToEml = 0; TODO\r |
55acbb2a M |
1621 | bool wantSaveToEmlFile = 0;\r |
1622 | \r | |
1623 | //var \r | |
39864b0b M |
1624 | int res = 0;\r |
1625 | int len = 0;\r | |
1626 | int blockLen = 0;\r | |
1627 | int num = 0;\r | |
1628 | int pckNum = 0;\r | |
1629 | uint8_t uid[8];\r | |
1630 | uint8_t atqa[2];\r | |
1631 | uint8_t sak;\r | |
1632 | bool isTag;\r | |
71d90e54 | 1633 | uint32_t parity;\r |
39864b0b M |
1634 | uint8_t buf[3000];\r |
1635 | uint8_t * bufPtr = buf;\r | |
1636 | memset(buf, 0x00, 3000);\r | |
b62a5a84 M |
1637 | \r |
1638 | if (param_getchar(Cmd, 0) == 'h') {\r | |
55acbb2a M |
1639 | PrintAndLog("It continuously get data from the field and saves it to: log, emulator, emulator file.");\r |
1640 | PrintAndLog("You can specify:");\r | |
1641 | PrintAndLog(" l - save encrypted sequence to logfile `uid.log`");\r | |
1642 | PrintAndLog(" d - decrypt sequence and put it to log file `uid.log`");\r | |
1643 | PrintAndLog(" n/a e - decrypt sequence, collect read and write commands and save the result of the sequence to emulator memory");\r | |
e0c635d1 | 1644 | PrintAndLog(" r - decrypt sequence, collect read and write commands and save the result of the sequence to emulator dump file `uid.eml`");\r |
55acbb2a M |
1645 | PrintAndLog("Usage: hf mf sniff [l][d][e][r]");\r |
1646 | PrintAndLog(" sample: hf mf sniff l d e");\r | |
b62a5a84 M |
1647 | return 0;\r |
1648 | } \r | |
1649 | \r | |
55acbb2a M |
1650 | for (int i = 0; i < 4; i++) {\r |
1651 | char ctmp = param_getchar(Cmd, i);\r | |
1652 | if (ctmp == 'l' || ctmp == 'L') wantLogToFile = true;\r | |
1653 | if (ctmp == 'd' || ctmp == 'D') wantDecrypt = true;\r | |
eede7162 | 1654 | //if (ctmp == 'e' || ctmp == 'E') wantSaveToEml = true; TODO\r |
55acbb2a M |
1655 | if (ctmp == 'f' || ctmp == 'F') wantSaveToEmlFile = true;\r |
1656 | }\r | |
1657 | \r | |
39864b0b M |
1658 | printf("-------------------------------------------------------------------------\n");\r |
1659 | printf("Executing command. \n");\r | |
1660 | printf("Press the key on the proxmark3 device to abort both proxmark3 and client.\n");\r | |
1661 | printf("Press the key on pc keyboard to abort the client.\n");\r | |
1662 | printf("-------------------------------------------------------------------------\n");\r | |
1663 | \r | |
c936a22f | 1664 | UsbCommand c = {CMD_MIFARE_SNIFFER, {0, 0, 0}};\r |
1665 | SendCommand(&c);\r | |
b62a5a84 | 1666 | \r |
39864b0b M |
1667 | // wait cycle\r |
1668 | while (true) {\r | |
1669 | printf(".");\r | |
1670 | fflush(stdout);\r | |
1671 | if (ukbhit()) {\r | |
1672 | getchar();\r | |
1673 | printf("\naborted via keyboard!\n");\r | |
1674 | break;\r | |
1675 | }\r | |
1676 | \r | |
902cb3c0 | 1677 | UsbCommand resp;\r |
1678 | if (WaitForResponseTimeout(CMD_ACK,&resp,2000)) {\r | |
1679 | res = resp.arg[0] & 0xff;\r | |
1680 | len = resp.arg[1];\r | |
1681 | num = resp.arg[2];\r | |
39864b0b M |
1682 | \r |
1683 | if (res == 0) return 0;\r | |
1684 | if (res == 1) {\r | |
1685 | if (num ==0) {\r | |
1686 | bufPtr = buf;\r | |
1687 | memset(buf, 0x00, 3000);\r | |
1688 | }\r | |
902cb3c0 | 1689 | memcpy(bufPtr, resp.d.asBytes, len);\r |
39864b0b M |
1690 | bufPtr += len;\r |
1691 | pckNum++;\r | |
1692 | }\r | |
1693 | if (res == 2) {\r | |
1694 | blockLen = bufPtr - buf;\r | |
1695 | bufPtr = buf;\r | |
1696 | printf(">\n");\r | |
1697 | PrintAndLog("received trace len: %d packages: %d", blockLen, pckNum);\r | |
1698 | num = 0;\r | |
1699 | while (bufPtr - buf + 9 < blockLen) {\r | |
7bc95e2e | 1700 | isTag = bufPtr[3] & 0x80 ? true:false;\r |
71d90e54 M |
1701 | bufPtr += 4;\r |
1702 | parity = *((uint32_t *)(bufPtr));\r | |
1703 | bufPtr += 4;\r | |
39864b0b M |
1704 | len = bufPtr[0];\r |
1705 | bufPtr++;\r | |
1706 | if ((len == 14) && (bufPtr[0] = 0xff) && (bufPtr[1] = 0xff)) {\r | |
1707 | memcpy(uid, bufPtr + 2, 7);\r | |
1708 | memcpy(atqa, bufPtr + 2 + 7, 2);\r | |
1709 | sak = bufPtr[11];\r | |
55acbb2a | 1710 | \r |
39864b0b | 1711 | PrintAndLog("tag select uid:%s atqa:%02x %02x sak:0x%02x", sprint_hex(uid, 7), atqa[0], atqa[1], sak);\r |
c936a22f | 1712 | if (wantLogToFile) {\r |
e0c635d1 | 1713 | FillFileNameByUID(logHexFileName, uid, ".log", 7);\r |
55acbb2a M |
1714 | AddLogCurrentDT(logHexFileName);\r |
1715 | } \r | |
e0c635d1 | 1716 | if (wantDecrypt) mfTraceInit(uid, atqa, sak, wantSaveToEmlFile);\r |
39864b0b M |
1717 | } else {\r |
1718 | PrintAndLog("%s(%d):%s", isTag ? "TAG":"RDR", num, sprint_hex(bufPtr, len));\r | |
55acbb2a | 1719 | if (wantLogToFile) AddLogHex(logHexFileName, isTag ? "TAG: ":"RDR: ", bufPtr, len);\r |
71d90e54 | 1720 | if (wantDecrypt) mfTraceDecode(bufPtr, len, parity, wantSaveToEmlFile);\r |
39864b0b M |
1721 | }\r |
1722 | bufPtr += len;\r | |
1723 | num++;\r | |
1724 | }\r | |
1725 | }\r | |
1726 | } // resp not NILL\r | |
1727 | } // while (true)\r | |
c936a22f | 1728 | return 0;\r |
b62a5a84 M |
1729 | }\r |
1730 | \r | |
26fdb4ab | 1731 | static command_t CommandTable[] =\r |
9ca155ba | 1732 | {\r |
d2f487af | 1733 | {"help", CmdHelp, 1, "This help"},\r |
8720c8f5 | 1734 | {"dbg", CmdHF14AMfDbg, 0, "Set default debug mode"},\r |
d2f487af | 1735 | {"rdbl", CmdHF14AMfRdBl, 0, "Read MIFARE classic block"},\r |
d2f487af | 1736 | {"rdsc", CmdHF14AMfRdSc, 0, "Read MIFARE classic sector"},\r |
1737 | {"dump", CmdHF14AMfDump, 0, "Dump MIFARE classic tag to binary file"},\r | |
8720c8f5 | 1738 | {"restore", CmdHF14AMfRestore, 0, "Restore MIFARE classic binary file to BLANK tag"},\r |
9ca155ba | 1739 | {"wrbl", CmdHF14AMfWrBl, 0, "Write MIFARE classic block"},\r |
8720c8f5 | 1740 | {"chk", CmdHF14AMfChk, 0, "Test block keys"},\r |
1741 | {"mifare", CmdHF14AMifare, 0, "Read parity error messages."},\r | |
1742 | {"nested", CmdHF14AMfNested, 0, "Test nested authentication"},\r | |
b62a5a84 | 1743 | {"sniff", CmdHF14AMfSniff, 0, "Sniff card-reader communication"},\r |
8720c8f5 | 1744 | {"sim", CmdHF14AMf1kSim, 0, "Simulate MIFARE card"},\r |
545a1f38 | 1745 | {"eclr", CmdHF14AMfEClear, 0, "Clear simulator memory block"},\r |
51969283 M |
1746 | {"eget", CmdHF14AMfEGet, 0, "Get simulator memory block"},\r |
1747 | {"eset", CmdHF14AMfESet, 0, "Set simulator memory block"},\r | |
9ca155ba M |
1748 | {"eload", CmdHF14AMfELoad, 0, "Load from file emul dump"},\r |
1749 | {"esave", CmdHF14AMfESave, 0, "Save to file emul dump"},\r | |
8720c8f5 | 1750 | {"ecfill", CmdHF14AMfECFill, 0, "Fill simulator memory with help of keys from simulator"},\r |
1751 | {"ekeyprn", CmdHF14AMfEKeyPrn, 0, "Print keys from simulator memory"},\r | |
1752 | {"csetuid", CmdHF14AMfCSetUID, 0, "Set UID for magic Chinese card"},\r | |
1753 | {"csetblk", CmdHF14AMfCSetBlk, 0, "Write block into magic Chinese card"},\r | |
1754 | {"cgetblk", CmdHF14AMfCGetBlk, 0, "Read block from magic Chinese card"},\r | |
1755 | {"cgetsc", CmdHF14AMfCGetSc, 0, "Read sector from magic Chinese card"},\r | |
208a0166 | 1756 | {"cload", CmdHF14AMfCLoad, 0, "Load dump into magic Chinese card"},\r |
545a1f38 | 1757 | {"csave", CmdHF14AMfCSave, 0, "Save dump from magic Chinese card into file or emulator"},\r |
9ca155ba M |
1758 | {NULL, NULL, 0, NULL}\r |
1759 | };\r | |
1760 | \r | |
1761 | int CmdHFMF(const char *Cmd)\r | |
1762 | {\r | |
1763 | // flush\r | |
7dd1908b | 1764 | WaitForResponseTimeout(CMD_ACK,NULL,100);\r |
9ca155ba M |
1765 | \r |
1766 | CmdsParse(CommandTable, Cmd);\r | |
1767 | return 0;\r | |
1768 | }\r | |
1769 | \r | |
1770 | int CmdHelp(const char *Cmd)\r | |
1771 | {\r | |
1772 | CmdsHelp(CommandTable);\r | |
1773 | return 0;\r | |
1774 | }\r |