]>
Commit | Line | Data |
---|---|---|
9ca155ba M |
1 | //-----------------------------------------------------------------------------\r |
2 | // Copyright (C) 2011 Merlok\r | |
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 | |
15 | \r | |
16 | int CmdHF14AMifare(const char *Cmd)\r | |
17 | {\r | |
18 | uint32_t uid = 0;\r | |
19 | uint32_t nt = 0;\r | |
20 | uint64_t par_list = 0, ks_list = 0, r_key = 0;\r | |
21 | uint8_t isOK = 0;\r | |
22 | uint8_t keyBlock[6] = {0,0,0,0,0,0};\r | |
23 | \r | |
24 | if (param_getchar(Cmd, 0) && param_gethex(Cmd, 0, keyBlock, 8)) {\r | |
25 | PrintAndLog("Nt must include 8 HEX symbols");\r | |
26 | return 1;\r | |
27 | }\r | |
28 | \r | |
29 | UsbCommand c = {CMD_READER_MIFARE, {(uint32_t)bytes_to_num(keyBlock, 4), 0, 0}};\r | |
30 | SendCommand(&c);\r | |
31 | \r | |
32 | //flush queue\r | |
33 | while (ukbhit()) getchar();\r | |
34 | \r | |
35 | // message\r | |
36 | printf("-------------------------------------------------------------------------\n");\r | |
37 | printf("Executing command. It may take up to 30 min.\n");\r | |
38 | printf("Press the key on proxmark3 device to abort proxmark3.\n");\r | |
39 | printf("Press the key on the proxmark3 device to abort both proxmark3 and client.\n");\r | |
40 | printf("-------------------------------------------------------------------------\n");\r | |
41 | \r | |
42 | // wait cycle\r | |
43 | while (true) {\r | |
44 | printf(".");\r | |
45 | if (ukbhit()) {\r | |
46 | getchar();\r | |
47 | printf("\naborted via keyboard!\n");\r | |
48 | break;\r | |
49 | }\r | |
50 | \r | |
51 | UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 2000);\r | |
52 | if (resp != NULL) {\r | |
53 | isOK = resp->arg[0] & 0xff;\r | |
54 | \r | |
55 | uid = (uint32_t)bytes_to_num(resp->d.asBytes + 0, 4);\r | |
56 | nt = (uint32_t)bytes_to_num(resp->d.asBytes + 4, 4);\r | |
57 | par_list = bytes_to_num(resp->d.asBytes + 8, 8);\r | |
58 | ks_list = bytes_to_num(resp->d.asBytes + 16, 8);\r | |
59 | \r | |
60 | printf("\n\n");\r | |
61 | PrintAndLog("isOk:%02x", isOK);\r | |
62 | if (!isOK) PrintAndLog("Proxmark can't get statistic info. Execution aborted.\n");\r | |
63 | break;\r | |
64 | }\r | |
65 | } \r | |
66 | printf("\n");\r | |
67 | \r | |
68 | // error\r | |
69 | if (isOK != 1) return 1;\r | |
70 | \r | |
71 | // execute original function from util nonce2key\r | |
72 | if (nonce2key(uid, nt, par_list, ks_list, &r_key)) return 2;\r | |
73 | printf("------------------------------------------------------------------\n");\r | |
74 | PrintAndLog("Key found:%012llx \n", r_key);\r | |
75 | \r | |
76 | num_to_bytes(r_key, 6, keyBlock);\r | |
77 | isOK = mfCheckKeys(0, 0, 1, keyBlock, &r_key);\r | |
78 | if (!isOK) \r | |
79 | PrintAndLog("Found valid key:%012llx", r_key);\r | |
80 | else\r | |
81 | PrintAndLog("Found invalid key. ( Nt=%08x", nt); \r | |
82 | \r | |
83 | \r | |
84 | return 0;\r | |
85 | }\r | |
86 | \r | |
87 | int CmdHF14AMfWrBl(const char *Cmd)\r | |
88 | {\r | |
89 | uint8_t blockNo = 0;\r | |
90 | uint8_t keyType = 0;\r | |
91 | uint8_t key[6] = {0, 0, 0, 0, 0, 0};\r | |
92 | uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};\r | |
93 | \r | |
94 | char cmdp = 0x00;\r | |
95 | \r | |
96 | if (strlen(Cmd)<3) {\r | |
97 | PrintAndLog("Usage: hf mf wrbl <block number> <key A/B> <key (12 hex symbols)> <block data (32 hex symbols)>");\r | |
98 | PrintAndLog(" sample: hf mf wrbl 0 A FFFFFFFFFFFF 000102030405060708090A0B0C0D0E0F");\r | |
99 | return 0;\r | |
100 | } \r | |
101 | \r | |
102 | blockNo = param_get8(Cmd, 0);\r | |
103 | cmdp = param_getchar(Cmd, 1);\r | |
104 | if (cmdp == 0x00) {\r | |
105 | PrintAndLog("Key type must be A or B");\r | |
106 | return 1;\r | |
107 | }\r | |
108 | if (cmdp != 'A' && cmdp != 'a') keyType = 1;\r | |
109 | if (param_gethex(Cmd, 2, key, 12)) {\r | |
110 | PrintAndLog("Key must include 12 HEX symbols");\r | |
111 | return 1;\r | |
112 | }\r | |
113 | if (param_gethex(Cmd, 3, bldata, 32)) {\r | |
114 | PrintAndLog("Block data must include 32 HEX symbols");\r | |
115 | return 1;\r | |
116 | }\r | |
117 | PrintAndLog("--block no:%02x key type:%02x key:%s", blockNo, keyType, sprint_hex(key, 6));\r | |
118 | PrintAndLog("--data: %s", sprint_hex(bldata, 16));\r | |
119 | \r | |
120 | UsbCommand c = {CMD_MIFARE_WRITEBL, {blockNo, keyType, 0}};\r | |
121 | memcpy(c.d.asBytes, key, 6);\r | |
122 | memcpy(c.d.asBytes + 10, bldata, 16);\r | |
123 | SendCommand(&c);\r | |
124 | UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);\r | |
125 | \r | |
126 | if (resp != NULL) {\r | |
127 | uint8_t isOK = resp->arg[0] & 0xff;\r | |
128 | \r | |
129 | PrintAndLog("isOk:%02x", isOK);\r | |
130 | } else {\r | |
131 | PrintAndLog("Command execute timeout");\r | |
132 | }\r | |
133 | \r | |
134 | return 0;\r | |
135 | }\r | |
136 | \r | |
137 | int CmdHF14AMfRdBl(const char *Cmd)\r | |
138 | {\r | |
139 | uint8_t blockNo = 0;\r | |
140 | uint8_t keyType = 0;\r | |
141 | uint8_t key[6] = {0, 0, 0, 0, 0, 0};\r | |
142 | \r | |
143 | char cmdp = 0x00;\r | |
144 | \r | |
145 | \r | |
146 | if (strlen(Cmd)<3) {\r | |
147 | PrintAndLog("Usage: hf mf rdbl <block number> <key A/B> <key (12 hex symbols)>");\r | |
148 | PrintAndLog(" sample: hf mf rdbl 0 A FFFFFFFFFFFF ");\r | |
149 | return 0;\r | |
150 | } \r | |
151 | \r | |
152 | blockNo = param_get8(Cmd, 0);\r | |
153 | cmdp = param_getchar(Cmd, 1);\r | |
154 | if (cmdp == 0x00) {\r | |
155 | PrintAndLog("Key type must be A or B");\r | |
156 | return 1;\r | |
157 | }\r | |
158 | if (cmdp != 'A' && cmdp != 'a') keyType = 1;\r | |
159 | if (param_gethex(Cmd, 2, key, 12)) {\r | |
160 | PrintAndLog("Key must include 12 HEX symbols");\r | |
161 | return 1;\r | |
162 | }\r | |
163 | PrintAndLog("--block no:%02x key type:%02x key:%s ", blockNo, keyType, sprint_hex(key, 6));\r | |
164 | \r | |
165 | UsbCommand c = {CMD_MIFARE_READBL, {blockNo, keyType, 0}};\r | |
166 | memcpy(c.d.asBytes, key, 6);\r | |
167 | SendCommand(&c);\r | |
168 | UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);\r | |
169 | \r | |
170 | if (resp != NULL) {\r | |
171 | uint8_t isOK = resp->arg[0] & 0xff;\r | |
172 | uint8_t * data = resp->d.asBytes;\r | |
173 | \r | |
174 | if (isOK)\r | |
175 | PrintAndLog("isOk:%02x data:%s", isOK, sprint_hex(data, 16));\r | |
176 | else\r | |
177 | PrintAndLog("isOk:%02x", isOK);\r | |
178 | } else {\r | |
179 | PrintAndLog("Command execute timeout");\r | |
180 | }\r | |
181 | \r | |
182 | return 0;\r | |
183 | }\r | |
184 | \r | |
185 | int CmdHF14AMfRdSc(const char *Cmd)\r | |
186 | {\r | |
187 | int i;\r | |
188 | uint8_t sectorNo = 0;\r | |
189 | uint8_t keyType = 0;\r | |
190 | uint8_t key[6] = {0, 0, 0, 0, 0, 0};\r | |
191 | \r | |
192 | uint8_t isOK = 0;\r | |
193 | uint8_t * data = NULL;\r | |
194 | \r | |
195 | char cmdp = 0x00;\r | |
196 | \r | |
197 | if (strlen(Cmd)<3) {\r | |
198 | PrintAndLog("Usage: hf mf rdsc <sector number> <key A/B> <key (12 hex symbols)>");\r | |
199 | PrintAndLog(" sample: hf mf rdsc 0 A FFFFFFFFFFFF ");\r | |
200 | return 0;\r | |
201 | } \r | |
202 | \r | |
203 | sectorNo = param_get8(Cmd, 0);\r | |
204 | if (sectorNo > 63) {\r | |
205 | PrintAndLog("Sector number must be less than 64");\r | |
206 | return 1;\r | |
207 | }\r | |
208 | cmdp = param_getchar(Cmd, 1);\r | |
209 | if (cmdp == 0x00) {\r | |
210 | PrintAndLog("Key type must be A or B");\r | |
211 | return 1;\r | |
212 | }\r | |
213 | if (cmdp != 'A' && cmdp != 'a') keyType = 1;\r | |
214 | if (param_gethex(Cmd, 2, key, 12)) {\r | |
215 | PrintAndLog("Key must include 12 HEX symbols");\r | |
216 | return 1;\r | |
217 | }\r | |
218 | PrintAndLog("--sector no:%02x key type:%02x key:%s ", sectorNo, keyType, sprint_hex(key, 6));\r | |
219 | \r | |
220 | UsbCommand c = {CMD_MIFARE_READSC, {sectorNo, keyType, 0}};\r | |
221 | memcpy(c.d.asBytes, key, 6);\r | |
222 | SendCommand(&c);\r | |
223 | UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);\r | |
224 | PrintAndLog(" ");\r | |
225 | \r | |
226 | if (resp != NULL) {\r | |
227 | isOK = resp->arg[0] & 0xff;\r | |
228 | data = resp->d.asBytes;\r | |
229 | \r | |
230 | PrintAndLog("isOk:%02x", isOK);\r | |
231 | if (isOK) \r | |
232 | for (i = 0; i < 2; i++) {\r | |
233 | PrintAndLog("data:%s", sprint_hex(data + i * 16, 16));\r | |
234 | }\r | |
235 | } else {\r | |
236 | PrintAndLog("Command1 execute timeout");\r | |
237 | }\r | |
238 | \r | |
239 | // response2\r | |
240 | resp = WaitForResponseTimeout(CMD_ACK, 500);\r | |
241 | PrintAndLog(" ");\r | |
242 | \r | |
243 | if (resp != NULL) {\r | |
244 | isOK = resp->arg[0] & 0xff;\r | |
245 | data = resp->d.asBytes;\r | |
246 | \r | |
247 | if (isOK) \r | |
248 | for (i = 0; i < 2; i++) {\r | |
249 | PrintAndLog("data:%s", sprint_hex(data + i * 16, 16));\r | |
250 | }\r | |
251 | } else {\r | |
252 | PrintAndLog("Command2 execute timeout");\r | |
253 | }\r | |
254 | \r | |
255 | return 0;\r | |
256 | }\r | |
257 | \r | |
258 | int CmdHF14AMfNested(const char *Cmd)\r | |
259 | {\r | |
260 | int i, j, res, iterations;\r | |
261 | sector * e_sector = NULL;\r | |
262 | uint8_t blockNo = 0;\r | |
263 | uint8_t keyType = 0;\r | |
264 | uint8_t trgBlockNo = 0;\r | |
265 | uint8_t trgKeyType = 0;\r | |
266 | uint8_t blDiff = 0;\r | |
267 | int SectorsCnt = 0;\r | |
268 | uint8_t key[6] = {0, 0, 0, 0, 0, 0};\r | |
269 | uint8_t keyBlock[16 * 6];\r | |
270 | uint64_t key64 = 0;\r | |
271 | \r | |
272 | char cmdp, ctmp;\r | |
273 | \r | |
274 | if (strlen(Cmd)<3) {\r | |
275 | PrintAndLog("Usage:");\r | |
276 | PrintAndLog(" all sectors: hf mf nested <card memory> <block number> <key A/B> <key (12 hex symbols)>");\r | |
277 | PrintAndLog(" one sector: hf mf nested o <block number> <key A/B> <key (12 hex symbols)>");\r | |
278 | PrintAndLog(" <target block number> <target key A/B>");\r | |
279 | PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");\r | |
280 | PrintAndLog(" ");\r | |
281 | PrintAndLog(" sample1: hf mf nested 1 0 A FFFFFFFFFFFF ");\r | |
282 | PrintAndLog(" sample2: hf mf nested o 0 A FFFFFFFFFFFF 4 A");\r | |
283 | return 0;\r | |
284 | } \r | |
285 | \r | |
286 | cmdp = param_getchar(Cmd, 0);\r | |
287 | blockNo = param_get8(Cmd, 1);\r | |
288 | ctmp = param_getchar(Cmd, 2);\r | |
289 | if (ctmp == 0x00) {\r | |
290 | PrintAndLog("Key type must be A or B");\r | |
291 | return 1;\r | |
292 | }\r | |
293 | if (ctmp != 'A' && ctmp != 'a') keyType = 1;\r | |
294 | if (param_gethex(Cmd, 3, key, 12)) {\r | |
295 | PrintAndLog("Key must include 12 HEX symbols");\r | |
296 | return 1;\r | |
297 | }\r | |
298 | \r | |
299 | if (cmdp =='o' || cmdp == 'O') {\r | |
300 | cmdp = 'o';\r | |
301 | trgBlockNo = param_get8(Cmd, 4);\r | |
302 | ctmp = param_getchar(Cmd, 5);\r | |
303 | if (ctmp == 0x00) {\r | |
304 | PrintAndLog("Target key type must be A or B");\r | |
305 | return 1;\r | |
306 | }\r | |
307 | if (ctmp != 'A' && ctmp != 'a') trgKeyType = 1;\r | |
308 | } else {\r | |
309 | switch (cmdp) {\r | |
310 | case '0': SectorsCnt = 05; break;\r | |
311 | case '1': SectorsCnt = 16; break;\r | |
312 | case '2': SectorsCnt = 32; break;\r | |
313 | case '4': SectorsCnt = 64; break;\r | |
314 | default: SectorsCnt = 16;\r | |
315 | }\r | |
316 | }\r | |
317 | \r | |
318 | PrintAndLog("--block no:%02x key type:%02x key:%s ", blockNo, keyType, sprint_hex(key, 6));\r | |
319 | if (cmdp == 'o')\r | |
320 | PrintAndLog("--target block no:%02x target key type:%02x ", trgBlockNo, trgKeyType);\r | |
321 | \r | |
322 | if (cmdp == 'o') {\r | |
323 | if (mfnested(blockNo, keyType, key, trgBlockNo, trgKeyType, keyBlock)) {\r | |
324 | PrintAndLog("Nested error.");\r | |
325 | return 2;\r | |
326 | }\r | |
327 | \r | |
328 | for (i = 0; i < 16; i++) {\r | |
329 | PrintAndLog("cnt=%d key= %s", i, sprint_hex(keyBlock + i * 6, 6));\r | |
330 | }\r | |
331 | \r | |
332 | // test keys\r | |
333 | res = mfCheckKeys(trgBlockNo, trgKeyType, 8, keyBlock, &key64);\r | |
334 | if (res)\r | |
335 | res = mfCheckKeys(trgBlockNo, trgKeyType, 8, &keyBlock[6 * 8], &key64);\r | |
336 | if (!res)\r | |
337 | PrintAndLog("Found valid key:%012llx", key64);\r | |
338 | else\r | |
339 | PrintAndLog("No valid key found");\r | |
340 | } else // ------------------------------------ multiple sectors working\r | |
341 | {\r | |
342 | blDiff = blockNo % 4;\r | |
343 | PrintAndLog("Block shift=%d", blDiff);\r | |
344 | e_sector = calloc(SectorsCnt, sizeof(sector));\r | |
345 | if (e_sector == NULL) return 1;\r | |
346 | \r | |
347 | //test current key 4 sectors\r | |
348 | memcpy(keyBlock, key, 6);\r | |
349 | num_to_bytes(0xa0a1a2a3a4a5, 6, (uint8_t*)(keyBlock + 1 * 6));\r | |
350 | num_to_bytes(0xb0b1b2b3b4b5, 6, (uint8_t*)(keyBlock + 2 * 6));\r | |
351 | num_to_bytes(0xffffffffffff, 6, (uint8_t*)(keyBlock + 3 * 6));\r | |
352 | num_to_bytes(0x000000000000, 6, (uint8_t*)(keyBlock + 4 * 6));\r | |
353 | num_to_bytes(0xaabbccddeeff, 6, (uint8_t*)(keyBlock + 5 * 6));\r | |
354 | \r | |
355 | PrintAndLog("Testing known keys. Sector count=%d", SectorsCnt);\r | |
356 | for (i = 0; i < SectorsCnt; i++) {\r | |
357 | for (j = 0; j < 2; j++) {\r | |
358 | if (e_sector[i].foundKey[j]) continue;\r | |
359 | \r | |
360 | res = mfCheckKeys(i * 4 + blDiff, j, 6, keyBlock, &key64);\r | |
361 | \r | |
362 | if (!res) {\r | |
363 | e_sector[i].Key[j] = key64;\r | |
364 | e_sector[i].foundKey[j] = 1;\r | |
365 | }\r | |
366 | }\r | |
367 | } \r | |
368 | \r | |
369 | \r | |
370 | // nested sectors\r | |
371 | iterations = 0;\r | |
372 | PrintAndLog("nested...");\r | |
373 | for (i = 0; i < NESTED_SECTOR_RETRY; i++) {\r | |
374 | for (trgBlockNo = blDiff; trgBlockNo < SectorsCnt * 4; trgBlockNo = trgBlockNo + 4) \r | |
375 | for (trgKeyType = 0; trgKeyType < 2; trgKeyType++) { \r | |
376 | if (e_sector[trgBlockNo / 4].foundKey[trgKeyType]) continue;\r | |
377 | if (mfnested(blockNo, keyType, key, trgBlockNo, trgKeyType, keyBlock)) continue;\r | |
378 | \r | |
379 | iterations++;\r | |
380 | \r | |
381 | //try keys from nested\r | |
382 | res = mfCheckKeys(trgBlockNo, trgKeyType, 8, keyBlock, &key64);\r | |
383 | if (res)\r | |
384 | res = mfCheckKeys(trgBlockNo, trgKeyType, 8, &keyBlock[6 * 8], &key64);\r | |
385 | if (!res) {\r | |
386 | PrintAndLog("Found valid key:%012llx", key64); \r | |
387 | e_sector[trgBlockNo / 4].foundKey[trgKeyType] = 1;\r | |
388 | e_sector[trgBlockNo / 4].Key[trgKeyType] = key64;\r | |
389 | }\r | |
390 | }\r | |
391 | }\r | |
392 | \r | |
393 | PrintAndLog("Iterations count: %d", iterations);\r | |
394 | //print them\r | |
395 | PrintAndLog("|---|----------------|---|----------------|---|");\r | |
396 | PrintAndLog("|sec|key A |res|key B |res|");\r | |
397 | PrintAndLog("|---|----------------|---|----------------|---|");\r | |
398 | for (i = 0; i < SectorsCnt; i++) {\r | |
399 | PrintAndLog("|%03d| %012llx | %d | %012llx | %d |", i, \r | |
400 | e_sector[i].Key[0], e_sector[i].foundKey[0], e_sector[i].Key[1], e_sector[i].foundKey[1]);\r | |
401 | }\r | |
402 | PrintAndLog("|---|----------------|---|----------------|---|");\r | |
403 | \r | |
404 | free(e_sector);\r | |
405 | }\r | |
406 | \r | |
407 | return 0;\r | |
408 | }\r | |
409 | \r | |
410 | int CmdHF14AMfChk(const char *Cmd)\r | |
411 | {\r | |
412 | int i, res;\r | |
413 | int keycnt = 0;\r | |
414 | char ctmp = 0x00;\r | |
415 | uint8_t blockNo = 0;\r | |
416 | uint8_t keyType = 0;\r | |
417 | uint8_t keyBlock[8 * 6];\r | |
418 | uint64_t key64 = 0;\r | |
419 | \r | |
420 | memset(keyBlock, 0x00, sizeof(keyBlock));\r | |
421 | \r | |
422 | if (strlen(Cmd)<3) {\r | |
423 | PrintAndLog("Usage: hf mf chk <block number> <key A/B> [<key (12 hex symbols)>]");\r | |
424 | PrintAndLog(" sample: hf mf chk 0 A FFFFFFFFFFFF a0a1a2a3a4a5 b01b2b3b4b5 ");\r | |
425 | return 0;\r | |
426 | } \r | |
427 | \r | |
428 | blockNo = param_get8(Cmd, 0);\r | |
429 | ctmp = param_getchar(Cmd, 1);\r | |
430 | if (ctmp == 0x00) {\r | |
431 | PrintAndLog("Key type must be A or B");\r | |
432 | return 1;\r | |
433 | }\r | |
434 | if (ctmp != 'A' && ctmp != 'a') keyType = 1;\r | |
435 | \r | |
436 | for (i = 0; i < 6; i++) {\r | |
437 | if (!isxdigit(param_getchar(Cmd, 2 + i))) break;\r | |
438 | \r | |
439 | if (param_gethex(Cmd, 2 + i, keyBlock + 6 * i, 12)) {\r | |
440 | PrintAndLog("Key[%d] must include 12 HEX symbols", i);\r | |
441 | return 1;\r | |
442 | }\r | |
443 | keycnt = i + 1;\r | |
444 | }\r | |
445 | \r | |
446 | if (keycnt == 0) {\r | |
447 | PrintAndLog("There is must be at least one key");\r | |
448 | return 1;\r | |
449 | }\r | |
450 | \r | |
451 | PrintAndLog("--block no:%02x key type:%02x key count:%d ", blockNo, keyType, keycnt);\r | |
452 | \r | |
453 | res = mfCheckKeys(blockNo, keyType, keycnt, keyBlock, &key64);\r | |
454 | if (res !=1) {\r | |
455 | if (!res)\r | |
456 | PrintAndLog("isOk:%02x valid key:%012llx", 1, key64);\r | |
457 | else\r | |
458 | PrintAndLog("isOk:%02x", 0);\r | |
459 | } else {\r | |
460 | PrintAndLog("Command execute timeout");\r | |
461 | }\r | |
462 | \r | |
463 | return 0;\r | |
464 | }\r | |
465 | \r | |
466 | int CmdHF14AMf1kSim(const char *Cmd)\r | |
467 | {\r | |
468 | uint8_t uid[4] = {0, 0, 0, 0};\r | |
469 | \r | |
470 | if (param_getchar(Cmd, 0) == 'h') {\r | |
471 | PrintAndLog("Usage: hf mf sim <uid (8 hex symbols)>");\r | |
472 | PrintAndLog(" sample: hf mf sim 0a0a0a0a ");\r | |
473 | return 0;\r | |
474 | } \r | |
475 | \r | |
476 | if (param_getchar(Cmd, 0) && param_gethex(Cmd, 0, uid, 8)) {\r | |
477 | PrintAndLog("UID must include 8 HEX symbols");\r | |
478 | return 1;\r | |
479 | }\r | |
480 | PrintAndLog(" uid:%s ", sprint_hex(uid, 4));\r | |
481 | \r | |
482 | UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {0, 0, 0}};\r | |
483 | memcpy(c.d.asBytes, uid, 4);\r | |
484 | SendCommand(&c);\r | |
485 | \r | |
486 | return 0;\r | |
487 | }\r | |
488 | \r | |
489 | int CmdHF14AMfDbg(const char *Cmd)\r | |
490 | {\r | |
491 | if (strlen(Cmd) < 1) {\r | |
492 | PrintAndLog("Usage: hf mf dbg <debug level>");\r | |
493 | PrintAndLog(" 0 - no debug messages");\r | |
494 | PrintAndLog(" 1 - error messages");\r | |
495 | PrintAndLog(" 2 - all messages");\r | |
496 | PrintAndLog(" 4 - extended debug mode");\r | |
497 | return 0;\r | |
498 | } \r | |
499 | \r | |
500 | PrintAndLog("No code here (");\r | |
501 | return 0;\r | |
502 | }\r | |
503 | \r | |
504 | int CmdHF14AMfEGet(const char *Cmd)\r | |
505 | {\r | |
506 | PrintAndLog("No code here (");\r | |
507 | return 0;\r | |
508 | }\r | |
509 | \r | |
510 | int CmdHF14AMfESet(const char *Cmd)\r | |
511 | {\r | |
512 | PrintAndLog("No code here (");\r | |
513 | return 0;\r | |
514 | }\r | |
515 | \r | |
516 | int CmdHF14AMfELoad(const char *Cmd)\r | |
517 | {\r | |
518 | PrintAndLog("No code here (");\r | |
519 | return 0;\r | |
520 | }\r | |
521 | \r | |
522 | int CmdHF14AMfESave(const char *Cmd)\r | |
523 | {\r | |
524 | PrintAndLog("No code here (");\r | |
525 | return 0;\r | |
526 | }\r | |
527 | \r | |
528 | static command_t CommandTable[] = \r | |
529 | {\r | |
530 | {"help", CmdHelp, 1, "This help"},\r | |
531 | {"dbg", CmdHF14AMfDbg, 0, "Set default debug mode"},\r | |
532 | {"rdbl", CmdHF14AMfRdBl, 0, "Read MIFARE classic block"},\r | |
533 | {"rdsc", CmdHF14AMfRdSc, 0, "Read MIFARE classic sector"},\r | |
534 | {"wrbl", CmdHF14AMfWrBl, 0, "Write MIFARE classic block"},\r | |
535 | {"chk", CmdHF14AMfChk, 0, "Test block up to 8 keys"},\r | |
536 | {"mifare", CmdHF14AMifare, 0, "Read parity error messages. param - <used card nonce>"},\r | |
537 | {"nested", CmdHF14AMfNested, 0, "Test nested authentication"},\r | |
538 | {"sim", CmdHF14AMf1kSim, 0, "Simulate MIFARE 1k card"},\r | |
539 | {"eget", CmdHF14AMfEGet, 0, "Set simulator memory block"},\r | |
540 | {"eset", CmdHF14AMfESet, 0, "Get simulator memory block"},\r | |
541 | {"eload", CmdHF14AMfELoad, 0, "Load from file emul dump"},\r | |
542 | {"esave", CmdHF14AMfESave, 0, "Save to file emul dump"},\r | |
543 | {NULL, NULL, 0, NULL}\r | |
544 | };\r | |
545 | \r | |
546 | int CmdHFMF(const char *Cmd)\r | |
547 | {\r | |
548 | // flush\r | |
549 | while (WaitForResponseTimeout(CMD_ACK, 500) != NULL) ;\r | |
550 | \r | |
551 | CmdsParse(CommandTable, Cmd);\r | |
552 | return 0;\r | |
553 | }\r | |
554 | \r | |
555 | int CmdHelp(const char *Cmd)\r | |
556 | {\r | |
557 | CmdsHelp(CommandTable);\r | |
558 | return 0;\r | |
559 | }\r |