]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlft55xx.c
fix: those pesky semicolons..
[proxmark3-svn] / client / cmdlft55xx.c
1 //-----------------------------------------------------------------------------
2 //
3 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
4 // at your option, any later version. See the LICENSE.txt file for the text of
5 // the license.
6 //-----------------------------------------------------------------------------
7 // Low frequency T55xx commands
8 //-----------------------------------------------------------------------------
9 #include "cmdlft55xx.h"
10
11 // Default configuration
12 t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = FALSE, .offset = 0x00, .block0 = 0x00, .Q5 = FALSE };
13
14 t55xx_conf_block_t Get_t55xx_Config(){
15 return config;
16 }
17 void Set_t55xx_Config(t55xx_conf_block_t conf){
18 config = conf;
19 }
20
21 int usage_t55xx_config(){
22 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>] [Q5]");
23 PrintAndLog("Options:");
24 PrintAndLog(" h - This help");
25 PrintAndLog(" b <8|16|32|40|50|64|100|128> - Set bitrate");
26 PrintAndLog(" d <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NRZ|BI|BIa> - Set demodulation FSK / ASK / PSK / NRZ / Biphase / Biphase A");
27 PrintAndLog(" i [1] - Invert data signal, defaults to normal");
28 PrintAndLog(" o [offset] - Set offset, where data should start decode in bitstream");
29 PrintAndLog(" Q5 - Set as Q5(T5555) chip instead of T55x7");
30 PrintAndLog(" ST - Set Sequence Terminator on");
31 PrintAndLog("");
32 PrintAndLog("Examples:");
33 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");
34 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");
35 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");
36 PrintAndLog("");
37 return 0;
38 }
39 int usage_t55xx_read(){
40 PrintAndLog("Usage: lf t55xx read [b <block>] [p <password>] <override_safety> <page1>");
41 PrintAndLog("Options:");
42 PrintAndLog(" b <block> - block number to read. Between 0-7");
43 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");
44 PrintAndLog(" o - OPTIONAL override safety check");
45 PrintAndLog(" 1 - OPTIONAL read Page 1 instead of Page 0");
46 PrintAndLog(" ****WARNING****");
47 PrintAndLog(" Use of read with password on a tag not configured for a pwd");
48 PrintAndLog(" can damage the tag");
49 PrintAndLog("");
50 PrintAndLog("Examples:");
51 PrintAndLog(" lf t55xx read b 0 - read data from block 0");
52 PrintAndLog(" lf t55xx read b 0 p feedbeef - read data from block 0 password feedbeef");
53 PrintAndLog(" lf t55xx read b 0 p feedbeef o - read data from block 0 password feedbeef safety check");
54 PrintAndLog("");
55 return 0;
56 }
57 int usage_t55xx_write(){
58 PrintAndLog("Usage: lf t55xx wr [b <block>] [d <data>] [p <password>] [1]");
59 PrintAndLog("Options:");
60 PrintAndLog(" b <block> - block number to write. Between 0-7");
61 PrintAndLog(" d <data> - 4 bytes of data to write (8 hex characters)");
62 PrintAndLog(" p <password> - OPTIONAL password 4bytes (8 hex characters)");
63 PrintAndLog(" 1 - OPTIONAL write Page 1 instead of Page 0");
64 PrintAndLog("");
65 PrintAndLog("Examples:");
66 PrintAndLog(" lf t55xx write b 3 d 11223344 - write 11223344 to block 3");
67 PrintAndLog(" lf t55xx write b 3 d 11223344 p feedbeef - write 11223344 to block 3 password feedbeef");
68 PrintAndLog("");
69 return 0;
70 }
71 int usage_t55xx_trace() {
72 PrintAndLog("Usage: lf t55xx trace [1]");
73 PrintAndLog("Options:");
74 PrintAndLog(" 1 - if set, use Graphbuffer otherwise read data from tag.");
75 PrintAndLog("");
76 PrintAndLog("Examples:");
77 PrintAndLog(" lf t55xx trace");
78 PrintAndLog(" lf t55xx trace 1");
79 PrintAndLog("");
80 return 0;
81 }
82 int usage_t55xx_info() {
83 PrintAndLog("Usage: lf t55xx info [1]");
84 PrintAndLog("Options:");
85 PrintAndLog(" 1 - if set, use Graphbuffer otherwise read data from tag.");
86 PrintAndLog("");
87 PrintAndLog("Examples:");
88 PrintAndLog(" lf t55xx info");
89 PrintAndLog(" lf t55xx info 1");
90 PrintAndLog("");
91 return 0;
92 }
93 int usage_t55xx_dump(){
94 PrintAndLog("Usage: lf t55xx dump <password> [o]");
95 PrintAndLog("Options:");
96 PrintAndLog(" <password> - OPTIONAL password 4bytes (8 hex symbols)");
97 PrintAndLog(" o - OPTIONAL override, force pwd read despite danger to card");
98 PrintAndLog("");
99 PrintAndLog("Examples:");
100 PrintAndLog(" lf t55xx dump");
101 PrintAndLog(" lf t55xx dump feedbeef o");
102 PrintAndLog("");
103 return 0;
104 }
105 int usage_t55xx_detect(){
106 PrintAndLog("Usage: lf t55xx detect [1] [p <password>]");
107 PrintAndLog("Options:");
108 PrintAndLog(" 1 - if set, use Graphbuffer otherwise read data from tag.");
109 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");
110 PrintAndLog("");
111 PrintAndLog("Examples:");
112 PrintAndLog(" lf t55xx detect");
113 PrintAndLog(" lf t55xx detect 1");
114 PrintAndLog(" lf t55xx detect p 11223344");
115 PrintAndLog("");
116 return 0;
117 }
118 int usage_t55xx_wakup(){
119 PrintAndLog("Usage: lf t55xx wakeup [h] p <password>");
120 PrintAndLog("This commands send the Answer-On-Request command and leaves the readerfield ON afterwards.");
121 PrintAndLog("Options:");
122 PrintAndLog(" h - this help");
123 PrintAndLog(" p <password> - password 4bytes (8 hex symbols)");
124 PrintAndLog("");
125 PrintAndLog("Examples:");
126 PrintAndLog(" lf t55xx wakeup p 11223344 - send wakeup password");
127 return 0;
128 }
129 int usage_t55xx_bruteforce(){
130 PrintAndLog("This command uses A) bruteforce to scan a number range");
131 PrintAndLog(" B) a dictionary attack");
132 PrintAndLog("press 'enter' to cancel the command");
133 PrintAndLog("Usage: lf t55xx bruteforce [h] <start password> <end password> [i <*.dic>]");
134 PrintAndLog(" password must be 4 bytes (8 hex symbols)");
135 PrintAndLog("Options:");
136 PrintAndLog(" h - this help");
137 PrintAndLog(" <start_pwd> - 4 byte hex value to start pwd search at");
138 PrintAndLog(" <end_pwd> - 4 byte hex value to end pwd search at");
139 PrintAndLog(" i <*.dic> - loads a default keys dictionary file <*.dic>");
140 PrintAndLog("");
141 PrintAndLog("Examples:");
142 PrintAndLog(" lf t55xx bruteforce aaaaaaaa bbbbbbbb");
143 PrintAndLog(" lf t55xx bruteforce i default_pwd.dic");
144 PrintAndLog("");
145 return 0;
146 }
147 int usage_t55xx_recoverpw(){
148 PrintAndLog("This command uses a few tricks to try to recover mangled password");
149 PrintAndLog("press 'enter' to cancel the command");
150 PrintAndLog("WARNING: this may brick non-password protected chips!");
151 PrintAndLog("Usage: lf t55xx recoverpw [password]");
152 PrintAndLog(" password must be 4 bytes (8 hex symbols)");
153 PrintAndLog(" default password is 51243648, used by many cloners");
154 PrintAndLog("Options:");
155 PrintAndLog(" h - this help");
156 PrintAndLog(" [password] - 4 byte hex value of password written by cloner");
157 PrintAndLog("");
158 PrintAndLog("Examples:");
159 PrintAndLog(" lf t55xx recoverpw");
160 PrintAndLog(" lf t55xx recoverpw 51243648");
161 PrintAndLog("");
162 return 0;
163 }int usage_t55xx_wipe(){
164 PrintAndLog("Usage: lf t55xx wipe [h] [Q5]");
165 PrintAndLog("This commands wipes a tag, fills blocks 1-7 with zeros and a default configuration block");
166 PrintAndLog("Options:");
167 PrintAndLog(" h - this help");
168 PrintAndLog(" Q5 - indicates to use the T5555 (Q5) default configuration block");
169 PrintAndLog("");
170 PrintAndLog("Examples:");
171 PrintAndLog(" lf t55xx wipe - wipes a t55x7 tag, config block 0x000880E0");
172 PrintAndLog(" lf t55xx wipe Q5 - wipes a t5555 Q5 tag, config block 0x6001F004");
173 return 0;
174 }
175 static int CmdHelp(const char *Cmd);
176
177 void printT5xxHeader(uint8_t page){
178 PrintAndLog("Reading Page %d:", page);
179 PrintAndLog("blk | hex data | binary | ascii");
180 PrintAndLog("----+----------+----------------------------------+-------");
181 }
182
183 int CmdT55xxSetConfig(const char *Cmd) {
184
185 uint8_t offset = 0;
186 char modulation[5] = {0x00};
187 char tmp = 0x00;
188 uint8_t bitRate = 0;
189 uint8_t rates[9] = {8,16,32,40,50,64,100,128,0};
190 uint8_t cmdp = 0;
191 bool errors = FALSE;
192 while(param_getchar(Cmd, cmdp) != 0x00 && !errors)
193 {
194 tmp = param_getchar(Cmd, cmdp);
195 switch(tmp)
196 {
197 case 'h':
198 case 'H':
199 return usage_t55xx_config();
200 case 'b':
201 errors |= param_getdec(Cmd, cmdp+1, &bitRate);
202 if ( !errors){
203 uint8_t i = 0;
204 for (; i < 9; i++){
205 if (rates[i]==bitRate) {
206 config.bitrate = i;
207 break;
208 }
209 }
210 if (i==9) errors = TRUE;
211 }
212 cmdp+=2;
213 break;
214 case 'd':
215 param_getstr(Cmd, cmdp+1, modulation);
216 cmdp += 2;
217
218 if ( strcmp(modulation, "FSK" ) == 0) {
219 config.modulation = DEMOD_FSK;
220 } else if ( strcmp(modulation, "FSK1" ) == 0) {
221 config.modulation = DEMOD_FSK1;
222 config.inverted=1;
223 } else if ( strcmp(modulation, "FSK1a" ) == 0) {
224 config.modulation = DEMOD_FSK1a;
225 config.inverted=0;
226 } else if ( strcmp(modulation, "FSK2" ) == 0) {
227 config.modulation = DEMOD_FSK2;
228 config.inverted=0;
229 } else if ( strcmp(modulation, "FSK2a" ) == 0) {
230 config.modulation = DEMOD_FSK2a;
231 config.inverted=1;
232 } else if ( strcmp(modulation, "ASK" ) == 0) {
233 config.modulation = DEMOD_ASK;
234 } else if ( strcmp(modulation, "NRZ" ) == 0) {
235 config.modulation = DEMOD_NRZ;
236 } else if ( strcmp(modulation, "PSK1" ) == 0) {
237 config.modulation = DEMOD_PSK1;
238 } else if ( strcmp(modulation, "PSK2" ) == 0) {
239 config.modulation = DEMOD_PSK2;
240 } else if ( strcmp(modulation, "PSK3" ) == 0) {
241 config.modulation = DEMOD_PSK3;
242 } else if ( strcmp(modulation, "BIa" ) == 0) {
243 config.modulation = DEMOD_BIa;
244 config.inverted=1;
245 } else if ( strcmp(modulation, "BI" ) == 0) {
246 config.modulation = DEMOD_BI;
247 config.inverted=0;
248 } else {
249 PrintAndLog("Unknown modulation '%s'", modulation);
250 errors = TRUE;
251 }
252 break;
253 case 'i':
254 config.inverted = param_getchar(Cmd,cmdp+1) == '1';
255 cmdp+=2;
256 break;
257 case 'o':
258 errors |= param_getdec(Cmd, cmdp+1, &offset);
259 if ( !errors )
260 config.offset = offset;
261 cmdp+=2;
262 break;
263 case 'Q':
264 case 'q':
265 config.Q5 = TRUE;
266 cmdp++;
267 break;
268 case 'S':
269 case 's':
270 config.ST = TRUE;
271 cmdp++;
272 break;
273 default:
274 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
275 errors = TRUE;
276 break;
277 }
278 }
279
280 // No args
281 if (cmdp == 0) return printConfiguration( config );
282
283 //Validations
284 if (errors) return usage_t55xx_config();
285
286 config.block0 = 0;
287 return printConfiguration ( config );
288 }
289
290 int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, bool override, uint32_t password){
291 //Password mode
292 if ( usepwd ) {
293 // try reading the config block and verify that PWD bit is set before doing this!
294 if ( !override ) {
295
296 if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, false, 0 ) ) return 0;
297
298 if ( !tryDetectModulation() ) {
299 PrintAndLog("Safety Check: Could not detect if PWD bit is set in config block. Exits.");
300 return 0;
301 } else {
302 PrintAndLog("Safety Check: PWD bit is NOT set in config block. Reading without password...");
303 usepwd = false;
304 page1 = false;
305 }
306 } else {
307 PrintAndLog("Safety Check Overriden - proceeding despite risk");
308 }
309 }
310
311 if (!AquireData(page1, block, usepwd, password) ) return 0;
312 if (!DecodeT55xxBlock()) return 0;
313
314 char blk[10]={0};
315 sprintf(blk,"%02d", block);
316 printT55xxBlock(blk);
317 return 1;
318 }
319
320 int CmdT55xxReadBlock(const char *Cmd) {
321 uint8_t block = REGULAR_READ_MODE_BLOCK;
322 uint32_t password = 0; //default to blank Block 7
323 bool usepwd = false;
324 bool override = false;
325 bool page1 = false;
326 bool errors = false;
327 uint8_t cmdp = 0;
328 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
329 switch(param_getchar(Cmd, cmdp)) {
330 case 'h':
331 case 'H':
332 return usage_t55xx_read();
333 case 'b':
334 case 'B':
335 errors |= param_getdec(Cmd, cmdp+1, &block);
336 cmdp += 2;
337 break;
338 case 'o':
339 case 'O':
340 override = TRUE;
341 cmdp++;
342 break;
343 case 'p':
344 case 'P':
345 password = param_get32ex(Cmd, cmdp+1, 0, 16);
346 usepwd = true;
347 cmdp += 2;
348 break;
349 case '1':
350 page1 = true;
351 cmdp++;
352 break;
353 default:
354 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
355 errors = true;
356 break;
357 }
358 }
359 if (errors) return usage_t55xx_read();
360
361 if (block > 7 && block != REGULAR_READ_MODE_BLOCK ) {
362 PrintAndLog("Block must be between 0 and 7");
363 return 0;
364 }
365
366 printT5xxHeader(page1);
367 return T55xxReadBlock(block, page1, usepwd, override, password);
368 }
369
370 bool DecodeT55xxBlock(){
371
372 char buf[30] = {0x00};
373 char *cmdStr = buf;
374 int ans = 0;
375 bool ST = config.ST;
376 uint8_t bitRate[8] = {8,16,32,40,50,64,100,128};
377 DemodBufferLen = 0x00;
378
379 switch( config.modulation ){
380 case DEMOD_FSK:
381 snprintf(cmdStr, sizeof(buf),"%d %d", bitRate[config.bitrate], config.inverted );
382 ans = FSKrawDemod(cmdStr, FALSE);
383 break;
384 case DEMOD_FSK1:
385 case DEMOD_FSK1a:
386 snprintf(cmdStr, sizeof(buf),"%d %d 8 5", bitRate[config.bitrate], config.inverted );
387 ans = FSKrawDemod(cmdStr, FALSE);
388 break;
389 case DEMOD_FSK2:
390 case DEMOD_FSK2a:
391 snprintf(cmdStr, sizeof(buf),"%d %d 10 8", bitRate[config.bitrate], config.inverted );
392 ans = FSKrawDemod(cmdStr, FALSE);
393 break;
394 case DEMOD_ASK:
395 snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );
396 ans = ASKDemod_ext(cmdStr, FALSE, FALSE, 1, &ST);
397 break;
398 case DEMOD_PSK1:
399 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
400 save_restoreGB(1);
401 CmdLtrim("160");
402 snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );
403 ans = PSKDemod(cmdStr, FALSE);
404 //undo trim samples
405 save_restoreGB(0);
406 break;
407 case DEMOD_PSK2: //inverted won't affect this
408 case DEMOD_PSK3: //not fully implemented
409 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
410 save_restoreGB(1);
411 CmdLtrim("160");
412 snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );
413 ans = PSKDemod(cmdStr, FALSE);
414 psk1TOpsk2(DemodBuffer, DemodBufferLen);
415 //undo trim samples
416 save_restoreGB(0);
417 break;
418 case DEMOD_NRZ:
419 snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );
420 ans = NRZrawDemod(cmdStr, FALSE);
421 break;
422 case DEMOD_BI:
423 case DEMOD_BIa:
424 snprintf(cmdStr, sizeof(buf),"0 %d %d 1", bitRate[config.bitrate], config.inverted );
425 ans = ASKbiphaseDemod(cmdStr, FALSE);
426 break;
427 default:
428 return FALSE;
429 }
430 return (bool) ans;
431 }
432
433 bool DecodeT5555TraceBlock() {
434 DemodBufferLen = 0x00;
435
436 // According to datasheet. Always: RF/64, not inverted, Manchester
437 return (bool) ASKDemod("64 0 1", FALSE, FALSE, 1);
438 }
439
440 // sanity check. Don't use proxmark if it is offline and you didn't specify useGraphbuf
441 static int SanityOfflineCheck( bool useGraphBuffer ){
442 if ( !useGraphBuffer && offline) {
443 PrintAndLog("Your proxmark3 device is offline. Specify [1] to use graphbuffer data instead");
444 return 0;
445 }
446 return 1;
447 }
448
449 int CmdT55xxDetect(const char *Cmd){
450 bool errors = FALSE;
451 bool useGB = FALSE;
452 bool usepwd = FALSE;
453 uint32_t password = 0;
454 uint8_t cmdp = 0;
455
456 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
457 switch(param_getchar(Cmd, cmdp)) {
458 case 'h':
459 case 'H':
460 return usage_t55xx_detect();
461 case 'p':
462 case 'P':
463 password = param_get32ex(Cmd, cmdp+1, 0, 16);
464 usepwd = TRUE;
465 cmdp += 2;
466 break;
467 case '1':
468 // use Graphbuffer data
469 useGB = TRUE;
470 cmdp++;
471 break;
472 default:
473 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
474 errors = true;
475 break;
476 }
477 }
478 if (errors) return usage_t55xx_detect();
479
480 // sanity check.
481 if (!SanityOfflineCheck(useGB)) return 1;
482
483 if ( !useGB) {
484 if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password) )
485 return 1;
486 }
487
488 if ( !tryDetectModulation() )
489 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
490
491 return 0;
492 }
493
494 // detect configuration?
495 bool tryDetectModulation(){
496 uint8_t hits = 0;
497 t55xx_conf_block_t tests[15];
498 int bitRate=0;
499 uint8_t fc1 = 0, fc2 = 0, clk=0;
500
501 if (GetFskClock("", FALSE, FALSE)){
502 fskClocks(&fc1, &fc2, &clk, FALSE);
503 if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){
504 tests[hits].modulation = DEMOD_FSK;
505 if (fc1==8 && fc2 == 5)
506 tests[hits].modulation = DEMOD_FSK1a;
507 else if (fc1==10 && fc2 == 8)
508 tests[hits].modulation = DEMOD_FSK2;
509 tests[hits].bitrate = bitRate;
510 tests[hits].inverted = FALSE;
511 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
512 tests[hits].ST = FALSE;
513 ++hits;
514 }
515 if ( FSKrawDemod("0 1", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
516 tests[hits].modulation = DEMOD_FSK;
517 if (fc1 == 8 && fc2 == 5)
518 tests[hits].modulation = DEMOD_FSK1;
519 else if (fc1 == 10 && fc2 == 8)
520 tests[hits].modulation = DEMOD_FSK2a;
521 tests[hits].bitrate = bitRate;
522 tests[hits].inverted = TRUE;
523 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
524 tests[hits].ST = FALSE;
525 ++hits;
526 }
527 } else {
528 clk = GetAskClock("", FALSE, FALSE);
529 if (clk>0) {
530 tests[hits].ST = TRUE;
531 // "0 0 1 " == clock auto, invert false, maxError 1.
532 // false = no verbose
533 // false = no emSearch
534 // 1 = Ask/Man
535 // st = true
536 if ( ASKDemod_ext("0 0 1", FALSE, FALSE, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
537 tests[hits].modulation = DEMOD_ASK;
538 tests[hits].bitrate = bitRate;
539 tests[hits].inverted = FALSE;
540 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
541 ++hits;
542 }
543 tests[hits].ST = TRUE;
544 // "0 0 1 " == clock auto, invert true, maxError 1.
545 // false = no verbose
546 // false = no emSearch
547 // 1 = Ask/Man
548 // st = true
549 if ( ASKDemod_ext("0 1 1", FALSE, FALSE, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
550 tests[hits].modulation = DEMOD_ASK;
551 tests[hits].bitrate = bitRate;
552 tests[hits].inverted = TRUE;
553 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
554 ++hits;
555 }
556 if ( ASKbiphaseDemod("0 0 0 2", FALSE) && test(DEMOD_BI, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {
557 tests[hits].modulation = DEMOD_BI;
558 tests[hits].bitrate = bitRate;
559 tests[hits].inverted = FALSE;
560 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
561 tests[hits].ST = FALSE;
562 ++hits;
563 }
564 if ( ASKbiphaseDemod("0 0 1 2", FALSE) && test(DEMOD_BIa, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {
565 tests[hits].modulation = DEMOD_BIa;
566 tests[hits].bitrate = bitRate;
567 tests[hits].inverted = TRUE;
568 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
569 tests[hits].ST = FALSE;
570 ++hits;
571 }
572 }
573 //undo trim from ask
574 //save_restoreGB(0);
575 clk = GetNrzClock("", FALSE, FALSE);
576 if (clk>0) {
577 if ( NRZrawDemod("0 0 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
578 tests[hits].modulation = DEMOD_NRZ;
579 tests[hits].bitrate = bitRate;
580 tests[hits].inverted = FALSE;
581 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
582 tests[hits].ST = FALSE;
583 ++hits;
584 }
585
586 if ( NRZrawDemod("0 1 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
587 tests[hits].modulation = DEMOD_NRZ;
588 tests[hits].bitrate = bitRate;
589 tests[hits].inverted = TRUE;
590 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
591 tests[hits].ST = FALSE;
592 ++hits;
593 }
594 }
595
596 // allow undo
597 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
598 save_restoreGB(1);
599 CmdLtrim("160");
600 clk = GetPskClock("", FALSE, FALSE);
601 if (clk>0) {
602 if ( PSKDemod("0 0 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
603 tests[hits].modulation = DEMOD_PSK1;
604 tests[hits].bitrate = bitRate;
605 tests[hits].inverted = FALSE;
606 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
607 tests[hits].ST = FALSE;
608 ++hits;
609 }
610 if ( PSKDemod("0 1 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
611 tests[hits].modulation = DEMOD_PSK1;
612 tests[hits].bitrate = bitRate;
613 tests[hits].inverted = TRUE;
614 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
615 tests[hits].ST = FALSE;
616 ++hits;
617 }
618 // PSK2 - needs a call to psk1TOpsk2.
619 if ( PSKDemod("0 0 6", FALSE)) {
620 psk1TOpsk2(DemodBuffer, DemodBufferLen);
621 if (test(DEMOD_PSK2, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){
622 tests[hits].modulation = DEMOD_PSK2;
623 tests[hits].bitrate = bitRate;
624 tests[hits].inverted = FALSE;
625 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
626 tests[hits].ST = FALSE;
627 ++hits;
628 }
629 } // inverse waves does not affect this demod
630 // PSK3 - needs a call to psk1TOpsk2.
631 if ( PSKDemod("0 0 6", FALSE)) {
632 psk1TOpsk2(DemodBuffer, DemodBufferLen);
633 if (test(DEMOD_PSK3, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){
634 tests[hits].modulation = DEMOD_PSK3;
635 tests[hits].bitrate = bitRate;
636 tests[hits].inverted = FALSE;
637 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
638 tests[hits].ST = FALSE;
639 ++hits;
640 }
641 } // inverse waves does not affect this demod
642 }
643 //undo trim samples
644 save_restoreGB(0);
645 }
646 if ( hits == 1) {
647 config.modulation = tests[0].modulation;
648 config.bitrate = tests[0].bitrate;
649 config.inverted = tests[0].inverted;
650 config.offset = tests[0].offset;
651 config.block0 = tests[0].block0;
652 config.Q5 = tests[0].Q5;
653 config.ST = tests[0].ST;
654 printConfiguration( config );
655 return TRUE;
656 }
657
658 bool retval = FALSE;
659 if ( hits > 1) {
660 PrintAndLog("Found [%d] possible matches for modulation.",hits);
661 for(int i=0; i<hits; ++i){
662 retval = testKnownConfigBlock(tests[i].block0);
663 if ( retval ) {
664 PrintAndLog("--[%d]--------------- << selected this", i+1);
665 config.modulation = tests[i].modulation;
666 config.bitrate = tests[i].bitrate;
667 config.inverted = tests[i].inverted;
668 config.offset = tests[i].offset;
669 config.block0 = tests[i].block0;
670 config.Q5 = tests[i].Q5;
671 config.ST = tests[i].ST;
672 } else {
673 PrintAndLog("--[%d]---------------", i+1);
674 }
675 printConfiguration( tests[i] );
676 }
677 }
678 return retval;
679 }
680
681 bool testKnownConfigBlock(uint32_t block0) {
682 switch(block0){
683 case T55X7_DEFAULT_CONFIG_BLOCK:
684 case T55X7_RAW_CONFIG_BLOCK:
685 case T55X7_EM_UNIQUE_CONFIG_BLOCK:
686 case T55X7_FDXB_CONFIG_BLOCK:
687 case T55X7_HID_26_CONFIG_BLOCK:
688 case T55X7_PYRAMID_CONFIG_BLOCK:
689 case T55X7_INDALA_64_CONFIG_BLOCK:
690 case T55X7_INDALA_224_CONFIG_BLOCK:
691 case T55X7_GUARDPROXII_CONFIG_BLOCK:
692 case T55X7_VIKING_CONFIG_BLOCK:
693 case T55X7_NORALYS_CONFIG_BLOCK:
694 case T55X7_IOPROX_CONFIG_BLOCK:
695 case T55X7_PRESCO_CONFIG_BLOCK:
696 return TRUE;
697 }
698 return FALSE;
699 }
700
701 bool testModulation(uint8_t mode, uint8_t modread){
702 switch( mode ){
703 case DEMOD_FSK:
704 if (modread >= DEMOD_FSK1 && modread <= DEMOD_FSK2a) return TRUE;
705 break;
706 case DEMOD_ASK:
707 if (modread == DEMOD_ASK) return TRUE;
708 break;
709 case DEMOD_PSK1:
710 if (modread == DEMOD_PSK1) return TRUE;
711 break;
712 case DEMOD_PSK2:
713 if (modread == DEMOD_PSK2) return TRUE;
714 break;
715 case DEMOD_PSK3:
716 if (modread == DEMOD_PSK3) return TRUE;
717 break;
718 case DEMOD_NRZ:
719 if (modread == DEMOD_NRZ) return TRUE;
720 break;
721 case DEMOD_BI:
722 if (modread == DEMOD_BI) return TRUE;
723 break;
724 case DEMOD_BIa:
725 if (modread == DEMOD_BIa) return TRUE;
726 break;
727 default:
728 return FALSE;
729 }
730 return FALSE;
731 }
732
733 bool testQ5Modulation(uint8_t mode, uint8_t modread){
734 switch( mode ){
735 case DEMOD_FSK:
736 if (modread >= 4 && modread <= 5) return TRUE;
737 break;
738 case DEMOD_ASK:
739 if (modread == 0) return TRUE;
740 break;
741 case DEMOD_PSK1:
742 if (modread == 1) return TRUE;
743 break;
744 case DEMOD_PSK2:
745 if (modread == 2) return TRUE;
746 break;
747 case DEMOD_PSK3:
748 if (modread == 3) return TRUE;
749 break;
750 case DEMOD_NRZ:
751 if (modread == 7) return TRUE;
752 break;
753 case DEMOD_BI:
754 if (modread == 6) return TRUE;
755 break;
756 default:
757 return FALSE;
758 }
759 return FALSE;
760 }
761
762 int convertQ5bitRate(uint8_t bitRateRead) {
763 uint8_t expected[] = {8, 16, 32, 40, 50, 64, 100, 128};
764 for (int i=0; i<8; i++)
765 if (expected[i] == bitRateRead)
766 return i;
767
768 return -1;
769 }
770
771 bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){
772
773 if ( DemodBufferLen < 64 ) return FALSE;
774 uint8_t si = 0;
775 for (uint8_t idx = 28; idx < 64; idx++){
776 si = idx;
777 if ( PackBits(si, 28, DemodBuffer) == 0x00 ) continue;
778
779 uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key
780 uint8_t resv = PackBits(si, 8, DemodBuffer); si += 8;
781 // 2nibble must be zeroed.
782 if (safer != 0x6 && safer != 0x9) continue;
783 if ( resv > 0x00) continue;
784 //uint8_t pageSel = PackBits(si, 1, DemodBuffer); si += 1;
785 //uint8_t fastWrite = PackBits(si, 1, DemodBuffer); si += 1;
786 si += 1+1;
787 int bitRate = PackBits(si, 6, DemodBuffer)*2 + 2; si += 6; //bit rate
788 if (bitRate > 128 || bitRate < 8) continue;
789
790 //uint8_t AOR = PackBits(si, 1, DemodBuffer); si += 1;
791 //uint8_t PWD = PackBits(si, 1, DemodBuffer); si += 1;
792 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2; //could check psk cr
793 //uint8_t inverse = PackBits(si, 1, DemodBuffer); si += 1;
794 si += 1+1+2+1;
795 uint8_t modread = PackBits(si, 3, DemodBuffer); si += 3;
796 uint8_t maxBlk = PackBits(si, 3, DemodBuffer); si += 3;
797 //uint8_t ST = PackBits(si, 1, DemodBuffer); si += 1;
798 if (maxBlk == 0) continue;
799 //test modulation
800 if (!testQ5Modulation(mode, modread)) continue;
801 if (bitRate != clk) continue;
802 *fndBitRate = convertQ5bitRate(bitRate);
803 if (*fndBitRate < 0) continue;
804 *offset = idx;
805
806 return TRUE;
807 }
808 return FALSE;
809 }
810
811 bool testBitRate(uint8_t readRate, uint8_t clk){
812 uint8_t expected[] = {8, 16, 32, 40, 50, 64, 100, 128};
813 if (expected[readRate] == clk)
814 return true;
815
816 return false;
817 }
818
819 bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5){
820
821 if ( DemodBufferLen < 64 ) return FALSE;
822 uint8_t si = 0;
823 for (uint8_t idx = 28; idx < 64; idx++){
824 si = idx;
825 if ( PackBits(si, 28, DemodBuffer) == 0x00 ) continue;
826
827 uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key
828 uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode
829 // 2nibble must be zeroed.
830 // moved test to here, since this gets most faults first.
831 if ( resv > 0x00) continue;
832
833 uint8_t xtRate = PackBits(si, 3, DemodBuffer); si += 3; //extended mode part of rate
834 int bitRate = PackBits(si, 3, DemodBuffer); si += 3; //bit rate
835 if (bitRate > 7) continue;
836 uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1; //bit 15 extended mode
837 uint8_t modread = PackBits(si, 5, DemodBuffer); si += 5+2+1;
838 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //could check psk cr
839 //uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24, 30, 31 could be tested for 0 if not extended mode
840 //uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;
841
842 //if extended mode
843 bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? TRUE : FALSE;
844
845 if (!extMode){
846 if (xtRate) continue; //nml01 || nml02 || caused issues on noralys tags
847 }
848 //test modulation
849 if (!testModulation(mode, modread)) continue;
850 if (!testBitRate(bitRate, clk)) continue;
851 *fndBitRate = bitRate;
852 *offset = idx;
853 *Q5 = FALSE;
854 return TRUE;
855 }
856 if (testQ5(mode, offset, fndBitRate, clk)) {
857 *Q5 = TRUE;
858 return TRUE;
859 }
860 return FALSE;
861 }
862
863 void printT55xxBlock(const char *blockNum){
864
865 uint8_t i = config.offset;
866 uint8_t endpos = 32 + i;
867 uint32_t blockData = 0;
868 uint8_t bits[64] = {0x00};
869
870 if ( !DemodBufferLen) return;
871
872 if ( endpos > DemodBufferLen){
873 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i, DemodBufferLen-32);
874 return;
875 }
876
877 for (; i < endpos; ++i)
878 bits[i - config.offset] = DemodBuffer[i];
879
880 blockData = PackBits(0, 32, bits);
881 uint8_t bytes[4] = {0};
882 num_to_bytes(blockData, 4, bytes);
883
884 PrintAndLog(" %s | %08X | %s | %s", blockNum, blockData, sprint_bin(bits,32), sprint_ascii(bytes,4));
885 }
886
887 int special(const char *Cmd) {
888 uint32_t blockData = 0;
889 uint8_t bits[32] = {0x00};
890
891 PrintAndLog("OFFSET | DATA | BINARY | ASCII");
892 PrintAndLog("-------+-------+-------------------------------------+------");
893 int i,j = 0;
894 for (; j < 64; ++j){
895
896 for (i = 0; i < 32; ++i)
897 bits[i]=DemodBuffer[j+i];
898
899 blockData = PackBits(0, 32, bits);
900
901 PrintAndLog("%02d | 0x%08X | %s",j , blockData, sprint_bin(bits,32));
902 }
903 return 0;
904 }
905
906 int printConfiguration( t55xx_conf_block_t b){
907 PrintAndLog("Chip Type : %s", (b.Q5) ? "T5555(Q5)" : "T55x7");
908 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b.modulation) );
909 PrintAndLog("Bit Rate : %s", GetBitRateStr(b.bitrate) );
910 PrintAndLog("Inverted : %s", (b.inverted) ? "Yes" : "No" );
911 PrintAndLog("Offset : %d", b.offset);
912 PrintAndLog("Seq. Term. : %s", (b.ST) ? "Yes" : "No" );
913 PrintAndLog("Block0 : 0x%08X", b.block0);
914 PrintAndLog("");
915 return 0;
916 }
917
918 int CmdT55xxWakeUp(const char *Cmd) {
919 uint32_t password = 0;
920 uint8_t cmdp = 0;
921 bool errors = false;
922 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
923 switch(param_getchar(Cmd, cmdp)) {
924 case 'h':
925 case 'H':
926 return usage_t55xx_wakup();
927 case 'p':
928 case 'P':
929 password = param_get32ex(Cmd, cmdp+1, 0, 16);
930 cmdp += 2;
931 errors = false;
932 break;
933 default:
934 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
935 errors = true;
936 break;
937 }
938 }
939 if (errors) return usage_t55xx_wakup();
940
941 UsbCommand c = {CMD_T55XX_WAKEUP, {password, 0, 0}};
942 clearCommandBuffer();
943 SendCommand(&c);
944 PrintAndLog("Wake up command sent. Try read now");
945 return 0;
946 }
947
948 int CmdT55xxWriteBlock(const char *Cmd) {
949 uint8_t block = 0xFF; //default to invalid block
950 uint32_t data = 0; //default to blank Block
951 uint32_t password = 0; //default to blank Block 7
952 bool usepwd = false;
953 bool page1 = false;
954 bool gotdata = false;
955 bool errors = false;
956 uint8_t cmdp = 0;
957 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
958 switch(param_getchar(Cmd, cmdp)) {
959 case 'h':
960 case 'H':
961 return usage_t55xx_write();
962 case 'b':
963 case 'B':
964 errors |= param_getdec(Cmd, cmdp+1, &block);
965 cmdp += 2;
966 break;
967 case 'd':
968 case 'D':
969 data = param_get32ex(Cmd, cmdp+1, 0, 16);
970 gotdata = true;
971 cmdp += 2;
972 break;
973 case 'p':
974 case 'P':
975 password = param_get32ex(Cmd, cmdp+1, 0, 16);
976 usepwd = true;
977 cmdp += 2;
978 break;
979 case '1':
980 page1 = true;
981 cmdp++;
982 break;
983 default:
984 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
985 errors = true;
986 break;
987 }
988 }
989 if (errors || !gotdata) return usage_t55xx_write();
990
991 if (block > 7) {
992 PrintAndLog("Block number must be between 0 and 7");
993 return 0;
994 }
995
996 UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};
997 UsbCommand resp;
998 c.d.asBytes[0] = (page1) ? 0x2 : 0;
999
1000 char pwdStr[16] = {0};
1001 snprintf(pwdStr, sizeof(pwdStr), "pwd: 0x%08X", password);
1002
1003 PrintAndLog("Writing page %d block: %02d data: 0x%08X %s", page1, block, data, (usepwd) ? pwdStr : "" );
1004
1005 //Password mode
1006 if (usepwd) {
1007 c.arg[2] = password;
1008 c.d.asBytes[0] |= 0x1;
1009 }
1010 clearCommandBuffer();
1011 SendCommand(&c);
1012 if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)){
1013 PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)");
1014 return 0;
1015 }
1016 return 1;
1017 }
1018
1019 int CmdT55xxReadTrace(const char *Cmd) {
1020 char cmdp = param_getchar(Cmd, 0);
1021 bool pwdmode = false;
1022 uint32_t password = 0;
1023 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') return usage_t55xx_trace();
1024
1025 if (strlen(Cmd)==0) {
1026 // sanity check.
1027 if (!SanityOfflineCheck(FALSE)) return 1;
1028
1029 if ( !AquireData( T55x7_PAGE1, REGULAR_READ_MODE_BLOCK, pwdmode, password ) )
1030 return 1;
1031 }
1032
1033 if ( config.Q5 ){
1034 if (!DecodeT5555TraceBlock()) return 1;
1035 } else {
1036 if (!DecodeT55xxBlock()) return 1;
1037 }
1038
1039 if ( !DemodBufferLen ) return 1;
1040
1041 RepaintGraphWindow();
1042 uint8_t repeat = (config.offset > 5) ? 32 : 0;
1043
1044 uint8_t si = config.offset + repeat;
1045 uint32_t bl1 = PackBits(si, 32, DemodBuffer);
1046 uint32_t bl2 = PackBits(si+32, 32, DemodBuffer);
1047
1048 if (config.Q5) {
1049 uint32_t hdr = PackBits(si, 9, DemodBuffer); si += 9;
1050
1051 if (hdr != 0x1FF) {
1052 PrintAndLog("Invalid Q5 Trace data header (expected 0x1FF, found %X)", hdr);
1053 return 1;
1054 }
1055
1056 t5555_tracedata_t data = {.bl1 = bl1, .bl2 = bl2, .icr = 0, .lotidc = '?', .lotid = 0, .wafer = 0, .dw =0};
1057
1058 data.icr = PackBits(si, 2, DemodBuffer); si += 2;
1059 data.lotidc = 'Z' - PackBits(si, 2, DemodBuffer); si += 3;
1060
1061 data.lotid = PackBits(si, 4, DemodBuffer); si += 5;
1062 data.lotid <<= 4;
1063 data.lotid |= PackBits(si, 4, DemodBuffer); si += 5;
1064 data.lotid <<= 4;
1065 data.lotid |= PackBits(si, 4, DemodBuffer); si += 5;
1066 data.lotid <<= 4;
1067 data.lotid |= PackBits(si, 4, DemodBuffer); si += 5;
1068 data.lotid <<= 1;
1069 data.lotid |= PackBits(si, 1, DemodBuffer); si += 1;
1070
1071 data.wafer = PackBits(si, 3, DemodBuffer); si += 4;
1072 data.wafer <<= 2;
1073 data.wafer |= PackBits(si, 2, DemodBuffer); si += 2;
1074
1075 data.dw = PackBits(si, 2, DemodBuffer); si += 3;
1076 data.dw <<= 4;
1077 data.dw |= PackBits(si, 4, DemodBuffer); si += 5;
1078 data.dw <<= 4;
1079 data.dw |= PackBits(si, 4, DemodBuffer); si += 5;
1080 data.dw <<= 4;
1081 data.dw |= PackBits(si, 4, DemodBuffer); si += 5;
1082
1083 printT5555Trace(data, repeat);
1084
1085 } else {
1086
1087 t55x7_tracedata_t data = {.bl1 = bl1, .bl2 = bl2, .acl = 0, .mfc = 0, .cid = 0, .year = 0, .quarter = 0, .icr = 0, .lotid = 0, .wafer = 0, .dw = 0};
1088
1089 data.acl = PackBits(si, 8, DemodBuffer); si += 8;
1090 if ( data.acl != 0xE0 ) {
1091 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");
1092 return 1;
1093 }
1094
1095 data.mfc = PackBits(si, 8, DemodBuffer); si += 8;
1096 data.cid = PackBits(si, 5, DemodBuffer); si += 5;
1097 data.icr = PackBits(si, 3, DemodBuffer); si += 3;
1098 data.year = PackBits(si, 4, DemodBuffer); si += 4;
1099 data.quarter = PackBits(si, 2, DemodBuffer); si += 2;
1100 data.lotid = PackBits(si, 14, DemodBuffer); si += 14;
1101 data.wafer = PackBits(si, 5, DemodBuffer); si += 5;
1102 data.dw = PackBits(si, 15, DemodBuffer);
1103
1104 time_t t = time(NULL);
1105 struct tm tm = *localtime(&t);
1106 if ( data.year > tm.tm_year-110)
1107 data.year += 2000;
1108 else
1109 data.year += 2010;
1110
1111 printT55x7Trace(data, repeat);
1112 }
1113 return 0;
1114 }
1115
1116 void printT55x7Trace( t55x7_tracedata_t data, uint8_t repeat ){
1117 PrintAndLog("-- T55x7 Trace Information ----------------------------------");
1118 PrintAndLog("-------------------------------------------------------------");
1119 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", data.acl, data.acl);
1120 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", data.mfc, data.mfc, getTagInfo(data.mfc));
1121 PrintAndLog(" CID : 0x%02X (%d) - %s", data.cid, data.cid, GetModelStrFromCID(data.cid));
1122 PrintAndLog(" ICR IC Revision : %d", data.icr );
1123 PrintAndLog(" Manufactured");
1124 PrintAndLog(" Year/Quarter : %d/%d", data.year, data.quarter);
1125 PrintAndLog(" Lot ID : %d", data.lotid );
1126 PrintAndLog(" Wafer number : %d", data.wafer);
1127 PrintAndLog(" Die Number : %d", data.dw);
1128 PrintAndLog("-------------------------------------------------------------");
1129 PrintAndLog(" Raw Data - Page 1");
1130 PrintAndLog(" Block 1 : 0x%08X %s", data.bl1, sprint_bin(DemodBuffer+config.offset+repeat,32) );
1131 PrintAndLog(" Block 2 : 0x%08X %s", data.bl2, sprint_bin(DemodBuffer+config.offset+repeat+32,32) );
1132 PrintAndLog("-------------------------------------------------------------");
1133
1134 /*
1135 TRACE - BLOCK O
1136 Bits Definition HEX
1137 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
1138 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
1139 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
1140 22-24 ICR IC revision
1141 25-28 YEAR (BCD encoded) 9 (= 2009)
1142 29-30 QUARTER 1,2,3,4
1143 31-32 LOT ID
1144
1145 TRACE - BLOCK 1
1146 1-12 LOT ID
1147 13-17 Wafer number
1148 18-32 DW, die number sequential
1149 */
1150 }
1151
1152 void printT5555Trace( t5555_tracedata_t data, uint8_t repeat ){
1153 PrintAndLog("-- T5555 (Q5) Trace Information -----------------------------");
1154 PrintAndLog("-------------------------------------------------------------");
1155 PrintAndLog(" ICR IC Revision : %d", data.icr );
1156 PrintAndLog(" Lot : %c%d", data.lotidc, data.lotid);
1157 PrintAndLog(" Wafer number : %d", data.wafer);
1158 PrintAndLog(" Die Number : %d", data.dw);
1159 PrintAndLog("-------------------------------------------------------------");
1160 PrintAndLog(" Raw Data - Page 1");
1161 PrintAndLog(" Block 1 : 0x%08X %s", data.bl1, sprint_bin(DemodBuffer+config.offset+repeat,32) );
1162 PrintAndLog(" Block 2 : 0x%08X %s", data.bl2, sprint_bin(DemodBuffer+config.offset+repeat+32,32) );
1163
1164 /*
1165 ** Q5 **
1166 TRACE - BLOCK O and BLOCK1
1167 Bits Definition HEX
1168 1-9 Header 0x1FF
1169 10-11 IC Revision
1170 12-13 Lot ID char
1171 15-35 Lot ID (NB parity)
1172 36-41 Wafer number (NB parity)
1173 42-58 DW, die number sequential (NB parity)
1174 60-63 Parity bits
1175 64 Always zero
1176 */
1177 }
1178
1179 //need to add Q5 info...
1180 int CmdT55xxInfo(const char *Cmd){
1181 /*
1182 Page 0 Block 0 Configuration data.
1183 Normal mode
1184 Extended mode
1185 */
1186 bool pwdmode = false;
1187 uint32_t password = 0;
1188 char cmdp = param_getchar(Cmd, 0);
1189
1190 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') return usage_t55xx_info();
1191
1192 if (strlen(Cmd)==0){
1193 // sanity check.
1194 if (!SanityOfflineCheck(FALSE)) return 1;
1195
1196 if ( !AquireData( T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, pwdmode, password ) )
1197 return 1;
1198 }
1199
1200 if (!DecodeT55xxBlock()) return 1;
1201
1202 // too little space to start with
1203 if ( DemodBufferLen < 32) return 1;
1204
1205 //
1206 PrintAndLog("Offset+32 ==%d\n DemodLen == %d", config.offset + 32,DemodBufferLen );
1207
1208 uint8_t si = config.offset;
1209 uint32_t bl0 = PackBits(si, 32, DemodBuffer);
1210 uint32_t safer = PackBits(si, 4, DemodBuffer); si += 4;
1211 uint32_t resv = PackBits(si, 7, DemodBuffer); si += 7;
1212 uint32_t dbr = PackBits(si, 3, DemodBuffer); si += 3;
1213 uint32_t extend = PackBits(si, 1, DemodBuffer); si += 1;
1214 uint32_t datamod = PackBits(si, 5, DemodBuffer); si += 5;
1215 uint32_t pskcf = PackBits(si, 2, DemodBuffer); si += 2;
1216 uint32_t aor = PackBits(si, 1, DemodBuffer); si += 1;
1217 uint32_t otp = PackBits(si, 1, DemodBuffer); si += 1;
1218 uint32_t maxblk = PackBits(si, 3, DemodBuffer); si += 3;
1219 uint32_t pwd = PackBits(si, 1, DemodBuffer); si += 1;
1220 uint32_t sst = PackBits(si, 1, DemodBuffer); si += 1;
1221 uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;
1222 uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1;
1223 uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;
1224
1225 if (config.Q5) PrintAndLog("*** Warning *** Config Info read off a Q5 will not display as expected");
1226 PrintAndLog("");
1227 PrintAndLog("-- T55x7 Configuration & Tag Information --------------------");
1228 PrintAndLog("-------------------------------------------------------------");
1229 PrintAndLog(" Safer key : %s", GetSaferStr(safer));
1230 PrintAndLog(" reserved : %d", resv);
1231 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr));
1232 PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");
1233 PrintAndLog(" Modulation : %s", GetModulationStr(datamod));
1234 PrintAndLog(" PSK clock frequency : %d", pskcf);
1235 PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");
1236 PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );
1237 PrintAndLog(" Max block : %d", maxblk);
1238 PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");
1239 PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");
1240 PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");
1241 PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");
1242 PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");
1243 PrintAndLog("-------------------------------------------------------------");
1244 PrintAndLog(" Raw Data - Page 0");
1245 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+config.offset,32) );
1246 PrintAndLog("-------------------------------------------------------------");
1247
1248 return 0;
1249 }
1250
1251 int CmdT55xxDump(const char *Cmd){
1252
1253 uint32_t password = 0;
1254 bool override = false;
1255 char cmdp = param_getchar(Cmd, 0);
1256 if ( cmdp == 'h' || cmdp == 'H') return usage_t55xx_dump();
1257
1258 bool usepwd = ( strlen(Cmd) > 0);
1259 if ( usepwd ){
1260 password = param_get32ex(Cmd, 0, 0, 16);
1261 if (param_getchar(Cmd, 1) =='o' )
1262 override = true;
1263 }
1264
1265 printT5xxHeader(0);
1266 for ( uint8_t i = 0; i < 8; ++i)
1267 T55xxReadBlock(i, 0, usepwd, override, password);
1268
1269 printT5xxHeader(1);
1270 for ( uint8_t i = 0; i < 4; i++)
1271 T55xxReadBlock(i, 1, usepwd, override, password);
1272
1273 return 1;
1274 }
1275
1276 int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){
1277 // arg0 bitmodes:
1278 // bit0 = pwdmode
1279 // bit1 = page to read from
1280 // arg1: which block to read
1281 // arg2: password
1282 uint8_t arg0 = (page<<1) | pwdmode;
1283 UsbCommand c = {CMD_T55XX_READ_BLOCK, {arg0, block, password}};
1284 clearCommandBuffer();
1285 SendCommand(&c);
1286 if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
1287 PrintAndLog("command execution time out");
1288 return 0;
1289 }
1290
1291 //uint8_t got[12288];
1292 uint8_t got[7679];
1293 GetFromBigBuf(got, sizeof(got), 0);
1294 if ( !WaitForResponseTimeout(CMD_ACK, NULL, 8000) ) {
1295 PrintAndLog("command execution time out");
1296 return 0;
1297 }
1298 setGraphBuf(got, sizeof(got));
1299 return 1;
1300 }
1301
1302 char * GetBitRateStr(uint32_t id){
1303 static char buf[25];
1304
1305 char *retStr = buf;
1306 switch (id){
1307 case 0: snprintf(retStr,sizeof(buf),"%d - RF/8",id); break;
1308 case 1: snprintf(retStr,sizeof(buf),"%d - RF/16",id); break;
1309 case 2: snprintf(retStr,sizeof(buf),"%d - RF/32",id); break;
1310 case 3: snprintf(retStr,sizeof(buf),"%d - RF/40",id); break;
1311 case 4: snprintf(retStr,sizeof(buf),"%d - RF/50",id); break;
1312 case 5: snprintf(retStr,sizeof(buf),"%d - RF/64",id); break;
1313 case 6: snprintf(retStr,sizeof(buf),"%d - RF/100",id); break;
1314 case 7: snprintf(retStr,sizeof(buf),"%d - RF/128",id); break;
1315 default: snprintf(retStr,sizeof(buf),"%d - (Unknown)",id); break;
1316 }
1317 return buf;
1318 }
1319
1320 char * GetSaferStr(uint32_t id){
1321 static char buf[40];
1322 char *retStr = buf;
1323
1324 snprintf(retStr,sizeof(buf),"%d",id);
1325 if (id == 6) {
1326 snprintf(retStr,sizeof(buf),"%d - passwd",id);
1327 }
1328 if (id == 9 ){
1329 snprintf(retStr,sizeof(buf),"%d - testmode",id);
1330 }
1331
1332 return buf;
1333 }
1334
1335 char * GetModulationStr( uint32_t id){
1336 static char buf[60];
1337 char *retStr = buf;
1338
1339 switch (id){
1340 case 0: snprintf(retStr,sizeof(buf),"%d - DIRECT (ASK/NRZ)",id); break;
1341 case 1: snprintf(retStr,sizeof(buf),"%d - PSK 1 phase change when input changes",id); break;
1342 case 2: snprintf(retStr,sizeof(buf),"%d - PSK 2 phase change on bitclk if input high",id); break;
1343 case 3: snprintf(retStr,sizeof(buf),"%d - PSK 3 phase change on rising edge of input",id); break;
1344 case 4: snprintf(retStr,sizeof(buf),"%d - FSK 1 RF/8 RF/5",id); break;
1345 case 5: snprintf(retStr,sizeof(buf),"%d - FSK 2 RF/8 RF/10",id); break;
1346 case 6: snprintf(retStr,sizeof(buf),"%d - FSK 1a RF/5 RF/8",id); break;
1347 case 7: snprintf(retStr,sizeof(buf),"%d - FSK 2a RF/10 RF/8",id); break;
1348 case 8: snprintf(retStr,sizeof(buf),"%d - Manchester",id); break;
1349 case 16: snprintf(retStr,sizeof(buf),"%d - Biphase",id); break;
1350 case 0x18:snprintf(retStr,sizeof(buf),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id); break;
1351 case 17: snprintf(retStr,sizeof(buf),"%d - Reserved",id); break;
1352 default: snprintf(retStr,sizeof(buf),"0x%02X (Unknown)",id); break;
1353 }
1354 return buf;
1355 }
1356
1357 char * GetModelStrFromCID(uint32_t cid){
1358
1359 static char buf[10];
1360 char *retStr = buf;
1361
1362 if (cid == 1) snprintf(retStr, sizeof(buf),"ATA5577M1");
1363 if (cid == 2) snprintf(retStr, sizeof(buf),"ATA5577M2");
1364 return buf;
1365 }
1366
1367 char * GetSelectedModulationStr( uint8_t id){
1368
1369 static char buf[20];
1370 char *retStr = buf;
1371
1372 switch (id){
1373 case DEMOD_FSK: snprintf(retStr,sizeof(buf),"FSK"); break;
1374 case DEMOD_FSK1: snprintf(retStr,sizeof(buf),"FSK1"); break;
1375 case DEMOD_FSK1a: snprintf(retStr,sizeof(buf),"FSK1a"); break;
1376 case DEMOD_FSK2: snprintf(retStr,sizeof(buf),"FSK2"); break;
1377 case DEMOD_FSK2a: snprintf(retStr,sizeof(buf),"FSK2a"); break;
1378 case DEMOD_ASK: snprintf(retStr,sizeof(buf),"ASK"); break;
1379 case DEMOD_NRZ: snprintf(retStr,sizeof(buf),"DIRECT/NRZ"); break;
1380 case DEMOD_PSK1: snprintf(retStr,sizeof(buf),"PSK1"); break;
1381 case DEMOD_PSK2: snprintf(retStr,sizeof(buf),"PSK2"); break;
1382 case DEMOD_PSK3: snprintf(retStr,sizeof(buf),"PSK3"); break;
1383 case DEMOD_BI: snprintf(retStr,sizeof(buf),"BIPHASE"); break;
1384 case DEMOD_BIa: snprintf(retStr,sizeof(buf),"BIPHASEa - (CDP)"); break;
1385 default: snprintf(retStr,sizeof(buf),"(Unknown)"); break;
1386 }
1387 return buf;
1388 }
1389
1390 void t55x7_create_config_block( int tagtype ){
1391
1392 /*
1393 T55X7_DEFAULT_CONFIG_BLOCK, T55X7_RAW_CONFIG_BLOCK
1394 T55X7_EM_UNIQUE_CONFIG_BLOCK, T55X7_FDXB_CONFIG_BLOCK,
1395 T55X7_FDXB_CONFIG_BLOCK, T55X7_HID_26_CONFIG_BLOCK, T55X7_INDALA_64_CONFIG_BLOCK, T55X7_INDALA_224_CONFIG_BLOCK
1396 T55X7_GUARDPROXII_CONFIG_BLOCK, T55X7_VIKING_CONFIG_BLOCK, T55X7_NORALYS_CONFIG_BLOCK, T55X7_IOPROX_CONFIG_BLOCK
1397 */
1398 static char buf[60];
1399 char *retStr = buf;
1400
1401 switch (tagtype){
1402 case 0: snprintf(retStr, sizeof(buf),"%08X - T55X7 Default", T55X7_DEFAULT_CONFIG_BLOCK); break;
1403 case 1: snprintf(retStr, sizeof(buf),"%08X - T55X7 Raw", T55X7_RAW_CONFIG_BLOCK); break;
1404 case 2: snprintf(retStr, sizeof(buf),"%08X - T5555 Q5 Default", T5555_DEFAULT_CONFIG_BLOCK); break;
1405 default:
1406 break;
1407 }
1408 PrintAndLog(buf);
1409 }
1410
1411 int CmdResetRead(const char *Cmd) {
1412 UsbCommand c = {CMD_T55XX_RESET_READ, {0,0,0}};
1413 clearCommandBuffer();
1414 SendCommand(&c);
1415 if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
1416 PrintAndLog("command execution time out");
1417 return 0;
1418 }
1419
1420 uint8_t got[BIGBUF_SIZE-1];
1421 GetFromBigBuf(got,sizeof(got),0);
1422 WaitForResponse(CMD_ACK,NULL);
1423 setGraphBuf(got, sizeof(got));
1424 return 1;
1425 }
1426 // ADD T5555 (Q5) Default config block
1427 int CmdT55xxWipe(const char *Cmd) {
1428 char writeData[20] = {0};
1429 char *ptrData = writeData;
1430 char cmdp = param_getchar(Cmd, 0);
1431 if ( cmdp == 'h' || cmdp == 'H') return usage_t55xx_wipe();
1432
1433 bool Q5 = (cmdp == 'q' || cmdp == 'Q');
1434
1435 // Try with the default password to reset block 0
1436 // With a pwd should work even if pwd bit not set
1437 PrintAndLog("\nBeginning Wipe of a T55xx tag (assuming the tag is not password protected)\n");
1438
1439 if ( Q5 )
1440 snprintf(ptrData,sizeof(writeData),"b 0 d 6001F004 p 0");
1441 else
1442 snprintf(ptrData,sizeof(writeData),"b 0 d 000880E0 p 0");
1443
1444 if (!CmdT55xxWriteBlock(ptrData)) PrintAndLog("Error writing blk 0");
1445
1446 for (uint8_t blk = 1; blk<8; blk++) {
1447
1448 snprintf(ptrData,sizeof(writeData),"b %d d 0", blk);
1449
1450 if (!CmdT55xxWriteBlock(ptrData)) PrintAndLog("Error writing blk %d", blk);
1451
1452 memset(writeData,0x00, sizeof(writeData));
1453 }
1454 return 0;
1455 }
1456
1457 bool IsCancelled(void) {
1458 if (ukbhit()) {
1459 int ch = getchar();
1460 (void)ch;
1461 printf("\naborted via keyboard!\n");
1462 return TRUE;
1463 }
1464 return FALSE;
1465 }
1466
1467 int CmdT55xxBruteForce(const char *Cmd) {
1468
1469 // load a default pwd file.
1470 char line[9];
1471 char filename[FILE_PATH_SIZE]={0};
1472 int keycnt = 0;
1473 uint8_t stKeyBlock = 20;
1474 uint8_t *keyBlock = NULL, *p = NULL;
1475 uint32_t start_password = 0x00000000; //start password
1476 uint32_t end_password = 0xFFFFFFFF; //end password
1477 bool found = false;
1478
1479 memset(line, 0, sizeof(line));
1480
1481 char cmdp = param_getchar(Cmd, 0);
1482 if (cmdp == 'h' || cmdp == 'H') return usage_t55xx_bruteforce();
1483
1484 keyBlock = calloc(stKeyBlock, 4);
1485 if (keyBlock == NULL) return 1;
1486
1487 if (cmdp == 'i' || cmdp == 'I') {
1488
1489 int len = strlen(Cmd+2);
1490 if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE;
1491 memcpy(filename, Cmd+2, len);
1492
1493 FILE * f = fopen( filename , "r");
1494 if ( !f ) {
1495 PrintAndLog("File: %s: not found or locked.", filename);
1496 free(keyBlock);
1497 return 1;
1498 }
1499
1500 while( fgets(line, sizeof(line), f) ){
1501 if (strlen(line) < 8 || line[7] == '\n') continue;
1502
1503 //goto next line
1504 while (fgetc(f) != '\n' && !feof(f)) ;
1505
1506 //The line start with # is comment, skip
1507 if( line[0]=='#' ) continue;
1508
1509 if (!isxdigit(line[0])) {
1510 PrintAndLog("File content error. '%s' must include 8 HEX symbols", line);
1511 continue;
1512 }
1513
1514 line[8] = 0;
1515
1516 // realloc keyblock array size.
1517 if ( stKeyBlock - keycnt < 2) {
1518 p = realloc(keyBlock, 4 * (stKeyBlock += 10));
1519 if (!p) {
1520 PrintAndLog("Cannot allocate memory for defaultKeys");
1521 free(keyBlock);
1522 if (f)
1523 fclose(f);
1524 return 2;
1525 }
1526 keyBlock = p;
1527 }
1528 // clear mem
1529 memset(keyBlock + 4 * keycnt, 0, 4);
1530
1531 num_to_bytes( strtoll(line, NULL, 16), 4, keyBlock + 4*keycnt);
1532
1533 PrintAndLog("chk custom pwd[%2d] %08X", keycnt, bytes_to_num(keyBlock + 4 * keycnt, 4) );
1534 keycnt++;
1535 memset(line, 0, sizeof(line));
1536 }
1537 if (f)
1538 fclose(f);
1539
1540 if (keycnt == 0) {
1541 PrintAndLog("No keys found in file");
1542 free(keyBlock);
1543 return 1;
1544 }
1545 PrintAndLog("Loaded %d keys", keycnt);
1546
1547 // loop
1548 uint64_t testpwd = 0x00;
1549 for (uint16_t c = 0; c < keycnt; ++c ) {
1550
1551 if ( offline ) {
1552 printf("Device offline\n");
1553 free(keyBlock);
1554 return 2;
1555 }
1556
1557 if (IsCancelled()) {
1558 free(keyBlock);
1559 return 0;
1560 }
1561
1562 testpwd = bytes_to_num(keyBlock + 4*c, 4);
1563
1564 PrintAndLog("Testing %08X", testpwd);
1565
1566 if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, testpwd)) {
1567 PrintAndLog("Acquire data from device failed. Quitting");
1568 free(keyBlock);
1569 return 0;
1570 }
1571
1572 found = tryDetectModulation();
1573 if ( found ) {
1574 PrintAndLog("Found valid password: [%08X]", testpwd);
1575 //free(keyBlock);
1576 //return 0;
1577 }
1578 }
1579 PrintAndLog("Password NOT found.");
1580 free(keyBlock);
1581 return 0;
1582 }
1583
1584 // Try to read Block 7, first :)
1585
1586 // incremental pwd range search
1587 start_password = param_get32ex(Cmd, 0, 0, 16);
1588 end_password = param_get32ex(Cmd, 1, 0, 16);
1589
1590 if ( start_password >= end_password ) {
1591 free(keyBlock);
1592 return usage_t55xx_bruteforce();
1593 }
1594
1595 PrintAndLog("Search password range [%08X -> %08X]", start_password, end_password);
1596
1597 uint32_t i = start_password;
1598
1599 while ((!found) && (i <= end_password)){
1600
1601 printf(".");
1602 fflush(stdout);
1603
1604 if (IsCancelled()) {
1605 free(keyBlock);
1606 return 0;
1607 }
1608
1609 if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, i)) {
1610 PrintAndLog("Acquire data from device failed. Quitting");
1611 free(keyBlock);
1612 return 0;
1613 }
1614 found = tryDetectModulation();
1615
1616 if (found) break;
1617 i++;
1618 }
1619
1620 PrintAndLog("");
1621
1622 if (found)
1623 PrintAndLog("Found valid password: [%08x]", i);
1624 else
1625 PrintAndLog("Password NOT found. Last tried: [%08x]", --i);
1626
1627 free(keyBlock);
1628 return 0;
1629 }
1630
1631 int tryOnePassword(uint32_t password) {
1632 PrintAndLog("Trying password %08x", password);
1633 if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, password)) {
1634 PrintAndLog("Acquire data from device failed. Quitting");
1635 return -1;
1636 }
1637
1638 if (tryDetectModulation())
1639 return 1;
1640 else
1641 return 0;
1642 }
1643
1644 int CmdT55xxRecoverPW(const char *Cmd) {
1645 int bit = 0;
1646 uint32_t orig_password = 0x0;
1647 uint32_t curr_password = 0x0;
1648 uint32_t prev_password = 0xffffffff;
1649 uint32_t mask = 0x0;
1650 int found = 0;
1651 char cmdp = param_getchar(Cmd, 0);
1652 if (cmdp == 'h' || cmdp == 'H') return usage_t55xx_recoverpw();
1653
1654 orig_password = param_get32ex(Cmd, 0, 0x51243648, 16); //password used by handheld cloners
1655
1656 // first try fliping each bit in the expected password
1657 while (bit < 32) {
1658 curr_password = orig_password ^ ( 1 << bit );
1659 found = tryOnePassword(curr_password);
1660 if (found == -1) return 0;
1661 bit++;
1662
1663 if (IsCancelled()) return 0;
1664 }
1665
1666 // now try to use partial original password, since block 7 should have been completely
1667 // erased during the write sequence and it is possible that only partial password has been
1668 // written
1669 // not sure from which end the bit bits are written, so try from both ends
1670 // from low bit to high bit
1671 bit = 0;
1672 while (bit < 32) {
1673 mask += ( 1 << bit );
1674 curr_password = orig_password & mask;
1675 // if updated mask didn't change the password, don't try it again
1676 if (prev_password == curr_password) {
1677 bit++;
1678 continue;
1679 }
1680 found = tryOnePassword(curr_password);
1681 if (found == -1) return 0;
1682 bit++;
1683 prev_password = curr_password;
1684
1685 if (IsCancelled()) return 0;
1686 }
1687
1688 // from high bit to low
1689 bit = 0;
1690 mask = 0xffffffff;
1691 while (bit < 32) {
1692 mask -= ( 1 << bit );
1693 curr_password = orig_password & mask;
1694 // if updated mask didn't change the password, don't try it again
1695 if (prev_password == curr_password) {
1696 bit++;
1697 continue;
1698 }
1699 found = tryOnePassword(curr_password);
1700 if (found == -1)
1701 return 0;
1702 bit++;
1703 prev_password = curr_password;
1704
1705 if (IsCancelled()) return 0;
1706 }
1707
1708 PrintAndLog("");
1709
1710 if (found == 1)
1711 PrintAndLog("Found valid password: [%08x]", curr_password);
1712 else
1713 PrintAndLog("Password NOT found.");
1714
1715 return 0;
1716 }
1717
1718 static command_t CommandTable[] = {
1719 {"help", CmdHelp, 1, "This help"},
1720 {"bruteforce", CmdT55xxBruteForce,0, "<start password> <end password> [i <*.dic>] Simple bruteforce attack to find password"},
1721 {"config", CmdT55xxSetConfig, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},
1722 {"detect", CmdT55xxDetect, 1, "[1] Try detecting the tag modulation from reading the configuration block."},
1723 {"dump", CmdT55xxDump, 0, "[password] [o] Dump T55xx card block 0-7. Optional [password], [override]"},
1724 {"info", CmdT55xxInfo, 1, "[1] Show T55x7 configuration data (page 0/ blk 0)"},
1725 {"read", CmdT55xxReadBlock, 0, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"},
1726 {"resetread", CmdResetRead, 0, "Send Reset Cmd then lf read the stream to attempt to identify the start of it (needs a demod and/or plot after)"},
1727 {"recoverpw", CmdT55xxRecoverPW, 0, "[password] Try to recover from bad password write from a cloner. Only use on PW protected chips!"},
1728 {"special", special, 0, "Show block changes with 64 different offsets"},
1729 {"trace", CmdT55xxReadTrace, 1, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"},
1730 {"wakeup", CmdT55xxWakeUp, 0, "Send AOR wakeup command"},
1731 {"wipe", CmdT55xxWipe, 0, "[q] Wipe a T55xx tag and set defaults (will destroy any data on tag)"},
1732 {"write", CmdT55xxWriteBlock,0, "b <block> d <data> p [password] [1] -- Write T55xx block data. Optional [p password], [page1]"},
1733 {NULL, NULL, 0, NULL}
1734 };
1735
1736 int CmdLFT55XX(const char *Cmd) {
1737 clearCommandBuffer();
1738 CmdsParse(CommandTable, Cmd);
1739 return 0;
1740 }
1741
1742 int CmdHelp(const char *Cmd) {
1743 CmdsHelp(CommandTable);
1744 return 0;
1745 }
Impressum, Datenschutz