diff --git a/client/cmdanalyse.c b/client/cmdanalyse.c index 338f8c9d7..267f3ce48 100644 --- a/client/cmdanalyse.c +++ b/client/cmdanalyse.c @@ -12,58 +12,58 @@ static int CmdHelp(const char *Cmd); int usage_analyse_lcr(void) { - PrintAndLog("Specifying the bytes of a UID with a known LRC will find the last byte value"); - PrintAndLog("needed to generate that LRC with a rolling XOR. All bytes should be specified in HEX."); - PrintAndLog(""); - PrintAndLog("Usage: analyse lcr [h] "); - PrintAndLog("Options:"); - PrintAndLog(" h This help"); - PrintAndLog(" bytes to calc missing XOR in a LCR"); - PrintAndLog(""); - PrintAndLog("Examples:"); - PrintAndLog(" analyse lcr 04008064BA"); - PrintAndLog("expected output: Target (BA) requires final LRC XOR byte value: 5A"); + PrintAndLogEx(NORMAL, "Specifying the bytes of a UID with a known LRC will find the last byte value"); + PrintAndLogEx(NORMAL, "needed to generate that LRC with a rolling XOR. All bytes should be specified in HEX."); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Usage: analyse lcr [h] "); + PrintAndLogEx(NORMAL, "Options:"); + PrintAndLogEx(NORMAL, " h This help"); + PrintAndLogEx(NORMAL, " bytes to calc missing XOR in a LCR"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, " analyse lcr 04008064BA"); + PrintAndLogEx(NORMAL, "expected output: Target (BA) requires final LRC XOR byte value: 5A"); return 0; } int usage_analyse_checksum(void) { - PrintAndLog("The bytes will be added with eachother and than limited with the applied mask"); - PrintAndLog("Finally compute ones' complement of the least significant bytes"); - PrintAndLog(""); - PrintAndLog("Usage: analyse chksum [h] [v] b m "); - PrintAndLog("Options:"); - PrintAndLog(" h This help"); - PrintAndLog(" v supress header"); - PrintAndLog(" b bytes to calc missing XOR in a LCR"); - PrintAndLog(" m bit mask to limit the outpuyt"); - PrintAndLog(""); - PrintAndLog("Examples:"); - PrintAndLog(" analyse chksum b 137AF00A0A0D m FF"); - PrintAndLog("expected output: 0x61"); + PrintAndLogEx(NORMAL, "The bytes will be added with eachother and than limited with the applied mask"); + PrintAndLogEx(NORMAL, "Finally compute ones' complement of the least significant bytes"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Usage: analyse chksum [h] [v] b m "); + PrintAndLogEx(NORMAL, "Options:"); + PrintAndLogEx(NORMAL, " h This help"); + PrintAndLogEx(NORMAL, " v supress header"); + PrintAndLogEx(NORMAL, " b bytes to calc missing XOR in a LCR"); + PrintAndLogEx(NORMAL, " m bit mask to limit the outpuyt"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, " analyse chksum b 137AF00A0A0D m FF"); + PrintAndLogEx(NORMAL, "expected output: 0x61"); return 0; } int usage_analyse_crc(void){ - PrintAndLog("A stub method to test different crc implementations inside the PM3 sourcecode. Just because you figured out the poly, doesn't mean you get the desired output"); - PrintAndLog(""); - PrintAndLog("Usage: analyse crc [h] "); - PrintAndLog("Options:"); - PrintAndLog(" h This help"); - PrintAndLog(" bytes to calc crc"); - PrintAndLog(""); - PrintAndLog("Examples:"); - PrintAndLog(" analyse crc 137AF00A0A0D"); + PrintAndLogEx(NORMAL, "A stub method to test different crc implementations inside the PM3 sourcecode. Just because you figured out the poly, doesn't mean you get the desired output"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Usage: analyse crc [h] "); + PrintAndLogEx(NORMAL, "Options:"); + PrintAndLogEx(NORMAL, " h This help"); + PrintAndLogEx(NORMAL, " bytes to calc crc"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, " analyse crc 137AF00A0A0D"); return 0; } int usage_analyse_nuid(void){ - PrintAndLog("Generate 4byte NUID from 7byte UID"); - PrintAndLog(""); - PrintAndLog("Usage: analyse hid [h] "); - PrintAndLog("Options:"); - PrintAndLog(" h This help"); - PrintAndLog(" input bytes (14 hexsymbols)"); - PrintAndLog(""); - PrintAndLog("Examples:"); - PrintAndLog(" analyse nuid 11223344556677"); + PrintAndLogEx(NORMAL, "Generate 4byte NUID from 7byte UID"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Usage: analyse hid [h] "); + PrintAndLogEx(NORMAL, "Options:"); + PrintAndLogEx(NORMAL, " h This help"); + PrintAndLogEx(NORMAL, " input bytes (14 hexsymbols)"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, " analyse nuid 11223344556677"); return 0; } @@ -218,8 +218,8 @@ int CmdAnalyseLfsr(const char *Cmd){ uint8_t iv = param_get8ex(Cmd, 0, 0, 16); uint8_t find = param_get8ex(Cmd, 1, 0, 16); - printf("LEGIC LFSR IV 0x%02X: \n", iv); - printf(" bit# | lfsr | ^0x40 | 0x%02X ^ lfsr \n",find); + PrintAndLogEx(NORMAL, "LEGIC LFSR IV 0x%02X: \n", iv); + PrintAndLogEx(NORMAL, " bit# | lfsr | ^0x40 | 0x%02X ^ lfsr \n",find); for (uint8_t i = 0x01; i < 0x30; i += 1) { //period = 0; @@ -227,7 +227,7 @@ int CmdAnalyseLfsr(const char *Cmd){ legic_prng_forward(i); lfsr = legic_prng_get_bits(12); - printf(" %02X | %03X | %03X | %03X \n",i, lfsr, 0x40 ^ lfsr, find ^ lfsr); + PrintAndLogEx(NORMAL, " %02X | %03X | %03X | %03X \n",i, lfsr, 0x40 ^ lfsr, find ^ lfsr); } return 0; } @@ -241,7 +241,7 @@ int CmdAnalyseLCR(const char *Cmd) { if ( len%2 ) return usage_analyse_lcr(); len >>= 1; uint8_t finalXor = calculateLRC(data, len); - PrintAndLog("Target [%02X] requires final LRC XOR byte value: 0x%02X",data[len-1] ,finalXor); + PrintAndLogEx(NORMAL, "Target [%02X] requires final LRC XOR byte value: 0x%02X",data[len-1] ,finalXor); return 0; } int CmdAnalyseCRC(const char *Cmd) { @@ -262,73 +262,73 @@ int CmdAnalyseCRC(const char *Cmd) { } len >>= 1; - PrintAndLog("\nTests with (%d) | %s",len, sprint_hex(data, len)); + PrintAndLogEx(NORMAL, "\nTests with (%d) | %s",len, sprint_hex(data, len)); // 51 f5 7a d6 uint8_t uid[] = {0x51, 0xf5, 0x7a, 0xd6}; //12 34 56 init_table(CRC_LEGIC); uint8_t legic8 = CRC8Legic(uid, sizeof(uid)); - PrintAndLog("Legic 16 | %X (EF6F expected) [legic8 = %02x]", crc16_legic(data, len, legic8), legic8); + PrintAndLogEx(NORMAL, "Legic 16 | %X (EF6F expected) [legic8 = %02x]", crc16_legic(data, len, legic8), legic8); init_table(CRC_FELICA); - PrintAndLog("FeliCa | %X ", crc16_xmodem(data, len)); + PrintAndLogEx(NORMAL, "FeliCa | %X ", crc16_xmodem(data, len)); - PrintAndLog("\nTests of reflection. Current methods in source code"); - PrintAndLog(" reflect(0x3e23L,3) is %04X == 0x3e26", reflect(0x3e23L,3) ); - PrintAndLog(" reflect8(0x80) is %02X == 0x01", reflect8(0x80)); - PrintAndLog(" reflect16(0x8000) is %04X == 0x0001", reflect16(0xc6c6)); + PrintAndLogEx(NORMAL, "\nTests of reflection. Current methods in source code"); + PrintAndLogEx(NORMAL, " reflect(0x3e23L,3) is %04X == 0x3e26", reflect(0x3e23L,3) ); + PrintAndLogEx(NORMAL, " reflect8(0x80) is %02X == 0x01", reflect8(0x80)); + PrintAndLogEx(NORMAL, " reflect16(0x8000) is %04X == 0x0001", reflect16(0xc6c6)); // // Test of CRC16, '123456789' string. // uint8_t b1, b2; - printf("\n\nStandard test with 31 32 33 34 35 36 37 38 39 '123456789'\n\n"); + PrintAndLogEx(NORMAL, "\n\nStandard test with 31 32 33 34 35 36 37 38 39 '123456789'\n\n"); uint8_t dataStr[] = { 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39 }; legic8 = CRC8Legic(dataStr, sizeof(dataStr)); //these below has been tested OK. - PrintAndLog("Confirmed CRC Implementations"); - printf("-------------------------------------\n"); - printf("CRC 8 based\n\n"); - PrintAndLog("LEGIC: CRC8 : %X (C6 expected)", legic8); - PrintAndLog("MAXIM: CRC8 : %X (A1 expected)", CRC8Maxim(dataStr, sizeof(dataStr))); - printf("-------------------------------------\n"); - printf("CRC16 based\n\n"); + PrintAndLogEx(NORMAL, "Confirmed CRC Implementations"); + PrintAndLogEx(NORMAL, "-------------------------------------\n"); + PrintAndLogEx(NORMAL, "CRC 8 based\n\n"); + PrintAndLogEx(NORMAL, "LEGIC: CRC8 : %X (C6 expected)", legic8); + PrintAndLogEx(NORMAL, "MAXIM: CRC8 : %X (A1 expected)", CRC8Maxim(dataStr, sizeof(dataStr))); + PrintAndLogEx(NORMAL, "-------------------------------------\n"); + PrintAndLogEx(NORMAL, "CRC16 based\n\n"); // input from commandline - PrintAndLog("CCITT | %X (29B1 expected)", crc(CRC_CCITT, dataStr, sizeof(dataStr))); + PrintAndLogEx(NORMAL, "CCITT | %X (29B1 expected)", crc(CRC_CCITT, dataStr, sizeof(dataStr))); uint8_t poll[] = {0xb2,0x4d,0x12,0x01,0x01,0x2e,0x3d,0x17,0x26,0x47,0x80, 0x95,0x00,0xf1,0x00,0x00,0x00,0x01,0x43,0x00,0xb3,0x7f}; - PrintAndLog("FeliCa | %X (B37F expected)", crc(CRC_FELICA, poll+2, sizeof(poll)-4)); - PrintAndLog("FeliCa | %X (0000 expected)", crc(CRC_FELICA, poll+2, sizeof(poll)-2)); + PrintAndLogEx(NORMAL, "FeliCa | %X (B37F expected)", crc(CRC_FELICA, poll+2, sizeof(poll)-4)); + PrintAndLogEx(NORMAL, "FeliCa | %X (0000 expected)", crc(CRC_FELICA, poll+2, sizeof(poll)-2)); uint8_t sel_corr[] = { 0x40, 0xe1, 0xe1, 0xff, 0xfe, 0x5f, 0x02, 0x3c, 0x43, 0x01}; - PrintAndLog("iCLASS | %04x (0143 expected)", crc(CRC_ICLASS, sel_corr, sizeof(sel_corr)-2)); - printf("---------------------------------------------------------------\n\n\n"); + PrintAndLogEx(NORMAL, "iCLASS | %04x (0143 expected)", crc(CRC_ICLASS, sel_corr, sizeof(sel_corr)-2)); + PrintAndLogEx(NORMAL, "---------------------------------------------------------------\n\n\n"); // ISO14443 crc A compute_crc(CRC_14443_A, dataStr, sizeof(dataStr), &b1, &b2); uint16_t crcAA = b1 << 8 | b2; - printf("ISO14443 crc A | %04x or %04x (BF05 expected)\n", crcAA, crc(CRC_14443_A, dataStr, sizeof(dataStr)) ); + PrintAndLogEx(NORMAL, "ISO14443 crc A | %04x or %04x (BF05 expected)\n", crcAA, crc(CRC_14443_A, dataStr, sizeof(dataStr)) ); // ISO14443 crc B compute_crc(CRC_14443_B, dataStr, sizeof(dataStr), &b1, &b2); uint16_t crcBB = b1 << 8 | b2; - printf("ISO14443 crc B | %04x or %04x (906E expected)\n", crcBB, crc(CRC_14443_B, dataStr, sizeof(dataStr)) ); + PrintAndLogEx(NORMAL, "ISO14443 crc B | %04x or %04x (906E expected)\n", crcBB, crc(CRC_14443_B, dataStr, sizeof(dataStr)) ); // ISO15693 crc (x.25) compute_crc(CRC_15693, dataStr, sizeof(dataStr), &b1, &b2); uint16_t crcCC = b1 << 8 | b2; - printf("ISO15693 crc X25| %04x or %04x (906E expected)\n", crcCC, crc(CRC_15693, dataStr, sizeof(dataStr)) ); + PrintAndLogEx(NORMAL, "ISO15693 crc X25| %04x or %04x (906E expected)\n", crcCC, crc(CRC_15693, dataStr, sizeof(dataStr)) ); // ICLASS compute_crc(CRC_ICLASS, dataStr, sizeof(dataStr), &b1, &b2); uint16_t crcDD = b1 << 8 | b2; - printf("ICLASS crc | %04x or %04x\n", crcDD, crc(CRC_ICLASS, dataStr, sizeof(dataStr)) ); + PrintAndLogEx(NORMAL, "ICLASS crc | %04x or %04x\n", crcDD, crc(CRC_ICLASS, dataStr, sizeof(dataStr)) ); // FeliCa compute_crc(CRC_FELICA, dataStr, sizeof(dataStr), &b1, &b2); uint16_t crcEE = b1 << 8 | b2; - printf("FeliCa | %04x or %04x (31C3 expected)\n", crcEE, crc(CRC_FELICA, dataStr, sizeof(dataStr))); + PrintAndLogEx(NORMAL, "FeliCa | %04x or %04x (31C3 expected)\n", crcEE, crc(CRC_FELICA, dataStr, sizeof(dataStr))); free(data); return 0; @@ -366,7 +366,7 @@ int CmdAnalyseCHKSUM(const char *Cmd){ case 'H': return usage_analyse_checksum(); default: - PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp)); + PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); errors = true; break; } @@ -375,11 +375,11 @@ int CmdAnalyseCHKSUM(const char *Cmd){ if (errors || cmdp == 0 ) return usage_analyse_checksum(); if (useHeader) { - PrintAndLog(" add | sub | add 1's compl | sub 1's compl | xor"); - PrintAndLog("byte nibble crumb | byte nibble | byte nibble cumb | byte nibble | byte nibble cumb | BSD |"); - PrintAndLog("------------------+-------------+------------------+-----------------+--------------------"); + PrintAndLogEx(NORMAL, " add | sub | add 1's compl | sub 1's compl | xor"); + PrintAndLogEx(NORMAL, "byte nibble crumb | byte nibble | byte nibble cumb | byte nibble | byte nibble cumb | BSD |"); + PrintAndLogEx(NORMAL, "------------------+-------------+------------------+-----------------+--------------------"); } - PrintAndLog("0x%X 0x%X 0x%X | 0x%X 0x%X | 0x%X 0x%X 0x%X | 0x%X 0x%X | 0x%X 0x%X 0x%X | 0x%X 0x%X |\n", + PrintAndLogEx(NORMAL, "0x%X 0x%X 0x%X | 0x%X 0x%X | 0x%X 0x%X 0x%X | 0x%X 0x%X | 0x%X 0x%X 0x%X | 0x%X 0x%X |\n", calcSumByteAdd(data, len, mask) , calcSumNibbleAdd(data, len, mask) , calcSumCrumbAdd(data, len, mask) @@ -401,7 +401,7 @@ int CmdAnalyseCHKSUM(const char *Cmd){ int CmdAnalyseDates(const char *Cmd){ // look for datestamps in a given array of bytes - PrintAndLog("To be implemented. Feel free to contribute!"); + PrintAndLogEx(NORMAL, "To be implemented. Feel free to contribute!"); return 0; } int CmdAnalyseTEASelfTest(const char *Cmd){ @@ -415,7 +415,7 @@ int CmdAnalyseTEASelfTest(const char *Cmd){ cmdlen = ( sizeof(v)<<2 < cmdlen ) ? sizeof(v)<<2 : cmdlen; if ( param_gethex(Cmd, 0, v, cmdlen) > 0 ){ - PrintAndLog("can't read hex chars, uneven? :: %u", cmdlen); + PrintAndLogEx(WARNING, "Can't read hex chars, uneven? :: %u", cmdlen); return 1; } @@ -427,14 +427,14 @@ int CmdAnalyseTEASelfTest(const char *Cmd){ uint8_t* key_ptr = keyle; SwapEndian64ex(key , sizeof(key), 4, key_ptr); - PrintAndLog("TEST LE enc| %s", sprint_hex(v_ptr, 8)); + PrintAndLogEx(NORMAL, "TEST LE enc| %s", sprint_hex(v_ptr, 8)); tea_decrypt(v_ptr, key_ptr); - PrintAndLog("TEST LE dec | %s", sprint_hex_ascii(v_ptr, 8)); + PrintAndLogEx(NORMAL, "TEST LE dec | %s", sprint_hex_ascii(v_ptr, 8)); tea_encrypt(v_ptr, key_ptr); tea_encrypt(v_ptr, key_ptr); - PrintAndLog("TEST enc2 | %s", sprint_hex_ascii(v_ptr, 8)); + PrintAndLogEx(NORMAL, "TEST enc2 | %s", sprint_hex_ascii(v_ptr, 8)); return 0; } @@ -467,15 +467,15 @@ int CmdAnalyseA(const char *Cmd){ UsbCommand resp; if ( !WaitForResponseTimeout(CMD_ACK, &resp, 2000) ) { - PrintAndLog("timeout while waiting for reply."); + PrintAndLogEx(NORMAL, "timeout while waiting for reply."); return 1; } return 0; - printf("-- " _BLUE_(its my message) "\n"); - printf("-- " _RED_(its my message) "\n"); - printf("-- " _YELLOW_(its my message) "\n"); - printf("-- " _GREEN_(its my message) "\n"); + PrintAndLogEx(NORMAL, "-- " _BLUE_(its my message) "\n"); + PrintAndLogEx(NORMAL, "-- " _RED_(its my message) "\n"); + PrintAndLogEx(NORMAL, "-- " _YELLOW_(its my message) "\n"); + PrintAndLogEx(NORMAL, "-- " _GREEN_(its my message) "\n"); //uint8_t syncBit = 99; // The start bit is one ore more Sequence Y followed by a Sequence Z (... 11111111 00x11111). We need to distinguish from @@ -488,18 +488,18 @@ int CmdAnalyseA(const char *Cmd){ uint8_t byte_offset = 99; // reverse byte uint8_t rev = reflect8(bt); - printf("input %02x | %02x \n", bt, rev); + PrintAndLogEx(NORMAL, "input %02x | %02x \n", bt, rev); // add byte to shift register shiftReg = shiftReg << 8 | rev; - printf("shiftreg after %08x | pattern %08x \n", shiftReg, SYNC_16BIT); + PrintAndLogEx(NORMAL, "shiftreg after %08x | pattern %08x \n", shiftReg, SYNC_16BIT); uint8_t n0 = 0, n1 = 0; n0 = (rev & (uint8_t)(~(0xFF >> (8-4)))) >> 4; n1 = (n1 << 4) | (rev & (uint8_t)(~(0xFF << 4))); - printf("rev %02X | %02X %s | %02X %s |\n", rev, n0, pb(n0), n1, pb(n1) ); + PrintAndLogEx(NORMAL, "rev %02X | %02X %s | %02X %s |\n", rev, n0, pb(n0), n1, pb(n1) ); /* hex(0xb24d shr 0) 0xB24D 0b1011001001001101 @@ -508,7 +508,7 @@ hex(0xb24d shr 2) 0x2C93 */ for ( int i =0; i< 16; i++) { - printf(" (shiftReg >> %d) & 0xFFFF == %08x ---", i, (( shiftReg >> i) & 0xFFFF )); + PrintAndLogEx(NORMAL, " (shiftReg >> %d) & 0xFFFF == %08x ---", i, (( shiftReg >> i) & 0xFFFF )); // kolla om SYNC_PATTERN finns. if ((( shiftReg >> 7) & 0xFFFF ) == SYNC_16BIT) byte_offset = 7; @@ -520,7 +520,7 @@ for ( int i =0; i< 16; i++) { else if ((( shiftReg >> 1) & 0xFFFF ) == SYNC_16BIT) byte_offset = 1; else if ((( shiftReg >> 0) & 0xFFFF ) == SYNC_16BIT) byte_offset = 0; - printf("Offset %u \n", byte_offset); + PrintAndLogEx(NORMAL, "Offset %u \n", byte_offset); if ( byte_offset != 99 ) break; @@ -528,7 +528,7 @@ for ( int i =0; i< 16; i++) { } uint8_t p1 = (rev & (uint8_t)(~(0xFF << byte_offset))); - printf("Offset %u | leftovers %02x %s \n", byte_offset, p1, pb(p1) ); + PrintAndLogEx(NORMAL, "Offset %u | leftovers %02x %s \n", byte_offset, p1, pb(p1) ); @@ -545,17 +545,17 @@ pm3 --> da hex2bin 4db2 0100110110110010 n0 = (rev & (uint8_t)(~(0xFF >> (8-offset)))) >> offset; n1 = (n1 << offset) | (rev & (uint8_t)(~(0xFF << offset))); - printf("rev %02X | %02X %s | %02X %s |\n", rev, n0, pb(n0), n1, pb(n1) ); + PrintAndLogEx(NORMAL, "rev %02X | %02X %s | %02X %s |\n", rev, n0, pb(n0), n1, pb(n1) ); n0 = 0, n1 = 0; - // printf(" (0xFF >> offset) == %s |\n", pb( (0xFF >> offset)) ); - //printf("~(0xFF >> (8-offset)) == %s |\n", pb( (uint8_t)(~(0xFF >> (8-offset))) ) ); - //printf(" rev & xxx == %s\n\n", pb( (rev & (uint8_t)(~(0xFF << offset))) )); + // PrintAndLogEx(NORMAL, " (0xFF >> offset) == %s |\n", pb( (0xFF >> offset)) ); + //PrintAndLogEx(NORMAL, "~(0xFF >> (8-offset)) == %s |\n", pb( (uint8_t)(~(0xFF >> (8-offset))) ) ); + //PrintAndLogEx(NORMAL, " rev & xxx == %s\n\n", pb( (rev & (uint8_t)(~(0xFF << offset))) )); } return 0; // from A -- x bits into B and the rest into C. for ( uint8_t i=0; i<8; i++){ - printf("%u | %02X %s | %02X %s |\n", i, a, pb(a), b, pb(b) ); + PrintAndLogEx(NORMAL, "%u | %02X %s | %02X %s |\n", i, a, pb(a), b, pb(b) ); b = a & (a & (0xFF >> (8-i))); a >>=1; } @@ -566,32 +566,32 @@ return 0; // 14443-A uint8_t u14_c[] = {0x09, 0x78, 0x00, 0x92, 0x02, 0x54, 0x13, 0x02, 0x04, 0x2d, 0xe8 }; // atqs w crc uint8_t u14_w[] = {0x09, 0x78, 0x00, 0x92, 0x02, 0x54, 0x13, 0x02, 0x04, 0x2d, 0xe7 }; // atqs w crc - printf("14a check wrong crc | %s\n", (check_crc(CRC_14443_A, u14_w, sizeof(u14_w))) ? "YES": "NO" ); - printf("14a check correct crc | %s\n", (check_crc(CRC_14443_A, u14_c, sizeof(u14_c))) ? "YES": "NO" ); + PrintAndLogEx(FAILED, "14a check wrong crc | %s\n", (check_crc(CRC_14443_A, u14_w, sizeof(u14_w))) ? "YES": "NO" ); + PrintAndLogEx(SUCCESS, "14a check correct crc | %s\n", (check_crc(CRC_14443_A, u14_c, sizeof(u14_c))) ? "YES": "NO" ); // 14443-B uint8_t u14b[] = {0x05,0x00,0x08,0x39,0x73}; - printf("14b check crc | %s\n", (check_crc(CRC_14443_B, u14b, sizeof(u14b))) ? "YES": "NO"); + PrintAndLogEx(NORMAL, "14b check crc | %s\n", (check_crc(CRC_14443_B, u14b, sizeof(u14b))) ? "YES": "NO"); // 15693 test uint8_t u15_c[] = {0x05,0x00,0x08,0x39,0x73}; // correct uint8_t u15_w[] = {0x05,0x00,0x08,0x39,0x72}; // wrong - printf("15 check wrong crc | %s\n", (check_crc(CRC_15693, u15_w, sizeof(u15_w))) ? "YES": "NO"); - printf("15 check correct crc | %s\n", (check_crc(CRC_15693, u15_c, sizeof(u15_c))) ? "YES": "NO"); + PrintAndLogEx(FAILED, "15 check wrong crc | %s\n", (check_crc(CRC_15693, u15_w, sizeof(u15_w))) ? "YES": "NO"); + PrintAndLogEx(SUCCESS, "15 check correct crc | %s\n", (check_crc(CRC_15693, u15_c, sizeof(u15_c))) ? "YES": "NO"); // iCLASS test - wrong crc , swapped bytes. uint8_t iclass_w[] = { 0x40, 0xe1, 0xe1, 0xff, 0xfe, 0x5f, 0x02, 0x3c, 0x01, 0x43}; uint8_t iclass_c[] = { 0x40, 0xe1, 0xe1, 0xff, 0xfe, 0x5f, 0x02, 0x3c, 0x43, 0x01}; - printf("iCLASS check wrong crc | %s\n", (check_crc(CRC_ICLASS, iclass_w, sizeof(iclass_w))) ? "YES": "NO"); - printf("iCLASS check correct crc | %s\n", (check_crc(CRC_ICLASS, iclass_c, sizeof(iclass_c))) ? "YES": "NO"); + PrintAndLogEx(FAILED, "iCLASS check wrong crc | %s\n", (check_crc(CRC_ICLASS, iclass_w, sizeof(iclass_w))) ? "YES": "NO"); + PrintAndLogEx(SUCCESS, "iCLASS check correct crc | %s\n", (check_crc(CRC_ICLASS, iclass_c, sizeof(iclass_c))) ? "YES": "NO"); // FeliCa test uint8_t felica_w[] = {0x12,0x01,0x01,0x2e,0x3d,0x17,0x26,0x47,0x80, 0x95,0x00,0xf1,0x00,0x00,0x00,0x01,0x43,0x00,0xb3,0x7e}; uint8_t felica_c[] = {0x12,0x01,0x01,0x2e,0x3d,0x17,0x26,0x47,0x80, 0x95,0x00,0xf1,0x00,0x00,0x00,0x01,0x43,0x00,0xb3,0x7f}; - printf("FeliCa check wrong crc | %s\n", (check_crc(CRC_FELICA, felica_w, sizeof(felica_w))) ? "YES": "NO"); - printf("FeliCa check correct crc | %s\n", (check_crc(CRC_FELICA, felica_c, sizeof(felica_c))) ? "YES": "NO"); + PrintAndLogEx(FAILED, "FeliCa check wrong crc | %s\n", (check_crc(CRC_FELICA, felica_w, sizeof(felica_w))) ? "YES": "NO"); + PrintAndLogEx(SUCCESS, "FeliCa check correct crc | %s\n", (check_crc(CRC_FELICA, felica_c, sizeof(felica_c))) ? "YES": "NO"); - printf("\n\n"); + PrintAndLogEx(NORMAL, "\n\n"); return 0; /* @@ -604,7 +604,7 @@ return 0; star[3] = '/'; for (uint8_t k=0; k<4; k = (k+1) % 4 ) { - printf("\e[s%c\e[u", star[k]); + PrintAndLogEx(NORMAL, "\e[s%c\e[u", star[k]); fflush(stdout); if (ukbhit()) { int gc = getchar(); (void)gc; @@ -648,12 +648,12 @@ uint64_t d2[] = {0x6e442129, 0x8f699195, 0x0000004, 0, 0x00040f0f0305030e}; keycountB = nonce2key(d2[0], d2[1], d2[2], 0, d2[3], d2[4], &keylistB); switch (keycountA) { - case 0: printf("Key test A failed\n"); break; - case 1: printf("KEY A | %012" PRIX64 " ", keylistA[0]); break; + case 0: PrintAndLogEx(FAILED, "Key test A failed\n"); break; + case 1: PrintAndLogEx(SUCCESS, "KEY A | %012" PRIX64 " ", keylistA[0]); break; } switch (keycountB) { - case 0: printf("Key test B failed\n"); break; - case 1: printf("KEY B | %012" PRIX64 " ", keylistB[0]); break; + case 0: PrintAndLogEx(FAILED, "Key test B failed\n"); break; + case 1: PrintAndLogEx(SUCCESS, "KEY B | %012" PRIX64 " ", keylistB[0]); break; } free(keylistA); @@ -738,7 +738,7 @@ uint64_t d2[] = {0x6e442129, 0x8f699195, 0x0000004, 0, 0x00040f0f0305030e}; /* for (uint8_t i=0; i<31; i++){ uint64_t a = keys[i] ^ keys[i+1]; - printf("%u | %012" PRIX64 " | \n", i, a); + PrintAndLogEx(NORMAL, "%u | %012" PRIX64 " | \n", i, a); } */ @@ -756,8 +756,8 @@ uint64_t d2[] = {0x6e442129, 0x8f699195, 0x0000004, 0, 0x00040f0f0305030e}; 0x2F }; - printf("UID | %s\n", sprint_hex(uid,4 )); - printf("KEY A | %s\n", sprint_hex(key_s0a, 6)); + PrintAndLogEx(NORMAL, "UID | %s\n", sprint_hex(uid,4 )); + PrintAndLogEx(NORMAL, "KEY A | %s\n", sprint_hex(key_s0a, 6)); // arrays w all keys uint64_t foo[32] = {0}; @@ -777,7 +777,7 @@ uint64_t d2[] = {0x6e442129, 0x8f699195, 0x0000004, 0, 0x00040f0f0305030e}; uint64_t a = foo[i]; uint64_t b = foo[i+16]; - printf("%02u | %012" PRIX64 " %s | %012" PRIX64 " %s\n", + PrintAndLogEx(NORMAL, "%02u | %012" PRIX64 " %s | %012" PRIX64 " %s\n", i, a, ( a == keya[i])?"ok":"err", @@ -821,9 +821,9 @@ int CmdAnalyseNuid(const char *Cmd){ memcpy(uid, "\x04\x0d\x68\x1a\xb5\x22\x81", 7); generate4bNUID(uid, nuid); if ( 0 == memcmp(nuid, "\x8f\x43\x0f\xef", 4)) - printf("Selftest OK\n"); + PrintAndLogEx(SUCCESS, "Selftest OK\n"); else - printf("Selftest Failed\n"); + PrintAndLogEx(FAILED, "Selftest Failed\n"); return 0; } @@ -832,8 +832,8 @@ int CmdAnalyseNuid(const char *Cmd){ generate4bNUID(uid, nuid); - printf("UID | %s \n", sprint_hex(uid, 7)); - printf("NUID | %s \n", sprint_hex(nuid, 4)); + PrintAndLogEx(NORMAL, "UID | %s \n", sprint_hex(uid, 7)); + PrintAndLogEx(NORMAL, "NUID | %s \n", sprint_hex(nuid, 4)); return 0; } static command_t CommandTable[] = {