From a5b406bffa75b8e65dd532743f288ad251486c2e Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 24 Jun 2020 11:33:19 +0200 Subject: [PATCH 01/84] chg: empty call to powershell.exe triggers colors on ProxSpace --- pm3 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pm3 b/pm3 index 771dce77d..d9d402cf2 100755 --- a/pm3 +++ b/pm3 @@ -354,6 +354,12 @@ else echo >&2 "[!!] Script ran under unknown name, abort: $SCRIPT" exit 1 fi + +HOSTOS=$(uname | awk '{print toupper($0)}') +if [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then + $(powershell.exe -command "Out-Null") +fi + if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then HELP exit 0 @@ -389,7 +395,6 @@ if [ "$1" == "-n" ]; then fi fi -HOSTOS=$(uname | awk '{print toupper($0)}') if [ "$HOSTOS" = "LINUX" ]; then if uname -a|grep -q Microsoft; then # Test presence of wmic From c2df7ed824aab8543bd031614cfca70565e6f56a Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 24 Jun 2020 11:51:00 +0200 Subject: [PATCH 02/84] chg: trigger colorsmode (proxspace) in direct calls to client --- client/src/proxmark3.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/src/proxmark3.c b/client/src/proxmark3.c index d820e297d..50d7d660b 100644 --- a/client/src/proxmark3.c +++ b/client/src/proxmark3.c @@ -641,7 +641,6 @@ finish2: #if defined(_WIN32) static bool DetectWindowsAnsiSupport(void) { - bool ret = false; HKEY hKey = NULL; bool virtualTerminalLevelSet = false; bool forceV2Set = false; @@ -681,9 +680,15 @@ static bool DetectWindowsAnsiSupport(void) { } RegCloseKey(hKey); } + + HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD dwMode = 0; + GetConsoleMode(hOut, &dwMode); + dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; + SetConsoleMode(hOut, dwMode); + // If both VirtualTerminalLevel and ForceV2 is set, AnsiColor should work - ret = virtualTerminalLevelSet && forceV2Set; - return ret; + return virtualTerminalLevelSet && forceV2Set; } #endif From 4daa8aac2c4c3981a993fe2258c158111bf1207b Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 24 Jun 2020 11:53:00 +0200 Subject: [PATCH 03/84] Revert "chg: empty call to powershell.exe triggers colors on ProxSpace" This reverts commit a5b406bffa75b8e65dd532743f288ad251486c2e. --- pm3 | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pm3 b/pm3 index d9d402cf2..771dce77d 100755 --- a/pm3 +++ b/pm3 @@ -354,12 +354,6 @@ else echo >&2 "[!!] Script ran under unknown name, abort: $SCRIPT" exit 1 fi - -HOSTOS=$(uname | awk '{print toupper($0)}') -if [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then - $(powershell.exe -command "Out-Null") -fi - if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then HELP exit 0 @@ -395,6 +389,7 @@ if [ "$1" == "-n" ]; then fi fi +HOSTOS=$(uname | awk '{print toupper($0)}') if [ "$HOSTOS" = "LINUX" ]; then if uname -a|grep -q Microsoft; then # Test presence of wmic From c47679b5dd752f84bf20fe1094bac7f3c4e353a1 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 24 Jun 2020 22:13:41 +0200 Subject: [PATCH 04/84] addition --- client/resources/aid_desfire.json | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/client/resources/aid_desfire.json b/client/resources/aid_desfire.json index 206e003a0..6c444c920 100644 --- a/client/resources/aid_desfire.json +++ b/client/resources/aid_desfire.json @@ -10,11 +10,19 @@ { "AID": "D3494F", "Vendor": "HID", - "Country": "United States", + "Country": "US", "Name": "SIO DESFire Ev1", - "Description": "", + "Description": "Genuine HID", "Type": "pacs" }, + { + "AID": "D9494F", + "Vendor": "HID", + "Country": "US", + "Name": "Access control", + "Description": "Genuine HID", + "Type": "pacs" + } { "AID": "4F5931", "Vendor": "Transport of London", @@ -321,4 +329,5 @@ FFFFFF General Issuer Information (FIDs 00: MAD Version; 01: Card Holder; 02: Ca "Description": "CAR2GO - Member Card", "Type": "carsharing" } + ] From 2878a8d481591fb2bc1b657d5d0950200d1a4b43 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 24 Jun 2020 22:18:41 +0200 Subject: [PATCH 05/84] missing semi --- client/resources/aid_desfire.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/resources/aid_desfire.json b/client/resources/aid_desfire.json index 6c444c920..926bb1475 100644 --- a/client/resources/aid_desfire.json +++ b/client/resources/aid_desfire.json @@ -12,7 +12,7 @@ "Vendor": "HID", "Country": "US", "Name": "SIO DESFire Ev1", - "Description": "Genuine HID", + "Description": "Field Encoder", "Type": "pacs" }, { @@ -22,7 +22,7 @@ "Name": "Access control", "Description": "Genuine HID", "Type": "pacs" - } + }, { "AID": "4F5931", "Vendor": "Transport of London", From 173c1702e99b504e6bfc001cc40a3e82473866e4 Mon Sep 17 00:00:00 2001 From: Monster Date: Thu, 25 Jun 2020 12:15:51 +0300 Subject: [PATCH 06/84] Add support for new "Mikron JSC Russia" UL tag. --- client/src/cmdhfmfu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index a93caf510..da2071fb7 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -1088,8 +1088,8 @@ uint32_t GetHF14AMfU_Type(void) { MF0UNH1001DUx 0004030203000B03 NT2L1001G0DUx 0004040102000B03 NT2H1001G0DUx 0004040202000B03 + Micron UL 0034210101000E03 */ - if (memcmp(version, "\x00\x04\x03\x01\x01\x00\x0B", 7) == 0) { tagtype = UL_EV1_48; break; } else if (memcmp(version, "\x00\x04\x03\x01\x02\x00\x0B", 7) == 0) { tagtype = UL_NANO_40; break; } else if (memcmp(version, "\x00\x04\x03\x02\x01\x00\x0B", 7) == 0) { tagtype = UL_EV1_48; break; } @@ -1106,6 +1106,7 @@ uint32_t GetHF14AMfU_Type(void) { else if (memcmp(version, "\x00\x04\x04\x05\x02\x01\x15", 7) == 0) { tagtype = NTAG_I2C_2K; break; } else if (memcmp(version, "\x00\x04\x04\x05\x02\x02\x13", 7) == 0) { tagtype = NTAG_I2C_1K_PLUS; break; } else if (memcmp(version, "\x00\x04\x04\x05\x02\x02\x15", 7) == 0) { tagtype = NTAG_I2C_2K_PLUS; break; } + else if (memcmp(version, "\x00\x34\x21\x01\x01\x00\x0E", 7) == 0) { tagtype = UL; break; } else if (version[2] == 0x04) { tagtype = NTAG; break; } else if (version[2] == 0x03) { tagtype = UL_EV1; } break; From 7c2fe1e8e6e03fadd311d43d53331d1236e5d0b5 Mon Sep 17 00:00:00 2001 From: Aram Date: Thu, 25 Jun 2020 21:09:18 +0200 Subject: [PATCH 07/84] Show usage menu for invalid/missing commands --- client/src/cmdlfhitag.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/src/cmdlfhitag.c b/client/src/cmdlfhitag.c index b05405465..b80c84522 100644 --- a/client/src/cmdlfhitag.c +++ b/client/src/cmdlfhitag.c @@ -572,6 +572,7 @@ static int CmdLFHitagReader(const char *Cmd) { // No additional parameters needed break; } + default: case RHT1F_PLAIN: case RHT1F_AUTHENTICATE: case WHTSF_CHALLENGE: @@ -680,6 +681,7 @@ static int CmdLFHitagWriter(const char *Cmd) { num_to_bytes(param_get32ex(Cmd, 3, 0, 16), 4, htd.crypto.data); break; } + default: case RHT1F_PLAIN: case RHT1F_AUTHENTICATE: case RHTSF_CHALLENGE: From 6484bd641c24d3c92648caa306cac1f1c4b1b3c4 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 00:04:41 +0200 Subject: [PATCH 08/84] textual --- client/src/cmdlfio.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/client/src/cmdlfio.c b/client/src/cmdlfio.c index 92f914059..5e729fd82 100644 --- a/client/src/cmdlfio.c +++ b/client/src/cmdlfio.c @@ -47,12 +47,12 @@ static int usage_lf_io_sim(void) { PrintAndLogEx(NORMAL, "Usage: lf io sim [h] "); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " : 8bit version (decimal)"); - PrintAndLogEx(NORMAL, " : 8bit value facility code (hex)"); - PrintAndLogEx(NORMAL, " : 16bit value card number (decimal)"); + PrintAndLogEx(NORMAL, " : 8bit version (" _YELLOW_("decimal") ")"); + PrintAndLogEx(NORMAL, " : 8bit value facility code (" _YELLOW_("hex") ")"); + PrintAndLogEx(NORMAL, " : 16bit value card number (" _YELLOW_("decimal") ")"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf io sim 26 101 1337")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf io sim 01 101 1337")); return PM3_SUCCESS; } @@ -63,13 +63,13 @@ static int usage_lf_io_clone(void) { PrintAndLogEx(NORMAL, "Usage: lf io clone [h] [Q5]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " : 8bit version (decimal)"); - PrintAndLogEx(NORMAL, " : 8bit value facility code (hex)"); - PrintAndLogEx(NORMAL, " : 16bit value card number (decimal)"); + PrintAndLogEx(NORMAL, " : 8bit version (" _YELLOW_("decimal") ")"); + PrintAndLogEx(NORMAL, " : 8bit value facility code (" _YELLOW_("hex") ")"); + PrintAndLogEx(NORMAL, " : 16bit value card number (" _YELLOW_("decimal") ")"); PrintAndLogEx(NORMAL, " Q5 : optional - clone to Q5 (T5555) instead of T55x7 chip"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf io clone 26 101 1337")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf io clone 01 101 1337")); return PM3_SUCCESS; } From f4c91bc3aa75560afe22c591844c76b8db5afba6 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 00:43:56 +0200 Subject: [PATCH 09/84] space --- client/src/cmdhf.c | 2 +- client/src/cmdlf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/cmdhf.c b/client/src/cmdhf.c index 26723ca6a..989211f1b 100644 --- a/client/src/cmdhf.c +++ b/client/src/cmdhf.c @@ -231,7 +231,7 @@ int CmdHFTune(const char *Cmd) { } uint16_t volt = resp.data.asDwords[0] & 0xFFFF; - PrintAndLogEx(INPLACE, "%u mV / %2u V", volt, (uint16_t)(volt / 1000)); + PrintAndLogEx(INPLACE, " %u mV / %2u V", volt, (uint16_t)(volt / 1000)); } mode[0] = 3; diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 9403dc208..ace50f2d7 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -286,7 +286,7 @@ static int CmdLFTune(const char *Cmd) { } uint32_t volt = resp.data.asDwords[0]; - PrintAndLogEx(INPLACE, "%u mV / %3u V", volt, (uint32_t)(volt / 1000)); + PrintAndLogEx(INPLACE, " %u mV / %3u V", volt, (uint32_t)(volt / 1000)); } params[0] = 3; From 9ad944c4a1cbe946c04343bd170446ead5d195e1 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 12:02:32 +0200 Subject: [PATCH 10/84] color,text --- client/src/cmdlfawid.c | 12 ++-- client/src/cmdlfguard.c | 8 +-- client/src/cmdlfio.c | 15 ++-- client/src/cmdlfparadox.c | 134 ++++++++++++++++++++++++++---------- client/src/cmdlfpyramid.c | 12 ++-- client/src/cmdlfsecurakey.c | 4 +- 6 files changed, 122 insertions(+), 63 deletions(-) diff --git a/client/src/cmdlfawid.c b/client/src/cmdlfawid.c index c42c719f0..a6fb9f81b 100644 --- a/client/src/cmdlfawid.c +++ b/client/src/cmdlfawid.c @@ -290,21 +290,21 @@ static int CmdAWIDDemod(const char *Cmd) { fc = bytebits_to_byte(bits + 9, 8); cardnum = bytebits_to_byte(bits + 17, 16); code1 = bytebits_to_byte(bits + 8, fmtLen); - PrintAndLogEx(SUCCESS, "AWID Found - BitLength: %d, FC: %d, Card: %u - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "AWID Found - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi2, rawHi, rawLo); break; case 34: fc = bytebits_to_byte(bits + 9, 8); cardnum = bytebits_to_byte(bits + 17, 24); code1 = bytebits_to_byte(bits + 8, (fmtLen - 32)); code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32); - PrintAndLogEx(SUCCESS, "AWID Found - BitLength: %d, FC: %d, Card: %u - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "AWID Found - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo); break; case 37: fc = bytebits_to_byte(bits + 9, 13); cardnum = bytebits_to_byte(bits + 22, 18); code1 = bytebits_to_byte(bits + 8, (fmtLen - 32)); code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32); - PrintAndLogEx(SUCCESS, "AWID Found - BitLength: %d, FC: %d, Card: %u - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "AWID Found - len: " _GREEN_("%d")" FC: " _GREEN_("%d")" Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo); break; // case 40: // break; @@ -313,18 +313,18 @@ static int CmdAWIDDemod(const char *Cmd) { cardnum = bytebits_to_byte(bits + 25, 32); code1 = bytebits_to_byte(bits + 8, (fmtLen - 32)); code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32); - PrintAndLogEx(SUCCESS, "AWID Found - BitLength: %d, FC: %d, Card: %u - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "AWID Found - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo); break; default: if (fmtLen > 32) { cardnum = bytebits_to_byte(bits + 8 + (fmtLen - 17), 16); code1 = bytebits_to_byte(bits + 8, fmtLen - 32); code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32); - PrintAndLogEx(SUCCESS, "AWID Found - BitLength: %d -unknown BitLength- (%u) - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, code2, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "AWID Found - len: " _GREEN_("%d") " -unknown- (%u) - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, cardnum, code1, code2, rawHi2, rawHi, rawLo); } else { cardnum = bytebits_to_byte(bits + 8 + (fmtLen - 17), 16); code1 = bytebits_to_byte(bits + 8, fmtLen); - PrintAndLogEx(SUCCESS, "AWID Found - BitLength: %d -unknown BitLength- (%u) - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "AWID Found - len: " _GREEN_("%d") " -unknown- (%u) - Wiegand: " _GREEN_("%x") ", Raw: %08x%08x%08x", fmtLen, cardnum, code1, rawHi2, rawHi, rawLo); } break; } diff --git a/client/src/cmdlfguard.c b/client/src/cmdlfguard.c index 22579a54b..db67a3568 100644 --- a/client/src/cmdlfguard.c +++ b/client/src/cmdlfguard.c @@ -38,7 +38,7 @@ static int usage_lf_guard_clone(void) { PrintAndLogEx(NORMAL, " : 16-bit value card number"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf gprox clone 26 123 11223"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf gprox clone 26 123 11223")); return PM3_SUCCESS; } @@ -55,7 +55,7 @@ static int usage_lf_guard_sim(void) { PrintAndLogEx(NORMAL, " : 16-bit value card number"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf gprox sim 26 123 11223"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf gprox sim 26 123 11223")); return PM3_SUCCESS; } @@ -139,9 +139,9 @@ static int CmdGuardDemod(const char *Cmd) { break; } if (!unknown) - PrintAndLogEx(SUCCESS, "G-Prox-II Found: Format Len: %ubit - FC: %u - Card: %u, Raw: %08x%08x%08x", fmtLen, FC, Card, raw1, raw2, raw3); + PrintAndLogEx(SUCCESS, "G-Prox-II found - Fmt: " _GREEN_("%u")"bit FC: " _GREEN_("%u") " Card: " _GREEN_("%u") ", Raw: %08x%08x%08x", fmtLen, FC, Card, raw1, raw2, raw3); else - PrintAndLogEx(SUCCESS, "Unknown G-Prox-II Fmt Found: Format Len: %u, Raw: %08x%08x%08x", fmtLen, raw1, raw2, raw3); + PrintAndLogEx(SUCCESS, "Unknown G-Prox-II found - Fmt: %u, Raw: %08x%08x%08x", fmtLen, raw1, raw2, raw3); return PM3_SUCCESS; } diff --git a/client/src/cmdlfio.c b/client/src/cmdlfio.c index 5e729fd82..5502786b6 100644 --- a/client/src/cmdlfio.c +++ b/client/src/cmdlfio.c @@ -166,22 +166,21 @@ static int CmdIOProxDemod(const char *Cmd) { calccrc &= 0xff; calccrc = 0xff - calccrc; - char crcStr[30]; - memset(crcStr, 0x00, sizeof(crcStr)); + char crc_str[30] = {0}; if (crc == calccrc) { - snprintf(crcStr, 3, "ok"); - + snprintf(crc_str, sizeof(crc_str), "(" _GREEN_("ok") ")" ); } else { - PrintAndLogEx(DEBUG, "DEBUG: Error - IO prox crc failed"); - - snprintf(crcStr, sizeof(crcStr), "failed 0x%02X != 0x%02X", crc, calccrc); + snprintf(crc_str, sizeof(crc_str), "(" _RED_("fail") ") 0x%02X != 0x%02X", crc, calccrc); retval = PM3_ESOFT; } - PrintAndLogEx(SUCCESS, "IO Prox XSF(%02d)%02x:%05d (%08x%08x) [crc %s]", version, facilitycode, number, code, code2, crcStr); + PrintAndLogEx(SUCCESS, "IO Prox XSF(%02d)%02x:%05d (%08x%08x) %s", version, facilitycode, number, code, code2, crc_str); if (g_debugMode) { + if (crc != calccrc) + PrintAndLogEx(DEBUG, "DEBUG: Error - IO prox crc failed"); + PrintAndLogEx(DEBUG, "DEBUG: IO prox idx: %d, Len: %zu, Printing demod buffer:", idx, size); printDemodBuff(); } diff --git a/client/src/cmdlfparadox.c b/client/src/cmdlfparadox.c index c94e17cf7..662ea781c 100644 --- a/client/src/cmdlfparadox.c +++ b/client/src/cmdlfparadox.c @@ -24,6 +24,7 @@ #include "lfdemod.h" #include "protocols.h" // t55xx defines #include "cmdlft55xx.h" // clone.. +#include "crc.h" // maxim static int CmdHelp(const char *Cmd); @@ -36,7 +37,7 @@ static int usage_lf_paradox_clone(void) { PrintAndLogEx(NORMAL, " b : raw hex data. 12 bytes max"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf paradox clone b 0f55555695596a6a9999a59a"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf paradox clone b 0f55555695596a6a9999a59a")); return PM3_SUCCESS; } @@ -53,16 +54,33 @@ static int usage_lf_paradox_sim(void) { PrintAndLogEx(NORMAL, " : 16-bit value card number"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf paradox sim 123 11223"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf paradox sim 123 11223")); return PM3_SUCCESS; } */ +const uint8_t paradox_lut[] = { + 0xDB, 0xFC, 0x3F, 0xC5, 0x50, 0x14, 0x05, 0x47, + 0x9F, 0xED, 0x7D, 0x59, 0x22, 0x84, 0x21, 0x4E, + 0x39, 0x48, 0x12, 0x88, 0x53, 0xDE, 0xBB, 0xE4, + 0xB4, 0x2D, 0x4D, 0x55, 0xCA, 0xBE, 0xA3, 0xE2 + }; +// FC:108, Card01827 +// 00000000 01101100 00000111 00100011 +// hex(0xED xor 0x7D xor 0x22 xor 0x84 xor 0xDE xor 0xBB xor 0xE4 xor 0x4D xor 0xA3 xor 0xE2 xor 0x47) 0xFC + +#define PARADOX_PREAMBLE_LEN 8 + +static int CmdParadoxDemod(const char *Cmd) { + (void)Cmd; // Cmd is not used so far + return demodParadox(); +} + //by marshmellow //Paradox Prox demod - FSK2a RF/50 with preamble of 00001111 (then manchester encoded) //print full Paradox Prox ID and some bit format details if found -static int CmdParadoxDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + +int demodParadox(void) { //raw fsk demod no manchester decoding no start bit finding just get binary from wave uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0}; size_t size = getFromGraphBuf(bits); @@ -71,12 +89,10 @@ static int CmdParadoxDemod(const char *Cmd) { return PM3_ESOFT; } - uint32_t hi2 = 0, hi = 0, lo = 0; - int waveIdx = 0; + int wave_idx = 0; //get binary from fsk wave - int idx = detectParadox(bits, &size, &hi2, &hi, &lo, &waveIdx); + int idx = detectParadox(bits, &size, &wave_idx); if (idx < 0) { - if (idx == -1) PrintAndLogEx(DEBUG, "DEBUG: Error - Paradox not enough samples"); else if (idx == -2) @@ -85,16 +101,52 @@ static int CmdParadoxDemod(const char *Cmd) { PrintAndLogEx(DEBUG, "DEBUG: Error - Paradox problem during FSK demod"); else if (idx == -4) PrintAndLogEx(DEBUG, "DEBUG: Error - Paradox preamble not found"); - else if (idx == -5) - PrintAndLogEx(DEBUG, "DEBUG: Error - Paradox error in Manchester data, size %zu", size); else PrintAndLogEx(DEBUG, "DEBUG: Error - Paradox error demoding fsk %d", idx); return PM3_ESOFT; } + uint8_t *b = bits + idx; + uint8_t rawhex[12] = {0}; + for (uint8_t i = 0, m = 0, p = 1; i < 96; i++) { + + // convert hex + rawhex[m] <<= 1; + rawhex[m] |= (*b & 1); + b++; + + if (p == 8) { + m++; + p = 1; + } else { + p++; + } + } + + uint32_t hi2 = 0, hi = 0, lo = 0; + uint8_t error = 0; + + // Remove manchester encoding from FSK bits, skip pre + for (uint8_t i = idx + PARADOX_PREAMBLE_LEN; i < (idx + 96 - PARADOX_PREAMBLE_LEN ); i += 2) { + + // not manchester data + if (bits[i] == bits[i + 1]) { + PrintAndLogEx(WARNING, "Error Manchester at %u", i); + error++; + } + + hi2 = (hi2 << 1) | (hi >> 31); + hi = (hi << 1) | (lo >> 31); + lo <<= 1; + + if (bits[i] && !bits[i + 1]) { + lo |= 1; // 10 + } + } + setDemodBuff(bits, size, idx); - setClockGrid(50, waveIdx + (idx * 50)); + setClockGrid(50, wave_idx + (idx * 50)); if (hi2 == 0 && hi == 0 && lo == 0) { PrintAndLogEx(DEBUG, "DEBUG: Error - Paradox no value found"); @@ -103,15 +155,41 @@ static int CmdParadoxDemod(const char *Cmd) { uint32_t fc = ((hi & 0x3) << 6) | (lo >> 26); uint32_t cardnum = (lo >> 10) & 0xFFFF; + uint8_t chksum = (lo >> 2) & 0xFF; + + + // Calc CRC & Checksum + // 000088f0b - FC: 8 - Card: 36619 - Checksum: 05 - RAW: 0f55555559595aa559a5566a + // checksum? + uint8_t calc_chksum = 0x47; + uint8_t pos = 0; + for(uint8_t i = 0; i < 8; i++ ) { + + uint8_t ice = rawhex[i+1]; + for(uint8_t j = 0x80; j > 0; j >>= 2) { + + if (ice & j) { + calc_chksum ^= paradox_lut[pos]; + } + pos++; + } + } + + uint32_t crc = CRC8Maxim(rawhex + 1, 8); + PrintAndLogEx(DEBUG, " FSK/MAN raw : %s", sprint_hex(rawhex, sizeof(rawhex))); + PrintAndLogEx(DEBUG, " raw : %s = (maxim crc8) %02x == %02x", sprint_hex(rawhex + 1, 8), crc, calc_chksum); +// PrintAndLogEx(DEBUG, " OTHER sample CRC-8/MAXIM : 55 55 69 A5 55 6A 59 5A = FC"); + uint32_t rawLo = bytebits_to_byte(bits + idx + 64, 32); uint32_t rawHi = bytebits_to_byte(bits + idx + 32, 32); uint32_t rawHi2 = bytebits_to_byte(bits + idx, 32); - PrintAndLogEx(NORMAL, "Paradox TAG ID: %x%08x - FC: %d - Card: %d - Checksum: %02x - RAW: %08x%08x%08x", + PrintAndLogEx(INFO, "Paradox TAG ID: " _GREEN_("%x%08x") " - FC: " _GREEN_("%d") ", CN: " _GREEN_("%d") " - Checksum: %02x - RAW: %08x%08x%08x", hi >> 10, (hi & 0x3) << 26 | (lo >> 10), - fc, cardnum, - (lo >> 2) & 0xFF, + fc, + cardnum, + chksum, rawHi2, rawHi, rawLo @@ -244,43 +322,25 @@ int CmdLFParadox(const char *Cmd) { } // loop to get raw paradox waveform then FSK demodulate the TAG ID from it -int detectParadox(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx) { +int detectParadox(uint8_t *dest, size_t *size, int *wave_start_idx) { //make sure buffer has data if (*size < 96 * 50) return -1; if (getSignalProperties()->isnoise) return -2; // FSK demodulator - *size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // paradox fsk2a + *size = fskdemod(dest, *size, 50, 1, 10, 8, wave_start_idx); // paradox fsk2a //did we get a good demod? if (*size < 96) return -3; // 00001111 bit pattern represent start of frame, 01 pattern represents a 0 and 10 represents a 1 - size_t startIdx = 0; + size_t idx = 0; uint8_t preamble[] = {0, 0, 0, 0, 1, 1, 1, 1}; - if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx)) + if (!preambleSearch(dest, preamble, sizeof(preamble), size, &idx)) return -4; //preamble not found - size_t numStart = startIdx + sizeof(preamble); - // final loop, go over previously decoded FSK data and manchester decode into usable tag ID - for (size_t idx = numStart; (idx - numStart) < *size - sizeof(preamble); idx += 2) { - if (dest[idx] == dest[idx + 1]) - return -5; //not manchester data - - *hi2 = (*hi2 << 1) | (*hi >> 31); - *hi = (*hi << 1) | (*lo >> 31); - //Then, shift in a 0 or one into low - *lo <<= 1; - if (dest[idx] && !dest[idx + 1]) // 1 0 - *lo |= 1; - else // 0 1 - *lo |= 0; - } - return (int)startIdx; + return (int)idx; } -int demodParadox(void) { - return CmdParadoxDemod(""); -} diff --git a/client/src/cmdlfpyramid.c b/client/src/cmdlfpyramid.c index 03a9a751c..65004f897 100644 --- a/client/src/cmdlfpyramid.c +++ b/client/src/cmdlfpyramid.c @@ -43,7 +43,7 @@ static int usage_lf_pyramid_clone(void) { PrintAndLogEx(NORMAL, " Q5 : optional - clone to Q5 (T5555) instead of T55x7 chip"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf pyramid clone 123 11223"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf pyramid clone 123 11223")); return PM3_SUCCESS; } @@ -60,7 +60,7 @@ static int usage_lf_pyramid_sim(void) { PrintAndLogEx(NORMAL, " : 16-bit value card number"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf pyramid sim 123 11223"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf pyramid sim 123 11223")); return PM3_SUCCESS; } @@ -181,12 +181,12 @@ int demodPyramid(void) { uint32_t fc = bytebits_to_byte(bits + 73, 8); uint32_t cardnum = bytebits_to_byte(bits + 81, 16); uint32_t code1 = bytebits_to_byte(bits + 72, fmtLen); - PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d, FC: %d, Card: %d - Wiegand: %x, Raw: %08x%08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi3, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d, FC: " _GREEN_("%d") " Card: " _GREEN_("%d") " - Wiegand: " _GREEN_("%x")", Raw: %08x%08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi3, rawHi2, rawHi, rawLo); } else if (fmtLen == 45) { fmtLen = 42; //end = 10 bits not 7 like 26 bit fmt uint32_t fc = bytebits_to_byte(bits + 53, 10); uint32_t cardnum = bytebits_to_byte(bits + 63, 32); - PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d, FC: %d, Card: %d - Raw: %08x%08x%08x%08x", fmtLen, fc, cardnum, rawHi3, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d, FC: " _GREEN_("%d") " Card: " _GREEN_("%d") " - Raw: %08x%08x%08x%08x", fmtLen, fc, cardnum, rawHi3, rawHi2, rawHi, rawLo); /* } else if (fmtLen > 32) { uint32_t cardnum = bytebits_to_byte(bits + 81, 16); @@ -197,13 +197,13 @@ int demodPyramid(void) { } else { uint32_t cardnum = bytebits_to_byte(bits + 81, 16); //uint32_t code1 = bytebits_to_byte(bits+(size-fmtLen),fmtLen); - PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d -unknown BitLength- (%d), Raw: %08x%08x%08x%08x", fmtLen, cardnum, rawHi3, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d -unknown BitLength- Card: " _GREEN_("%d") ", Raw: %08x%08x%08x%08x", fmtLen, cardnum, rawHi3, rawHi2, rawHi, rawLo); } PrintAndLogEx(DEBUG, "DEBUG: Pyramid: checksum : 0x%02X - %02X - %s" , checksum , checkCS - , (checksum == checkCS) ? _GREEN_("Passed") : _RED_("Fail") + , (checksum == checkCS) ? _GREEN_("ok") : _RED_("fail") ); PrintAndLogEx(DEBUG, "DEBUG: Pyramid: idx: %d, Len: %d, Printing Demod Buffer:", idx, 128); diff --git a/client/src/cmdlfsecurakey.c b/client/src/cmdlfsecurakey.c index 4b01afe2d..3fd689360 100644 --- a/client/src/cmdlfsecurakey.c +++ b/client/src/cmdlfsecurakey.c @@ -118,9 +118,9 @@ int demodSecurakey(void) { // test parities - evenparity32 looks to add an even parity returns 0 if already even... bool parity = !evenparity32(lWiegand) && !oddparity32(rWiegand); - PrintAndLogEx(SUCCESS, "Securakey Tag Found--BitLen: %u, Card ID: %u, FC: 0x%X, Raw: %08X%08X%08X", bitLen, cardid, fc, raw1, raw2, raw3); + PrintAndLogEx(SUCCESS, "Securakey Tag Found--BitLen: " _GREEN_("%u") ", Card ID: " _GREEN_("%u") ", FC: " _GREEN_("0x%X")" Raw: %08X%08X%08X", bitLen, cardid, fc, raw1, raw2, raw3); if (bitLen <= 32) - PrintAndLogEx(SUCCESS, "Wiegand: %08X, Parity: %s", (lWiegand << (bitLen / 2)) | rWiegand, parity ? "Passed" : "Failed"); + PrintAndLogEx(SUCCESS, "Wiegand: " _GREEN_("%08X") ", Parity: %s", (lWiegand << (bitLen / 2)) | rWiegand, parity ? _GREEN_("ok") : _RED_("fail")); PrintAndLogEx(INFO, "\nHow the FC translates to printed FC is unknown"); PrintAndLogEx(INFO, "How the checksum is calculated is unknown"); From dbc2fb188a98b4f93ded774d76bab30f2c65c44d Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 12:02:57 +0200 Subject: [PATCH 11/84] text,color --- client/src/cmdlfgallagher.c | 8 ++++---- client/src/cmdlfparadox.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/cmdlfgallagher.c b/client/src/cmdlfgallagher.c index 30d836072..010fbaf47 100644 --- a/client/src/cmdlfgallagher.c +++ b/client/src/cmdlfgallagher.c @@ -36,7 +36,7 @@ static int usage_lf_gallagher_clone(void) { PrintAndLogEx(NORMAL, " b : raw hex data. 12 bytes max"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf gallagher clone b 0FFD5461A9DA1346B2D1AC32 "); + PrintAndLogEx(NORMAL, _YELLOW_(" lf gallagher clone b 0FFD5461A9DA1346B2D1AC32")); return PM3_SUCCESS; } @@ -127,10 +127,10 @@ static int CmdGallagherDemod(const char *Cmd) { // 4bit issue level uint8_t il = arr[7] & 0x0F; - PrintAndLogEx(SUCCESS, "GALLAGHER Tag Found -- Region: %u FC: %u CN: %u Issue Level: %u", rc, fc, cn, il); - PrintAndLogEx(SUCCESS, " Printed: %C%u", rc + 0x40, fc); + PrintAndLogEx(SUCCESS, "GALLAGHER Tag Found -- Region: " _GREEN_("%u") " FC: " _GREEN_("%u") " CN: " _GREEN_("%u") " Issue Level: " _GREEN_("%u"), rc, fc, cn, il); + PrintAndLogEx(SUCCESS, " Printed: " _GREEN_("%C%u"), rc + 0x40, fc); PrintAndLogEx(SUCCESS, " Raw: %08X%08X%08X", raw1, raw2, raw3); - PrintAndLogEx(SUCCESS, " CRC: %02X - %02X (%s)", crc, calc_crc, (crc == calc_crc) ? "OK" : "Failed"); + PrintAndLogEx(SUCCESS, " CRC: %02X - %02X (%s)", crc, calc_crc, (crc == calc_crc) ? "ok" : "fail"); return PM3_SUCCESS; } diff --git a/client/src/cmdlfparadox.h b/client/src/cmdlfparadox.h index 34c3cb6cd..159d66da9 100644 --- a/client/src/cmdlfparadox.h +++ b/client/src/cmdlfparadox.h @@ -14,5 +14,5 @@ int CmdLFParadox(const char *Cmd); int demodParadox(void); -int detectParadox(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx); +int detectParadox(uint8_t *dest, size_t *size, int *wave_start_idx); #endif From 5643eb685d88bcfa2a1dce1ba951c6fb991453c5 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 13:01:17 +0200 Subject: [PATCH 12/84] text, color --- client/src/cmdlfawid.c | 12 ++++++------ client/src/cmdlffdx.c | 8 ++++---- client/src/cmdlfgallagher.c | 2 +- client/src/cmdlfguard.c | 4 ++-- client/src/cmdlfhid.c | 8 +++++--- client/src/cmdlfindala.c | 33 +++++++++++++-------------------- client/src/cmdlfio.c | 2 +- client/src/cmdlfjablotron.c | 14 +++++--------- client/src/cmdlfkeri.c | 15 +++++++-------- client/src/cmdlfmotorola.c | 9 ++++----- client/src/cmdlfnedap.c | 14 +++++++------- client/src/cmdlfnexwatch.c | 12 ++++++------ client/src/cmdlfnoralsy.c | 6 +++--- client/src/cmdlfpac.c | 8 ++++---- client/src/cmdlfparadox.c | 2 +- client/src/cmdlfpresco.c | 8 ++++---- client/src/cmdlfpyramid.c | 6 +++--- client/src/cmdlfsecurakey.c | 4 ++-- client/src/cmdlfverichip.c | 4 ++-- client/src/cmdlfviking.c | 10 +++++----- client/src/cmdlfvisa2000.c | 6 +++--- 21 files changed, 88 insertions(+), 99 deletions(-) diff --git a/client/src/cmdlfawid.c b/client/src/cmdlfawid.c index a6fb9f81b..fcabbbd2b 100644 --- a/client/src/cmdlfawid.c +++ b/client/src/cmdlfawid.c @@ -290,21 +290,21 @@ static int CmdAWIDDemod(const char *Cmd) { fc = bytebits_to_byte(bits + 9, 8); cardnum = bytebits_to_byte(bits + 17, 16); code1 = bytebits_to_byte(bits + 8, fmtLen); - PrintAndLogEx(SUCCESS, "AWID Found - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "AWID - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi2, rawHi, rawLo); break; case 34: fc = bytebits_to_byte(bits + 9, 8); cardnum = bytebits_to_byte(bits + 17, 24); code1 = bytebits_to_byte(bits + 8, (fmtLen - 32)); code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32); - PrintAndLogEx(SUCCESS, "AWID Found - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "AWID - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo); break; case 37: fc = bytebits_to_byte(bits + 9, 13); cardnum = bytebits_to_byte(bits + 22, 18); code1 = bytebits_to_byte(bits + 8, (fmtLen - 32)); code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32); - PrintAndLogEx(SUCCESS, "AWID Found - len: " _GREEN_("%d")" FC: " _GREEN_("%d")" Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "AWID - len: " _GREEN_("%d")" FC: " _GREEN_("%d")" Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo); break; // case 40: // break; @@ -313,18 +313,18 @@ static int CmdAWIDDemod(const char *Cmd) { cardnum = bytebits_to_byte(bits + 25, 32); code1 = bytebits_to_byte(bits + 8, (fmtLen - 32)); code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32); - PrintAndLogEx(SUCCESS, "AWID Found - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "AWID - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo); break; default: if (fmtLen > 32) { cardnum = bytebits_to_byte(bits + 8 + (fmtLen - 17), 16); code1 = bytebits_to_byte(bits + 8, fmtLen - 32); code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32); - PrintAndLogEx(SUCCESS, "AWID Found - len: " _GREEN_("%d") " -unknown- (%u) - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, cardnum, code1, code2, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "AWID - len: " _GREEN_("%d") " -unknown- (%u) - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, cardnum, code1, code2, rawHi2, rawHi, rawLo); } else { cardnum = bytebits_to_byte(bits + 8 + (fmtLen - 17), 16); code1 = bytebits_to_byte(bits + 8, fmtLen); - PrintAndLogEx(SUCCESS, "AWID Found - len: " _GREEN_("%d") " -unknown- (%u) - Wiegand: " _GREEN_("%x") ", Raw: %08x%08x%08x", fmtLen, cardnum, code1, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "AWID - len: " _GREEN_("%d") " -unknown- (%u) - Wiegand: " _GREEN_("%x") ", Raw: %08x%08x%08x", fmtLen, cardnum, code1, rawHi2, rawHi, rawLo); } break; } diff --git a/client/src/cmdlffdx.c b/client/src/cmdlffdx.c index c9af2fffc..98f93baed 100644 --- a/client/src/cmdlffdx.c +++ b/client/src/cmdlffdx.c @@ -61,8 +61,8 @@ static int usage_lf_fdx_clone(void) { PrintAndLogEx(NORMAL, " : Specify write to Q5 (t5555 instead of t55x7)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf fdx clone 999 112233"); - PrintAndLogEx(NORMAL, " lf fdx clone 999 112233 16a"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf fdx clone 999 112233")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf fdx clone 999 112233 16a")); return PM3_SUCCESS; } @@ -78,8 +78,8 @@ static int usage_lf_fdx_sim(void) { PrintAndLogEx(NORMAL, " : Extended data"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf fdx sim 999 112233"); - PrintAndLogEx(NORMAL, " lf fdx sim 999 112233 16a"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf fdx sim 999 112233")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf fdx sim 999 112233 16a")); return PM3_SUCCESS; } diff --git a/client/src/cmdlfgallagher.c b/client/src/cmdlfgallagher.c index 010fbaf47..3bd68a89d 100644 --- a/client/src/cmdlfgallagher.c +++ b/client/src/cmdlfgallagher.c @@ -127,7 +127,7 @@ static int CmdGallagherDemod(const char *Cmd) { // 4bit issue level uint8_t il = arr[7] & 0x0F; - PrintAndLogEx(SUCCESS, "GALLAGHER Tag Found -- Region: " _GREEN_("%u") " FC: " _GREEN_("%u") " CN: " _GREEN_("%u") " Issue Level: " _GREEN_("%u"), rc, fc, cn, il); + PrintAndLogEx(SUCCESS, "GALLAGHER - Region: " _GREEN_("%u") " FC: " _GREEN_("%u") " CN: " _GREEN_("%u") " Issue Level: " _GREEN_("%u"), rc, fc, cn, il); PrintAndLogEx(SUCCESS, " Printed: " _GREEN_("%C%u"), rc + 0x40, fc); PrintAndLogEx(SUCCESS, " Raw: %08X%08X%08X", raw1, raw2, raw3); PrintAndLogEx(SUCCESS, " CRC: %02X - %02X (%s)", crc, calc_crc, (crc == calc_crc) ? "ok" : "fail"); diff --git a/client/src/cmdlfguard.c b/client/src/cmdlfguard.c index db67a3568..746ef7f11 100644 --- a/client/src/cmdlfguard.c +++ b/client/src/cmdlfguard.c @@ -139,9 +139,9 @@ static int CmdGuardDemod(const char *Cmd) { break; } if (!unknown) - PrintAndLogEx(SUCCESS, "G-Prox-II found - Fmt: " _GREEN_("%u")"bit FC: " _GREEN_("%u") " Card: " _GREEN_("%u") ", Raw: %08x%08x%08x", fmtLen, FC, Card, raw1, raw2, raw3); + PrintAndLogEx(SUCCESS, "G-Prox-II - len: " _GREEN_("%u")" FC: " _GREEN_("%u") " Card: " _GREEN_("%u") ", Raw: %08x%08x%08x", fmtLen, FC, Card, raw1, raw2, raw3); else - PrintAndLogEx(SUCCESS, "Unknown G-Prox-II found - Fmt: %u, Raw: %08x%08x%08x", fmtLen, raw1, raw2, raw3); + PrintAndLogEx(SUCCESS, "G-Prox-II - Unknown len: " _GREEN_("%u") ", Raw: %08x%08x%08x", fmtLen, raw1, raw2, raw3); return PM3_SUCCESS; } diff --git a/client/src/cmdlfhid.c b/client/src/cmdlfhid.c index 83a97c41d..35a00ab11 100644 --- a/client/src/cmdlfhid.c +++ b/client/src/cmdlfhid.c @@ -195,7 +195,7 @@ static int CmdHIDDemod(const char *Cmd) { } if (hi2 != 0) { //extra large HID tags - PrintAndLogEx(SUCCESS, "HID Prox TAG ID: " _GREEN_("%x%08x%08x (%u)"), hi2, hi, lo, (lo >> 1) & 0xFFFF); + PrintAndLogEx(SUCCESS, "HID Prox - " _GREEN_("%x%08x%08x (%u)"), hi2, hi, lo, (lo >> 1) & 0xFFFF); } else { //standard HID tags <38 bits uint8_t fmtLen = 0; uint32_t cc = 0; @@ -241,9 +241,11 @@ static int CmdHIDDemod(const char *Cmd) { fc = ((hi & 0xF) << 12) | (lo >> 20); } if (fmtLen == 32 && (lo & 0x40000000)) { //if 32 bit and Kastle bit set - PrintAndLogEx(SUCCESS, "HID Prox TAG (Kastle format) ID: " _GREEN_("%x%08x (%u)")" - Format Len: 32bit - CC: %u - FC: %u - Card: %u", hi, lo, (lo >> 1) & 0xFFFF, cc, fc, cardnum); + PrintAndLogEx(SUCCESS, + "HID Prox (Kastle format) - " _GREEN_("%x%08x (%u)") " - len: " _GREEN_("32") " bit CC: " _GREEN_("%u") " FC: " _GREEN_("%u") " Card: " _GREEN_("%u"), hi, lo, (lo >> 1) & 0xFFFF, cc, fc, cardnum); } else { - PrintAndLogEx(SUCCESS, "HID Prox TAG ID: " _GREEN_("%x%08x (%u)")" - Format Len: " _GREEN_("%u bit")" - OEM: %03u - FC: " _GREEN_("%u")" - Card: " _GREEN_("%u"), + PrintAndLogEx(SUCCESS, + "HID Prox - " _GREEN_("%x%08x (%u)") " - len: " _GREEN_("%u") " bit - OEM: " _GREEN_("%03u") " FC: " _GREEN_("%u")" Card: " _GREEN_("%u"), hi, lo, cardnum, fmtLen, oem, fc, cardnum); } } diff --git a/client/src/cmdlfindala.c b/client/src/cmdlfindala.c index 6457bf671..919c914b2 100644 --- a/client/src/cmdlfindala.c +++ b/client/src/cmdlfindala.c @@ -50,10 +50,10 @@ static int usage_lf_indala_demod(void) { PrintAndLogEx(NORMAL, " maxerror : Set maximum allowed errors, default = 100."); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf indala demod"); - PrintAndLogEx(NORMAL, " lf indala demod 32 = demod a Indala tag from GraphBuffer using a clock of RF/32"); - PrintAndLogEx(NORMAL, " lf indala demod 32 1 = demod a Indala tag from GraphBuffer using a clock of RF/32 and inverting data"); - PrintAndLogEx(NORMAL, " lf indala demod 64 1 0 = demod a Indala tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf indala demod")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf indala demod 32") " = demod a Indala tag from GraphBuffer using a clock of RF/32"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf indala demod 32 1") " = demod a Indala tag from GraphBuffer using a clock of RF/32 and inverting data"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf indala demod 64 1 0") " = demod a Indala tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors"); return PM3_SUCCESS; } @@ -68,7 +68,7 @@ static int usage_lf_indala_sim(void) { PrintAndLogEx(NORMAL, " c : Cardnumber for Heden 2L format (decimal)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf indala sim deadc0de"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf indala sim deadc0de")); return PM3_SUCCESS; } @@ -143,7 +143,7 @@ static void decodeHeden2L(uint8_t *bits) { if (bits[offset + 7]) cardnumber += 16384; if (bits[offset + 23]) cardnumber += 32768; - PrintAndLogEx(SUCCESS, "\tHeden-2L | " _YELLOW_("%u"), cardnumber); + PrintAndLogEx(SUCCESS, "\tHeden-2L | " _GREEN_("%u"), cardnumber); } // Indala 26 bit decode @@ -193,13 +193,7 @@ static int CmdIndalaDemod(const char *Cmd) { uint64_t foo = uid2 & 0x7FFFFFFF; if (DemodBufferLen == 64) { - PrintAndLogEx( - SUCCESS - , "Indala Found - bitlength %zu, Raw " _YELLOW_("%x%08x") - , DemodBufferLen - , uid1 - , uid2 - ); + PrintAndLogEx(SUCCESS, "Indala - len %zu, Raw: %x%08x", DemodBufferLen, uid1, uid2); uint16_t p1 = 0; p1 |= DemodBuffer[32 + 3] << 8; @@ -246,8 +240,7 @@ static int CmdIndalaDemod(const char *Cmd) { checksum |= DemodBuffer[62] << 1; // b2 checksum |= DemodBuffer[63] << 0; // b1 - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(SUCCESS, "Fmt 26 bit FC " _YELLOW_("%u") ", CN " _YELLOW_("%u") ", checksum " _YELLOW_("%1d%1d") + PrintAndLogEx(SUCCESS, "Fmt " _GREEN_("26") " FC: " _GREEN_("%u") " Card: " _GREEN_("%u") " checksum: " _GREEN_("%1d%1d") , fc , csn , checksum >> 1 & 0x01 @@ -267,7 +260,7 @@ static int CmdIndalaDemod(const char *Cmd) { uint32_t uid7 = bytebits_to_byte(DemodBuffer + 192, 32); PrintAndLogEx( SUCCESS - , "Indala Found - bitlength %zu, Raw 0x%x%08x%08x%08x%08x%08x%08x" + , "Indala - len %zu, Raw: 0x%x%08x%08x%08x%08x%08x%08x" , DemodBufferLen , uid1 , uid2 @@ -564,10 +557,10 @@ static int CmdIndalaClone(const char *Cmd) { CLIParserInit(&ctx, "lf indala clone", "clone INDALA tag to T55x7 (or to q5/T5555)", "Examples:\n" - "\tlf indala clone --heden 888\n" - "\tlf indala clone --fc 123 --cn 1337\n" - "\tlf indala clone -r a0000000a0002021\n" - "\tlf indala clone -l -r 80000001b23523a6c2e31eba3cbee4afb3c6ad1fcf649393928c14e5"); + _YELLOW_("\tlf indala clone --heden 888\n") + _YELLOW_("\tlf indala clone --fc 123 --cn 1337\n") + _YELLOW_("\tlf indala clone -r a0000000a0002021\n") + _YELLOW_("\tlf indala clone -l -r 80000001b23523a6c2e31eba3cbee4afb3c6ad1fcf649393928c14e5")); void *argtable[] = { arg_param_begin, diff --git a/client/src/cmdlfio.c b/client/src/cmdlfio.c index 5502786b6..10a4b5419 100644 --- a/client/src/cmdlfio.c +++ b/client/src/cmdlfio.c @@ -175,7 +175,7 @@ static int CmdIOProxDemod(const char *Cmd) { retval = PM3_ESOFT; } - PrintAndLogEx(SUCCESS, "IO Prox XSF(%02d)%02x:%05d (%08x%08x) %s", version, facilitycode, number, code, code2, crc_str); + PrintAndLogEx(SUCCESS, "IO Prox - " _GREEN_("XSF(%02d)%02x:%05d") ", Raw: %08x%08x %s", version, facilitycode, number, code, code2, crc_str); if (g_debugMode) { if (crc != calccrc) diff --git a/client/src/cmdlfjablotron.c b/client/src/cmdlfjablotron.c index 3d586215e..5d09fe066 100644 --- a/client/src/cmdlfjablotron.c +++ b/client/src/cmdlfjablotron.c @@ -38,7 +38,7 @@ static int usage_lf_jablotron_clone(void) { PrintAndLogEx(NORMAL, " : specify write to Q5 (t5555 instead of t55x7)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf jablotron clone 112233"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf jablotron clone 112233")); return PM3_SUCCESS; } @@ -52,7 +52,7 @@ static int usage_lf_jablotron_sim(void) { PrintAndLogEx(NORMAL, " : jablotron card ID"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf jablotron sim 112233"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf jablotron sim 112233")); return PM3_SUCCESS; } @@ -115,20 +115,16 @@ static int CmdJablotronDemod(const char *Cmd) { uint64_t rawid = ((uint64_t)(bytebits_to_byte(DemodBuffer + 16, 8) & 0xff) << 32) | bytebits_to_byte(DemodBuffer + 24, 32); uint64_t id = getJablontronCardId(rawid); - PrintAndLogEx(SUCCESS, "Jablotron Tag Found: Card ID: %"PRIx64" :: Raw: %08X%08X", id, raw1, raw2); + PrintAndLogEx(SUCCESS, "Jablotron - Card: " _GREEN_("%"PRIx64) ", Raw: %08X%08X", id, raw1, raw2); uint8_t chksum = raw2 & 0xFF; bool isok = (chksum == jablontron_chksum(DemodBuffer)); - PrintAndLogEx(isok ? SUCCESS : INFO, - "Checksum: %02X [%s]", - chksum, - isok ? _GREEN_("OK") : _RED_("Fail") - ); + PrintAndLogEx(DEBUG, "Checksum: %02X (%s)", chksum, isok ? _GREEN_("ok") : _RED_("Fail")); id = DEC2BCD(id); // Printed format: 1410-nn-nnnn-nnnn - PrintAndLogEx(SUCCESS, "Printed: 1410-%02X-%04X-%04X", + PrintAndLogEx(SUCCESS, "Printed: " _GREEN_("1410-%02X-%04X-%04X"), (uint8_t)(id >> 32) & 0xFF, (uint16_t)(id >> 16) & 0xFFFF, (uint16_t)id & 0xFFFF diff --git a/client/src/cmdlfkeri.c b/client/src/cmdlfkeri.c index a26278f1c..7f5a83693 100644 --- a/client/src/cmdlfkeri.c +++ b/client/src/cmdlfkeri.c @@ -41,9 +41,9 @@ static int usage_lf_keri_clone(void) { PrintAndLogEx(NORMAL, " : Card Number"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf keri clone 112233"); - PrintAndLogEx(NORMAL, " lf keri clone type ms fc 6 cn 12345"); - PrintAndLogEx(NORMAL, " lf keri clone t m f 6 c 12345"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf keri clone 112233")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf keri clone type ms fc 6 cn 12345")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf keri clone t m f 6 c 12345")); return PM3_SUCCESS; } @@ -58,7 +58,7 @@ static int usage_lf_keri_sim(void) { PrintAndLogEx(NORMAL, " : Keri Internal ID"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf keri sim 112233"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf keri sim 112233")); return PM3_SUCCESS; } @@ -129,7 +129,7 @@ static int CmdKeriMSScramble(KeriMSScramble_t Action, uint32_t *FC, uint32_t *ID // Bit 31 was fixed but not in check/parity bits *CardID |= 1UL << 31; - PrintAndLogEx(SUCCESS, "Scrambled MS : FC %d - CN %d to RAW : E0000000%08X", *FC, *ID, *CardID); + PrintAndLogEx(SUCCESS, "Scrambled MS - FC: " _GREEN_("%d") " Card: " _GREEN_("%d") ", Raw: E0000000%08X", *FC, *ID, *CardID); } return PM3_SUCCESS; } @@ -184,8 +184,7 @@ static int CmdKeriDemod(const char *Cmd) { Might be a hash of FC & CN to generate Internal ID */ - PrintAndLogEx(SUCCESS, "KERI Tag Found -- Internal ID: %u", ID); - PrintAndLogEx(SUCCESS, "Raw: %08X%08X", raw1, raw2); + PrintAndLogEx(SUCCESS, "KERI - Internal ID: " _GREEN_("%u") ", Raw: %08X%08X" , ID, raw1, raw2); /* Descramble Data. */ @@ -195,7 +194,7 @@ static int CmdKeriDemod(const char *Cmd) { // Just need to the low 32 bits without the 111 trailer CmdKeriMSScramble(Descramble, &fc, &cardid, &raw2); - PrintAndLogEx(SUCCESS, "Descrambled MS : FC %d - CN %d\n", fc, cardid); + PrintAndLogEx(SUCCESS, "Descrambled MS - FC: " _GREEN_("%d") " Card: " _GREEN_("%d"), fc, cardid); if (invert) { PrintAndLogEx(INFO, "Had to Invert - probably KERI"); diff --git a/client/src/cmdlfmotorola.c b/client/src/cmdlfmotorola.c index fc2156c1a..1af4f120c 100644 --- a/client/src/cmdlfmotorola.c +++ b/client/src/cmdlfmotorola.c @@ -113,10 +113,9 @@ static int CmdMotorolaDemod(const char *Cmd) { checksum |= DemodBuffer[62] << 1; // b2 checksum |= DemodBuffer[63] << 0; // b1 - PrintAndLogEx(SUCCESS, "Motorola Tag Found -- Raw: %08X%08X", raw1, raw2); - PrintAndLogEx(SUCCESS, "Fmt 26 bit FC %u , CSN %u , checksum %1d%1d", fc, csn, checksum >> 1 & 0x01, checksum & 0x01); - PrintAndLogEx(NORMAL, ""); - + + PrintAndLogEx(SUCCESS, "Motorola - len: " _GREEN_("26") " FC: " _GREEN_("%u") " Card: " _GREEN_("%u") ", Raw: %08X%08X", fc, csn, raw1, raw2); + PrintAndLogEx(DEBUG, "checksum: " _GREEN_("%1d%1d"), fc, csn, checksum >> 1 & 0x01, checksum & 0x01); return PM3_SUCCESS; } @@ -156,7 +155,7 @@ static int CmdMotorolaClone(const char *Cmd) { "defaults to 64.\n", "\n" "Samples:\n" - "\tlf motorola clone a0000000a0002021\n" + _YELLOW_("\tlf motorola clone a0000000a0002021") "\n" ); void *argtable[] = { diff --git a/client/src/cmdlfnedap.c b/client/src/cmdlfnedap.c index c748a262a..da4354a49 100644 --- a/client/src/cmdlfnedap.c +++ b/client/src/cmdlfnedap.c @@ -41,7 +41,7 @@ static int usage_lf_nedap_gen(void) { PrintAndLogEx(NORMAL, " l : optional - long (128), default to short (64)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf nedap generate s 1 c 123 i 12345"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf nedap generate s 1 c 123 i 12345")); return PM3_SUCCESS; } @@ -58,7 +58,7 @@ static int usage_lf_nedap_clone(void) { // PrintAndLogEx(NORMAL, " Q5 : optional - clone to Q5 (T5555) instead of T55x7 chip"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf nedap clone s 1 c 123 i 12345"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf nedap clone s 1 c 123 i 12345")); return PM3_SUCCESS; } @@ -76,7 +76,7 @@ static int usage_lf_nedap_sim(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); // TODO proper example? - PrintAndLogEx(NORMAL, " lf nedap sim s 1 c 7 i 1337"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf nedap sim s 1 c 7 i 1337")); return PM3_SUCCESS; } @@ -172,7 +172,7 @@ static int CmdLFNedapDemod(const char *Cmd) { customerCode = ((data[1] & 0x01) << 11) | (data[2] << 3) | ((data[3] & 0xe0) >> 5); if (isValid == false) { - PrintAndLogEx(ERR, "Checksum : %s (calc 0x%04X != 0x%04X)", _RED_("failed"), checksum, checksum2); + PrintAndLogEx(ERR, "Checksum : %s (calc 0x%04X != 0x%04X)", _RED_("fail"), checksum, checksum2); ret = PM3_ESOFT; } @@ -192,8 +192,8 @@ static int CmdLFNedapDemod(const char *Cmd) { badgeId = r1 * 10000 + r2 * 1000 + r3 * 100 + r4 * 10 + r5; - PrintAndLogEx(SUCCESS, "NEDAP Tag Found: Card ID "_YELLOW_("%05u")" subtype: "_YELLOW_("%1u")" customer code: "_YELLOW_("%03x"), badgeId, subtype, customerCode); - PrintAndLogEx(SUCCESS, "Checksum is %s (0x%04X)", _GREEN_("OK"), checksum); + PrintAndLogEx(SUCCESS, "NEDAP - Card: " _YELLOW_("%05u") " subtype: " _YELLOW_("%1u")" customer code: " _YELLOW_("%03x"), badgeId, subtype, customerCode); + PrintAndLogEx(SUCCESS, "Checksum (%s) 0x%04X", _GREEN_("ok"), checksum); PrintAndLogEx(SUCCESS, "Raw: %s", sprint_hex(data, size / 8)); } else { PrintAndLogEx(ERR, "Invalid idx (1:%02x - 2:%02x - 3:%02x - 4:%02x - 5:%02x)", idxC1, idxC2, idxC3, idxC4, idxC5); @@ -239,7 +239,7 @@ static int CmdLFNedapDemod(const char *Cmd) { if (!r0 && (r1 < 10) && (r2 < 10) && (r3 < 10) && (r4 < 10) && (r5 < 10)) { badgeId = r1 * 10000 + r2 * 1000 + r3 * 100 + r4 * 10 + r5; - PrintAndLogEx(SUCCESS, "Second Card Id " _YELLOW_("%05u"), badgeId); + PrintAndLogEx(SUCCESS, "Second Card: " _YELLOW_("%05u"), badgeId); if ((fixed0 == FIXED_71) && (fixed1 == FIXED_40)) PrintAndLogEx(DEBUG, "Fixed part {0 = 0x%02x, 1 = 0x%02x}", fixed0, fixed1); diff --git a/client/src/cmdlfnexwatch.c b/client/src/cmdlfnexwatch.c index fbf2d55eb..fda84b9b6 100644 --- a/client/src/cmdlfnexwatch.c +++ b/client/src/cmdlfnexwatch.c @@ -46,9 +46,9 @@ static int usage_lf_nexwatch_clone(void) { PrintAndLogEx(NORMAL, " q : Quadrakey credential"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf nexwatch clone r 5600000000213C9F8F150C"); - PrintAndLogEx(NORMAL, " lf nexwatch clone c 521512301 m 1 n -- Nexkey credential"); - PrintAndLogEx(NORMAL, " lf nexwatch clone c 521512301 m 1 q -- Quadrakey credential"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf nexwatch clone r 5600000000213C9F8F150C")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf nexwatch clone c 521512301 m 1 n") " -- Nexkey credential"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf nexwatch clone c 521512301 m 1 q") " -- Quadrakey credential"); return PM3_SUCCESS; } @@ -68,9 +68,9 @@ static int usage_lf_nexwatch_sim(void) { PrintAndLogEx(NORMAL, " q : Quadrakey credential"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf nexwatch sim r 5600000000213C9F8F150C"); - PrintAndLogEx(NORMAL, " lf nexwatch sim c 521512301 m 1 n -- Nexkey credential"); - PrintAndLogEx(NORMAL, " lf nexwatch sim c 521512301 m 1 q -- Quadrakey credential"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf nexwatch sim r 5600000000213C9F8F150C")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf nexwatch sim c 521512301 m 1 n") " -- Nexkey credential"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf nexwatch sim c 521512301 m 1 q") " -- Quadrakey credential"); return PM3_SUCCESS; } diff --git a/client/src/cmdlfnoralsy.c b/client/src/cmdlfnoralsy.c index a0ab69e3f..553450f12 100644 --- a/client/src/cmdlfnoralsy.c +++ b/client/src/cmdlfnoralsy.c @@ -35,7 +35,7 @@ static int usage_lf_noralsy_clone(void) { PrintAndLogEx(NORMAL, " : specify write to Q5 (t5555 instead of t55x7)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf noralsy clone 112233"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf noralsy clone 112233")); return PM3_SUCCESS; } @@ -50,7 +50,7 @@ static int usage_lf_noralsy_sim(void) { PrintAndLogEx(NORMAL, " : Tag allocation year"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf noralsy sim 112233"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf noralsy sim 112233")); return PM3_SUCCESS; } @@ -124,7 +124,7 @@ static int CmdNoralsyDemod(const char *Cmd) { return PM3_ESOFT; } - PrintAndLogEx(SUCCESS, "Noralsy Tag Found: Card ID %u, Year: %u Raw: %08X%08X%08X", cardid, year, raw1, raw2, raw3); + PrintAndLogEx(SUCCESS, "Noralsy - Card: " _GREEN_("%u")", Year: " _GREEN_("%u") ", Raw: %08X%08X%08X", cardid, year, raw1, raw2, raw3); if (raw1 != 0xBB0214FF) { PrintAndLogEx(WARNING, "Unknown bits set in first block! Expected 0xBB0214FF, Found: 0x%08X", raw1); PrintAndLogEx(WARNING, "Please post this output in forum to further research on this format"); diff --git a/client/src/cmdlfpac.c b/client/src/cmdlfpac.c index a8e0401af..10365358e 100644 --- a/client/src/cmdlfpac.c +++ b/client/src/cmdlfpac.c @@ -37,8 +37,8 @@ static int usage_lf_pac_clone(void) { PrintAndLogEx(NORMAL, " b : raw hex data. 16 bytes max"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf pac clone c CD4F5552 "); - PrintAndLogEx(NORMAL, " lf pac clone b FF2049906D8511C593155B56D5B2649F "); + PrintAndLogEx(NORMAL, _YELLOW_(" lf pac clone c CD4F5552 ")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf pac clone b FF2049906D8511C593155B56D5B2649F ")); return PM3_SUCCESS; } static int usage_lf_pac_sim(void) { @@ -51,7 +51,7 @@ static int usage_lf_pac_sim(void) { PrintAndLogEx(NORMAL, " : 8 byte PAC/Stanley card id"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf pac sim 12345678"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf pac sim 12345678")); return PM3_SUCCESS; } // by danshuk @@ -176,7 +176,7 @@ static int CmdPacDemod(const char *Cmd) { int retval = demodbuf_to_pacid(DemodBuffer, DemodBufferLen, cardid, sizeof(cardid)); if (retval == PM3_SUCCESS) - PrintAndLogEx(SUCCESS, "PAC/Stanley Tag Found -- Card ID: %s, Raw: %08X%08X%08X%08X", cardid, raw1, raw2, raw3, raw4); + PrintAndLogEx(SUCCESS, "PAC/Stanley - Card: " _GREEN_("%s") ", Raw: %08X%08X%08X%08X", cardid, raw1, raw2, raw3, raw4); return retval; } diff --git a/client/src/cmdlfparadox.c b/client/src/cmdlfparadox.c index 662ea781c..92cea3755 100644 --- a/client/src/cmdlfparadox.c +++ b/client/src/cmdlfparadox.c @@ -184,7 +184,7 @@ int demodParadox(void) { uint32_t rawHi = bytebits_to_byte(bits + idx + 32, 32); uint32_t rawHi2 = bytebits_to_byte(bits + idx, 32); - PrintAndLogEx(INFO, "Paradox TAG ID: " _GREEN_("%x%08x") " - FC: " _GREEN_("%d") ", CN: " _GREEN_("%d") " - Checksum: %02x - RAW: %08x%08x%08x", + PrintAndLogEx(INFO, "Paradox - ID: " _GREEN_("%x%08x") " FC: " _GREEN_("%d") " Card: " _GREEN_("%d") ", Checksum: %02x, Raw: %08x%08x%08x", hi >> 10, (hi & 0x3) << 26 | (lo >> 10), fc, diff --git a/client/src/cmdlfpresco.c b/client/src/cmdlfpresco.c index d7024633d..c9eb2ce29 100644 --- a/client/src/cmdlfpresco.c +++ b/client/src/cmdlfpresco.c @@ -36,7 +36,7 @@ static int usage_lf_presco_clone(void) { PrintAndLogEx(NORMAL, " : specify write to Q5 (t5555 instead of t55x7)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf presco clone d 123456789"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf presco clone d 123456789")); return PM3_SUCCESS; } @@ -52,7 +52,7 @@ static int usage_lf_presco_sim(void) { PrintAndLogEx(NORMAL, " c : 8 digit hex card number"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf presco sim d 123456789"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf presco sim d 123456789")); return PM3_SUCCESS; } @@ -86,14 +86,14 @@ static int CmdPrescoDemod(const char *Cmd) { uint32_t raw3 = bytebits_to_byte(DemodBuffer + 64, 32); uint32_t raw4 = bytebits_to_byte(DemodBuffer + 96, 32); uint32_t cardid = raw4; - PrintAndLogEx(SUCCESS, "Presco Tag Found: Card ID %08X, Raw: %08X%08X%08X%08X", cardid, raw1, raw2, raw3, raw4); + PrintAndLogEx(SUCCESS, "Presco - Card: " _GREEN_("%08X") ", Raw: %08X%08X%08X%08X", cardid, raw1, raw2, raw3, raw4); uint32_t sitecode = 0, usercode = 0, fullcode = 0; bool Q5 = false; char cmd[12] = {0}; sprintf(cmd, "H %08X", cardid); getWiegandFromPresco(cmd, &sitecode, &usercode, &fullcode, &Q5); - PrintAndLogEx(SUCCESS, "SiteCode %u, UserCode %u, FullCode, %08X", sitecode, usercode, fullcode); + PrintAndLogEx(SUCCESS, "SiteCode: " _GREEN_("%u") " UserCode: " _GREEN_("%u") " FullCode: " _GREEN_("%08X"), sitecode, usercode, fullcode); return PM3_SUCCESS; } diff --git a/client/src/cmdlfpyramid.c b/client/src/cmdlfpyramid.c index 65004f897..71fe1ab7e 100644 --- a/client/src/cmdlfpyramid.c +++ b/client/src/cmdlfpyramid.c @@ -181,12 +181,12 @@ int demodPyramid(void) { uint32_t fc = bytebits_to_byte(bits + 73, 8); uint32_t cardnum = bytebits_to_byte(bits + 81, 16); uint32_t code1 = bytebits_to_byte(bits + 72, fmtLen); - PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d, FC: " _GREEN_("%d") " Card: " _GREEN_("%d") " - Wiegand: " _GREEN_("%x")", Raw: %08x%08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi3, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "Pyramid - len: " _GREEN_("%d") ", FC: " _GREEN_("%d") " Card: " _GREEN_("%d") " - Wiegand: " _GREEN_("%x")", Raw: %08x%08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi3, rawHi2, rawHi, rawLo); } else if (fmtLen == 45) { fmtLen = 42; //end = 10 bits not 7 like 26 bit fmt uint32_t fc = bytebits_to_byte(bits + 53, 10); uint32_t cardnum = bytebits_to_byte(bits + 63, 32); - PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d, FC: " _GREEN_("%d") " Card: " _GREEN_("%d") " - Raw: %08x%08x%08x%08x", fmtLen, fc, cardnum, rawHi3, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "Pyramid - len: " _GREEN_("%d") ", FC: " _GREEN_("%d") " Card: " _GREEN_("%d") ", Raw: %08x%08x%08x%08x", fmtLen, fc, cardnum, rawHi3, rawHi2, rawHi, rawLo); /* } else if (fmtLen > 32) { uint32_t cardnum = bytebits_to_byte(bits + 81, 16); @@ -197,7 +197,7 @@ int demodPyramid(void) { } else { uint32_t cardnum = bytebits_to_byte(bits + 81, 16); //uint32_t code1 = bytebits_to_byte(bits+(size-fmtLen),fmtLen); - PrintAndLogEx(SUCCESS, "Pyramid ID Found - BitLength: %d -unknown BitLength- Card: " _GREEN_("%d") ", Raw: %08x%08x%08x%08x", fmtLen, cardnum, rawHi3, rawHi2, rawHi, rawLo); + PrintAndLogEx(SUCCESS, "Pyramid - len: " _GREEN_("%d") " -unknown- Card: " _GREEN_("%d") ", Raw: %08x%08x%08x%08x", fmtLen, cardnum, rawHi3, rawHi2, rawHi, rawLo); } PrintAndLogEx(DEBUG, "DEBUG: Pyramid: checksum : 0x%02X - %02X - %s" diff --git a/client/src/cmdlfsecurakey.c b/client/src/cmdlfsecurakey.c index 3fd689360..ea188ec3b 100644 --- a/client/src/cmdlfsecurakey.c +++ b/client/src/cmdlfsecurakey.c @@ -118,9 +118,9 @@ int demodSecurakey(void) { // test parities - evenparity32 looks to add an even parity returns 0 if already even... bool parity = !evenparity32(lWiegand) && !oddparity32(rWiegand); - PrintAndLogEx(SUCCESS, "Securakey Tag Found--BitLen: " _GREEN_("%u") ", Card ID: " _GREEN_("%u") ", FC: " _GREEN_("0x%X")" Raw: %08X%08X%08X", bitLen, cardid, fc, raw1, raw2, raw3); + PrintAndLogEx(SUCCESS, "Securakey - len: " _GREEN_("%u") " FC: " _GREEN_("0x%X")" Card: " _GREEN_("%u") ", Raw: %08X%08X%08X", bitLen, fc, cardid, raw1, raw2, raw3); if (bitLen <= 32) - PrintAndLogEx(SUCCESS, "Wiegand: " _GREEN_("%08X") ", Parity: %s", (lWiegand << (bitLen / 2)) | rWiegand, parity ? _GREEN_("ok") : _RED_("fail")); + PrintAndLogEx(SUCCESS, "Wiegand: " _GREEN_("%08X") " parity (%s)", (lWiegand << (bitLen / 2)) | rWiegand, parity ? _GREEN_("ok") : _RED_("fail")); PrintAndLogEx(INFO, "\nHow the FC translates to printed FC is unknown"); PrintAndLogEx(INFO, "How the checksum is calculated is unknown"); diff --git a/client/src/cmdlfverichip.c b/client/src/cmdlfverichip.c index c3201e1f6..0eec31bf1 100644 --- a/client/src/cmdlfverichip.c +++ b/client/src/cmdlfverichip.c @@ -33,7 +33,7 @@ static int usage_lf_verichip_clone(void) { PrintAndLogEx(NORMAL, " b : raw hex data. 12 bytes max"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf verichip clone b FF2049906D8511C593155B56D5B2649F "); + PrintAndLogEx(NORMAL, _YELLOW_(" lf verichip clone b FF2049906D8511C593155B56D5B2649F ")); return PM3_SUCCESS; } @@ -72,7 +72,7 @@ static int CmdVerichipDemod(const char *Cmd) { // 11111111001000000 10 01001100 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 10001100 10 100000001 // unknown checksum 9 bits at the end - PrintAndLogEx(SUCCESS, "VERICHIP Tag Found -- Raw: %08X%08X%08X%08X", raw1, raw2, raw3, raw4); + PrintAndLogEx(SUCCESS, "VERICHIP - Raw: %08X%08X%08X%08X", raw1, raw2, raw3, raw4); PrintAndLogEx(INFO, "How the Raw ID is translated by the reader is unknown. Share your trace file on forum"); return PM3_SUCCESS; } diff --git a/client/src/cmdlfviking.c b/client/src/cmdlfviking.c index dccdb16c5..07d80af86 100644 --- a/client/src/cmdlfviking.c +++ b/client/src/cmdlfviking.c @@ -34,7 +34,7 @@ static int usage_lf_viking_clone(void) { PrintAndLogEx(NORMAL, " : specify write to Q5 (t5555 instead of t55x7)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf viking clone 1A337 Q5"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf viking clone 1A337 Q5")); return PM3_SUCCESS; } @@ -48,7 +48,7 @@ static int usage_lf_viking_sim(void) { PrintAndLogEx(NORMAL, " : 8 digit hex viking card number"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf viking sim 1A337"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf viking sim 1A337")); return PM3_SUCCESS; } @@ -76,8 +76,8 @@ int demodViking(void) { uint32_t raw2 = bytebits_to_byte(DemodBuffer + ans + 32, 32); uint32_t cardid = bytebits_to_byte(DemodBuffer + ans + 24, 32); uint8_t checksum = bytebits_to_byte(DemodBuffer + ans + 32 + 24, 8); - PrintAndLogEx(SUCCESS, "Viking Tag Found: Card ID " _YELLOW_("%08X")" checksum "_YELLOW_("%02X"), cardid, checksum); - PrintAndLogEx(SUCCESS, "Raw hex: %08X%08X", raw1, raw2); + PrintAndLogEx(SUCCESS, "Viking - Card " _GREEN_("%08X") ", Raw: %08X%08X", cardid, raw1, raw2); + PrintAndLogEx(DEBUG, "Checksum: %02X", checksum); setDemodBuff(DemodBuffer, 64, ans); setClockGrid(g_DemodClock, g_DemodStartIdx + (ans * g_DemodClock)); return PM3_SUCCESS; @@ -139,7 +139,7 @@ static int CmdVikingSim(const char *Cmd) { rawID = getVikingBits(id); - PrintAndLogEx(SUCCESS, "Simulating Viking - ID " _YELLOW_("%08X")" raw "_YELLOW_("%08X%08X"), id, (uint32_t)(rawID >> 32), (uint32_t)(rawID & 0xFFFFFFFF)); + PrintAndLogEx(SUCCESS, "Simulating Viking - ID " _YELLOW_("%08X") " raw " _YELLOW_("%08X%08X"), id, (uint32_t)(rawID >> 32), (uint32_t)(rawID & 0xFFFFFFFF)); uint8_t bs[64]; num_to_bytebits(rawID, sizeof(bs), bs); diff --git a/client/src/cmdlfvisa2000.c b/client/src/cmdlfvisa2000.c index 91ad70490..4260fe6d4 100644 --- a/client/src/cmdlfvisa2000.c +++ b/client/src/cmdlfvisa2000.c @@ -143,7 +143,7 @@ int demodVisa2k(void) { // test checksums if (chk != calc) { - PrintAndLogEx(DEBUG, "DEBUG: error: Visa2000 checksum failed %x - %x\n", chk, calc); + PrintAndLogEx(DEBUG, "DEBUG: error: Visa2000 checksum (%s) %x - %x\n", _RED_("fail"), chk, calc); save_restoreGB(GRAPH_RESTORE); return PM3_ESOFT; } @@ -151,11 +151,11 @@ int demodVisa2k(void) { uint8_t calc_par = visa_parity(raw2); uint8_t chk_par = (raw3 & 0xFF0) >> 4; if (calc_par != chk_par) { - PrintAndLogEx(DEBUG, "DEBUG: error: Visa2000 parity failed %x - %x\n", chk_par, calc_par); + PrintAndLogEx(DEBUG, "DEBUG: error: Visa2000 parity (%s) %x - %x\n", _RED_("fail"), chk_par, calc_par); save_restoreGB(GRAPH_RESTORE); return PM3_ESOFT; } - PrintAndLogEx(SUCCESS, "Visa2000 Tag Found: Card ID " _GREEN_("%u") " Raw: %08X%08X%08X", raw2, raw1, raw2, raw3); + PrintAndLogEx(SUCCESS, "Visa2000 - Card " _GREEN_("%u") ", Raw: %08X%08X%08X", raw2, raw1, raw2, raw3); return PM3_SUCCESS; } From ba8f60298a14cec105b9d54a7826487b52d058e2 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 13:17:41 +0200 Subject: [PATCH 13/84] text --- client/src/cmdlf.c | 3 ++- client/src/cmdlffdx.c | 4 +++- client/src/cmdlfhid.c | 4 ++++ client/src/cmdlfindala.c | 6 ++++-- client/src/cmdlfio.c | 3 +++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index ace50f2d7..0d3703808 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -1274,6 +1274,7 @@ int CmdLFfind(const char *Cmd) { if (demodHID() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("HID Prox ID") " found!"); goto out;} if (demodAWID() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("AWID ID") " found!"); goto out;} + if (demodIOProx() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("IO Prox ID") " found!"); goto out;} if (demodParadox() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Paradox ID") " found!"); goto out;} if (demodEM410x() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("EM410x ID") " found!"); goto out;} @@ -1281,7 +1282,7 @@ int CmdLFfind(const char *Cmd) { if (demodGuard() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Guardall G-Prox II ID") " found!"); goto out; } if (demodIdteck() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Idteck ID") " found!"); goto out;} if (demodIndala() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Indala ID") " found!"); goto out;} - if (demodIOProx() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("IO Prox ID") " found!"); goto out;} + if (demodJablotron() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Jablotron ID") " found!"); goto out;} if (demodNedap() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("NEDAP ID") " found!"); goto out;} if (demodNexWatch() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("NexWatch ID") " found!"); goto out;} diff --git a/client/src/cmdlffdx.c b/client/src/cmdlffdx.c index 98f93baed..28d3ff12c 100644 --- a/client/src/cmdlffdx.c +++ b/client/src/cmdlffdx.c @@ -247,7 +247,7 @@ int demodFDX(void) { uint8_t raw[8]; num_to_bytes(rawid, 8, raw); - PrintAndLogEx(SUCCESS, "\nFDX-B / ISO 11784/5 Animal Tag ID Found: Raw : %s", sprint_hex(raw, 8)); + PrintAndLogEx(SUCCESS, "FDX-B / ISO 11784/5 Animal"); PrintAndLogEx(SUCCESS, "Animal ID " _GREEN_("%04u-%012"PRIu64), countryCode, NationalCode); PrintAndLogEx(SUCCESS, "National Code " _GREEN_("%012" PRIu64) " (0x%" PRIx64 ")", NationalCode, NationalCode); PrintAndLogEx(SUCCESS, "Country Code %04u", countryCode); @@ -259,6 +259,8 @@ int demodFDX(void) { compute_crc(CRC_11784, raw, sizeof(raw), &c[0], &c[1]); PrintAndLogEx(SUCCESS, "CRC-16 0x%04X (%s) ", crc, (crc == (c[1] << 8 | c[0])) ? _GREEN_("ok") : _RED_("fail")); + PrintAndLogEx(SUCCESS, "Raw " _GREEN_("%s"), sprint_hex(raw, 8)); + if (g_debugMode) { PrintAndLogEx(DEBUG, "Start marker %d; Size %zu", preambleIndex, size); char *bin = sprint_bin_break(DemodBuffer, size, 16); diff --git a/client/src/cmdlfhid.c b/client/src/cmdlfhid.c index 35a00ab11..be34148a6 100644 --- a/client/src/cmdlfhid.c +++ b/client/src/cmdlfhid.c @@ -51,6 +51,7 @@ static int usage_lf_hid_watch(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf hid watch")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } static int usage_lf_hid_sim(void) { @@ -63,6 +64,7 @@ static int usage_lf_hid_sim(void) { PrintAndLogEx(NORMAL, " ID - HID id"); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf hid sim 2006ec0c86")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } static int usage_lf_hid_clone(void) { @@ -76,6 +78,7 @@ static int usage_lf_hid_clone(void) { PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf hid clone 2006ec0c86")); PrintAndLogEx(NORMAL, _YELLOW_(" lf hid clone l 2006ec0c86")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } static int usage_lf_hid_brute(void) { @@ -100,6 +103,7 @@ static int usage_lf_hid_brute(void) { PrintAndLogEx(NORMAL, _YELLOW_(" lf hid brute w H10301 f 224")); PrintAndLogEx(NORMAL, _YELLOW_(" lf hid brute w H10301 f 21 d 2000")); PrintAndLogEx(NORMAL, _YELLOW_(" lf hid brute v w H10301 f 21 c 200 d 2000")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } diff --git a/client/src/cmdlfindala.c b/client/src/cmdlfindala.c index 919c914b2..421c3001a 100644 --- a/client/src/cmdlfindala.c +++ b/client/src/cmdlfindala.c @@ -52,8 +52,9 @@ static int usage_lf_indala_demod(void) { PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf indala demod")); PrintAndLogEx(NORMAL, _YELLOW_(" lf indala demod 32") " = demod a Indala tag from GraphBuffer using a clock of RF/32"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf indala demod 32 1") " = demod a Indala tag from GraphBuffer using a clock of RF/32 and inverting data"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf indala demod 32 1") " = demod a Indala tag from GraphBuffer using a clock of RF/32 and inverting data"); PrintAndLogEx(NORMAL, _YELLOW_(" lf indala demod 64 1 0") " = demod a Indala tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors"); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -69,6 +70,7 @@ static int usage_lf_indala_sim(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf indala sim deadc0de")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -260,7 +262,7 @@ static int CmdIndalaDemod(const char *Cmd) { uint32_t uid7 = bytebits_to_byte(DemodBuffer + 192, 32); PrintAndLogEx( SUCCESS - , "Indala - len %zu, Raw: 0x%x%08x%08x%08x%08x%08x%08x" + , "Indala - len %zu, Raw: %x%08x%08x%08x%08x%08x%08x" , DemodBufferLen , uid1 , uid2 diff --git a/client/src/cmdlfio.c b/client/src/cmdlfio.c index 10a4b5419..e9a0b25ae 100644 --- a/client/src/cmdlfio.c +++ b/client/src/cmdlfio.c @@ -37,6 +37,7 @@ static int usage_lf_io_watch(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf io watch")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -53,6 +54,7 @@ static int usage_lf_io_sim(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf io sim 01 101 1337")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -70,6 +72,7 @@ static int usage_lf_io_clone(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf io clone 01 101 1337")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } From c65c683d065f647b6386e123d02978a75d65f462 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 13:21:32 +0200 Subject: [PATCH 14/84] text --- client/src/cmdlfjablotron.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/client/src/cmdlfjablotron.c b/client/src/cmdlfjablotron.c index 5d09fe066..464b6e282 100644 --- a/client/src/cmdlfjablotron.c +++ b/client/src/cmdlfjablotron.c @@ -39,6 +39,7 @@ static int usage_lf_jablotron_clone(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf jablotron clone 112233")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -53,6 +54,7 @@ static int usage_lf_jablotron_sim(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf jablotron sim 112233")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -79,7 +81,10 @@ static uint64_t getJablontronCardId(uint64_t rawcode) { //see ASKDemod for what args are accepted static int CmdJablotronDemod(const char *Cmd) { (void)Cmd; // Cmd is not used so far + return demodJablotron(); +} +int demodJablotron(void) { //Differential Biphase / di-phase (inverted biphase) //get binary from ask wave if (ASKbiphaseDemod("0 64 1 0", false) != PM3_SUCCESS) { @@ -133,8 +138,8 @@ static int CmdJablotronDemod(const char *Cmd) { } static int CmdJablotronRead(const char *Cmd) { - lf_read(true, 10000); - return CmdJablotronDemod(Cmd); + lf_read(false, 16000); + return demodJablotron(); } static int CmdJablotronClone(const char *Cmd) { @@ -276,6 +281,3 @@ int detectJablotron(uint8_t *bits, size_t *size) { return (int)startIdx; } -int demodJablotron(void) { - return CmdJablotronDemod(""); -} From 42415e41ab7f26a703143d150f43199ca078f8ef Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 13:23:37 +0200 Subject: [PATCH 15/84] text --- client/src/cmdlfkeri.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/cmdlfkeri.c b/client/src/cmdlfkeri.c index 7f5a83693..b1a73cc9d 100644 --- a/client/src/cmdlfkeri.c +++ b/client/src/cmdlfkeri.c @@ -44,7 +44,7 @@ static int usage_lf_keri_clone(void) { PrintAndLogEx(NORMAL, _YELLOW_(" lf keri clone 112233")); PrintAndLogEx(NORMAL, _YELLOW_(" lf keri clone type ms fc 6 cn 12345")); PrintAndLogEx(NORMAL, _YELLOW_(" lf keri clone t m f 6 c 12345")); - + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -59,6 +59,7 @@ static int usage_lf_keri_sim(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf keri sim 112233")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } From 1fd3afa0025bb8a475bd2de7e413c6553e3be05f Mon Sep 17 00:00:00 2001 From: tharexde Date: Fri, 26 Jun 2020 14:19:41 +0200 Subject: [PATCH 16/84] added 4x50_sread --- armsrc/em4x50.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index b9295e9ed..1df07798c 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -754,6 +754,49 @@ void em4x50_info(em4x50_data_t *etd) { reply_ng(CMD_ACK, status, (uint8_t *)tag.sectors, 238); } +void em4x50_sread(em4x50_data_t *etd) { + + // reads single word in two alternative ways: + // - using "selective read mode" -> bidirectional communication + // - using "standard read mode" -> unidirectional communication (read + // data that tag transmits "voluntarily") + + bool bsuccess = false, blogin = false; + int now = 0; + uint8_t status = 0; + uint8_t addresses[] = {0x00, 0x00, 0x00, 0x00}; // fwr = 0, lwr = 33 + + init_tag(); + em4x50_setup_read(); + + // set gHigh and gLow + get_signalproperties(); + + if (etd->addr_given) { + + // selective read mode + + // try to login with given password + if (etd->pwd_given) + blogin = login(etd->password); + + // only one word has to be read -> first word read = last word read + addresses[2] = addresses[3] = etd->address; + bsuccess = selective_read(addresses); + + } else { + + // standard read mode + bsuccess = standard_read(&now); + + } + status = (now << 2) + (bsuccess << 1) + blogin; + + lf_finalize(); + reply_ng(CMD_ACK, status, (uint8_t *)tag.sectors, 238); +} + + // write functions static bool write(uint8_t word[4], uint8_t address) { @@ -864,7 +907,7 @@ void em4x50_write(em4x50_data_t *etd) { if (etd->pwd_given) blogin &= login(etd->password); - // perform a selective read + // call a selective read addresses[2] = addresses[3] = etd->address; if (selective_read(addresses)) { From e7531ac6faf954eca2609358ea78d26d9f63b828 Mon Sep 17 00:00:00 2001 From: tharexde Date: Fri, 26 Jun 2020 14:19:54 +0200 Subject: [PATCH 17/84] added 4x50_sread --- armsrc/em4x50.h | 1 + 1 file changed, 1 insertion(+) diff --git a/armsrc/em4x50.h b/armsrc/em4x50.h index 746ca4811..aecaea78e 100644 --- a/armsrc/em4x50.h +++ b/armsrc/em4x50.h @@ -20,5 +20,6 @@ typedef struct { void em4x50_info(em4x50_data_t *etd); void em4x50_write(em4x50_data_t *etd); void em4x50_write_password(em4x50_data_t *etd); +void em4x50_sread(em4x50_data_t *etd); #endif /* EM4X50_H */ From 0136c0f9c9f8f7435b6958803bff10ee17883476 Mon Sep 17 00:00:00 2001 From: tharexde Date: Fri, 26 Jun 2020 14:20:08 +0200 Subject: [PATCH 18/84] added 4x50_sread --- armsrc/appmain.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index ad02eae2f..604d44c34 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1019,6 +1019,11 @@ static void PacketReceived(PacketCommandNG *packet) { em4x50_write_password((em4x50_data_t *)packet->data.asBytes); break; } + case CMD_LF_EM4X50_SREAD: { + em4x50_sread((em4x50_data_t *)packet->data.asBytes); + break; + } + #endif #ifdef WITH_ISO15693 From 8376b67ea0e93186411c62445fb43836ba1d6579 Mon Sep 17 00:00:00 2001 From: tharexde Date: Fri, 26 Jun 2020 14:20:19 +0200 Subject: [PATCH 19/84] added 4x50_sread --- client/src/cmdlfem4x50.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/src/cmdlfem4x50.h b/client/src/cmdlfem4x50.h index 732d05d5b..8f4b63a4f 100644 --- a/client/src/cmdlfem4x50.h +++ b/client/src/cmdlfem4x50.h @@ -14,9 +14,11 @@ int usage_lf_em4x50_info(void); int usage_lf_em4x50_write(void); int usage_lf_em4x50_write_password(void); +int usage_lf_em4x50_sread(void); int CmdEM4x50Info(const char *Cmd); int CmdEM4x50Write(const char *Cmd); int CmdEM4x50WritePassword(const char *Cmd); +int CmdEM4x50SRead(const char *Cmd); #endif From 871fa6b7331cba3b97b1c9f84484a2d2de838637 Mon Sep 17 00:00:00 2001 From: tharexde Date: Fri, 26 Jun 2020 14:20:46 +0200 Subject: [PATCH 20/84] added 4x50_sread --- client/src/cmdlfem4x50.c | 193 ++++++++++++++++++++++++++++++++------- 1 file changed, 159 insertions(+), 34 deletions(-) diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index 1f4420c5b..d8a6ef53d 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -15,33 +15,6 @@ #include "commonutil.h" #include "em4x50.h" -#define EM4X50_NO_WORDS 34 - -// special words -#define EM4X50_DEVICE_PASSWORD 0 -#define EM4X50_PROTECTION 1 -#define EM4X50_CONTROL 2 -#define EM4X50_DEVICE_SERIAL 32 -#define EM4X50_DEVICE_ID 33 - -// control word (word = 4 bytes) -#define FIRST_WORD_READ 0 // first byte -#define LAST_WORD_READ 1 // second byte -#define CONFIG_BLOCK 2 // third byte -#define PASSWORD_CHECK 0x80 // first bit in third byte -#define READ_AFTER_WRITE 0x40 // second bit in third byte - -// protection word -#define FIRST_WORD_READ_PROTECTED 0 // first byte -#define LAST_WORD_READ_PROTECTED 1 // second byte -#define FIRST_WORD_WRITE_INHIBITED 2 // third byte -#define LAST_WORD_WRITE_INHIBITED 3 // fourth byte - -// misc -#define STATUS_SUCCESS 0x2 -#define STATUS_LOGIN 0x1 -#define NO_CHARS_MAX 400 - int usage_lf_em4x50_info(void) { PrintAndLogEx(NORMAL, "Read all information of EM4x50. Tag nust be on antenna."); PrintAndLogEx(NORMAL, ""); @@ -81,6 +54,19 @@ int usage_lf_em4x50_write_password(void) { PrintAndLogEx(NORMAL, " lf em 4x50_write_password p 11223344 n 01020304"); return PM3_SUCCESS; } +int usage_lf_em4x50_sread(void) { + PrintAndLogEx(NORMAL, "Read EM4x50 word(s). Tag must be on antenna. "); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Usage: lf em 4x50_sread [h] a
p "); + PrintAndLogEx(NORMAL, "Options:"); + PrintAndLogEx(NORMAL, " h - this help"); + PrintAndLogEx(NORMAL, " a - memory address to read (dec) (optional)"); + PrintAndLogEx(NORMAL, " p - password (hex) (optional)"); + PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, " lf em 4x50_sread"); + PrintAndLogEx(NORMAL, " lf em 4x50_sread a 2 p 00000000"); + return PM3_SUCCESS; +} static void prepare_result(const uint8_t *byte, int fwr, int lwr, em4x50_word_t *words) { @@ -121,13 +107,13 @@ static void prepare_result(const uint8_t *byte, int fwr, int lwr, em4x50_word_t } // check column parities - words[i].col_parity = byte[i*7+5] ; + words[i].col_parity = byte[i*7+5]; for (int j = 0; j < 8; j++) { words[i].cparity[j] = (((words[i].col_parity >> (7-j)) & 1) == c[j]) ? true : false; if (!words[i].cparity[j]) - words[i].parity = false; + words[i].parity = false; } // check stop bit @@ -204,7 +190,7 @@ static void print_bit_table(const em4x50_word_t word) { string[0] = '\0'; } -static void print_result(const em4x50_word_t *words, int fwr, int lwr) { +static void print_result(const em4x50_word_t *words, int fwr, int lwr) { // print available information for given word from fwr to lwr, i.e. // bit table + summary lines with hex notation of word (msb + lsb) @@ -251,7 +237,7 @@ static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd, char pstring[NO_CHARS_MAX] = {0}, string[NO_CHARS_MAX] = {0}; bool bpwd_given = etd->pwd_given; - bool bsuccess = resp->status & STATUS_SUCCESS; + bool bsuccess = (resp->status & STATUS_SUCCESS) >> 1; bool blogin = resp->status & STATUS_LOGIN; prepare_result(data, 0, EM4X50_NO_WORDS - 1, words); @@ -455,7 +441,7 @@ int CmdEM4x50Info(const char *Cmd) { // print result print_info_result(&resp, &etd, verbose); - success = resp.status & STATUS_SUCCESS; + success = (resp.status & STATUS_SUCCESS) >> 1; return (success) ? PM3_SUCCESS : PM3_ESOFT; } @@ -464,7 +450,7 @@ static void print_write_result(PacketResponseNG *resp, const em4x50_data_t *etd) // display result of writing operation in structured format bool pwd_given = etd->pwd_given; - bool success = resp->status & STATUS_SUCCESS; + bool success = (resp->status & STATUS_SUCCESS) >> 1; bool login = resp->status & STATUS_LOGIN; uint8_t *data = resp->data.asBytes; char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; @@ -574,7 +560,7 @@ int CmdEM4x50Write(const char *Cmd) { // get, prepare and print response print_write_result(&resp, &etd); - success = resp.status & STATUS_SUCCESS; + success = (resp.status & STATUS_SUCCESS) >> 1; return (success) ? PM3_SUCCESS : PM3_ESOFT; } @@ -661,3 +647,142 @@ int CmdEM4x50WritePassword(const char *Cmd) { return ((bool)resp.status) ? PM3_SUCCESS : PM3_ESOFT; } + +static void print_sread_result(PacketResponseNG *resp, const em4x50_data_t *etd) { + + // display result of writing operation in structured format + + bool addr_given = etd->addr_given; + bool pwd_given = etd->pwd_given; + bool login = resp->status & STATUS_LOGIN; + bool success = (resp->status & STATUS_SUCCESS) >> 1; + int now = (resp->status & STATUS_NO_WORDS) >> 2; + char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; + uint8_t *data = resp->data.asBytes; + em4x50_word_t word; + + if (!success) { + + sprintf(pstring, "\n reading " _RED_("failed")); + strcat(string, pstring); + + PrintAndLogEx(NORMAL,"%s\n", string); + + } else { + + if (addr_given) { + + // selective read mode + + prepare_result(data, etd->address, etd->address, &word); + print_result(&word, etd->address, etd->address); + + sprintf(pstring, "\n reading " _GREEN_("ok ")); + strcat(string, pstring); + + if (pwd_given) { + if (login) { + sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)", + etd->password[0], etd->password[1], + etd->password[2], etd->password[3]); + strcat(string, pstring); + } else { + sprintf(pstring, "(login failed)"); + strcat(string, pstring); + } + } else { + sprintf(pstring, "(no login)"); + strcat(string, pstring); + } + + } else { + + //standard read mode + + prepare_result(data, 0, now - 1, &word); + print_result(&word, 0, now - 1); + + sprintf(pstring, "\n reading " _GREEN_("ok ")); + strcat(string, pstring); + + if (pwd_given) { + sprintf(pstring, "(standard read mode, password ignored)"); + strcat(string, pstring); + } else { + sprintf(pstring, "(standard read mode)"); + strcat(string, pstring); + } + } + + PrintAndLogEx(NORMAL,"%s\n", string); + } +} + +int CmdEM4x50SRead(const char *Cmd) { + + // envoke reading + // - without option -> standard read mode + // - with given address (option a) and optional password if address is + // read protected -> selective read mode + + bool errors = false, success = false; + uint8_t cmdp = 0; + em4x50_data_t etd; + PacketResponseNG resp; + + // init + etd.pwd_given = false; + etd.addr_given = false; + + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_lf_em4x50_sread(); + + case 'p': + if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) { + PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n"); + return PM3_EINVARG; + } + etd.pwd_given = true; + cmdp += 2; + break; + + case 'a': + param_getdec(Cmd, cmdp + 1, &etd.address); + + // validation + if (etd.address <= 0 || etd.address >= EM4X50_NO_WORDS) { + PrintAndLogEx(FAILED, "\n error, address has to be in range [1-33]\n"); + return PM3_EINVARG; + } + etd.addr_given = true; + cmdp += 2; + break; + + default: + PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp)); + errors = true; + break; + } + } + + if (errors) + return usage_lf_em4x50_sread(); + + clearCommandBuffer(); + SendCommandNG(CMD_LF_EM4X50_SREAD, (uint8_t *)&etd, sizeof(etd)); + + + if (!WaitForResponse(CMD_ACK, &resp)) { + PrintAndLogEx(WARNING, "\n timeout while waiting for reply.\n"); + return PM3_ETIMEOUT; + } + + // get, prepare and print response + print_sread_result(&resp, &etd); + + success = (resp.status & STATUS_SUCCESS) >> 1; + return (success) ? PM3_SUCCESS : PM3_ESOFT; +} From 445a367b4909eec32d5b367f5ab69104d01d5afa Mon Sep 17 00:00:00 2001 From: tharexde Date: Fri, 26 Jun 2020 14:21:09 +0200 Subject: [PATCH 21/84] added 4x50_sread --- client/src/cmdlfem4x.c | 1 + 1 file changed, 1 insertion(+) diff --git a/client/src/cmdlfem4x.c b/client/src/cmdlfem4x.c index a94882cb6..ef8cbdc13 100644 --- a/client/src/cmdlfem4x.c +++ b/client/src/cmdlfem4x.c @@ -1759,6 +1759,7 @@ static command_t CommandTable[] = { {"4x50_info", CmdEM4x50Info, IfPm3Lf, "read complete data from EM4x50"}, {"4x50_write", CmdEM4x50Write, IfPm3Lf, "write word data to EM4x50"}, {"4x50_write_password", CmdEM4x50WritePassword, IfPm3Lf, "change passwword of EM4x50 tag"}, + {"4x50_sread", CmdEM4x50SRead, IfPm3Lf, "read word data from EM4x50 on device"}, {NULL, NULL, NULL, NULL} }; From 3cf04e6cb91fa2c69dff69490fdb4bc01c237107 Mon Sep 17 00:00:00 2001 From: tharexde Date: Fri, 26 Jun 2020 14:21:29 +0200 Subject: [PATCH 22/84] added 4x50_sread --- include/pm3_cmd.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 125db9a7f..05c42dfd8 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -405,6 +405,7 @@ typedef struct { #define CMD_LF_EM4X50_INFO 0x0240 #define CMD_LF_EM4X50_WRITE 0x0241 #define CMD_LF_EM4X50_WRITE_PASSWORD 0x0242 +#define CMD_LF_EM4X50_SREAD 0x0243 // Sampling configuration for LF reader/sniffer #define CMD_LF_SAMPLING_SET_CONFIG 0x021D #define CMD_LF_FSK_SIMULATE 0x021E From 972ad78a40b9ba9203ed90dab31fa4f3e104f99f Mon Sep 17 00:00:00 2001 From: tharexde Date: Fri, 26 Jun 2020 14:21:54 +0200 Subject: [PATCH 23/84] rearranged defines --- include/em4x50.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/include/em4x50.h b/include/em4x50.h index 11b2509b7..ddda32f7f 100644 --- a/include/em4x50.h +++ b/include/em4x50.h @@ -11,9 +11,36 @@ #ifndef EM4X50_H__ #define EM4X50_H__ +#define EM4X50_NO_WORDS 34 + +// special words +#define EM4X50_DEVICE_PASSWORD 0 +#define EM4X50_PROTECTION 1 +#define EM4X50_CONTROL 2 +#define EM4X50_DEVICE_SERIAL 32 +#define EM4X50_DEVICE_ID 33 + +// control word (word = 4 bytes) +#define FIRST_WORD_READ 0 // first byte +#define LAST_WORD_READ 1 // second byte +#define CONFIG_BLOCK 2 // third byte +#define PASSWORD_CHECK 0x80 // first bit in third byte +#define READ_AFTER_WRITE 0x40 // second bit in third byte + +// protection word +#define FIRST_WORD_READ_PROTECTED 0 // first byte +#define LAST_WORD_READ_PROTECTED 1 // second byte +#define FIRST_WORD_WRITE_INHIBITED 2 // third byte +#define LAST_WORD_WRITE_INHIBITED 3 // fourth byte + +// misc +#define STATUS_NO_WORDS 0xfc +#define STATUS_SUCCESS 0x2 +#define STATUS_LOGIN 0x1 +#define NO_CHARS_MAX 400 + typedef struct { - bool fwr_given; - bool lwr_given; + bool addr_given; bool pwd_given; bool newpwd_given; uint8_t password[4]; From e1f571e8daa43e935ea177a495c4fa4a0cfea96e Mon Sep 17 00:00:00 2001 From: tharexde Date: Fri, 26 Jun 2020 14:58:08 +0200 Subject: [PATCH 24/84] forgot to terminate string variable --- client/src/cmdlfem4x50.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index d8a6ef53d..1c3af381e 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -206,6 +206,7 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr) { print_bit_table(words[i]); // final result + string[0] = '\0'; sprintf(pstring, "\n word[%i] msb: " _GREEN_("0x"), i); strcat(string, pstring); @@ -223,8 +224,6 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr) { } PrintAndLogEx(NORMAL,string); - - string[0] = '\0'; } } @@ -677,6 +676,7 @@ static void print_sread_result(PacketResponseNG *resp, const em4x50_data_t *etd) prepare_result(data, etd->address, etd->address, &word); print_result(&word, etd->address, etd->address); + string[0] = '\0'; sprintf(pstring, "\n reading " _GREEN_("ok ")); strcat(string, pstring); @@ -702,6 +702,7 @@ static void print_sread_result(PacketResponseNG *resp, const em4x50_data_t *etd) prepare_result(data, 0, now - 1, &word); print_result(&word, 0, now - 1); + string[0] = '\0'; sprintf(pstring, "\n reading " _GREEN_("ok ")); strcat(string, pstring); From f330f3925b1fd6627fd150127fffc5b9614740b6 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 18:33:56 +0200 Subject: [PATCH 25/84] text --- client/src/cmdlf.c | 6 +++--- client/src/cmdlfjablotron.c | 2 +- client/src/cmdlfmotorola.c | 11 ++++++----- client/src/cmdlfnedap.c | 9 ++++++--- client/src/cmdlfnexwatch.c | 20 +++++++++----------- client/src/cmdlfviking.c | 1 + 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 0d3703808..748c9557a 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -1276,16 +1276,16 @@ int CmdLFfind(const char *Cmd) { if (demodAWID() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("AWID ID") " found!"); goto out;} if (demodIOProx() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("IO Prox ID") " found!"); goto out;} if (demodParadox() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Paradox ID") " found!"); goto out;} - + if (demodNexWatch() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("NexWatch ID") " found!"); goto out;} + if (demodIndala() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Indala ID") " found!"); goto out;} + if (demodEM410x() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("EM410x ID") " found!"); goto out;} if (demodFDX() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("FDX-B ID") " found!"); goto out;} if (demodGuard() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Guardall G-Prox II ID") " found!"); goto out; } if (demodIdteck() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Idteck ID") " found!"); goto out;} - if (demodIndala() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Indala ID") " found!"); goto out;} if (demodJablotron() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Jablotron ID") " found!"); goto out;} if (demodNedap() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("NEDAP ID") " found!"); goto out;} - if (demodNexWatch() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("NexWatch ID") " found!"); goto out;} if (demodNoralsy() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Noralsy ID") " found!"); goto out;} if (demodKeri() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("KERI ID") " found!"); goto out;} if (demodPac() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("PAC/Stanley ID") " found!"); goto out;} diff --git a/client/src/cmdlfjablotron.c b/client/src/cmdlfjablotron.c index 464b6e282..a2859fbb4 100644 --- a/client/src/cmdlfjablotron.c +++ b/client/src/cmdlfjablotron.c @@ -120,7 +120,7 @@ int demodJablotron(void) { uint64_t rawid = ((uint64_t)(bytebits_to_byte(DemodBuffer + 16, 8) & 0xff) << 32) | bytebits_to_byte(DemodBuffer + 24, 32); uint64_t id = getJablontronCardId(rawid); - PrintAndLogEx(SUCCESS, "Jablotron - Card: " _GREEN_("%"PRIx64) ", Raw: %08X%08X", id, raw1, raw2); + PrintAndLogEx(SUCCESS, "Jablotron - Card: " _GREEN_("%"PRIx64) ", Raw: %08X%08X", id, raw1, raw2); uint8_t chksum = raw2 & 0xFF; bool isok = (chksum == jablontron_chksum(DemodBuffer)); diff --git a/client/src/cmdlfmotorola.c b/client/src/cmdlfmotorola.c index 1af4f120c..36777be02 100644 --- a/client/src/cmdlfmotorola.c +++ b/client/src/cmdlfmotorola.c @@ -30,7 +30,12 @@ static int CmdHelp(const char *Cmd); //see PSKDemod for what args are accepted static int CmdMotorolaDemod(const char *Cmd) { + (void)Cmd; + return demodMotorola(); +} +int demodMotorola(void) { + //PSK1 if (PSKDemod("32 1", true) != PM3_SUCCESS) { PrintAndLogEx(DEBUG, "DEBUG: Error - Motorola: PSK Demod failed"); @@ -140,7 +145,7 @@ static int CmdMotorolaRead(const char *Cmd) { sc.divisor = LF_DIVISOR_125; sc.samples_to_skip = 0; lf_config(&sc); - return CmdMotorolaDemod(Cmd); + return demodMotorola(); } static int CmdMotorolaClone(const char *Cmd) { @@ -252,10 +257,6 @@ int detectMotorola(uint8_t *dest, size_t *size) { return (int)start_idx; } -int demodMotorola(void) { - return CmdMotorolaDemod(""); -} - int readMotorolaUid(void) { return (CmdMotorolaRead("") == PM3_SUCCESS); } diff --git a/client/src/cmdlfnedap.c b/client/src/cmdlfnedap.c index da4354a49..ddd734eb3 100644 --- a/client/src/cmdlfnedap.c +++ b/client/src/cmdlfnedap.c @@ -42,6 +42,7 @@ static int usage_lf_nedap_gen(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf nedap generate s 1 c 123 i 12345")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -59,6 +60,7 @@ static int usage_lf_nedap_clone(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, _YELLOW_(" lf nedap clone s 1 c 123 i 12345")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -77,6 +79,7 @@ static int usage_lf_nedap_sim(void) { PrintAndLogEx(NORMAL, "Examples:"); // TODO proper example? PrintAndLogEx(NORMAL, _YELLOW_(" lf nedap sim s 1 c 7 i 1337")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -192,9 +195,9 @@ static int CmdLFNedapDemod(const char *Cmd) { badgeId = r1 * 10000 + r2 * 1000 + r3 * 100 + r4 * 10 + r5; - PrintAndLogEx(SUCCESS, "NEDAP - Card: " _YELLOW_("%05u") " subtype: " _YELLOW_("%1u")" customer code: " _YELLOW_("%03x"), badgeId, subtype, customerCode); - PrintAndLogEx(SUCCESS, "Checksum (%s) 0x%04X", _GREEN_("ok"), checksum); - PrintAndLogEx(SUCCESS, "Raw: %s", sprint_hex(data, size / 8)); + PrintAndLogEx(SUCCESS, "NEDAP - Card: " _YELLOW_("%05u") " subtype: " _YELLOW_("%1u")" customer code: " _YELLOW_("%03x") ", Raw: %s", badgeId, subtype, customerCode, sprint_hex(data, size / 8)); + PrintAndLogEx(DEBUG, "Checksum (%s) 0x%04X", _GREEN_("ok"), checksum); + } else { PrintAndLogEx(ERR, "Invalid idx (1:%02x - 2:%02x - 3:%02x - 4:%02x - 5:%02x)", idxC1, idxC2, idxC3, idxC4, idxC5); ret = PM3_ESOFT; diff --git a/client/src/cmdlfnexwatch.c b/client/src/cmdlfnexwatch.c index fda84b9b6..11541b29c 100644 --- a/client/src/cmdlfnexwatch.c +++ b/client/src/cmdlfnexwatch.c @@ -244,18 +244,16 @@ int demodNexWatch(void) { } PrintAndLogEx(SUCCESS, " 88bit id : " _YELLOW_("%"PRIu32) " (" _YELLOW_("0x%"PRIx32)")", cn, cn); PrintAndLogEx(SUCCESS, " mode : %x", mode); - if (parity == calc_parity) { - PrintAndLogEx(SUCCESS, " parity : %s (0x%X)", _GREEN_("ok"), parity); - } else { - PrintAndLogEx(WARNING, " parity : %s (0x%X != 0x%X)", _RED_("fail"), parity, calc_parity); - } - if (m_idx < ARRAYLEN(items)) { - PrintAndLogEx(SUCCESS, " checksum : %s (0x%02X)", _GREEN_("ok"), chk); - } else { - PrintAndLogEx(WARNING, " checksum : %s (0x%02X)", _RED_("fail"), chk); - } - PrintAndLogEx(INFO, " raw : " _YELLOW_("%"PRIX32"%"PRIX32"%"PRIX32), raw1, raw2, raw3); + if (parity == calc_parity) { + PrintAndLogEx(DEBUG, " parity : %s (0x%X)", _GREEN_("ok"), parity); + } else { + PrintAndLogEx(DEBUG, " parity : %s (0x%X != 0x%X)", _RED_("fail"), parity, calc_parity); + } + + PrintAndLogEx(DEBUG, " checksum : %s (0x%02X)", (m_idx < ARRAYLEN(items)) ? _GREEN_("ok") : _RED_("fail"), chk); + + PrintAndLogEx(INFO, " Raw : " _YELLOW_("%"PRIX32"%"PRIX32"%"PRIX32), raw1, raw2, raw3); return PM3_SUCCESS; } diff --git a/client/src/cmdlfviking.c b/client/src/cmdlfviking.c index 07d80af86..445dbc209 100644 --- a/client/src/cmdlfviking.c +++ b/client/src/cmdlfviking.c @@ -34,6 +34,7 @@ static int usage_lf_viking_clone(void) { PrintAndLogEx(NORMAL, " : specify write to Q5 (t5555 instead of t55x7)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf viking clone 1A337")); PrintAndLogEx(NORMAL, _YELLOW_(" lf viking clone 1A337 Q5")); return PM3_SUCCESS; } From 669bb1d5971e394248d95a39046f49372e97ad36 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 21:49:19 +0200 Subject: [PATCH 26/84] client/src/cmdhficlass.c --- client/src/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/util.c b/client/src/util.c index 5e1e55d67..80def08ef 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -301,7 +301,7 @@ char *sprint_hex_ascii(const uint8_t *data, const size_t len) { memset(buf, 0x00, UTIL_BUFFER_SIZE_SPRINT); size_t max_len = (len > 1010) ? 1010 : len; - snprintf(tmp, UTIL_BUFFER_SIZE_SPRINT, "%s | ", sprint_hex(data, max_len)); + snprintf(tmp, UTIL_BUFFER_SIZE_SPRINT, "%s| ", sprint_hex(data, max_len)); size_t i = 0; size_t pos = (max_len * 3) + 2; From 71e30a8c4faf9d179cb8c95801f46718debf41d4 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 21:49:50 +0200 Subject: [PATCH 27/84] layout --- client/src/cmdhficlass.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 98fd29562..3f7dd178d 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -1419,7 +1419,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { // print the dump PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "------+--+-------------------------+----------"); - PrintAndLogEx(INFO, " CSN |00| " _GREEN_("%s") " |", sprint_hex(tag_data, 8)); + PrintAndLogEx(INFO, " CSN |00| " _GREEN_("%s") "|", sprint_hex(tag_data, 8)); printIclassDumpContents(tag_data, 1, (gotBytes / 8), gotBytes); if (filename[0] == 0) { @@ -2055,7 +2055,7 @@ static int CmdHFiClassReadTagFile(const char *Cmd) { uint8_t *csn = dump; PrintAndLogEx(INFO, "------+--+-------------------------+----------"); - PrintAndLogEx(INFO, " CSN |00| " _GREEN_("%s") " |", sprint_hex(csn, 8)); + PrintAndLogEx(INFO, " CSN |00| " _GREEN_("%s") "|", sprint_hex(csn, 8)); printIclassDumpContents(dump, startblock, endblock, bytes_read); free(dump); return PM3_SUCCESS; From 5cce99db99044393e553da651e7b972d5d7919df Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 21:50:49 +0200 Subject: [PATCH 28/84] cleaning --- client/src/cmdhfmfu.c | 1 + client/src/cmdhfmfu.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index da2071fb7..c4a8ce0eb 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -1090,6 +1090,7 @@ uint32_t GetHF14AMfU_Type(void) { NT2H1001G0DUx 0004040202000B03 Micron UL 0034210101000E03 */ + if (memcmp(version, "\x00\x04\x03\x01\x01\x00\x0B", 7) == 0) { tagtype = UL_EV1_48; break; } else if (memcmp(version, "\x00\x04\x03\x01\x02\x00\x0B", 7) == 0) { tagtype = UL_NANO_40; break; } else if (memcmp(version, "\x00\x04\x03\x02\x01\x00\x0B", 7) == 0) { tagtype = UL_EV1_48; break; } diff --git a/client/src/cmdhfmfu.h b/client/src/cmdhfmfu.h index eb81c8dea..67e405677 100644 --- a/client/src/cmdhfmfu.h +++ b/client/src/cmdhfmfu.h @@ -22,7 +22,6 @@ typedef struct { uint32_t GetHF14AMfU_Type(void); int ul_print_type(uint32_t tagtype, uint8_t spaces); -void printMFUdump(mfu_dump_t *card); void printMFUdumpEx(mfu_dump_t *card, uint16_t pages, uint8_t startpage); int CmdHFMFUltra(const char *Cmd); From 1a490470c979179c134a557aa521790fe56807dd Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 21:53:19 +0200 Subject: [PATCH 29/84] chg: 15693 use bigbuf malloc to keep tracelog --- armsrc/iso15693.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index 9dbdd4f94..d88bae1f0 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -387,9 +387,10 @@ static int DemodAnswer(uint8_t *received, uint8_t *dest, uint16_t samplecount) { // returns: // number of decoded bytes // logging enabled +#define SIGNAL_BUFF_SIZE 20000 + static int GetIso15693AnswerFromTag(uint8_t *received, int *elapsed) { -#define SIGNAL_BUFF_SIZE 15000 // get current clock uint32_t time_0 = GetCountSspClk(); uint32_t time_stop = 0; @@ -446,7 +447,7 @@ static int GetIso15693AnswerFromSniff(uint8_t *received, int *samples, int *elap bool getNext = false; int counter = 0, ci, cq = 0; uint32_t time_0 = 0, time_stop = 0; - uint8_t *buf = BigBuf_get_addr(); + uint8_t *buf = BigBuf_malloc(SIGNAL_BUFF_SIZE); // get current clock time_0 = GetCountSspClk(); @@ -481,6 +482,7 @@ static int GetIso15693AnswerFromSniff(uint8_t *received, int *samples, int *elap time_stop = GetCountSspClk(); int k = DemodAnswer(received, buf, counter); LogTrace(received, k, time_0 << 4, time_stop << 4, NULL, false); + BigBuf_free(); return k; } @@ -521,7 +523,6 @@ void AcquireRawAdcSamplesIso15693(void) { } } - LogTrace(cmd, CMD_ID_RESP, time_start << 4, GetCountSspClk() << 4, NULL, true); FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR); From 06aecb09b79deae925abe73bcbea5680a828b136 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 22:20:32 +0200 Subject: [PATCH 30/84] chg: hf iclass reader - textual --- client/src/cmdhficlass.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 3f7dd178d..0505ecb80 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -465,13 +465,14 @@ static void mem_app_config(const picopass_hdr *hdr) { if (applimit < 6) applimit = 26; if (kb == 2 && (applimit > 0x1f)) applimit = 26; - PrintAndLogEx(INFO, "------ " _CYAN_("Memory") "------"); - PrintAndLogEx(INFO, " %u KBits/%u App Areas (%u * 8 bytes) [%02X]", kb, app_areas, max_blk, mem); - PrintAndLogEx(INFO, " AA1 blocks 06-%02X", applimit); - PrintAndLogEx(INFO, " AA2 blocks %02X-%02X", applimit + 1, max_blk); - PrintAndLogEx(INFO, " OTP 0x%02X%02X", hdr->conf.otp[1], hdr->conf.otp[0]); + PrintAndLogEx(INFO, "------ " _CYAN_("Memory") " ------"); + PrintAndLogEx(INFO, " %u KBits/%u App Areas (%u bytes), max blocks 0x%02X (%02d)", kb, app_areas, max_blk * 8, mem, mem); + PrintAndLogEx(INFO, " AA1 blocks 0x06 - 0x%02X (06 - %02d)", applimit, applimit); + PrintAndLogEx(INFO, " AA2 blocks 0x%02X - 0x%02X (%02d - %02d)", applimit + 1, max_blk, applimit + 1, max_blk); + PrintAndLogEx(INFO, " OTP 0x%02X%02X", hdr->conf.otp[1], hdr->conf.otp[0]); - PrintAndLogEx(INFO, "------ " _CYAN_("KeyAccess") "------"); + PrintAndLogEx(INFO, "------ " _CYAN_("KeyAccess") " ------"); + PrintAndLogEx(INFO, " Kd = Debit key (AA1), Kc = Credit key (AA2)"); uint8_t book = isset(mem, 0x20); if (book) { PrintAndLogEx(INFO, " Read A - Kd"); @@ -2941,9 +2942,12 @@ int readIclass(bool loop, bool verbose) { DropField(); return PM3_EOPABORTED; } + + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " --------------------------"); + PrintAndLogEx(INFO, "-------------------------------------------------------------"); if (readStatus & FLAG_ICLASS_READER_CSN) { - PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(SUCCESS, " CSN: " _YELLOW_("%s"), sprint_hex(data, 8)); tagFound = true; } @@ -2964,7 +2968,9 @@ int readIclass(bool loop, bool verbose) { bool se_enabled = (memcmp((uint8_t *)(data + 8 * 5), "\xff\xff\xff\x00\x06\xff\xff\xff", 8) == 0); + PrintAndLogEx(INFO, "--------- " _CYAN_("AIA") " ---------"); PrintAndLogEx(SUCCESS, " App IA: %s", sprint_hex(data + 8 * 5, 8)); + PrintAndLogEx(INFO, "------ " _CYAN_("fingerprint") " ------"); if (isHidRange) { @@ -2982,6 +2988,7 @@ int readIclass(bool loop, bool verbose) { } if (tagFound && !loop) { + PrintAndLogEx(NORMAL, ""); DropField(); return PM3_SUCCESS; } @@ -2991,6 +2998,7 @@ int readIclass(bool loop, bool verbose) { } if (!loop) break; } + PrintAndLogEx(NORMAL, ""); DropField(); return res; } From 2aa7c8f6604e911742391f9e6757a317cc9b7a81 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 23:31:32 +0200 Subject: [PATCH 31/84] textual --- client/src/cmdhf.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/client/src/cmdhf.c b/client/src/cmdhf.c index 989211f1b..4fc138a98 100644 --- a/client/src/cmdhf.c +++ b/client/src/cmdhf.c @@ -94,7 +94,7 @@ int CmdHFSearch(const char *Cmd) { int res = PM3_ESOFT; PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, "Searching for ThinFilm tag..."); + PrintAndLogEx(INPLACE, " Searching for ThinFilm tag..."); if (IfPm3NfcBarcode()) { if (infoThinFilm(false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Thinfilm tag") " found\n"); @@ -103,7 +103,7 @@ int CmdHFSearch(const char *Cmd) { } PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, "Searching for LTO-CM tag..."); + PrintAndLogEx(INPLACE, " Searching for LTO-CM tag..."); if (IfPm3Iso14443a()) { if (infoLTO(false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("LTO-CM tag") " found\n"); @@ -112,7 +112,7 @@ int CmdHFSearch(const char *Cmd) { } PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, "Searching for ISO14443-A tag..."); + PrintAndLogEx(INPLACE, " Searching for ISO14443-A tag..."); if (IfPm3Iso14443a()) { if (infoHF14A(false, false, false) > 0) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO14443-A tag") " found\n"); @@ -121,7 +121,7 @@ int CmdHFSearch(const char *Cmd) { } PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, "Searching for ISO15693 tag..."); + PrintAndLogEx(INPLACE, " Searching for ISO15693 tag..."); if (IfPm3Iso15693()) { if (readHF15Uid(false)) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO15693 tag") " found\n"); @@ -130,7 +130,7 @@ int CmdHFSearch(const char *Cmd) { } PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, "Searching for LEGIC tag..."); + PrintAndLogEx(INPLACE, " Searching for LEGIC tag..."); if (IfPm3Legicrf()) { if (readLegicUid(false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("LEGIC Prime tag") " found\n"); @@ -139,7 +139,7 @@ int CmdHFSearch(const char *Cmd) { } PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, "Searching for Topaz tag..."); + PrintAndLogEx(INPLACE, " Searching for Topaz tag..."); if (IfPm3Iso14443a()) { if (readTopazUid(false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Topaz tag") " found\n"); @@ -148,7 +148,7 @@ int CmdHFSearch(const char *Cmd) { } PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, "Searching for FeliCa tag..."); + PrintAndLogEx(INPLACE, " Searching for FeliCa tag..."); if (IfPm3Felica()) { if (readFelicaUid(false) == PM3_SUCCESS) { PrintAndLogEx(NORMAL, "\nValid " _GREEN_("ISO18092 / FeliCa tag") " found\n"); @@ -158,7 +158,7 @@ int CmdHFSearch(const char *Cmd) { /* // 14b and iclass is the longest test (put last) PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, "Searching for CryptoRF tag..."); + PrintAndLogEx(INPLACE, " Searching for CryptoRF tag..."); if (IfPm3Iso14443b()) { if (readHFCryptoRF(false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("CryptoRF tag") " found\n"); @@ -169,7 +169,7 @@ int CmdHFSearch(const char *Cmd) { // 14b and iclass is the longest test (put last) PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, "Searching for ISO14443-B tag..."); + PrintAndLogEx(INPLACE, " Searching for ISO14443-B tag..."); if (IfPm3Iso14443b()) { if (readHF14B(false) == 1) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO14443-B tag") " found\n"); @@ -178,7 +178,7 @@ int CmdHFSearch(const char *Cmd) { } PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, "Searching for iClass / PicoPass tag..."); + PrintAndLogEx(INPLACE, " Searching for iClass / PicoPass tag..."); if (IfPm3Iclass()) { if (readIclass(false, false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("iClass tag / PicoPass tag") " found\n"); From e7514ecbc0b7fed2175138d889b8c0ac3973e227 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 23:50:22 +0200 Subject: [PATCH 32/84] text --- client/src/cmdhf15.c | 5 +++-- client/src/cmdhfmf.c | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/client/src/cmdhf15.c b/client/src/cmdhf15.c index 627e7e4bc..2b8812d33 100644 --- a/client/src/cmdhf15.c +++ b/client/src/cmdhf15.c @@ -1835,6 +1835,7 @@ static int CmdHF15CSetUID(const char *Cmd) { } static command_t CommandTable[] = { + {"-----------", CmdHF15Help, AlwaysAvailable, "--------------------- " _CYAN_("General") " ---------------------"}, {"help", CmdHF15Help, AlwaysAvailable, "This help"}, {"list", CmdHF15List, AlwaysAvailable, "List ISO15693 history"}, {"demod", CmdHF15Demod, AlwaysAvailable, "Demodulate ISO15693 from tag"}, @@ -1850,11 +1851,11 @@ static command_t CommandTable[] = { {"samples", CmdHF15Samples, IfPm3Iso15693, "Acquire Samples as Reader (enables carrier, sends inquiry)"}, {"sim", CmdHF15Sim, IfPm3Iso15693, "Fake an ISO15693 tag"}, {"write", CmdHF15Write, IfPm3Iso15693, "Write a block"}, - {"-----------", CmdHF15Help, IfPm3Iso15693, ""}, + {"-----------", CmdHF15Help, IfPm3Iso15693, "----------------------- " _CYAN_("afi") " -----------------------"}, {"findafi", CmdHF15FindAfi, IfPm3Iso15693, "Brute force AFI of an ISO15693 tag"}, {"writeafi", CmdHF15WriteAfi, IfPm3Iso15693, "Writes the AFI on an ISO15693 tag"}, {"writedsfid", CmdHF15WriteDsfid, IfPm3Iso15693, "Writes the DSFID on an ISO15693 tag"}, - {"-----------", CmdHF15Help, IfPm3Iso15693, ""}, + {"-----------", CmdHF15Help, IfPm3Iso15693, "----------------------- " _CYAN_("magic") " -----------------------"}, {"csetuid", CmdHF15CSetUID, IfPm3Iso15693, "Set UID for magic Chinese card"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index eb9670b70..0aa6bfd9b 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -4828,6 +4828,7 @@ static int CmdHF14AMfList(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, {"list", CmdHF14AMfList, AlwaysAvailable, "List MIFARE history"}, + {"-----------", CmdHelp, IfPm3Iso14443a, "----------------------- " _CYAN_("recovery") " -----------------------"}, {"darkside", CmdHF14AMfDarkside, IfPm3Iso14443a, "Darkside attack"}, {"nested", CmdHF14AMfNested, IfPm3Iso14443a, "Nested attack"}, {"hardnested", CmdHF14AMfNestedHard, AlwaysAvailable, "Nested attack for hardened MIFARE Classic cards"}, @@ -4838,7 +4839,7 @@ static command_t CommandTable[] = { {"chk", CmdHF14AMfChk, IfPm3Iso14443a, "Check keys"}, {"fchk", CmdHF14AMfChk_fast, IfPm3Iso14443a, "Check keys fast, targets all keys on card"}, {"decrypt", CmdHf14AMfDecryptBytes, AlwaysAvailable, "[nt] [ar_enc] [at_enc] [data] - to decrypt sniff or trace"}, - {"-----------", CmdHelp, IfPm3Iso14443a, ""}, + {"-----------", CmdHelp, IfPm3Iso14443a, "----------------------- " _CYAN_("operations") " -----------------------"}, {"auth4", CmdHF14AMfAuth4, IfPm3Iso14443a, "ISO14443-4 AES authentication"}, {"dump", CmdHF14AMfDump, IfPm3Iso14443a, "Dump MIFARE classic tag to binary file"}, {"mad", CmdHF14AMfMAD, IfPm3Iso14443a, "Checks and prints MAD"}, @@ -4850,7 +4851,7 @@ static command_t CommandTable[] = { {"wrbl", CmdHF14AMfWrBl, IfPm3Iso14443a, "Write MIFARE classic block"}, {"setmod", CmdHf14AMfSetMod, IfPm3Iso14443a, "Set MIFARE Classic EV1 load modulation strength"}, // {"sniff", CmdHF14AMfSniff, 0, "Sniff card-reader communication"}, - {"-----------", CmdHelp, IfPm3Iso14443a, ""}, + {"-----------", CmdHelp, IfPm3Iso14443a, "----------------------- " _CYAN_("simulation") " -----------------------"}, {"sim", CmdHF14AMfSim, IfPm3Iso14443a, "Simulate MIFARE card"}, {"eclr", CmdHF14AMfEClear, IfPm3Iso14443a, "Clear simulator memory"}, {"eget", CmdHF14AMfEGet, IfPm3Iso14443a, "Get simulator memory block"}, @@ -4859,7 +4860,7 @@ static command_t CommandTable[] = { {"esave", CmdHF14AMfESave, IfPm3Iso14443a, "Save to file emul dump"}, {"ecfill", CmdHF14AMfECFill, IfPm3Iso14443a, "Fill simulator memory with help of keys from simulator"}, {"ekeyprn", CmdHF14AMfEKeyPrn, IfPm3Iso14443a, "Print keys from simulator memory"}, - {"-----------", CmdHelp, IfPm3Iso14443a, ""}, + {"-----------", CmdHelp, IfPm3Iso14443a, "----------------------- " _CYAN_("magic") " -----------------------"}, {"csetuid", CmdHF14AMfCSetUID, IfPm3Iso14443a, "Set UID (magic chinese card)"}, {"cwipe", CmdHF14AMfCWipe, IfPm3Iso14443a, "Wipe card to default UID/Sectors/Keys"}, {"csetblk", CmdHF14AMfCSetBlk, IfPm3Iso14443a, "Write block (magic chinese card)"}, @@ -4867,7 +4868,7 @@ static command_t CommandTable[] = { {"cgetsc", CmdHF14AMfCGetSc, IfPm3Iso14443a, "Read sector (magic chinese card)"}, {"cload", CmdHF14AMfCLoad, IfPm3Iso14443a, "Load dump (magic chinese card)"}, {"csave", CmdHF14AMfCSave, IfPm3Iso14443a, "Save dump from magic chinese card into file or emulator"}, - {"-----------", CmdHelp, IfPm3Iso14443a, ""}, + {"-----------", CmdHelp, IfPm3Iso14443a, "----------------------- " _CYAN_("i") " -----------------------"}, {"ice", CmdHF14AMfice, IfPm3Iso14443a, "collect MIFARE Classic nonces to file"}, {NULL, NULL, NULL, NULL} }; From 5e7911becb75ceab802a45dddcea8948b63ec37d Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 23:50:36 +0200 Subject: [PATCH 33/84] text --- client/src/cmdhffelica.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/src/cmdhffelica.c b/client/src/cmdhffelica.c index 1fcf23fa3..f62a9a8ff 100644 --- a/client/src/cmdhffelica.c +++ b/client/src/cmdhffelica.c @@ -1848,7 +1848,8 @@ int readFelicaUid(bool verbose) { } static command_t CommandTable[] = { - {"----------- General -----------", CmdHelp, AlwaysAvailable, ""}, + + {"-----------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("General") " -----------------------"}, {"help", CmdHelp, AlwaysAvailable, "This help"}, {"list", CmdHFFelicaList, AlwaysAvailable, "List ISO 18092/FeliCa history"}, {"reader", CmdHFFelicaReader, IfPm3Felica, "Act like an ISO18092/FeliCa reader"}, @@ -1856,7 +1857,7 @@ static command_t CommandTable[] = { {"raw", CmdHFFelicaCmdRaw, IfPm3Felica, "Send raw hex data to tag"}, {"rdunencrypted", CmdHFFelicaReadWithoutEncryption, IfPm3Felica, "read Block Data from authentication-not-required Service."}, {"wrunencrypted", CmdHFFelicaWriteWithoutEncryption, IfPm3Felica, "write Block Data to an authentication-not-required Service."}, - {"----------- FeliCa Standard -----------", CmdHelp, AlwaysAvailable, ""}, + {"-----------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("FeliCa Standard") " -----------------------"}, //{"dump", CmdHFFelicaDump, IfPm3Felica, "Wait for and try dumping FeliCa"}, {"rqservice", CmdHFFelicaRequestService, IfPm3Felica, "verify the existence of Area and Service, and to acquire Key Version."}, {"rqresponse", CmdHFFelicaRequestResponse, IfPm3Felica, "verify the existence of a card and its Mode."}, @@ -1875,7 +1876,7 @@ static command_t CommandTable[] = { //{"readv2", CmdHFFelicaNotImplementedYet, IfPm3Felica, "read Block Data from authentication-required Service."}, //{"writev2", CmdHFFelicaNotImplementedYet, IfPm3Felica, "write Block Data to authentication-required Service."}, //{"uprandomid", CmdHFFelicaNotImplementedYet, IfPm3Felica, "update Random ID (IDr)."}, - {"----------- FeliCa Light -----------", CmdHelp, AlwaysAvailable, ""}, + {"-----------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("FeliCa Light") " -----------------------"}, {"litesim", CmdHFFelicaSimLite, IfPm3Felica, " - only reply to poll request"}, {"litedump", CmdHFFelicaDumpLite, IfPm3Felica, "Wait for and try dumping FelicaLite"}, // {"sim", CmdHFFelicaSim, IfPm3Felica, " -- Simulate ISO 18092/FeliCa tag"} From d4b752e23b46b21ade13cbe5dcdf73b9136a9ad2 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Jun 2020 23:53:34 +0200 Subject: [PATCH 34/84] text --- client/src/cmdmain.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/cmdmain.c b/client/src/cmdmain.c index 0ca9826d8..1c6cbd82c 100644 --- a/client/src/cmdmain.c +++ b/client/src/cmdmain.c @@ -50,7 +50,7 @@ static int usage_hints(void) { PrintAndLogEx(NORMAL, " <0|1> off or on"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hints 1"); + PrintAndLogEx(NORMAL, _YELLOW_(" hints 1")); return PM3_SUCCESS; } @@ -63,7 +63,7 @@ static int usage_msleep(void) { PrintAndLogEx(NORMAL, " time in milliseconds"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " msleep 100"); + PrintAndLogEx(NORMAL, _YELLOW_(" msleep 100")); return PM3_SUCCESS; } @@ -75,7 +75,7 @@ static int usage_auto(void) { PrintAndLogEx(NORMAL, " h This help"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " auto"); + PrintAndLogEx(NORMAL, _YELLOW_(" auto")); return PM3_SUCCESS; } @@ -249,7 +249,7 @@ static int CmdPref(const char *Cmd) { static command_t CommandTable[] = { - {"--------",CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("sub") " -----------------------"}, + {"--------",CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Technology") " -----------------------"}, {"analyse", CmdAnalyse, AlwaysAvailable, "{ Analyse utils... }"}, {"data", CmdData, AlwaysAvailable, "{ Plot window / data buffer manipulation... }"}, @@ -264,7 +264,7 @@ static command_t CommandTable[] = { {"trace", CmdTrace, AlwaysAvailable, "{ Trace manipulation... }"}, {"usart", CmdUsart, IfPm3FpcUsartFromUsb, "{ USART commands... }"}, {"wiegand", CmdWiegand, AlwaysAvailable, "{ Wiegand format manipulation... }"}, - {"--------",CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("sub") " -----------------------"}, + {"--------",CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("General") " -----------------------"}, {"auto", CmdAuto, IfPm3Present, "Automated detection process for unknown tags"}, {"help", CmdHelp, AlwaysAvailable, "This help. Use " _YELLOW_("' help'") " for details of a particular command."}, {"hints", CmdHints, AlwaysAvailable, "Turn hints on / off"}, From b06ffe947393716fdcd46d34a1ab486fa242ea12 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 27 Jun 2020 00:06:03 +0200 Subject: [PATCH 35/84] text --- doc/cheatsheet.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/cheatsheet.md b/doc/cheatsheet.md index 0ae47b68c..0217600d6 100644 --- a/doc/cheatsheet.md +++ b/doc/cheatsheet.md @@ -205,7 +205,7 @@ k : key filename, if no given, UID will be used as filename" f : data filename, if no given, UID will be used as filename pm3 --> hf mf dump 1 -pm3 --> hf mf dump 1 k hf-mf-A29558E4-key.bin f hf-mf-A29558E4-data.bin +pm3 --> hf mf dump 1 k hf-mf-A29558E4-key.bin f hf-mf-A29558E4-dump.bin ``` Convert .bin to .eml @@ -275,7 +275,7 @@ Clone Mifare 1K Sequence ``` pm3 --> hf mf chk *1 ? d mfc_default_keys pm3 --> hf mf dump -pm3 --> hf mf restore 1 u 4A6CE843 k hf-mf-A29558E4-key.bin f hf-mf-A29558E4-data.bin +pm3 --> hf mf restore 1 u 4A6CE843 k hf-mf-A29558E4-key.bin f hf-mf-A29558E4-dump.bin ``` Read Mifare Ultralight EV1 From fb2735ef86c04c7cad6d9c94aaf2d8f05e37776c Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 27 Jun 2020 00:07:09 +0200 Subject: [PATCH 36/84] text --- tools/pm3_mf7b_wipe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pm3_mf7b_wipe.py b/tools/pm3_mf7b_wipe.py index 9f7b29c6b..1bc0db4b9 100755 --- a/tools/pm3_mf7b_wipe.py +++ b/tools/pm3_mf7b_wipe.py @@ -79,7 +79,7 @@ import subprocess # EML data var te get keys of -EML_FILE_DATA = """PLACE RAW hf-mf-CARD_UID-data.eml FILE CONTENT OF CURRENTLY LOADED CARD HERE""" +EML_FILE_DATA = """PLACE RAW hf-mf-CARD_UID-dump.eml FILE CONTENT OF CURRENTLY LOADED CARD HERE""" # Change your device name here if it differs from the default Proxmark3 RDV4.0 PROXMARK_BIN_EXEC_STRING = 'proxmark3 -c "%s" /dev/tty.usbmodemiceman1' # Constants From 86eaac46dcc2b4e347b24935ae9780ca85e2f383 Mon Sep 17 00:00:00 2001 From: tharexde Date: Sat, 27 Jun 2020 00:20:56 +0200 Subject: [PATCH 37/84] formal adjustments --- armsrc/em4x50.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index 1df07798c..cfbfb9fe0 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -604,7 +604,9 @@ static int get_word_from_bitstream(uint8_t bits[EM4X50_TAG_WORD]) { } } +//============================================================================== // login function +//============================================================================== static bool login(uint8_t password[4]) { @@ -631,7 +633,9 @@ static bool login(uint8_t password[4]) { return false; } +//============================================================================== // reset function +//============================================================================== static bool reset(void) { @@ -653,7 +657,9 @@ static bool reset(void) { return false; } +//============================================================================== // read functions +//============================================================================== static bool standard_read(int *now) { @@ -756,7 +762,7 @@ void em4x50_info(em4x50_data_t *etd) { void em4x50_sread(em4x50_data_t *etd) { - // reads single word in two alternative ways: + // reads in two different ways: // - using "selective read mode" -> bidirectional communication // - using "standard read mode" -> unidirectional communication (read // data that tag transmits "voluntarily") @@ -764,7 +770,7 @@ void em4x50_sread(em4x50_data_t *etd) { bool bsuccess = false, blogin = false; int now = 0; uint8_t status = 0; - uint8_t addresses[] = {0x00, 0x00, 0x00, 0x00}; // fwr = 0, lwr = 33 + uint8_t addresses[] = {0x00, 0x00, 0x00, 0x00}; init_tag(); em4x50_setup_read(); @@ -790,14 +796,16 @@ void em4x50_sread(em4x50_data_t *etd) { bsuccess = standard_read(&now); } + status = (now << 2) + (bsuccess << 1) + blogin; lf_finalize(); reply_ng(CMD_ACK, status, (uint8_t *)tag.sectors, 238); } - +//============================================================================== // write functions +//============================================================================== static bool write(uint8_t word[4], uint8_t address) { From f264473b69e87c3aed1341d0580602058752d622 Mon Sep 17 00:00:00 2001 From: tharexde Date: Sat, 27 Jun 2020 00:21:56 +0200 Subject: [PATCH 38/84] formal adjustments --- client/src/cmdlfem4x50.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index 1c3af381e..cee6ece71 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -723,8 +723,8 @@ int CmdEM4x50SRead(const char *Cmd) { // envoke reading // - without option -> standard read mode - // - with given address (option a) and optional password if address is - // read protected -> selective read mode + // - with given address (option a) (and optional password if address is + // read protected) -> selective read mode bool errors = false, success = false; uint8_t cmdp = 0; From 1f04fa7ba0d3472637c18ce9a9b878aab2da88a6 Mon Sep 17 00:00:00 2001 From: tharexde Date: Sat, 27 Jun 2020 00:25:04 +0200 Subject: [PATCH 39/84] added lf em function 4x50_sread --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6791e748a..416f063b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Added lf em function: 4x50_sread (@tharexde) - Added lf em functions: 4x50_info, 4x50_write, 4x50_write_password (@tharexde) - Fix em4x50 demodulation error (@tharexde) - Fix `hf mfdes` authentification issues, DES working (@bkerler) From b300899f8c1977ef085227dba45e743f2b7753fb Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 27 Jun 2020 18:14:29 +0200 Subject: [PATCH 40/84] hf 14a info - MIFARE DESFire MF3ICD40 detection --- client/src/cmdhf14a.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index b41dabb7f..6ce4d077e 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -1328,6 +1328,7 @@ static int detect_nxp_card(uint8_t sak, uint16_t atqa) { if ((sak & 0x20) == 0x20) { if (atqa == 0x0344) { + printTag("MIFARE DESFire MF3ICD40"); printTag("MIFARE DESFire EV1 2K/4K/8K / DESFire EV1 CL2 2K/4K/8K"); printTag("MIFARE NTAG424DNA"); type |= MTDESFIRE; @@ -1431,6 +1432,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { PrintAndLogEx(SUCCESS, "------ " _CYAN_("ISO14443-a Information") "------------------"); PrintAndLogEx(SUCCESS, "-------------------------------------------------------------"); } + PrintAndLogEx(SUCCESS, " UID: " _GREEN_("%s"), sprint_hex(card.uid, card.uidlen)); PrintAndLogEx(SUCCESS, "ATQA: " _GREEN_("%02x %02x"), card.atqa[1], card.atqa[0]); PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02x [%" PRIu64 "]"), card.sak, resp.oldarg[0]); From c3a833b10184c0d3183006a0e67fe61f6b314bdc Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 27 Jun 2020 22:22:15 +0200 Subject: [PATCH 41/84] text --- client/resources/aid_desfire.json | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/client/resources/aid_desfire.json b/client/resources/aid_desfire.json index 926bb1475..4dddc2a52 100644 --- a/client/resources/aid_desfire.json +++ b/client/resources/aid_desfire.json @@ -20,9 +20,17 @@ "Vendor": "HID", "Country": "US", "Name": "Access control", - "Description": "Genuine HID", + "Description": "Field Encoder", "Type": "pacs" - }, + }, + { + "AID": "53494F", + "Vendor": "HID", + "Country": "US", + "Name": "Access control", + "Description": "HID Factory", + "Type": "pacs" + }, { "AID": "4F5931", "Vendor": "Transport of London", @@ -54,7 +62,7 @@ "Name": "Legic", "Description": "(FID 02: EF-CONF)", "Type": "" - }, + }, { "AID": "578000", "Vendor": "NORTIC", @@ -329,5 +337,4 @@ FFFFFF General Issuer Information (FIDs 00: MAD Version; 01: Card Holder; 02: Ca "Description": "CAR2GO - Member Card", "Type": "carsharing" } - ] From fe3e77915deb83e411f9ab69191360c42d2d4196 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 28 Jun 2020 19:13:01 +0200 Subject: [PATCH 42/84] hf iclass reader - output redesign --- client/src/cmdhficlass.c | 71 ++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 0505ecb80..501190170 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -388,9 +388,9 @@ static void fuse_config(const picopass_hdr *hdr) { uint8_t fuses = hdr->conf.fuses; if (isset(fuses, FUSE_FPERS)) - PrintAndLogEx(SUCCESS, " Mode: " _GREEN_("Personalization [programmable]")); + PrintAndLogEx(SUCCESS, " Mode: " _GREEN_("Personalization (programmable)")); else - PrintAndLogEx(SUCCESS, " Mode: " _YELLOW_("Application [locked]")); + PrintAndLogEx(SUCCESS, " Mode: " _YELLOW_("Application (locked)")); if (isset(fuses, FUSE_CODING1)) { PrintAndLogEx(SUCCESS, "Coding: RFU"); @@ -414,9 +414,20 @@ static void fuse_config(const picopass_hdr *hdr) { else PrintAndLogEx(INFO, " RA: Read access not enabled"); - PrintAndLogEx(INFO, " Block write lock 0x%02X", hdr->conf.block_writelock); - PrintAndLogEx(INFO, " EAS 0x%02X", hdr->conf.eas); - + PrintAndLogEx(INFO, + "App limit " _YELLOW_("0x%02X") ", OTP " _YELLOW_("0x%02X%02X") ", Block write lock " _YELLOW_("0x%02X") + , hdr->conf.app_limit + , hdr->conf.otp[1] + , hdr->conf.otp[0] + , hdr->conf.block_writelock + ); + PrintAndLogEx(INFO, + " Chip " _YELLOW_("0x%02X") ", Mem " _YELLOW_("0x%02X") ", EAS " _YELLOW_("0x%02X") ", Fuses " _YELLOW_("0x%02X") + , hdr->conf.chip_config + , hdr->conf.mem_config + , hdr->conf.eas + , hdr->conf.fuses + ); } static void getMemConfig(uint8_t mem_cfg, uint8_t chip_cfg, uint8_t *max_blk, uint8_t *app_areas, uint8_t *kb) { @@ -467,9 +478,8 @@ static void mem_app_config(const picopass_hdr *hdr) { PrintAndLogEx(INFO, "------ " _CYAN_("Memory") " ------"); PrintAndLogEx(INFO, " %u KBits/%u App Areas (%u bytes), max blocks 0x%02X (%02d)", kb, app_areas, max_blk * 8, mem, mem); - PrintAndLogEx(INFO, " AA1 blocks 0x06 - 0x%02X (06 - %02d)", applimit, applimit); - PrintAndLogEx(INFO, " AA2 blocks 0x%02X - 0x%02X (%02d - %02d)", applimit + 1, max_blk, applimit + 1, max_blk); - PrintAndLogEx(INFO, " OTP 0x%02X%02X", hdr->conf.otp[1], hdr->conf.otp[0]); + PrintAndLogEx(INFO, " AA1 blocks %u { 0x06 - 0x%02X (06 - %02d) }", applimit - 5 , applimit, applimit); + PrintAndLogEx(INFO, " AA2 blocks %u { 0x%02X - 0x%02X (%02d - %02d) }", max_blk - applimit, applimit + 1, max_blk, applimit + 1, max_blk); PrintAndLogEx(INFO, "------ " _CYAN_("KeyAccess") " ------"); PrintAndLogEx(INFO, " Kd = Debit key (AA1), Kc = Credit key (AA2)"); @@ -492,6 +502,7 @@ static void mem_app_config(const picopass_hdr *hdr) { } static void print_picopass_info(const picopass_hdr *hdr) { + PrintAndLogEx(INFO, "------ " _CYAN_("card configuration") " ------"); fuse_config(hdr); mem_app_config(hdr); } @@ -2923,7 +2934,7 @@ int readIclass(bool loop, bool verbose) { uint32_t res = PM3_ETIMEOUT; // loop in client not device - else on windows have a communication error - while (!kbd_enter_pressed()) { + while (kbd_enter_pressed() == false) { clearCommandBuffer(); SendCommandMIX(CMD_HF_ICLASS_READER, flags, 0, 0, NULL, 0); @@ -2932,34 +2943,49 @@ int readIclass(bool loop, bool verbose) { if (WaitForResponseTimeout(CMD_ACK, &resp, 4500)) { uint8_t readStatus = resp.oldarg[0] & 0xff; - uint8_t *data = resp.data.asBytes; - -// if (verbose) PrintAndLogEx(INFO, "Readstatus:%02x", readStatus); // no tag found or button pressed if ((readStatus == 0 && !loop) || readStatus == 0xFF) { - // abort DropField(); return PM3_EOPABORTED; } + + uint8_t *data = resp.data.asBytes; + picopass_hdr *hdr = (picopass_hdr *)data; + uint16_t length = resp.length; + if ( length != sizeof(picopass_hdr)) + continue; + PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " --------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------"); if (readStatus & FLAG_ICLASS_READER_CSN) { - PrintAndLogEx(SUCCESS, " CSN: " _YELLOW_("%s"), sprint_hex(data, 8)); + PrintAndLogEx(SUCCESS, " CSN: " _GREEN_("%s") " (uid)", sprint_hex(hdr->csn, sizeof(hdr->csn))); tagFound = true; } - if (readStatus & FLAG_ICLASS_READER_CC) { - PrintAndLogEx(SUCCESS, " CC: %s", sprint_hex(data + 16, 8)); + if (readStatus & FLAG_ICLASS_READER_CONF) { + PrintAndLogEx(SUCCESS, " Config: %s (Card configuration)", sprint_hex((uint8_t *)&hdr->conf, sizeof(hdr->conf))); } + if (readStatus & FLAG_ICLASS_READER_CC) { + PrintAndLogEx(SUCCESS, "E-purse: %s (Card challenge, CC)", sprint_hex(hdr->epurse, sizeof(hdr->epurse))); + } + + PrintAndLogEx(SUCCESS, " Kd: %s (Debit key, hidden)", sprint_hex(hdr->key_d, sizeof(hdr->key_d))); + PrintAndLogEx(SUCCESS, " Kc: %s (Credit key, hidden)", sprint_hex(hdr->key_c, sizeof(hdr->key_c))); + + if (readStatus & FLAG_ICLASS_READER_AIA) { +// PrintAndLogEx(INFO, "--------- " _CYAN_("AIA") " ---------"); + PrintAndLogEx(SUCCESS, " AIA: %s (Application Issuer area)", sprint_hex(hdr->app_issuer_area, sizeof(hdr->app_issuer_area))); + } + if (readStatus & FLAG_ICLASS_READER_CONF) { printIclassDumpInfo(data); } - + // if CSN ends with FF12E0, it's inside HID CSN range. bool isHidRange = (memcmp((uint8_t *)(data + 5), "\xFF\x12\xE0", 3) == 0); @@ -2967,20 +2993,15 @@ int readIclass(bool loop, bool verbose) { bool legacy = (memcmp((uint8_t *)(data + 8 * 5), "\xff\xff\xff\xff\xff\xff\xff\xff", 8) == 0); bool se_enabled = (memcmp((uint8_t *)(data + 8 * 5), "\xff\xff\xff\x00\x06\xff\xff\xff", 8) == 0); - - PrintAndLogEx(INFO, "--------- " _CYAN_("AIA") " ---------"); - PrintAndLogEx(SUCCESS, " App IA: %s", sprint_hex(data + 8 * 5, 8)); - PrintAndLogEx(INFO, "------ " _CYAN_("fingerprint") " ------"); + PrintAndLogEx(INFO, "------ " _CYAN_("Fingerprint") " ------"); if (isHidRange) { - PrintAndLogEx(SUCCESS, _YELLOW_("iClass")" (CSN is in HID range)"); - if (legacy) - PrintAndLogEx(SUCCESS, " possible "_YELLOW_("iClass legacy")" credential"); + PrintAndLogEx(SUCCESS, _GREEN_("iCLASS legacy")" credential"); if (se_enabled) - PrintAndLogEx(SUCCESS, " possible "_YELLOW_("iClass SE")" credential"); + PrintAndLogEx(SUCCESS, _GREEN_("iCLASS SE")" credential"); } else { PrintAndLogEx(SUCCESS, _YELLOW_("PicoPass")" (CSN is not in HID range)"); From 9ce9a8280383af01f7ee36cd8d458e0e9047ddad Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 21:31:39 +0200 Subject: [PATCH 43/84] defined stop condition for reading processes, otherwise pm 'crashes' if there's no tag on device --- armsrc/em4x50.c | 153 +++++++++++++++++++++++++++--------------------- 1 file changed, 87 insertions(+), 66 deletions(-) diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index cfbfb9fe0..bcf48bd55 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -75,6 +75,7 @@ static em4x50_tag_t tag = { #define EM4X50_T_WAITING_FOR_LIW 500 #define EM4X50_T_TAG_TPP 64 #define EM4X50_T_TAG_TWA 64 +#define EM4X50_T_TAG_INIT 2112 #define EM4X50_TAG_TOLERANCE 8 #define EM4X50_TAG_WORD 45 @@ -237,19 +238,34 @@ static void em4x50_setup_read(void) { // functions for "reader" use case -static void get_signalproperties(void) { +static bool get_signalproperties(void) { // calculate signal properties (mean amplitudes) from measured data: // 32 amplitudes (maximum values) -> mean amplitude value -> gHigh -> gLow + bool signal_found = false; int no_periods = 32, pct = 75, noise = 140; uint8_t sample = 0, sample_ref = 127; uint8_t sample_max_mean = 0; uint8_t sample_max[no_periods]; uint32_t sample_max_sum = 0; + - // wait until signal/noise > 1 - while (AT91C_BASE_SSC->SSC_RHR < noise); + // wait until signal/noise > 1 (max. 32 periods) + for (int i = 0; i < T0 * no_periods; i++) { + + // about 2 samples per bit period + wait_timer(0, T0 * EM4X50_T_TAG_HALF_PERIOD); + + if (AT91C_BASE_SSC->SSC_RHR > noise) { + signal_found = true; + break; + } + + } + + if (!signal_found) + return false; // calculate mean maximum value of 32 periods, each period has a length of // 3 single "full periods" to eliminate the influence of a listen window @@ -274,6 +290,7 @@ static void get_signalproperties(void) { gHigh = sample_ref + pct * (sample_max_mean - sample_ref) / 100; gLow = sample_ref - pct * (sample_max_mean - sample_ref) / 100; + return true; } static int get_next_bit(void) { @@ -736,31 +753,32 @@ void em4x50_info(em4x50_data_t *etd) { init_tag(); em4x50_setup_read(); - + // set gHigh and gLow - get_signalproperties(); - - if (etd->pwd_given) { + if (get_signalproperties()) { - // try to login with given password - blogin = login(etd->password); + if (etd->pwd_given) { - } else { - - // if no password is given, try to login with "0x00000000" - blogin = login(password); + // try to login with given password + blogin = login(etd->password); + } else { + + // if no password is given, try to login with "0x00000000" + blogin = login(password); + + } + + bsuccess = selective_read(addresses); } - - bsuccess = selective_read(addresses); - + status = (bsuccess << 1) + blogin; lf_finalize(); reply_ng(CMD_ACK, status, (uint8_t *)tag.sectors, 238); } -void em4x50_sread(em4x50_data_t *etd) { +void em4x50_read(em4x50_data_t *etd) { // reads in two different ways: // - using "selective read mode" -> bidirectional communication @@ -776,25 +794,26 @@ void em4x50_sread(em4x50_data_t *etd) { em4x50_setup_read(); // set gHigh and gLow - get_signalproperties(); + if (get_signalproperties()) { - if (etd->addr_given) { + if (etd->addr_given) { - // selective read mode - - // try to login with given password - if (etd->pwd_given) - blogin = login(etd->password); - - // only one word has to be read -> first word read = last word read - addresses[2] = addresses[3] = etd->address; - bsuccess = selective_read(addresses); - - } else { - - // standard read mode - bsuccess = standard_read(&now); - + // selective read mode + + // try to login with given password + if (etd->pwd_given) + blogin = login(etd->password); + + // only one word has to be read -> first word read = last word read + addresses[2] = addresses[3] = etd->address; + bsuccess = selective_read(addresses); + + } else { + + // standard read mode + bsuccess = standard_read(&now); + + } } status = (now << 2) + (bsuccess << 1) + blogin; @@ -896,40 +915,41 @@ void em4x50_write(em4x50_data_t *etd) { em4x50_setup_read(); // set gHigh and gLow - get_signalproperties(); + if (get_signalproperties()) { - // reorder word according to datasheet - msb2lsb_word(etd->word); - - // if password is given try to login first - if (etd->pwd_given) - blogin = login(etd->password); - - // write word to given address - if (write(etd->word, etd->address)) { + // reorder word according to datasheet + msb2lsb_word(etd->word); + + // if password is given try to login first + if (etd->pwd_given) + blogin = login(etd->password); + + // write word to given address + if (write(etd->word, etd->address)) { - // to verify result reset EM4x50 - if (reset()) { + // to verify result reset EM4x50 + if (reset()) { - // if password is given login - if (etd->pwd_given) - blogin &= login(etd->password); + // if password is given login + if (etd->pwd_given) + blogin &= login(etd->password); - // call a selective read - addresses[2] = addresses[3] = etd->address; - if (selective_read(addresses)) { + // call a selective read + addresses[2] = addresses[3] = etd->address; + if (selective_read(addresses)) { - // compare with given word - word[0] = tag.sectors[etd->address][0]; - word[1] = tag.sectors[etd->address][1]; - word[2] = tag.sectors[etd->address][2]; - word[3] = tag.sectors[etd->address][3]; - msb2lsb_word(word); - - bsuccess = true; - for (int i = 0; i < 4; i++) - bsuccess &= (word[i] == etd->word[i]) ? true : false; + // compare with given word + word[0] = tag.sectors[etd->address][0]; + word[1] = tag.sectors[etd->address][1]; + word[2] = tag.sectors[etd->address][2]; + word[3] = tag.sectors[etd->address][3]; + msb2lsb_word(word); + + bsuccess = true; + for (int i = 0; i < 4; i++) + bsuccess &= (word[i] == etd->word[i]) ? true : false; + } } } } @@ -950,11 +970,12 @@ void em4x50_write_password(em4x50_data_t *etd) { em4x50_setup_read(); // set gHigh and gLow - get_signalproperties(); + if (get_signalproperties()) { - // login and change password - if (login(etd->password)) { - bsuccess = write_password(etd->password, etd->new_password); + // login and change password + if (login(etd->password)) { + bsuccess = write_password(etd->password, etd->new_password); + } } lf_finalize(); From b6359def47da0c7cfef183fd191f4d4a329044c0 Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 21:32:52 +0200 Subject: [PATCH 44/84] renamed 'sread" to 'read' --- armsrc/em4x50.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/armsrc/em4x50.h b/armsrc/em4x50.h index aecaea78e..d786e61c0 100644 --- a/armsrc/em4x50.h +++ b/armsrc/em4x50.h @@ -20,6 +20,6 @@ typedef struct { void em4x50_info(em4x50_data_t *etd); void em4x50_write(em4x50_data_t *etd); void em4x50_write_password(em4x50_data_t *etd); -void em4x50_sread(em4x50_data_t *etd); +void em4x50_read(em4x50_data_t *etd); #endif /* EM4X50_H */ From 955c7a642d0a269fd7caadaf53e05dc2e89df4c9 Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 21:33:37 +0200 Subject: [PATCH 45/84] renamed 'sread' to 'read' --- client/src/cmdlfem4x50.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/src/cmdlfem4x50.h b/client/src/cmdlfem4x50.h index 8f4b63a4f..7b3fb53a0 100644 --- a/client/src/cmdlfem4x50.h +++ b/client/src/cmdlfem4x50.h @@ -11,14 +11,18 @@ #ifndef CMDLFEM4X50_H__ #define CMDLFEM4X50_H__ +#include"common.h" + int usage_lf_em4x50_info(void); int usage_lf_em4x50_write(void); int usage_lf_em4x50_write_password(void); -int usage_lf_em4x50_sread(void); +int usage_lf_em4x50_read(void); + +int EM4x50Read(const char *Cmd, bool verbose); int CmdEM4x50Info(const char *Cmd); int CmdEM4x50Write(const char *Cmd); int CmdEM4x50WritePassword(const char *Cmd); -int CmdEM4x50SRead(const char *Cmd); +int CmdEM4x50Read(const char *Cmd); #endif From c6435d2f9662f50491e9b17cf741a07e5c4d6f55 Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 21:35:06 +0200 Subject: [PATCH 46/84] output changes due to integration of 'read' into 'lf search' process --- client/src/cmdlfem4x50.c | 378 ++++++++++++++++++++------------------- 1 file changed, 194 insertions(+), 184 deletions(-) diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index cee6ece71..20db97a14 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -54,17 +54,17 @@ int usage_lf_em4x50_write_password(void) { PrintAndLogEx(NORMAL, " lf em 4x50_write_password p 11223344 n 01020304"); return PM3_SUCCESS; } -int usage_lf_em4x50_sread(void) { +int usage_lf_em4x50_read(void) { PrintAndLogEx(NORMAL, "Read EM4x50 word(s). Tag must be on antenna. "); PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf em 4x50_sread [h] a
p "); + PrintAndLogEx(NORMAL, "Usage: lf em 4x50_read [h] a
p "); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h - this help"); PrintAndLogEx(NORMAL, " a - memory address to read (dec) (optional)"); PrintAndLogEx(NORMAL, " p - password (hex) (optional)"); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf em 4x50_sread"); - PrintAndLogEx(NORMAL, " lf em 4x50_sread a 2 p 00000000"); + PrintAndLogEx(NORMAL, " lf em 4x50_read"); + PrintAndLogEx(NORMAL, " lf em 4x50_read a 2 p 00000000"); return PM3_SUCCESS; } @@ -190,7 +190,7 @@ static void print_bit_table(const em4x50_word_t word) { string[0] = '\0'; } -static void print_result(const em4x50_word_t *words, int fwr, int lwr) { +static void print_result(const em4x50_word_t *words, int fwr, int lwr, bool verbose) { // print available information for given word from fwr to lwr, i.e. // bit table + summary lines with hex notation of word (msb + lsb) @@ -199,28 +199,41 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr) { for (int i = fwr; i <= lwr; i++) { - // blank line before each bit table - PrintAndLogEx(NORMAL, ""); + if (verbose) { + + // blank line before each bit table + PrintAndLogEx(NORMAL, ""); - // print bit table - print_bit_table(words[i]); - - // final result - string[0] = '\0'; - sprintf(pstring, "\n word[%i] msb: " _GREEN_("0x"), i); - strcat(string, pstring); + // print bit table + print_bit_table(words[i]); - for (int j = 0; j < 4; j++) { - sprintf(pstring, _GREEN_("%02x"), words[i].byte[j]); + // final result + string[0] = '\0'; + sprintf(pstring, "\n word[%i] msb: " _GREEN_("0x"), i); strcat(string, pstring); - } - - sprintf(pstring, "\n word[%i] lsb: 0x", i); - strcat(string, pstring); - for (int j = 0; j < 4; j++) { - sprintf(pstring, "%02x", reflect8(words[i].byte[3-j])); + for (int j = 0; j < 4; j++) { + sprintf(pstring, _GREEN_("%02x"), words[i].byte[j]); + strcat(string, pstring); + } + + sprintf(pstring, "\n word[%i] lsb: 0x", i); strcat(string, pstring); + + for (int j = 0; j < 4; j++) { + sprintf(pstring, "%02x", reflect8(words[i].byte[3-j])); + strcat(string, pstring); + } + } else { + + string[0] = '\0'; + sprintf(pstring, "[" _GREEN_("+") "] word[%i]: " _YELLOW_("0x"), i); + strcat(string, pstring); + + for (int j = 0; j < 4; j++) { + sprintf(pstring, _YELLOW_("%02x"), words[i].byte[j]); + strcat(string, pstring); + } } PrintAndLogEx(NORMAL,string); @@ -236,7 +249,6 @@ static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd, char pstring[NO_CHARS_MAX] = {0}, string[NO_CHARS_MAX] = {0}; bool bpwd_given = etd->pwd_given; - bool bsuccess = (resp->status & STATUS_SUCCESS) >> 1; bool blogin = resp->status & STATUS_LOGIN; prepare_result(data, 0, EM4X50_NO_WORDS - 1, words); @@ -256,7 +268,7 @@ static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd, if (bverbose) { // detailed data section - print_result(words, 0, EM4X50_NO_WORDS - 1); + print_result(words, 0, EM4X50_NO_WORDS - 1, true); } else { @@ -336,47 +348,38 @@ static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd, sprintf(pstring, " reading "); strcat(string, pstring); - if (!bsuccess) { + sprintf(pstring, _GREEN_("ok ")); + strcat(string, pstring); + + if (blogin) { + + if (bpwd_given) { + + sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)", + etd->password[0], etd->password[1], + etd->password[2], etd->password[3]); + strcat(string, pstring); - sprintf(pstring, _RED_("failed")); - strcat(string, pstring); - - } else { - - sprintf(pstring, _GREEN_("ok ")); - strcat(string, pstring); - - if (blogin) { - - if (bpwd_given) { - - sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)", - etd->password[0], etd->password[1], - etd->password[2], etd->password[3]); - strcat(string, pstring); - - } else { - - sprintf(pstring, "(login with default password 0x00000000)"); - strcat(string, pstring); - - } - } else { - if (bpwd_given) { + sprintf(pstring, "(login with default password 0x00000000)"); + strcat(string, pstring); - sprintf(pstring, "(login failed)"); - strcat(string, pstring); - - } else { - - sprintf(pstring, "(no login)"); - strcat(string, pstring); - - } } + } else { + + if (bpwd_given) { + + sprintf(pstring, "(login failed)"); + strcat(string, pstring); + + } else { + + sprintf(pstring, "(no login)"); + strcat(string, pstring); + + } } PrintAndLogEx(NORMAL,"%s\n", string); @@ -432,15 +435,19 @@ int CmdEM4x50Info(const char *Cmd) { // get result - if (!WaitForResponse(CMD_ACK, &resp)) { - PrintAndLogEx(WARNING, " timeout while waiting for reply."); + if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) { + PrintAndLogEx(WARNING, "timeout while waiting for reply."); return PM3_ETIMEOUT; } - // print result - print_info_result(&resp, &etd, verbose); - success = (resp.status & STATUS_SUCCESS) >> 1; + + // print result + if (success) + print_info_result(&resp, &etd, verbose); + else + PrintAndLogEx(NORMAL,"\nreading " _RED_("failed") "\n"); + return (success) ? PM3_SUCCESS : PM3_ESOFT; } @@ -449,41 +456,32 @@ static void print_write_result(PacketResponseNG *resp, const em4x50_data_t *etd) // display result of writing operation in structured format bool pwd_given = etd->pwd_given; - bool success = (resp->status & STATUS_SUCCESS) >> 1; bool login = resp->status & STATUS_LOGIN; uint8_t *data = resp->data.asBytes; char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; em4x50_word_t word; - if (!success) { - - sprintf(pstring, "\n writing " _RED_("failed")); - strcat(string, pstring); + prepare_result(data, etd->address, etd->address, &word); + print_result(&word, etd->address, etd->address, true); - } else { - - prepare_result(data, etd->address, etd->address, &word); - print_result(&word, etd->address, etd->address); + sprintf(pstring, "\n writing " _GREEN_("ok ")); + strcat(string, pstring); - sprintf(pstring, "\n writing " _GREEN_("ok ")); - strcat(string, pstring); - - if (pwd_given) { - - if (login) { - sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)", - etd->password[0], etd->password[1], - etd->password[2], etd->password[3]); - strcat(string, pstring); - } else { - sprintf(pstring, "(login failed)"); - strcat(string, pstring); - } + if (pwd_given) { + if (login) { + sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)", + etd->password[0], etd->password[1], + etd->password[2], etd->password[3]); + strcat(string, pstring); } else { - sprintf(pstring, "(no login)"); + sprintf(pstring, "(login failed)"); strcat(string, pstring); } + + } else { + sprintf(pstring, "(no login)"); + strcat(string, pstring); } PrintAndLogEx(NORMAL,"%s\n", string); @@ -551,15 +549,19 @@ int CmdEM4x50Write(const char *Cmd) { SendCommandNG(CMD_LF_EM4X50_WRITE, (uint8_t *)&etd, sizeof(etd)); - if (!WaitForResponse(CMD_ACK, &resp)) { - PrintAndLogEx(WARNING, "\n timeout while waiting for reply.\n"); + if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) { + PrintAndLogEx(WARNING, "timeout while waiting for reply."); return PM3_ETIMEOUT; } - // get, prepare and print response - print_write_result(&resp, &etd); - success = (resp.status & STATUS_SUCCESS) >> 1; + + // get, prepare and print response + if (success) + print_write_result(&resp, &etd); + else + PrintAndLogEx(NORMAL,"\nwriting " _RED_("failed") "\n"); + return (success) ? PM3_SUCCESS : PM3_ESOFT; } @@ -567,19 +569,10 @@ static void print_write_password_result(PacketResponseNG *resp, const em4x50_dat // display result of password changing operation - bool success = resp->status; char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; - if (!success) { - - sprintf(pstring, "\n writing new password " _RED_("failed")); - strcat(string, pstring); - - } else { - - sprintf(pstring, "\n writing new password " _GREEN_("ok")); - strcat(string, pstring); - } + sprintf(pstring, "\n writing new password " _GREEN_("ok")); + strcat(string, pstring); PrintAndLogEx(NORMAL,"%s\n", string); } @@ -588,7 +581,7 @@ int CmdEM4x50WritePassword(const char *Cmd) { // envokes changing the password of EM4x50 tag - bool errors = false, bpwd = false, bnpwd = false; + bool errors = false, bpwd = false, bnpwd = false, success = false; uint8_t cmdp = 0; em4x50_data_t etd; PacketResponseNG resp; @@ -636,71 +629,69 @@ int CmdEM4x50WritePassword(const char *Cmd) { clearCommandBuffer(); SendCommandNG(CMD_LF_EM4X50_WRITE_PASSWORD, (uint8_t *)&etd, sizeof(etd)); - if (!WaitForResponse(CMD_ACK, &resp)) { - PrintAndLogEx(WARNING, "\n timeout while waiting for reply.\n"); + if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) { + PrintAndLogEx(WARNING, "timeout while waiting for reply."); return PM3_ETIMEOUT; } + success = (bool)resp.status; // get, prepare and print response - print_write_password_result(&resp, &etd); - - return ((bool)resp.status) ? PM3_SUCCESS : PM3_ESOFT; + if (success) + print_write_password_result(&resp, &etd); + else + PrintAndLogEx(NORMAL,"\nwriting password " _RED_("failed") "\n"); + + return (success) ? PM3_SUCCESS : PM3_ESOFT; } -static void print_sread_result(PacketResponseNG *resp, const em4x50_data_t *etd) { +static void print_read_result(PacketResponseNG *resp, const em4x50_data_t *etd, bool verbose) { // display result of writing operation in structured format bool addr_given = etd->addr_given; bool pwd_given = etd->pwd_given; bool login = resp->status & STATUS_LOGIN; - bool success = (resp->status & STATUS_SUCCESS) >> 1; int now = (resp->status & STATUS_NO_WORDS) >> 2; char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; uint8_t *data = resp->data.asBytes; em4x50_word_t word; - if (!success) { + if (addr_given) { - sprintf(pstring, "\n reading " _RED_("failed")); + // selective read mode + + prepare_result(data, etd->address, etd->address, &word); + print_result(&word, etd->address, etd->address, true); + + string[0] = '\0'; + sprintf(pstring, "\n reading " _GREEN_("ok ")); strcat(string, pstring); + + if (pwd_given) { + if (login) { + sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)", + etd->password[0], etd->password[1], + etd->password[2], etd->password[3]); + strcat(string, pstring); + } else { + sprintf(pstring, "(login failed)"); + strcat(string, pstring); + } + } else { + sprintf(pstring, "(no login)"); + strcat(string, pstring); + } PrintAndLogEx(NORMAL,"%s\n", string); } else { + + //standard read mode - if (addr_given) { - - // selective read mode + prepare_result(data, 0, now - 1, &word); + print_result(&word, 0, now - 1, verbose); - prepare_result(data, etd->address, etd->address, &word); - print_result(&word, etd->address, etd->address); - - string[0] = '\0'; - sprintf(pstring, "\n reading " _GREEN_("ok ")); - strcat(string, pstring); - - if (pwd_given) { - if (login) { - sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)", - etd->password[0], etd->password[1], - etd->password[2], etd->password[3]); - strcat(string, pstring); - } else { - sprintf(pstring, "(login failed)"); - strcat(string, pstring); - } - } else { - sprintf(pstring, "(no login)"); - strcat(string, pstring); - } - - } else { - - //standard read mode - - prepare_result(data, 0, now - 1, &word); - print_result(&word, 0, now - 1); + if (verbose) { string[0] = '\0'; sprintf(pstring, "\n reading " _GREEN_("ok ")); @@ -713,14 +704,14 @@ static void print_sread_result(PacketResponseNG *resp, const em4x50_data_t *etd) sprintf(pstring, "(standard read mode)"); strcat(string, pstring); } - } - PrintAndLogEx(NORMAL,"%s\n", string); + PrintAndLogEx(NORMAL,"%s\n", string); + } } } -int CmdEM4x50SRead(const char *Cmd) { - +int EM4x50Read(const char *Cmd, bool verbose) { + // envoke reading // - without option -> standard read mode // - with given address (option a) (and optional password if address is @@ -735,55 +726,74 @@ int CmdEM4x50SRead(const char *Cmd) { etd.pwd_given = false; etd.addr_given = false; - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + if (verbose) { + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lf_em4x50_sread(); + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_lf_em4x50_read(); - case 'p': - if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) { - PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n"); - return PM3_EINVARG; - } - etd.pwd_given = true; - cmdp += 2; - break; + case 'p': + if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) { + PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n"); + return PM3_EINVARG; + } + etd.pwd_given = true; + cmdp += 2; + break; - case 'a': - param_getdec(Cmd, cmdp + 1, &etd.address); + case 'a': + param_getdec(Cmd, cmdp + 1, &etd.address); - // validation - if (etd.address <= 0 || etd.address >= EM4X50_NO_WORDS) { - PrintAndLogEx(FAILED, "\n error, address has to be in range [1-33]\n"); - return PM3_EINVARG; - } - etd.addr_given = true; - cmdp += 2; - break; + // validation + if (etd.address <= 0 || etd.address >= EM4X50_NO_WORDS) { + PrintAndLogEx(FAILED, "\n error, address has to be in range [1-33]\n"); + return PM3_EINVARG; + } + etd.addr_given = true; + cmdp += 2; + break; - default: - PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp)); - errors = true; - break; + default: + PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp)); + errors = true; + break; + } } + + if (errors) + return usage_lf_em4x50_read(); + } - if (errors) - return usage_lf_em4x50_sread(); - clearCommandBuffer(); - SendCommandNG(CMD_LF_EM4X50_SREAD, (uint8_t *)&etd, sizeof(etd)); + SendCommandNG(CMD_LF_EM4X50_READ, (uint8_t *)&etd, sizeof(etd)); - if (!WaitForResponse(CMD_ACK, &resp)) { - PrintAndLogEx(WARNING, "\n timeout while waiting for reply.\n"); + if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) { + PrintAndLogEx(WARNING, "timeout while waiting for reply."); return PM3_ETIMEOUT; } - // get, prepare and print response - print_sread_result(&resp, &etd); - success = (resp.status & STATUS_SUCCESS) >> 1; + + // get, prepare and print response + if (success) + print_read_result(&resp, &etd, verbose); + else if (verbose) + PrintAndLogEx(NORMAL,"\nreading " _RED_("failed") "\n"); + return (success) ? PM3_SUCCESS : PM3_ESOFT; + +} + +int CmdEM4x50Read(const char *Cmd) { + + // envoke reading function + // verbose = true for manual call + // verbose = false for automatic call (e.g. lf search) + + bool verbose = true; + + return EM4x50Read(Cmd, verbose); } From eddaf70ef90fb0acdeccce1432d638d6ed021b7a Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 21:35:49 +0200 Subject: [PATCH 47/84] added timeout value if there's no tag on device --- include/em4x50.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/em4x50.h b/include/em4x50.h index ddda32f7f..b70072c32 100644 --- a/include/em4x50.h +++ b/include/em4x50.h @@ -38,6 +38,7 @@ #define STATUS_SUCCESS 0x2 #define STATUS_LOGIN 0x1 #define NO_CHARS_MAX 400 +#define TIMEOUT 2000 typedef struct { bool addr_given; From a01c5aff0e64f301f348fb81f73262644269e1de Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 21:37:12 +0200 Subject: [PATCH 48/84] deleted EM4x50 functions due to switch to new 'read' function for EM4x50 tag (device side) --- client/src/cmdlfem4x.h | 1 - 1 file changed, 1 deletion(-) diff --git a/client/src/cmdlfem4x.h b/client/src/cmdlfem4x.h index d727cb551..62ecafa23 100644 --- a/client/src/cmdlfem4x.h +++ b/client/src/cmdlfem4x.h @@ -16,7 +16,6 @@ int CmdLFEM4X(const char *Cmd); int demodEM410x(void); -int EM4x50Read(const char *Cmd, bool verbose); bool EM4x05IsBlock0(uint32_t *word); void printEM410x(uint32_t hi, uint64_t id); From 1cf51410f406fb37ebf5de9c0035fd62206fd9ca Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 21:37:53 +0200 Subject: [PATCH 49/84] renamed 'lread' to 'read' --- armsrc/appmain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 604d44c34..95b42982a 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1019,8 +1019,8 @@ static void PacketReceived(PacketCommandNG *packet) { em4x50_write_password((em4x50_data_t *)packet->data.asBytes); break; } - case CMD_LF_EM4X50_SREAD: { - em4x50_sread((em4x50_data_t *)packet->data.asBytes); + case CMD_LF_EM4X50_READ: { + em4x50_read((em4x50_data_t *)packet->data.asBytes); break; } From 942493970e69b7c6bb85f62965db85245244eec6 Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 21:38:19 +0200 Subject: [PATCH 50/84] renamed 'sread' to 'read' --- include/pm3_cmd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 05c42dfd8..117eea672 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -405,7 +405,7 @@ typedef struct { #define CMD_LF_EM4X50_INFO 0x0240 #define CMD_LF_EM4X50_WRITE 0x0241 #define CMD_LF_EM4X50_WRITE_PASSWORD 0x0242 -#define CMD_LF_EM4X50_SREAD 0x0243 +#define CMD_LF_EM4X50_READ 0x0243 // Sampling configuration for LF reader/sniffer #define CMD_LF_SAMPLING_SET_CONFIG 0x021D #define CMD_LF_FSK_SIMULATE 0x021E From c572a2bab8926a140292ebd46a74275e7ea7ca0b Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 21:39:27 +0200 Subject: [PATCH 51/84] introduced 'IfPm3EM4x50' function --- client/src/cmdparser.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/src/cmdparser.c b/client/src/cmdparser.c index 529a3d553..dee76a8fe 100644 --- a/client/src/cmdparser.c +++ b/client/src/cmdparser.c @@ -89,6 +89,12 @@ bool IfPm3Hitag(void) { return pm3_capabilities.compiled_with_hitag; } +bool IfPm3EM4x50(void) { + if (!IfPm3Present()) + return false; + return pm3_capabilities.compiled_with_em4x50; +} + bool IfPm3Hfsniff(void) { if (!IfPm3Present()) return false; From 91ff0350df909b9b2b319f1e3422a8b6db9d808a Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 21:39:59 +0200 Subject: [PATCH 52/84] introduced 'IfPm3EM4x50' function --- client/src/cmdparser.h | 1 + 1 file changed, 1 insertion(+) diff --git a/client/src/cmdparser.h b/client/src/cmdparser.h index 1105f63ae..baade0bcb 100644 --- a/client/src/cmdparser.h +++ b/client/src/cmdparser.h @@ -33,6 +33,7 @@ bool IfPm3FpcUsartDevFromUsb(void); bool IfPm3FpcUsartFromUsb(void); bool IfPm3Lf(void); bool IfPm3Hitag(void); +bool IfPm3EM4x50(void); bool IfPm3Hfsniff(void); bool IfPm3Hfplot(void); bool IfPm3Iso14443a(void); From 78511df9f28dd7b067176ed9a0052f302adf489e Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 21:41:21 +0200 Subject: [PATCH 53/84] integrated 'lread' into 'lf search' process and renamed 'lread' to 'read' --- client/src/cmdlf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 748c9557a..35ce4c1b7 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -30,6 +30,7 @@ #include "cmddata.h" // for `lf search` #include "cmdlfawid.h" // for awid menu #include "cmdlfem4x.h" // for em4x menu +#include "cmdlfem4x50.h" // for em4x50 #include "cmdlfhid.h" // for hid menu #include "cmdlfhitag.h" // for hitag menu #include "cmdlfio.h" // for ioprox menu @@ -1250,6 +1251,13 @@ int CmdLFfind(const char *Cmd) { } } + if (IfPm3EM4x50()) { + if (EM4x50Read("", false) == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("EM4x50 ID") " found!"); + return PM3_SUCCESS; + } + } + // only run if graphbuffer is just noise as it should be for hitag // The improved noise detection will find Cotag. if (getSignalProperties()->isnoise) { @@ -1270,8 +1278,6 @@ int CmdLFfind(const char *Cmd) { } } - if (EM4x50Read("", false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("EM4x50 ID") " found!"); return PM3_SUCCESS;} - if (demodHID() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("HID Prox ID") " found!"); goto out;} if (demodAWID() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("AWID ID") " found!"); goto out;} if (demodIOProx() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("IO Prox ID") " found!"); goto out;} From 9aafc094b6426b7e590037727147a0ba0f348476 Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 21:43:13 +0200 Subject: [PATCH 54/84] deleted nearly all EM4x50 code; new EM4x50 code is in 'cmdlfem4x50.c' (device side instead GraphBuffer) --- client/src/cmdlfem4x.c | 369 +---------------------------------------- 1 file changed, 4 insertions(+), 365 deletions(-) diff --git a/client/src/cmdlfem4x.c b/client/src/cmdlfem4x.c index ef8cbdc13..27de68519 100644 --- a/client/src/cmdlfem4x.c +++ b/client/src/cmdlfem4x.c @@ -116,41 +116,6 @@ static int usage_lf_em410x_brute(void) { return PM3_SUCCESS; } -//////////////// 4050 / 4450 commands -static int usage_lf_em4x50_demod(void) { - PrintAndLogEx(NORMAL, "Usage: lf em 4x50_demod [h]"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h - this help"); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf em 4x50_demod"); - return PM3_SUCCESS; -} -static int usage_lf_em4x50_dump(void) { - PrintAndLogEx(NORMAL, "Dump EM4x50/EM4x69. Tag must be on antenna. "); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf em 4x50_dump [h] "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h - this help"); - PrintAndLogEx(NORMAL, " pwd - password (hex) (optional)"); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf em 4x50_dump"); - PrintAndLogEx(NORMAL, " lf em 4x50_dump 11223344"); - return PM3_SUCCESS; -} -static int usage_lf_em4x50_read(void) { - PrintAndLogEx(NORMAL, "Read EM 4x50/EM4x69. Tag must be on antenna. "); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf em 4x50_read [h]
"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h - this help"); - PrintAndLogEx(NORMAL, " address - memory address to read. (0-15)"); - PrintAndLogEx(NORMAL, " pwd - password (hex) (optional)"); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf em 4x50_read 1"); - PrintAndLogEx(NORMAL, " lf em 4x50_read 1 11223344"); - return PM3_SUCCESS; -} - //////////////// 4205 / 4305 commands static int usage_lf_em4x05_dump(void) { PrintAndLogEx(NORMAL, "Dump EM4x05/EM4x69. Tag must be on antenna. "); @@ -723,329 +688,6 @@ static bool EM_ColParityTest(uint8_t *bs, size_t size, uint8_t rows, uint8_t col return true; } -// even parity ROW -static bool EM_RowParityTest(uint8_t *bs, size_t size, uint8_t rows, uint8_t cols, uint8_t pType) { - if (rows * cols > size) return false; - uint8_t rowP = 0; - - for (uint8_t r = 0; r < rows - 1; r++) { - for (uint8_t c = 0; c < cols; c++) { - rowP ^= bs[(r * cols) + c]; - } - if (rowP != pType) return false; - rowP = 0; - } - return true; -} - -// EM word parity test. -// 9*5 = 45 bits in total -// 012345678|r0 -// 012345678|r1 -// 012345678|r2 -// 012345678|r3 -// ------------ -//c012345678| 0 -// |- must be zero - -/* -static int EMwordparitytest(uint8_t *bits) { - - // last row/col parity must be 0 - if (bits[44] != 0) return PM3_ESOFT; - - // col parity check - uint8_t c1 = bytebits_to_byte(bits, 8) ^ bytebits_to_byte(bits + 9, 8) ^ bytebits_to_byte(bits + 18, 8) ^ bytebits_to_byte(bits + 27, 8); - uint8_t c2 = bytebits_to_byte(bits + 36, 8); - if (c1 != c2) return PM3_ESOFT; - - // row parity check - uint8_t rowP = 0; - for (uint8_t i = 0; i < 36; ++i) { - - rowP ^= bits[i]; - if (i > 0 && (i % 9) == 0) { - - if (rowP != EVEN) - return PM3_ESOFT; - - rowP = 0; - } - } - // all checks ok. - return PM3_SUCCESS; -} -*/ - -//////////////// 4050 / 4450 commands - -static uint32_t OutputEM4x50_Block(uint8_t *BitStream, size_t size, bool verbose, bool pTest) { - if (size < 45) return 0; - - uint32_t code = bytebits_to_byte(BitStream, 8); - code = code << 8 | bytebits_to_byte(BitStream + 9, 8); - code = code << 8 | bytebits_to_byte(BitStream + 18, 8); - code = code << 8 | bytebits_to_byte(BitStream + 27, 8); - - if (verbose || g_debugMode) { - for (uint8_t i = 0; i < 5; i++) { - if (i == 4) PrintAndLogEx(NORMAL, ""); //parity byte spacer - PrintAndLogEx(NORMAL, "%d%d%d%d%d%d%d%d %d -> 0x%02x", - BitStream[i * 9], - BitStream[i * 9 + 1], - BitStream[i * 9 + 2], - BitStream[i * 9 + 3], - BitStream[i * 9 + 4], - BitStream[i * 9 + 5], - BitStream[i * 9 + 6], - BitStream[i * 9 + 7], - BitStream[i * 9 + 8], - bytebits_to_byte(BitStream + i * 9, 8) - ); - } - - PrintAndLogEx(SUCCESS, "Parity checks | %s", (pTest) ? _GREEN_("Passed") : _RED_("Fail")); - } - return code; -} - -/* Read the transmitted data of an EM4x50 tag from the graphbuffer - * Format: - * - * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity - * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity - * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity - * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity - * CCCCCCC0 <- column parity bits - * 0 <- stop bit - * LW <- Listen Window - * - * This pattern repeats for every block of data being transmitted. - * Transmission starts with two Listen Windows (LW - a modulated - * pattern of 320 cycles each (32/32/128/64/64)). - * - * Note that this data may or may not be the UID. It is whatever data - * is stored in the blocks defined in the control word First and Last - * Word Read values. UID is stored in block 32. - */ -//completed by Marshmellow -int EM4x50Read(const char *Cmd, bool verbose) { - int clk = 0, invert = 0, tol = 0, phaseoff; - int i = 0, j = 0, startblock, skip, block, start, end, low = 0, high = 0; - uint32_t Code[6]; - char tmp[6]; - char tmp2[20]; - bool complete = false; - - int tmpbuff[MAX_GRAPH_TRACE_LEN / 64]; - memset(tmpbuff, 0, sizeof(tmpbuff)); - - // get user entry if any - sscanf(Cmd, "%i %i", &clk, &invert); - - uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0}; - size_t size = getFromGraphBuf(bits); - - if (size < 4000) { - if (verbose || g_debugMode) PrintAndLogEx(ERR, "Error: EM4x50 - Too little data in Graphbuffer"); - return PM3_ESOFT; - } - - computeSignalProperties(bits, size); - - // get fuzzed HI / LOW limits in signal - getHiLo(&high, &low, 75, 75); - - // get to first full low to prime loop and skip incomplete first pulse - size_t offset = 0; - getNextHigh(bits, size, high, &offset); - getNextLow(bits, size, low, &offset); - - i = (int)offset; - skip = offset; - - // set clock - if (clk == 0) { - DetectASKClock(bits, size, &clk, 0); - if (clk == 0) { - if (verbose || g_debugMode) PrintAndLogEx(ERR, "Error: EM4x50 - didn't find a clock"); - return PM3_ESOFT; - } - } - // tolerance - tol = clk / 8; - - // populate tmpbuff buffer with pulse lengths - while (i < size) { - // measure from low to low - while ((i < size) && (bits[i] > low)) - ++i; - start = i; - - while ((i < size) && (bits[i] < high)) - ++i; - - while ((i < size) && (bits[i] > low)) - ++i; - - if (j >= (MAX_GRAPH_TRACE_LEN / 64)) { - break; - } - tmpbuff[j++] = i - start; - } - - // look for data start - should be 2 pairs of LW (pulses of clk*3,clk*2) - start = -1; - for (i = 0; i < j - 4 ; ++i) { - skip += tmpbuff[i]; - if (tmpbuff[i] >= clk * 3 - tol && tmpbuff[i] <= clk * 3 + tol) //3 clocks - if (tmpbuff[i + 1] >= clk * 2 - tol && tmpbuff[i + 1] <= clk * 2 + tol) //2 clocks - if (tmpbuff[i + 2] >= clk * 3 - tol && tmpbuff[i + 2] <= clk * 3 + tol) //3 clocks - if (tmpbuff[i + 3] >= clk - tol) { //1.5 to 2 clocks - depends on bit following - start = i + 4; - break; - } - } - startblock = i + 4; - - // skip over the remainder of LW - skip += (tmpbuff[i + 1] + tmpbuff[i + 2] + clk); - - if (tmpbuff[i + 3] > clk) - phaseoff = tmpbuff[i + 3] - clk; - else - phaseoff = 0; - - // now do it again to find the end - for (i += 3; i < j - 4 ; ++i) { - if (tmpbuff[i] >= clk * 3 - tol && tmpbuff[i] <= clk * 3 + tol) //3 clocks - if (tmpbuff[i + 1] >= clk * 2 - tol && tmpbuff[i + 1] <= clk * 2 + tol) //2 clocks - if (tmpbuff[i + 2] >= clk * 3 - tol && tmpbuff[i + 2] <= clk * 3 + tol) //3 clocks - if (tmpbuff[i + 3] >= clk - tol) { //1.5 to 2 clocks - depends on bit following - complete = true; - break; - } - } - end = i; - - // report back - if (verbose || g_debugMode) { - if (start >= 0) { - PrintAndLogEx(INFO, "\nNote: one block = 50 bits (32 data, 12 parity, 6 marker)"); - } else { - PrintAndLogEx(INFO, "No data found!, clock tried: " _YELLOW_("%d"), clk); - PrintAndLogEx(HINT, "Try again with more samples"); - PrintAndLogEx(HINT, " or after a " _YELLOW_("'data askedge'") " command to clean up the read"); - return PM3_ESOFT; - } - } else if (start < 0) { - return PM3_ESOFT; - } - - start = skip; - - snprintf(tmp2, sizeof(tmp2), "%d %d 1000 %d", clk, invert, clk * 47); - - // save GraphBuffer - to restore it later - save_restoreGB(GRAPH_SAVE); - - // get rid of leading crap - snprintf(tmp, sizeof(tmp), "%i", skip); - CmdLtrim(tmp); - - bool AllPTest = true; - - // now work through remaining buffer printing out data blocks - block = 0; - i = startblock; - while (block < 6) { - if (verbose || g_debugMode) PrintAndLogEx(NORMAL, "\nBlock %i:", block); - skip = phaseoff; - - // look for LW before start of next block - for (; i < j - 4 ; ++i) { - skip += tmpbuff[i]; - if (tmpbuff[i] >= clk * 3 - tol && tmpbuff[i] <= clk * 3 + tol) - if (tmpbuff[i + 1] >= clk - tol) - break; - } - if (i >= j - 4) break; //next LW not found - skip += clk; - if (tmpbuff[i + 1] > clk) - phaseoff = tmpbuff[i + 1] - clk; - else - phaseoff = 0; - - i += 2; - - if (ASKDemod(tmp2, false, false, 1) != PM3_SUCCESS) { - save_restoreGB(GRAPH_RESTORE); - return PM3_ESOFT; - } - - //set DemodBufferLen to just one block - DemodBufferLen = skip / clk; - //test parities - bool pTest = EM_RowParityTest(DemodBuffer, DemodBufferLen, 5, 9, 0); - pTest &= EM_ColParityTest(DemodBuffer, DemodBufferLen, 5, 9, 0); - AllPTest &= pTest; - //get output - Code[block] = OutputEM4x50_Block(DemodBuffer, DemodBufferLen, verbose, pTest); - PrintAndLogEx(DEBUG, "\nskipping %d samples, bits:%d", skip, skip / clk); - //skip to start of next block - snprintf(tmp, sizeof(tmp), "%i", skip); - CmdLtrim(tmp); - block++; - if (i >= end) break; //in case chip doesn't output 6 blocks - } - - //print full code: - if (verbose || g_debugMode || AllPTest) { - if (!complete) { - PrintAndLogEx(WARNING, _RED_("* **Warning!")); - PrintAndLogEx(INFO, "Partial data - no end found!"); - PrintAndLogEx(HINT, "Try again with more samples."); - } - PrintAndLogEx(INFO, "Found data at sample: %i - using clock: %i", start, clk); - end = block; - PrintAndLogEx(INFO, "blk | data"); - PrintAndLogEx(INFO, "----+--------------"); - for (block = 0; block < end; block++) { - PrintAndLogEx(INFO, "%03d | %08x", block, Code[block]); - } - PrintAndLogEx(INFO, "----+--------------"); - PrintAndLogEx((AllPTest) ? SUCCESS : WARNING, "Parities checks | %s", (AllPTest) ? _GREEN_("Passed") : _RED_("Fail")); - - if (AllPTest == false) { - PrintAndLogEx(HINT, "Try cleaning the read samples with " _YELLOW_("'data askedge'")); - } - } - - //restore GraphBuffer - save_restoreGB(GRAPH_RESTORE); - return AllPTest ? PM3_SUCCESS : PM3_ESOFT; -} - -static int CmdEM4x50Demod(const char *Cmd) { - uint8_t ctmp = tolower(param_getchar(Cmd, 0)); - if (ctmp == 'h') return usage_lf_em4x50_demod(); - return EM4x50Read(Cmd, true); -} - -static int CmdEM4x50Read(const char *Cmd) { - uint8_t ctmp = tolower(param_getchar(Cmd, 0)); - if (ctmp == 'h') return usage_lf_em4x50_read(); - lf_read(false, 24000); - return EM4x50Read(Cmd, true); -} - -static int CmdEM4x50Dump(const char *Cmd) { - uint8_t ctmp = tolower(param_getchar(Cmd, 0)); - if (ctmp == 'h') return usage_lf_em4x50_dump(); - PrintAndLogEx(NORMAL, "no implemented yet"); - return PM3_SUCCESS; -} - #define EM_PREAMBLE_LEN 6 // download samples from device and copy to Graphbuffer static bool downloadSamplesEM(void) { @@ -1753,13 +1395,10 @@ static command_t CommandTable[] = { {"4x05_read", CmdEM4x05Read, IfPm3Lf, "read word data from EM4x05/EM4x69"}, {"4x05_write", CmdEM4x05Write, IfPm3Lf, "write word data to EM4x05/EM4x69"}, {"----------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("EM 4x50") " -----------------------"}, - {"4x50_demod", CmdEM4x50Demod, AlwaysAvailable, "demodulate a EM4x50 tag from the GraphBuffer"}, - {"4x50_dump", CmdEM4x50Dump, IfPm3Lf, "dump EM4x50 tag"}, - {"4x50_read", CmdEM4x50Read, IfPm3Lf, "read word data from EM4x50"}, - {"4x50_info", CmdEM4x50Info, IfPm3Lf, "read complete data from EM4x50"}, - {"4x50_write", CmdEM4x50Write, IfPm3Lf, "write word data to EM4x50"}, - {"4x50_write_password", CmdEM4x50WritePassword, IfPm3Lf, "change passwword of EM4x50 tag"}, - {"4x50_sread", CmdEM4x50SRead, IfPm3Lf, "read word data from EM4x50 on device"}, + {"4x50_info", CmdEM4x50Info, IfPm3EM4x50, "read complete data from EM4x50"}, + {"4x50_write", CmdEM4x50Write, IfPm3EM4x50, "write word data to EM4x50"}, + {"4x50_write_password", CmdEM4x50WritePassword, IfPm3EM4x50, "change passwword of EM4x50 tag"}, + {"4x50_read", CmdEM4x50Read, IfPm3EM4x50, "read word data from EM4x50"}, {NULL, NULL, NULL, NULL} }; From 8854c7b688a12d2512fc2ac2c978e4470cc7112b Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 28 Jun 2020 23:33:01 +0200 Subject: [PATCH 55/84] - changed termination condition in "listen window detection" (old one didn't work) - decreased debug sensitivity --- armsrc/em4x50.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index bcf48bd55..639342c2c 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -72,10 +72,9 @@ static em4x50_tag_t tag = { #define EM4X50_T_TAG_HALF_PERIOD 32 #define EM4X50_T_TAG_THREE_QUARTER_PERIOD 48 #define EM4X50_T_TAG_FULL_PERIOD 64 -#define EM4X50_T_WAITING_FOR_LIW 500 #define EM4X50_T_TAG_TPP 64 #define EM4X50_T_TAG_TWA 64 -#define EM4X50_T_TAG_INIT 2112 +#define EM4X50_T_WAITING_FOR_LIW 8 // determined empiracally #define EM4X50_TAG_TOLERANCE 8 #define EM4X50_TAG_WORD 45 @@ -425,10 +424,13 @@ static bool find_double_listen_window(bool bcommand) { // find two successive listen windows that indicate the beginning of // data transmission + // listen windows should be detected within T0 * EM4X50_T_WAITING_FOR_LIW + // pulses (empirically determined) + + int cnt_pulses = 0; + + while (cnt_pulses < T0 * EM4X50_T_WAITING_FOR_LIW) { - AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG; - while (AT91C_BASE_TC0->TC_CV < T0 * EM4X50_T_WAITING_FOR_LIW) { - // identification of listen window is done via evaluation of // pulse lengths if (check_pulse_length(get_pulse_length(), 3 * EM4X50_T_TAG_FULL_PERIOD)) { @@ -471,6 +473,8 @@ static bool find_double_listen_window(bool bcommand) { return true; } } + } else { + cnt_pulses++; } } @@ -643,7 +647,7 @@ static bool login(uint8_t password[4]) { return true; } else { - if (DBGLEVEL >= DBG_ERROR) + if (DBGLEVEL >= DBG_DEBUG) Dbprintf("error in command request"); } @@ -667,7 +671,7 @@ static bool reset(void) { return true; } else { - if (DBGLEVEL >= DBG_ERROR) + if (DBGLEVEL >= DBG_DEBUG) Dbprintf("error in command request"); } @@ -699,7 +703,7 @@ static bool standard_read(int *now) { return true; } else { - if (DBGLEVEL >= DBG_ERROR) + if (DBGLEVEL >= DBG_DEBUG) Dbprintf("didn't find a listen window"); } @@ -733,7 +737,7 @@ static bool selective_read(uint8_t addresses[4]) { return true; } else { - if (DBGLEVEL >= DBG_ERROR) + if (DBGLEVEL >= DBG_DEBUG) Dbprintf("error in command request"); } @@ -855,7 +859,7 @@ static bool write(uint8_t word[4], uint8_t address) { } } else { - if (DBGLEVEL >= DBG_ERROR) + if (DBGLEVEL >= DBG_DEBUG) Dbprintf("error in command request"); } @@ -894,7 +898,7 @@ static bool write_password(uint8_t password[4], uint8_t new_password[4]) { } } else { - if (DBGLEVEL >= DBG_ERROR) + if (DBGLEVEL >= DBG_DEBUG) Dbprintf("error in command request"); } From 3f70f1154bce8dbfb352f437e94a21501711fc8d Mon Sep 17 00:00:00 2001 From: tharexde Date: Mon, 29 Jun 2020 00:01:19 +0200 Subject: [PATCH 56/84] updated conditions for stopping the detection of a double listen window --- armsrc/em4x50.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index 639342c2c..5644962b8 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -74,7 +74,7 @@ static em4x50_tag_t tag = { #define EM4X50_T_TAG_FULL_PERIOD 64 #define EM4X50_T_TAG_TPP 64 #define EM4X50_T_TAG_TWA 64 -#define EM4X50_T_WAITING_FOR_LIW 8 // determined empiracally +#define EM4X50_T_WAITING_FOR_DBLLIW 1600 #define EM4X50_TAG_TOLERANCE 8 #define EM4X50_TAG_WORD 45 @@ -424,12 +424,13 @@ static bool find_double_listen_window(bool bcommand) { // find two successive listen windows that indicate the beginning of // data transmission - // listen windows should be detected within T0 * EM4X50_T_WAITING_FOR_LIW - // pulses (empirically determined) + // double listen window to be detected within 1600 pulses -> worst case + // reason: first detectable double listen window after 34 words + // -> 34 words + 34 single listen windows -> about 1600 pulses int cnt_pulses = 0; - while (cnt_pulses < T0 * EM4X50_T_WAITING_FOR_LIW) { + while (cnt_pulses < EM4X50_T_WAITING_FOR_DBLLIW) { // identification of listen window is done via evaluation of // pulse lengths From f57a304362ba91b5413e0861bf628405769f54d5 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 08:05:43 +0200 Subject: [PATCH 57/84] fix #823 --- client/src/cmdlfio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/cmdlfio.c b/client/src/cmdlfio.c index e9a0b25ae..421ed6927 100644 --- a/client/src/cmdlfio.c +++ b/client/src/cmdlfio.c @@ -169,7 +169,7 @@ static int CmdIOProxDemod(const char *Cmd) { calccrc &= 0xff; calccrc = 0xff - calccrc; - char crc_str[30] = {0}; + char crc_str[36] = {0}; if (crc == calccrc) { snprintf(crc_str, sizeof(crc_str), "(" _GREEN_("ok") ")" ); From 4eb7776a07da6bff1e7b87cafdfb3c3efcfb7e71 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 10:25:51 +0200 Subject: [PATCH 58/84] text and cleanup --- client/src/cmddata.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/client/src/cmddata.c b/client/src/cmddata.c index b1f43244b..3765c2ded 100644 --- a/client/src/cmddata.c +++ b/client/src/cmddata.c @@ -1276,8 +1276,7 @@ int PSKDemod(const char *Cmd, bool verbose) { return PM3_SUCCESS; } -static int CmdIdteckDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far +int demodIdteck(void) { if (PSKDemod("", false) != PM3_SUCCESS) { PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck PSKDemod failed"); @@ -1337,10 +1336,12 @@ static int CmdIdteckDemod(const char *Cmd) { return PM3_SUCCESS; } -int demodIdteck(void) { - return CmdIdteckDemod(""); +/* +static int CmdIdteckDemod(const char *Cmd) { + (void)Cmd; // Cmd is not used so far + return demodIdteck(); } - +*/ // by marshmellow // takes 3 arguments - clock, invert, maxErr as integers @@ -1710,6 +1711,7 @@ int CmdTuneSamples(const char *Cmd) { } PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "---------- " _CYAN_("LF Antenna") " ----------"); // in mVolt struct p { uint32_t v_lf134; @@ -1746,8 +1748,9 @@ int CmdTuneSamples(const char *Cmd) { else sprintf(judgement, _GREEN_("OK")); - PrintAndLogEx((package->peak_v < LF_UNUSABLE_V) ? WARNING : SUCCESS, "LF antenna is %s \n", judgement); + PrintAndLogEx((package->peak_v < LF_UNUSABLE_V) ? WARNING : SUCCESS, "LF antenna is %s", judgement); + PrintAndLogEx(INFO, "---------- " _CYAN_("HF Antenna") " ----------"); // HF evaluation if (package->v_hf > NON_VOLTAGE) PrintAndLogEx(SUCCESS, "HF antenna: %5.2f V - 13.56 MHz", (package->v_hf * ANTENNA_ERROR) / 1000.0); @@ -1761,7 +1764,7 @@ int CmdTuneSamples(const char *Cmd) { else sprintf(judgement, _GREEN_("OK")); - PrintAndLogEx((package->v_hf < HF_UNUSABLE_V) ? WARNING : SUCCESS, "HF antenna is %s \n", judgement); + PrintAndLogEx((package->v_hf < HF_UNUSABLE_V) ? WARNING : SUCCESS, "HF antenna is %s", judgement); // graph LF measurements // even here, these values has 3% error. From 18ca4cb883dc4a843f5e4a558af9c888eacd1c6c Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 10:26:27 +0200 Subject: [PATCH 59/84] textal --- client/src/cmdhfmf.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index 0aa6bfd9b..c8ab85b14 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -1693,7 +1693,7 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { uint8_t key[6] = {0, 0, 0, 0, 0, 0}; uint8_t trgkey[6] = {0, 0, 0, 0, 0, 0}; uint8_t cmdp = 0; - char filename[FILE_PATH_SIZE] = {0}, *fptr; + char filename[FILE_PATH_SIZE] = {0}; char szTemp[FILE_PATH_SIZE - 20]; char ctmp; @@ -1706,19 +1706,21 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { switch (tolower(param_getchar(Cmd, cmdp))) { case 'h': return usage_hf14_hardnested(); - case 'r': - fptr = GenerateFilename("hf-mf-", "-nonces.bin"); + case 'r': { + char *fptr = GenerateFilename("hf-mf-", "-nonces.bin"); if (fptr == NULL) strncpy(filename, "nonces.bin", FILE_PATH_SIZE - 1); else strncpy(filename, fptr, FILE_PATH_SIZE - 1); + free(fptr); nonce_file_read = true; if (!param_gethex(Cmd, cmdp + 1, trgkey, 12)) { know_target_key = true; } cmdp++; break; + } case 't': tests = param_get32ex(Cmd, cmdp + 1, 100, 10); if (!param_gethex(Cmd, cmdp + 2, trgkey, 12)) { @@ -1729,9 +1731,9 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { default: if (param_getchar(Cmd, cmdp) == 0x00) { PrintAndLogEx(WARNING, "Block number is missing"); - return 1; - + return usage_hf14_hardnested(); } + blockNo = param_get8(Cmd, cmdp); ctmp = tolower(param_getchar(Cmd, cmdp + 1)); if (ctmp != 'a' && ctmp != 'b') { @@ -1775,13 +1777,15 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { case 's': slow = true; break; - case 'w': + case 'w': { nonce_file_write = true; - fptr = GenerateFilename("hf-mf-", "-nonces.bin"); + char *fptr = GenerateFilename("hf-mf-", "-nonces.bin"); if (fptr == NULL) return 1; strncpy(filename, fptr, FILE_PATH_SIZE - 1); + free(fptr); break; + } case 'u': param_getstr(Cmd, cmdp + 1, szTemp, FILE_PATH_SIZE - 20); snprintf(filename, FILE_PATH_SIZE, "hf-mf-%s-nonces.bin", szTemp); @@ -1837,7 +1841,7 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { // check if tag doesn't have static nonce if (detect_classic_static_nonce() == 1) { PrintAndLogEx(WARNING, "Static nonce detected. Quitting..."); - PrintAndLogEx(INFO, "\t Try use `" _YELLOW_("hf mf staticnested") "`"); + PrintAndLogEx(HINT, "\tTry use `" _YELLOW_("hf mf staticnested") "`"); return PM3_EOPABORTED; } @@ -1849,11 +1853,13 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { } } - PrintAndLogEx(NORMAL, "--target block no:%3d, target key type:%c, known target key: 0x%02x%02x%02x%02x%02x%02x%s, file action: %s, Slow: %s, Tests: %d ", + PrintAndLogEx(INFO, "Target block no:%3d, target key type:%c, known target key: 0x%02x%02x%02x%02x%02x%02x%s", trgBlockNo, trgKeyType ? 'B' : 'A', trgkey[0], trgkey[1], trgkey[2], trgkey[3], trgkey[4], trgkey[5], - know_target_key ? "" : " (not set)", + know_target_key ? "" : " (not set)" + ); + PrintAndLogEx(INFO , "File action: %s, Slow: %s, Tests: %d ", nonce_file_write ? "write" : nonce_file_read ? "read" : "none", slow ? "Yes" : "No", tests); @@ -1861,7 +1867,9 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { uint64_t foundkey = 0; int16_t isOK = mfnestedhard(blockNo, keyType, key, trgBlockNo, trgKeyType, know_target_key ? trgkey : NULL, nonce_file_read, nonce_file_write, slow, tests, &foundkey, filename); - if (tests == 0) DropField(); + if (tests == 0) + DropField(); + if (isOK) { switch (isOK) { case 1 : From 8bd1a44ba72cbe8161eff6471093256567829a7a Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 10:26:58 +0200 Subject: [PATCH 60/84] textual --- client/src/cmdhfmfp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/cmdhfmfp.c b/client/src/cmdhfmfp.c index a3c9d195c..1e1f7aeef 100644 --- a/client/src/cmdhfmfp.c +++ b/client/src/cmdhfmfp.c @@ -1429,9 +1429,9 @@ static int CmdHFMFPNDEF(const char *Cmd) { CLIParserInit(&ctx, "hf mfp ndef", "Prints NFC Data Exchange Format (NDEF)", "Usage:\n" - "\thf mfp ndef -> shows NDEF data\n" - "\thf mfp ndef -vv -> shows NDEF parsed and raw data\n" - "\thf mfp ndef -a e103 -k d3f7d3f7d3f7d3f7d3f7d3f7d3f7d3f7 -> shows NDEF data with custom AID and key\n"); + _YELLOW_("\thf mfp ndef") " -> shows NDEF data\n" + _YELLOW_("\thf mfp ndef -vv") " -> shows NDEF parsed and raw data\n" + _YELLOW_("\thf mfp ndef -a e103 -k d3f7d3f7d3f7d3f7d3f7d3f7d3f7d3f7") " -> shows NDEF data with custom AID and key\n"); void *argtable[] = { arg_param_begin, @@ -1530,12 +1530,12 @@ static int CmdHFMFPNDEF(const char *Cmd) { if (verbose2) { PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "--- " _CYAN_("MFC NDEF raw") " ----------------"); + PrintAndLogEx(INFO, "--- " _CYAN_("MF Plus NDEF raw") " ----------------"); dump_buffer(data, datalen, stdout, 1); } NDEFDecodeAndPrint(data, datalen, verbose); - PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mf ndef -vv`") " for more details"); + PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mfp ndef -vv`") " for more details"); return PM3_SUCCESS; } From 8fd4bb6e33b000b00229650abadd72c1de51ca28 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 10:29:12 +0200 Subject: [PATCH 61/84] preparing ndef command for desfire --- client/src/cmdhfmfdes.c | 149 +++++++++++++++++++++++++++++++++------- 1 file changed, 126 insertions(+), 23 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 2adbeae75..d45275969 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -30,6 +30,8 @@ #include "mifare/desfire_crypto.h" #include "crapto1/crapto1.h" #include "fileutils.h" +#include "mifare/mifaredefault.h" // default keys +#include "mifare/ndef.h" // NDEF #define MAX_KEY_LEN 24 #define MAX_KEYS_LIST_LEN 1024 @@ -4470,6 +4472,107 @@ static int CmdHF14ADesList(const char *Cmd) { return CmdTraceList("des"); } +/* +static int CmdHF14aDesNDEF(const char *Cmd) { + DropField(); + + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf mfdes ndef", + "Prints NFC Data Exchange Format (NDEF)", + "Usage:\n" + _YELLOW_("\thf mfdes ndef") " -> shows NDEF data\n" + _YELLOW_("\thf mfdes ndef -vv") " -> shows NDEF parsed and raw data\n" + _YELLOW_("\thf mfdes ndef -a e103 -k d3f7d3f7d3f7d3f7d3f7d3f7d3f7d3f7") " -> shows NDEF data with custom AID and key\n"); + + void *argtable[] = { + arg_param_begin, + arg_litn("vV", "verbose", 0, 2, "show technical data"), + arg_str0("", "aid", "", "replace default aid for NDEF"), + arg_str0("kK", "key", "", "replace default key for NDEF"), + arg_lit0("bB", "keyb", "use key B for access sectors (by default: key A)"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + + bool verbose = arg_get_lit(ctx, 1); + bool verbose2 = arg_get_lit(ctx, 1) > 1; + uint8_t aid[2] = {0}; + int aidlen; + CLIGetHexWithReturn(ctx, 2, aid, &aidlen); + uint8_t key[16] = {0}; + int keylen; + CLIGetHexWithReturn(ctx, 3, key, &keylen); + bool keyB = arg_get_lit(ctx, 4); + + uint16_t ndefAID = 0xe103; + if (aidlen == 2) + ndefAID = (aid[0] << 8) + aid[1]; + + uint8_t ndefkey[16] = {0}; + memcpy(ndefkey, g_mifarep_ndef_key, 16); + if (keylen == 16) { + memcpy(ndefkey, key, 16); + } + + uint8_t data[4096] = {0}; + int datalen = 0; + + for (int j = (int)file_ids_len - 1; j >= 0; j--) { + PrintAndLogEx(SUCCESS, "\n\n Fileid %d (0x%02x)", file_ids[j], file_ids[j]); + + uint8_t filesettings[20] = {0}; + uint32_t fileset_len = 0; + + res = handler_desfire_filesettings(file_ids[j], filesettings, &fileset_len); + if (res != PM3_SUCCESS) continue; + + int maclen = 0; // To be implemented + + if (fileset_len == 1 + 1 + 2 + 3 + maclen) { + int filesize = (filesettings[6] << 16) + (filesettings[5] << 8) + filesettings[4]; + mfdes_data_t fdata; + fdata.fileno = file_ids[j]; + memset(fdata.offset, 0, 3); + memset(fdata.length, 0, 3); + + uint8_t *data = (uint8_t *)calloc(filesize, sizeof(uint8_t)); + if (data == NULL) { + DropField(); + return PM3_EMALLOC; + } + + fdata.data = data; + int res = handler_desfire_readdata(&fdata, MFDES_DATA_FILE, filesettings[1]); + if (res == PM3_SUCCESS) { + uint32_t len = le24toh(fdata.length); + NDEFDecodeAndPrint(data, datalen, verbose); + + } else { + PrintAndLogEx(ERR, "Couldn't read value. Error %d", res); + res = handler_desfire_select_application(aid); + if (res != PM3_SUCCESS) continue; + } + + free(data); + } + +// PrintAndLogEx(INFO, "reading data from tag"); + + if (!datalen) { + PrintAndLogEx(ERR, "no NDEF data"); + return PM3_SUCCESS; + } + + if (verbose2) { + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "--- " _CYAN_("DESfire NDEF raw") " ----------------"); + dump_buffer(data, datalen, stdout, 1); + } + PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mfdes ndef -vv`") " for more details"); + return PM3_SUCCESS; +} +*/ + /*static int CmdTest(const char *Cmd) { (void)Cmd; // Cmd is not used so far uint8_t IV[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -4495,29 +4598,29 @@ static int CmdHF14ADesList(const char *Cmd) { */ static command_t CommandTable[] = { - {"help", CmdHelp, AlwaysAvailable, "This help"}, - //{"test", CmdTest, AlwaysAvailable, "Test"}, - {"info", CmdHF14ADesInfo, IfPm3Iso14443a, "Tag information"}, - {"list", CmdHF14ADesList, AlwaysAvailable, "List DESFire (ISO 14443A) history"}, - {"enum", CmdHF14ADesEnumApplications, IfPm3Iso14443a, "Tries enumerate all applications"}, - {"auth", CmdHF14ADesAuth, IfPm3Iso14443a, "Tries a MIFARE DesFire Authentication"}, - {"getuid", CmdHF14ADesGetUID, IfPm3Iso14443a, "Get random uid"}, - {"selectaid", CmdHF14ADesSelectApp, IfPm3Iso14443a, "Select Application ID"}, - {"createaid", CmdHF14ADesCreateApp, IfPm3Iso14443a, "Create Application ID"}, - {"deleteaid", CmdHF14ADesDeleteApp, IfPm3Iso14443a, "Delete Application ID"}, - {"createfile", CmdHF14ADesCreateFile, IfPm3Iso14443a, "Create Standard/Backup File"}, - {"createvaluefile", CmdHF14ADesCreateValueFile, IfPm3Iso14443a, "Create Value File"}, - {"createrecordfile", CmdHF14ADesCreateRecordFile, IfPm3Iso14443a, "Create Linear/Cyclic Record File"}, - {"deletefile", CmdHF14ADesDeleteFile, IfPm3Iso14443a, "Create Delete File"}, - {"clearfile", CmdHF14ADesClearRecordFile, IfPm3Iso14443a, "Clear record File"}, - {"readdata", CmdHF14ADesReadData, IfPm3Iso14443a, "Read data from standard/backup/record file"}, - {"writedata", CmdHF14ADesWriteData, IfPm3Iso14443a, "Write data to standard/backup/record file"}, - {"getvalue", CmdHF14ADesGetValueData, IfPm3Iso14443a, "Get value of file"}, - {"changevalue", CmdHF14ADesChangeValue, IfPm3Iso14443a, "Write value of a value file (credit/debit/clear)"}, - {"changekey", CmdHF14ADesChangeKey, IfPm3Iso14443a, "Change Key"}, - {"formatpicc", CmdHF14ADesFormatPICC, IfPm3Iso14443a, "Format PICC"}, - {"dump", CmdHF14ADesDump, IfPm3Iso14443a, "Dump all files"}, - {"chk", CmdHF14aDesChk, IfPm3Iso14443a, "Check keys"}, + {"help", CmdHelp, AlwaysAvailable, "This help"}, + {"info", CmdHF14ADesInfo, IfPm3Iso14443a, "Tag information"}, + {"list", CmdHF14ADesList, AlwaysAvailable, "List DESFire (ISO 14443A) history"}, + {"enum", CmdHF14ADesEnumApplications, IfPm3Iso14443a, "Tries enumerate all applications"}, + {"auth", CmdHF14ADesAuth, IfPm3Iso14443a, "Tries a MIFARE DesFire Authentication"}, + {"getuid", CmdHF14ADesGetUID, IfPm3Iso14443a, "Get random uid"}, + {"selectaid", CmdHF14ADesSelectApp, IfPm3Iso14443a, "Select Application ID"}, + {"createaid", CmdHF14ADesCreateApp, IfPm3Iso14443a, "Create Application ID"}, + {"deleteaid", CmdHF14ADesDeleteApp, IfPm3Iso14443a, "Delete Application ID"}, + {"createfile", CmdHF14ADesCreateFile, IfPm3Iso14443a, "Create Standard/Backup File"}, + {"createvaluefile", CmdHF14ADesCreateValueFile, IfPm3Iso14443a, "Create Value File"}, + {"createrecordfile", CmdHF14ADesCreateRecordFile, IfPm3Iso14443a, "Create Linear/Cyclic Record File"}, + {"deletefile", CmdHF14ADesDeleteFile, IfPm3Iso14443a, "Create Delete File"}, + {"clearfile", CmdHF14ADesClearRecordFile, IfPm3Iso14443a, "Clear record File"}, + {"readdata", CmdHF14ADesReadData, IfPm3Iso14443a, "Read data from standard/backup/record file"}, + {"writedata", CmdHF14ADesWriteData, IfPm3Iso14443a, "Write data to standard/backup/record file"}, + {"getvalue", CmdHF14ADesGetValueData, IfPm3Iso14443a, "Get value of file"}, + {"changevalue", CmdHF14ADesChangeValue, IfPm3Iso14443a, "Write value of a value file (credit/debit/clear)"}, + {"changekey", CmdHF14ADesChangeKey, IfPm3Iso14443a, "Change Key"}, + {"formatpicc", CmdHF14ADesFormatPICC, IfPm3Iso14443a, "Format PICC"}, + {"dump", CmdHF14ADesDump, IfPm3Iso14443a, "Dump all files"}, + {"chk", CmdHF14aDesChk, IfPm3Iso14443a, "Check keys"}, +// {"ndef", CmdHF14aDesNDEF, IfPm3Iso14443a, "Prints NDEF records from card"}, {NULL, NULL, NULL, NULL} }; From 29a4a888a4062f7c961446b9a323fe9e52caea59 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 10:32:35 +0200 Subject: [PATCH 62/84] fix coverity 290965 --- client/src/cmdhfmfdes.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index d45275969..7b41eeebd 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -3216,24 +3216,20 @@ static int CmdHF14ADesFormatPICC(const char *Cmd) { "\n\thf mfdes formatpicc\n" "Make sure to authenticate picc before running this command.\n" ); - + CLIParserFree(ctx); sAPDU apdu = {0x90, MFDES_FORMAT_PICC, 0x00, 0x00, 0, NULL}; // 0xDF uint16_t sw = 0; uint32_t recvlen = 0; int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't format picc -> %s"), GetErrorString(res, &sw)); - DropField(); - return res; } else { PrintAndLogEx(INFO, "Card successfully reset"); - return PM3_SUCCESS; } DropField(); - return PM3_SUCCESS; + return res; } - static int CmdHF14ADesInfo(const char *Cmd) { (void)Cmd; // Cmd is not used so far DropField(); @@ -3372,7 +3368,6 @@ static int CmdHF14ADesInfo(const char *Cmd) { return PM3_SUCCESS; } - static void DecodeFileType(uint8_t filetype) { switch (filetype) { case 0x00: From b5b552054607295fd0438f313946851985a5bf2d Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 10:42:22 +0200 Subject: [PATCH 63/84] fix coverity 286922 --- client/src/cmdhfmfdes.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 7b41eeebd..4bfb15edb 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -2292,7 +2292,6 @@ static int selectfile(uint8_t *aid, uint32_t fileno, uint8_t *cs) { return res; } - static int CmdHF14ADesClearRecordFile(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf mfdes clearrecord", @@ -2822,7 +2821,6 @@ static int CmdHF14ADesChangeValue(const char *Cmd) { return res; } - static int CmdHF14ADesWriteData(const char *Cmd) { CLIParserContext *ctx; @@ -2853,14 +2851,12 @@ static int CmdHF14ADesWriteData(const char *Cmd) { uint8_t offset[3] = {0}; CLIParamHexToBuf(arg_get_str(ctx, 2), offset, 3, &offsetlength); - int dlength = 0xFFFF; - uint8_t *data = (uint8_t *)calloc(dlength, sizeof(uint8_t)); - if (data == NULL) { - PrintAndLogEx(ERR, "failed to allocate memory"); - CLIParserFree(ctx); - return PM3_EMALLOC; - } - CLIParamHexToBuf(arg_get_str(ctx, 3), data, 0xFFFF, &dlength); + // iceman: we only have a 1024 byte commandline input array. So this is pointlessly large. + // with 2char hex, 512bytes could be input. + // Instead large binary inputs should be BINARY files and written to card. + int dlength = 512; + uint8_t data[512] = {0}; + CLIParamHexToBuf(arg_get_str(ctx, 3), data, 512, &dlength); int type = arg_get_int(ctx, 4); int aidlength = 3; @@ -2874,31 +2870,26 @@ static int CmdHF14ADesWriteData(const char *Cmd) { if (type < 0 || type > 1) { PrintAndLogEx(ERR, "Unknown type (0=Standard/Backup, 1=Record)"); - if (data) free(data); return PM3_EINVARG; } if (dlength == 0) { PrintAndLogEx(ERR, "Data needs some hex bytes to write"); - if (data) free(data); return PM3_EINVARG; } if (offsetlength != 3 && offsetlength != 0) { PrintAndLogEx(ERR, "Offset needs 3 hex bytes"); - if (data) free(data); return PM3_EINVARG; } if (filenolen != 1) { PrintAndLogEx(ERR, "File number is missing"); - if (data) free(data); return PM3_EINVARG; } if (_fileno[0] > 0x1F) { PrintAndLogEx(ERR, "File number range is invalid (0x00-0x1F)"); - if (data) free(data); return PM3_EINVARG; } @@ -2921,25 +2912,22 @@ static int CmdHF14ADesWriteData(const char *Cmd) { uint8_t cs = 0; if (selectfile(aid, _fileno[0], &cs) != PM3_SUCCESS) { PrintAndLogEx(ERR, _RED_(" Error on selecting file.")); + DropField(); return PM3_ESOFT; } int res = PM3_ESOFT; - if (data != NULL) { - ft.data = data; - res = handler_desfire_writedata(&ft, type, cs); - if (res == PM3_SUCCESS) { - PrintAndLogEx(SUCCESS, "Successfully wrote data"); - } else { - PrintAndLogEx(ERR, "Couldn't read data. Error %d", res); - } - free(data); + ft.data = data; + res = handler_desfire_writedata(&ft, type, cs); + if (res == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "Successfully wrote data"); + } else { + PrintAndLogEx(ERR, "Couldn't read data. Error %d", res); } DropField(); return res; } - static int CmdHF14ADesCreateRecordFile(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf mfdes createrecordfile", From 5d08dae554f733c8488e8f7cf349a19bea86b4f6 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 11:10:02 +0200 Subject: [PATCH 64/84] fix coverity 290769, 290768 --- client/src/mifare/mad.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/client/src/mifare/mad.c b/client/src/mifare/mad.c index badc4b813..1fe3cfb02 100644 --- a/client/src/mifare/mad.c +++ b/client/src/mifare/mad.c @@ -121,9 +121,13 @@ static int print_aid_description(json_t *root, uint16_t aid, char *fmt, bool ver const char *company = mad_json_get_str(elm, "company"); const char *provider = mad_json_get_str(elm, "service_provider"); const char *integrator = mad_json_get_str(elm, "system_integrator"); - char result[4 + strlen(application) + strlen(company)]; - sprintf(result, " %s [%s]", application, company); - PrintAndLogEx(INFO, fmt, result); + + if (application && company) { + char result[4 + strlen(application) + strlen(company)]; + sprintf(result, " %s [%s]", application, company); + PrintAndLogEx(INFO, fmt, result); + } + if (verbose) { PrintAndLogEx(SUCCESS, " MAD: %s", vmad); if (application) From 682de4eee0d0eb48f775c60100c5c9169137ccd6 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 11:21:46 +0200 Subject: [PATCH 65/84] fix coverity 290962, 290961 --- client/src/cmdhfmfdes.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 4bfb15edb..0bd8aac6d 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -36,6 +36,8 @@ #define MAX_KEY_LEN 24 #define MAX_KEYS_LIST_LEN 1024 +#define status(x) ( ((uint16_t)(0x91<<8)) + (uint16_t)x ) + struct desfire_key default_key = {0}; uint8_t desdefaultkeys[3][8] = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //Official @@ -115,8 +117,6 @@ typedef enum { MFDES_VALUE_FILE } MFDES_FILE_TYPE_T; -#define status(x) ( ((uint16_t)(0x91<<8)) + (uint16_t)x ) - // NXP Appnote AN10787 - Application Directory (MAD) typedef enum { CL_ADMIN = 0, @@ -391,7 +391,6 @@ static char *getVersionStr(uint8_t major, uint8_t minor) { return buf; } - static int DESFIRESendApdu(bool activate_field, bool leavefield_on, sAPDU apdu, uint8_t *result, uint32_t max_result_len, uint32_t *result_len, uint16_t *sw) { *result_len = 0; @@ -958,7 +957,6 @@ static void AuthToError(int error) { } } - // -- test if card supports 0x0A static int test_desfire_authenticate(void) { uint8_t data[] = {0x00}; @@ -1013,7 +1011,8 @@ static int desfire_print_freemem(uint32_t free_mem) { static int handler_desfire_freemem(uint32_t *free_mem) { if (free_mem == NULL) return PM3_EINVARG; - sAPDU apdu = {0x90, MFDES_GET_FREE_MEMORY, 0x00, 0x00, 0x00, NULL}; // 0x6E + uint8_t data[] = {0x00}; + sAPDU apdu = {0x90, MFDES_GET_FREE_MEMORY, 0x00, 0x00, 0x00, data}; // 0x6E *free_mem = 0; uint32_t recv_len = 0; uint16_t sw = 0; @@ -1073,7 +1072,7 @@ static int mifare_desfire_change_key(uint8_t key_no, uint8_t *new_key, uint8_t n break; } - uint32_t cmdcnt = 0; + size_t cmdcnt = 0; memcpy(data + cmdcnt + 1, new_key, new_key_length); if ((tag->authenticated_key_no & 0x0f) != (key_no & 0x0f)) { @@ -1407,16 +1406,16 @@ static int handler_desfire_appids(uint8_t *dest, uint32_t *app_ids_len) { // --- GET DF NAMES static int handler_desfire_dfnames(dfname_t *dest, uint8_t *dfname_count) { - *dfname_count = 0; + if (g_debugMode > 1) { - if (dest == NULL) PrintAndLogEx(ERR, "DEST=NULL"); - if (dfname_count == NULL) PrintAndLogEx(ERR, "DFNAME_COUNT=NULL"); + if (dest == NULL) PrintAndLogEx(ERR, "DEST = NULL"); + if (dfname_count == NULL) PrintAndLogEx(ERR, "DFNAME_COUNT = NULL"); } - if (dest == NULL || dfname_count == NULL) return PM3_EINVARG; + if (dest == NULL || dfname_count == NULL) + return PM3_EINVARG; *dfname_count = 0; - sAPDU apdu = {0x90, MFDES_GET_DF_NAMES, 0x00, 0x00, 0x00, NULL}; //0x6d uint32_t recv_len = 0; uint16_t sw = 0; @@ -1650,9 +1649,11 @@ static int handler_desfire_readdata(mfdes_data_t *data, MFDES_FILE_TYPE_T type, return res; } - static int handler_desfire_getvalue(mfdes_value_t *value, uint32_t *resplen, uint8_t cs) { - if (value->fileno > 0x1F) return PM3_EINVARG; + + if (value->fileno > 0x1F) + return PM3_EINVARG; + sAPDU apdu = {0x90, MFDES_GET_VALUE, 0x00, 0x00, 0x01, &value->fileno}; // 0xBD uint16_t sw = 0; *resplen = 0; @@ -1737,7 +1738,6 @@ static int handler_desfire_writedata(mfdes_data_t *data, MFDES_FILE_TYPE_T type, return res; } - static int handler_desfire_deletefile(uint8_t fileno) { if (fileno > 0x1F) return PM3_EINVARG; sAPDU apdu = {0x90, MFDES_DELETE_FILE, 0x00, 0x00, 1, &fileno}; // 0xDF @@ -2098,7 +2098,6 @@ static int CmdHF14ADesSelectApp(const char *Cmd) { return res; } - static int CmdHF14ADesCreateApp(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf mfdes createaid", From d5b379207e4facb619999c514195099c14715101 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 11:22:09 +0200 Subject: [PATCH 66/84] fix coverity --- client/src/mifare/desfire_crypto.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/client/src/mifare/desfire_crypto.c b/client/src/mifare/desfire_crypto.c index 7260f4731..9eca32e44 100644 --- a/client/src/mifare/desfire_crypto.c +++ b/client/src/mifare/desfire_crypto.c @@ -389,7 +389,7 @@ void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, return data; switch (communication_settings & MDCM_MASK) { - case MDCM_PLAIN: + case MDCM_PLAIN: { if (AS_LEGACY == DESFIRE(tag)->authentication_scheme) break; @@ -404,9 +404,9 @@ void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, */ append_mac = false; - + } /* pass through */ - case MDCM_MACED: + case MDCM_MACED: { communication_settings |= NO_CRC; switch (DESFIRE(tag)->authentication_scheme) { @@ -455,7 +455,8 @@ void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, } break; - case MDCM_ENCIPHERED: + } + case MDCM_ENCIPHERED: { /* |<-------------- data -------------->| * |<--- offset -->| | * +---------------+--------------------+-----+---------+ @@ -473,21 +474,25 @@ void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, if (!(communication_settings & ENC_COMMAND)) break; + edl = enciphered_data_length(tag, *nbytes - offset, communication_settings) + offset; // Fill in the crypto buffer with data ... memcpy(res, data, *nbytes); + if (!(communication_settings & NO_CRC)) { // ... CRC ... switch (DESFIRE(tag)->authentication_scheme) { - case AS_LEGACY: + case AS_LEGACY: { AddCrc14A(res + offset, *nbytes - offset); *nbytes += 2; break; - case AS_NEW: + } + case AS_NEW: { crc32_append(res, *nbytes); *nbytes += 4; break; + } } } // ... and padding @@ -497,11 +502,12 @@ void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, mifare_cypher_blocks_chained(tag, NULL, NULL, res + offset, *nbytes - offset, MCD_SEND, (AS_NEW == DESFIRE(tag)->authentication_scheme) ? MCO_ENCYPHER : MCO_DECYPHER); break; - default: - + } + default: { *nbytes = -1; res = NULL; break; + } } return res; From e6bb7a8a87274003e76104ec8ec11e96db325926 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 11:32:38 +0200 Subject: [PATCH 67/84] fix coverity 292481 --- client/src/cmdlfem4x50.c | 54 ++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index cee6ece71..dc883211b 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -227,7 +227,7 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr) { } } -static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd, bool bverbose) { +static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd, bool verbose) { // display all information of info result in structured format @@ -235,9 +235,9 @@ static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd, em4x50_word_t words[EM4X50_NO_WORDS]; char pstring[NO_CHARS_MAX] = {0}, string[NO_CHARS_MAX] = {0}; - bool bpwd_given = etd->pwd_given; - bool bsuccess = (resp->status & STATUS_SUCCESS) >> 1; - bool blogin = resp->status & STATUS_LOGIN; + bool pwd_given = etd->pwd_given; + bool success = (resp->status & STATUS_SUCCESS) >> 1; + bool login = resp->status & STATUS_LOGIN; prepare_result(data, 0, EM4X50_NO_WORDS - 1, words); @@ -253,7 +253,7 @@ static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd, // data section PrintAndLogEx(NORMAL, _YELLOW_("\n em4x50 data:")); - if (bverbose) { + if (verbose) { // detailed data section print_result(words, 0, EM4X50_NO_WORDS - 1); @@ -336,47 +336,34 @@ static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd, sprintf(pstring, " reading "); strcat(string, pstring); - if (!bsuccess) { - + if (success == false) { sprintf(pstring, _RED_("failed")); strcat(string, pstring); - } else { sprintf(pstring, _GREEN_("ok ")); strcat(string, pstring); - if (blogin) { - - if (bpwd_given) { - + if (login) { + if (pwd_given) { sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)", etd->password[0], etd->password[1], etd->password[2], etd->password[3]); strcat(string, pstring); - } else { - sprintf(pstring, "(login with default password 0x00000000)"); strcat(string, pstring); - } } else { - - if (bpwd_given) { - + if (pwd_given) { sprintf(pstring, "(login failed)"); strcat(string, pstring); - } else { - sprintf(pstring, "(no login)"); strcat(string, pstring); - } } - } PrintAndLogEx(NORMAL,"%s\n", string); @@ -453,17 +440,15 @@ static void print_write_result(PacketResponseNG *resp, const em4x50_data_t *etd) bool login = resp->status & STATUS_LOGIN; uint8_t *data = resp->data.asBytes; char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; - em4x50_word_t word; + em4x50_word_t words[EM4X50_NO_WORDS]; - if (!success) { - + if (success == false) { sprintf(pstring, "\n writing " _RED_("failed")); strcat(string, pstring); - } else { - prepare_result(data, etd->address, etd->address, &word); - print_result(&word, etd->address, etd->address); + prepare_result(data, etd->address, etd->address, words); + print_result(words, etd->address, etd->address); sprintf(pstring, "\n writing " _GREEN_("ok ")); strcat(string, pstring); @@ -658,13 +643,12 @@ static void print_sread_result(PacketResponseNG *resp, const em4x50_data_t *etd) int now = (resp->status & STATUS_NO_WORDS) >> 2; char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; uint8_t *data = resp->data.asBytes; - em4x50_word_t word; + em4x50_word_t words[EM4X50_NO_WORDS]; - if (!success) { + if (success == false) { sprintf(pstring, "\n reading " _RED_("failed")); strcat(string, pstring); - PrintAndLogEx(NORMAL,"%s\n", string); } else { @@ -673,8 +657,8 @@ static void print_sread_result(PacketResponseNG *resp, const em4x50_data_t *etd) // selective read mode - prepare_result(data, etd->address, etd->address, &word); - print_result(&word, etd->address, etd->address); + prepare_result(data, etd->address, etd->address, words); + print_result(words, etd->address, etd->address); string[0] = '\0'; sprintf(pstring, "\n reading " _GREEN_("ok ")); @@ -699,8 +683,8 @@ static void print_sread_result(PacketResponseNG *resp, const em4x50_data_t *etd) //standard read mode - prepare_result(data, 0, now - 1, &word); - print_result(&word, 0, now - 1); + prepare_result(data, 0, now - 1, words); + print_result(words, 0, now - 1); string[0] = '\0'; sprintf(pstring, "\n reading " _GREEN_("ok ")); From a9b27526732d6363c919f5109fbd913b5133c099 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 11:56:18 +0200 Subject: [PATCH 68/84] fix coverity 292483 --- client/src/cmdlfem4x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/cmdlfem4x.c b/client/src/cmdlfem4x.c index ef8cbdc13..d788bfbe2 100644 --- a/client/src/cmdlfem4x.c +++ b/client/src/cmdlfem4x.c @@ -659,7 +659,7 @@ static int CmdEM410xWrite(const char *Cmd) { // Allowed clock rates: 16, 32, 40 and 64 if ((clock1 != 16) && (clock1 != 32) && (clock1 != 64) && (clock1 != 40)) { - PrintAndLogEx(ERR, "error, clock rate" _RED_("%d")" not valid"); + PrintAndLogEx(FAILED, "error, clock rate" _RED_("%d")" not valid", clock1); PrintAndLogEx(INFO, "supported clock rates: " _YELLOW_("16, 32, 40, 60") "\n", clock1); usage_lf_em410x_write(); return PM3_EINVARG; From 714652b1f2b3befcd44ae88178bb79ac6572f6c9 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 11:56:56 +0200 Subject: [PATCH 69/84] fix coverity 226321 --- client/src/cmdlfem4x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/cmdlfem4x.c b/client/src/cmdlfem4x.c index d788bfbe2..508a425e3 100644 --- a/client/src/cmdlfem4x.c +++ b/client/src/cmdlfem4x.c @@ -660,7 +660,7 @@ static int CmdEM410xWrite(const char *Cmd) { // Allowed clock rates: 16, 32, 40 and 64 if ((clock1 != 16) && (clock1 != 32) && (clock1 != 64) && (clock1 != 40)) { PrintAndLogEx(FAILED, "error, clock rate" _RED_("%d")" not valid", clock1); - PrintAndLogEx(INFO, "supported clock rates: " _YELLOW_("16, 32, 40, 60") "\n", clock1); + PrintAndLogEx(INFO, "supported clock rates: " _YELLOW_("16, 32, 40, 60") "\n"); usage_lf_em410x_write(); return PM3_EINVARG; } From a6cc73a4d58253a9693d2e2634c985a917dd3f19 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 11:58:24 +0200 Subject: [PATCH 70/84] fix coverity 293468 --- client/src/cmdlfmotorola.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/cmdlfmotorola.c b/client/src/cmdlfmotorola.c index 36777be02..16d1d8dc5 100644 --- a/client/src/cmdlfmotorola.c +++ b/client/src/cmdlfmotorola.c @@ -119,8 +119,8 @@ int demodMotorola(void) { checksum |= DemodBuffer[63] << 0; // b1 - PrintAndLogEx(SUCCESS, "Motorola - len: " _GREEN_("26") " FC: " _GREEN_("%u") " Card: " _GREEN_("%u") ", Raw: %08X%08X", fc, csn, raw1, raw2); - PrintAndLogEx(DEBUG, "checksum: " _GREEN_("%1d%1d"), fc, csn, checksum >> 1 & 0x01, checksum & 0x01); + PrintAndLogEx(SUCCESS, "Motorola - fmt: " _GREEN_("26") " FC: " _GREEN_("%u") " Card: " _GREEN_("%u") ", Raw: %08X%08X", fc, csn, raw1, raw2); + PrintAndLogEx(DEBUG, "checksum: " _GREEN_("%1d%1d"), checksum >> 1 & 0x01, checksum & 0x01); return PM3_SUCCESS; } From ac12a892b0f34729c554a004dd5caa5e91242f62 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 12:11:17 +0200 Subject: [PATCH 71/84] fix coverity 290964, 286679, 286658, 286652 --- client/src/cmdhfmfdes.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 0bd8aac6d..fe69d1909 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -2442,7 +2442,7 @@ static int CmdHF14ADesCreateFile(const char *Cmd) { int fidlength = 0; uint8_t fid[2] = {0}; - CLIParamHexToBuf(arg_get_str(ctx, 2), fid, 2, &fidlength); + int res_flen = CLIParamHexToBuf(arg_get_str(ctx, 2), fid, 2, &fidlength); uint8_t comset = arg_get_int(ctx, 3); int arlength = 0; @@ -2487,7 +2487,7 @@ static int CmdHF14ADesCreateFile(const char *Cmd) { return PM3_EINVARG; } - if (fidlength != 2) { + if (res_flen || fidlength != 2) { PrintAndLogEx(ERR, "ISO File id must have 2 hex bytes length."); return PM3_EINVARG; } @@ -2633,11 +2633,11 @@ static int CmdHF14ADesReadData(const char *Cmd) { int offsetlength = 0; uint8_t offset[3] = {0}; - CLIParamHexToBuf(arg_get_str(ctx, 2), offset, 3, &offsetlength); + int res_offset = CLIParamHexToBuf(arg_get_str(ctx, 2), offset, 3, &offsetlength); int flength = 0; uint8_t filesize[3] = {0}; - CLIParamHexToBuf(arg_get_str(ctx, 3), filesize, 3, &flength); + int res_flen = CLIParamHexToBuf(arg_get_str(ctx, 3), filesize, 3, &flength); int type = arg_get_int(ctx, 4); @@ -2652,7 +2652,7 @@ static int CmdHF14ADesReadData(const char *Cmd) { return PM3_EINVARG; } - if (offsetlength != 3 && offsetlength != 0) { + if (res_offset || (offsetlength != 3 && offsetlength != 0)) { PrintAndLogEx(ERR, "Offset needs 3 hex bytes"); return PM3_EINVARG; } @@ -2667,6 +2667,11 @@ static int CmdHF14ADesReadData(const char *Cmd) { return PM3_EINVARG; } + if (res_flen) { + PrintAndLogEx(ERR, "File size input error"); + return PM3_EINVARG; + } + swap24(filesize); swap24(offset); @@ -2750,7 +2755,7 @@ static int CmdHF14ADesChangeValue(const char *Cmd) { value.fileno = _fileno[0]; int vlength = 0x0; - CLIParamHexToBuf(arg_get_str(ctx, 2), value.value, 4, &vlength); + int res_val = CLIParamHexToBuf(arg_get_str(ctx, 2), value.value, 4, &vlength); int mode = arg_get_int(ctx, 3); int aidlength = 3; @@ -2765,7 +2770,7 @@ static int CmdHF14ADesChangeValue(const char *Cmd) { return PM3_EINVARG; } - if (vlength != 4) { + if (res_val || vlength != 4) { PrintAndLogEx(ERR, "Value needs 4 hex bytes."); return PM3_EINVARG; } @@ -2848,14 +2853,14 @@ static int CmdHF14ADesWriteData(const char *Cmd) { int offsetlength = 0; uint8_t offset[3] = {0}; - CLIParamHexToBuf(arg_get_str(ctx, 2), offset, 3, &offsetlength); + int res_offset = CLIParamHexToBuf(arg_get_str(ctx, 2), offset, 3, &offsetlength); // iceman: we only have a 1024 byte commandline input array. So this is pointlessly large. // with 2char hex, 512bytes could be input. // Instead large binary inputs should be BINARY files and written to card. int dlength = 512; uint8_t data[512] = {0}; - CLIParamHexToBuf(arg_get_str(ctx, 3), data, 512, &dlength); + int res_data = CLIParamHexToBuf(arg_get_str(ctx, 3), data, 512, &dlength); int type = arg_get_int(ctx, 4); int aidlength = 3; @@ -2872,12 +2877,12 @@ static int CmdHF14ADesWriteData(const char *Cmd) { return PM3_EINVARG; } - if (dlength == 0) { + if (res_data || dlength == 0) { PrintAndLogEx(ERR, "Data needs some hex bytes to write"); return PM3_EINVARG; } - if (offsetlength != 3 && offsetlength != 0) { + if (res_offset || (offsetlength != 3 && offsetlength != 0)) { PrintAndLogEx(ERR, "Offset needs 3 hex bytes"); return PM3_EINVARG; } @@ -2956,7 +2961,7 @@ static int CmdHF14ADesCreateRecordFile(const char *Cmd) { int fidlength = 0; uint8_t fid[2] = {0}; - CLIParamHexToBuf(arg_get_str(ctx, 2), fid, 2, &fidlength); + int res_flen = CLIParamHexToBuf(arg_get_str(ctx, 2), fid, 2, &fidlength); uint8_t comset = arg_get_int(ctx, 3); int arlength = 0; @@ -3017,7 +3022,7 @@ static int CmdHF14ADesCreateRecordFile(const char *Cmd) { return PM3_EINVARG; } - if (fidlength != 2) { + if (res_flen || fidlength != 2) { PrintAndLogEx(ERR, "ISO File id must have 2 hex bytes length."); return PM3_EINVARG; } @@ -3761,11 +3766,13 @@ static int CmdHF14ADesChangeKey(const char *Cmd) { uint8_t cmdAuthAlgo = arg_get_int_def(ctx, 2, 0); uint8_t key[24] = {0}; int keylen = 0; - CLIParamHexToBuf(arg_get_str(ctx, 3), key, 24, &keylen); + int res_klen = CLIParamHexToBuf(arg_get_str(ctx, 3), key, 24, &keylen); + uint8_t newcmdAuthAlgo = arg_get_int_def(ctx, 4, 0); uint8_t newkey[24] = {0}; int newkeylen = 0; - CLIParamHexToBuf(arg_get_str(ctx, 5), newkey, 24, &newkeylen); + int res_newklen = CLIParamHexToBuf(arg_get_str(ctx, 5), newkey, 24, &newkeylen); + uint8_t aesversion = arg_get_int_def(ctx, 6, 0); CLIParserFree(ctx); @@ -3789,12 +3796,12 @@ static int CmdHF14ADesChangeKey(const char *Cmd) { newkeylength = 24; } - if ((keylen < 8) || (keylen > 24)) { + if (res_klen || (keylen < 8) || (keylen > 24)) { PrintAndLogEx(ERR, "Specified key must have %d bytes length.", keylen); return PM3_EINVARG; } - if ((newkeylen < 8) || (newkeylen > 24)) { + if (res_newklen || (newkeylen < 8) || (newkeylen > 24)) { PrintAndLogEx(ERR, "Specified key must have %d bytes length.", newkeylen); return PM3_EINVARG; } From 2fe42173de9ddfe68cbfe540316367c4bd713e15 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 18:10:40 +0200 Subject: [PATCH 72/84] chg: when pressing ctrl-c, the command history is saved --- client/src/proxmark3.c | 43 ++++++++++++++++++++++++++++++++++-------- client/src/ui.h | 1 + 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/client/src/proxmark3.c b/client/src/proxmark3.c index 50d7d660b..cb739df13 100644 --- a/client/src/proxmark3.c +++ b/client/src/proxmark3.c @@ -18,8 +18,10 @@ #ifdef HAVE_READLINE #include #include +#include #endif #include + #include "usart_defs.h" #include "util_posix.h" #include "proxgui.h" @@ -134,6 +136,23 @@ static int check_comm(void) { } return 0; } +static void flush_history(void) { +#ifdef HAVE_READLINE + if (session.history_path) { + write_history(session.history_path); + free(session.history_path); + } +#endif +} + +#ifdef HAVE_READLINE +struct sigaction old_action; +static void terminate_handler(int signum) { + sigaction(SIGINT, &old_action, NULL); + flush_history(); + kill(0, SIGINT); +} +#endif // first slot is always NULL, indicating absence of script when idx=0 static FILE *cmdscriptfile[MAX_NESTED_CMDSCRIPT + 1] = {0}; @@ -211,16 +230,26 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { } #ifdef HAVE_READLINE - char *my_history_path = NULL; - if (searchHomeFilePath(&my_history_path, NULL, PROXHISTORY, true) != PM3_SUCCESS) { + session.history_path = NULL; + if (searchHomeFilePath(&session.history_path, NULL, PROXHISTORY, true) != PM3_SUCCESS) { PrintAndLogEx(ERR, "No history will be recorded"); - my_history_path = NULL; + session.history_path = NULL; } else { - read_history(my_history_path); + + struct sigaction action; + memset(&action, 0, sizeof(action)); + action.sa_handler = &terminate_handler; + sigaction(SIGINT, &action, &old_action); + + rl_catch_signals = 1; + rl_set_signals(); + read_history(session.history_path); } #endif + // loops every time enter is pressed... while (1) { + bool printprompt = false; if (session.pm3_present) { if (conn.send_via_fpc_usart == false) @@ -391,11 +420,9 @@ check_script: pop_cmdscriptfile(); #ifdef HAVE_READLINE - if (my_history_path) { - write_history(my_history_path); - free(my_history_path); - } + flush_history(); #endif + if (cmd) { free(cmd); cmd = NULL; diff --git a/client/src/ui.h b/client/src/ui.h index 60064c0aa..7a5b7911d 100644 --- a/client/src/ui.h +++ b/client/src/ui.h @@ -43,6 +43,7 @@ typedef struct { // char *defaultPaths[spItemCount]; // Array should allow loop searching for files clientdebugLevel_t client_debug_level; // uint8_t device_debug_level; + char *history_path; } session_arg_t; extern session_arg_t session; From 8d7a0c7fc734a70889d74ee6501e59cba4ffa32e Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 18:16:28 +0200 Subject: [PATCH 73/84] pref show - textual --- client/src/preferences.c | 64 +++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/client/src/preferences.c b/client/src/preferences.c index 8ddd0f150..02e0b80cb 100644 --- a/client/src/preferences.c +++ b/client/src/preferences.c @@ -86,7 +86,6 @@ int preferences_load(void) { // to better control json cant find file error msg. char *fn = prefGetFilename(); if (fileExists(fn)) { - PrintAndLogEx(INFO, "Loading preferences..."); if (loadFileJSON(fn, &dummyData, sizeof(dummyData), &dummyDL, &preferences_load_callback) == PM3_SUCCESS) { session.preferences_loaded = true; } @@ -384,75 +383,75 @@ static const char *prefShowMsg(prefShowOpt_t Opt) { return ""; } -static void showEmojiState(prefShowOpt_t Opt) { +static void showEmojiState(prefShowOpt_t opt) { switch (session.emoji_mode) { case ALIAS: - PrintAndLogEx(NORMAL, " %s emoji.................. "_GREEN_("alias"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s emoji.................. "_GREEN_("alias"), prefShowMsg(opt)); break; case EMOJI: - PrintAndLogEx(NORMAL, " %s emoji.................. "_GREEN_("emoji"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s emoji.................. "_GREEN_("emoji"), prefShowMsg(opt)); break; case ALTTEXT: - PrintAndLogEx(NORMAL, " %s emoji.................. "_GREEN_("alttext"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s emoji.................. "_GREEN_("alttext"), prefShowMsg(opt)); break; case ERASE: - PrintAndLogEx(NORMAL, " %s emoji.................. "_GREEN_("erase"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s emoji.................. "_GREEN_("erase"), prefShowMsg(opt)); break; default: - PrintAndLogEx(NORMAL, " %s emoji.................. "_RED_("unknown"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s emoji.................. "_RED_("unknown"), prefShowMsg(opt)); } } -static void showColorState(prefShowOpt_t Opt) { +static void showColorState(prefShowOpt_t opt) { if (session.supports_colors) - PrintAndLogEx(NORMAL, " %s color.................. "_GREEN_("ansi"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s color.................. "_GREEN_("ansi"), prefShowMsg(opt)); else - PrintAndLogEx(NORMAL, " %s color.................. "_WHITE_("off"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s color.................. "_WHITE_("off"), prefShowMsg(opt)); } -static void showClientDebugState(prefShowOpt_t Opt) { +static void showClientDebugState(prefShowOpt_t opt) { switch (session.client_debug_level) { case cdbOFF: - PrintAndLogEx(NORMAL, " %s client debug........... "_WHITE_("off"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s client debug........... "_WHITE_("off"), prefShowMsg(opt)); break; case cdbSIMPLE: - PrintAndLogEx(NORMAL, " %s client debug........... "_GREEN_("simple"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s client debug........... "_GREEN_("simple"), prefShowMsg(opt)); break; case cdbFULL: - PrintAndLogEx(NORMAL, " %s client debug........... "_GREEN_("full"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s client debug........... "_GREEN_("full"), prefShowMsg(opt)); break; default: - PrintAndLogEx(NORMAL, " %s client debug........... "_RED_("unknown"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s client debug........... "_RED_("unknown"), prefShowMsg(opt)); } } /* -static void showDeviceDebugState(prefShowOpt_t Opt) { +static void showDeviceDebugState(prefShowOpt_t opt) { switch (session.device_debug_level) { case ddbOFF: - PrintAndLogEx(NORMAL, " %s device debug........... "_WHITE_("off"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s device debug........... "_WHITE_("off"), prefShowMsg(opt)); break; case ddbERROR: - PrintAndLogEx(NORMAL, " %s device debug........... "_GREEN_("error"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s device debug........... "_GREEN_("error"), prefShowMsg(opt)); break; case ddbINFO: - PrintAndLogEx(NORMAL, " %s device debug........... "_GREEN_("info"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s device debug........... "_GREEN_("info"), prefShowMsg(opt)); break; case ddbDEBUG: - PrintAndLogEx(NORMAL, " %s device debug........... "_GREEN_("debug"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s device debug........... "_GREEN_("debug"), prefShowMsg(opt)); break; case ddbEXTENDED: - PrintAndLogEx(NORMAL, " %s device debug........... "_GREEN_("extended"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s device debug........... "_GREEN_("extended"), prefShowMsg(opt)); break; default: - PrintAndLogEx(NORMAL, " %s device debug........... "_RED_("unknown"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s device debug........... "_RED_("unknown"), prefShowMsg(opt)); } } */ /* -static void showSavePathState(savePaths_t pathIndex, prefShowOpt_t Opt) { +static void showSavePathState(savePaths_t pathIndex, prefShowOpt_t opt) { char tempStr[50]; @@ -470,29 +469,30 @@ static void showSavePathState(savePaths_t pathIndex, prefShowOpt_t Opt) { strcpy (tempStr,_RED_("unknown")" save path......"); } if ((session.defaultPaths[pathIndex] == NULL) || (strcmp(session.defaultPaths[pathIndex],"") == 0)) - PrintAndLogEx(NORMAL, " %s %s "_WHITE_("not set"), prefShowMsg(Opt),tempStr); + PrintAndLogEx(INFO, " %s %s "_WHITE_("not set"), prefShowMsg(opt),tempStr); else - PrintAndLogEx(NORMAL, " %s %s "_GREEN_("%s"), prefShowMsg(Opt), tempStr, session.defaultPaths[pathIndex]); + PrintAndLogEx(INFO, " %s %s "_GREEN_("%s"), prefShowMsg(opt), tempStr, session.defaultPaths[pathIndex]); } static void showPlotPosState(void) { - PrintAndLogEx(NORMAL, " Plot window............ X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"), + PrintAndLogEx(INFO, " Plot window............ X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"), session.plot.x, session.plot.y, session.plot.h, session.plot.w); } static void showOverlayPosState(void) { - PrintAndLogEx(NORMAL, " Slider/Overlay window.. X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"), + PrintAndLogEx(INFO, " Slider/Overlay window.. X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"), session.overlay.x, session.overlay.y, session.overlay.h, session.overlay.w); } */ -static void showHintsState(prefShowOpt_t Opt) { +static void showHintsState(prefShowOpt_t opt) { if (session.show_hints) - PrintAndLogEx(NORMAL, " %s hints.................. "_GREEN_("on"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s hints.................. "_GREEN_("on"), prefShowMsg(opt)); else - PrintAndLogEx(NORMAL, " %s hints.................. "_WHITE_("off"), prefShowMsg(Opt)); + PrintAndLogEx(INFO, " %s hints.................. "_WHITE_("off"), prefShowMsg(opt)); } + static int setCmdEmoji(const char *Cmd) { uint8_t cmdp = 0; bool errors = false; @@ -909,13 +909,14 @@ static int CmdPrefShow(const char *Cmd) { if (session.preferences_loaded) { char *fn = prefGetFilename(); PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, _CYAN_("Preferences loaded from " _YELLOW_("%s")), fn); + PrintAndLogEx(INFO, "Using "_YELLOW_("%s"), fn); free(fn); } else { PrintAndLogEx(ERR, "Preferences not loaded"); return PM3_ESOFT; } + PrintAndLogEx(INFO, "Current settings"); showEmojiState(prefShowNone); showHintsState(prefShowNone); showColorState(prefShowNone); @@ -927,6 +928,7 @@ static int CmdPrefShow(const char *Cmd) { showClientDebugState(prefShowNone); // showDeviceDebugState(prefShowNone); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } /* From 2abd7e08b42f278bfb07777fb81199ce09f69403 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 29 Jun 2020 22:23:46 +0200 Subject: [PATCH 74/84] chg: disable ctrl-c on mingw/ps --- client/src/proxmark3.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/client/src/proxmark3.c b/client/src/proxmark3.c index cb739df13..1bf08f1d3 100644 --- a/client/src/proxmark3.c +++ b/client/src/proxmark3.c @@ -146,6 +146,18 @@ static void flush_history(void) { } #ifdef HAVE_READLINE + +# if defined(_WIN32) +/* +static bool WINAPI terminate_handler(DWORD t) { + if (t == CTRL_C_EVENT) { + flush_history(); + return true; + } + return false; +} +*/ +# else struct sigaction old_action; static void terminate_handler(int signum) { sigaction(SIGINT, &old_action, NULL); @@ -154,6 +166,8 @@ static void terminate_handler(int signum) { } #endif +#endif + // first slot is always NULL, indicating absence of script when idx=0 static FILE *cmdscriptfile[MAX_NESTED_CMDSCRIPT + 1] = {0}; static uint8_t cmdscriptfile_idx = 0; @@ -236,11 +250,14 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { session.history_path = NULL; } else { +# if defined(_WIN32) +// SetConsoleCtrlHandler((PHANDLER_ROUTINE)terminate_handler, true); +# else struct sigaction action; memset(&action, 0, sizeof(action)); action.sa_handler = &terminate_handler; sigaction(SIGINT, &action, &old_action); - +# endif rl_catch_signals = 1; rl_set_signals(); read_history(session.history_path); @@ -1054,7 +1071,7 @@ int main(int argc, char *argv[]) { #ifdef HAVE_GUI -# ifdef _WIN32 +# if defined(_WIN32) InitGraphics(argc, argv, script_cmds_file, script_cmd, stayInCommandLoop); MainGraphics(); # else From a1f760259254c6d729e4fe6dbfba01b2d8d15803 Mon Sep 17 00:00:00 2001 From: tharexde Date: Tue, 30 Jun 2020 01:50:31 +0200 Subject: [PATCH 75/84] fixed: if tag status = NAK -> following detection of double listen window took too long --- armsrc/em4x50.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index 5644962b8..0132ff2fd 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -74,7 +74,7 @@ static em4x50_tag_t tag = { #define EM4X50_T_TAG_FULL_PERIOD 64 #define EM4X50_T_TAG_TPP 64 #define EM4X50_T_TAG_TWA 64 -#define EM4X50_T_WAITING_FOR_DBLLIW 1600 +#define EM4X50_T_WAITING_FOR_DBLLIW 1550 #define EM4X50_TAG_TOLERANCE 8 #define EM4X50_TAG_WORD 45 @@ -535,6 +535,10 @@ static bool check_ack(bool bliw) { return true; } } + } else { + + // It's NAK -> stop searching + break; } } } From 9c263b3fb8792cd9ef0a01a22f9154a115d72e78 Mon Sep 17 00:00:00 2001 From: tharexde Date: Tue, 30 Jun 2020 01:51:24 +0200 Subject: [PATCH 76/84] fixed simple compilation errors --- client/src/cmdlfem4x50.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index 62d8c143f..b38a2cc56 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -461,8 +461,8 @@ static void print_write_result(PacketResponseNG *resp, const em4x50_data_t *etd) char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; em4x50_word_t words[EM4X50_NO_WORDS]; - prepare_result(data, etd->address, etd->address, &word); - print_result(&word, etd->address, etd->address, true); + prepare_result(data, etd->address, etd->address, words); + print_result(words, etd->address, etd->address, true); sprintf(pstring, "\n writing " _GREEN_("ok ")); strcat(string, pstring); @@ -660,8 +660,8 @@ static void print_read_result(PacketResponseNG *resp, const em4x50_data_t *etd, // selective read mode - prepare_result(data, etd->address, etd->address, &word); - print_result(&word, etd->address, etd->address, true); + prepare_result(data, etd->address, etd->address, words); + print_result(words, etd->address, etd->address, true); string[0] = '\0'; sprintf(pstring, "\n reading " _GREEN_("ok ")); @@ -688,8 +688,8 @@ static void print_read_result(PacketResponseNG *resp, const em4x50_data_t *etd, //standard read mode - prepare_result(data, 0, now - 1, &word); - print_result(&word, 0, now - 1, verbose); + prepare_result(data, 0, now - 1, words); + print_result(words, 0, now - 1, verbose); if (verbose) { From a3a7f0d4ad068d61301fcdca62bc2ecbd5882412 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 30 Jun 2020 12:50:31 +0200 Subject: [PATCH 77/84] hw tia, status - textual --- client/src/cmdhw.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index 487d5eb2b..f19eff1a7 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -507,19 +507,23 @@ static int CmdStatus(const char *Cmd) { clearCommandBuffer(); PacketResponseNG resp; SendCommandNG(CMD_STATUS, NULL, 0); - if (WaitForResponseTimeout(CMD_STATUS, &resp, 2000) == false) - PrintAndLogEx(WARNING, "Status command failed. Communication speed test timed out"); + if (WaitForResponseTimeout(CMD_STATUS, &resp, 2000) == false) { + PrintAndLogEx(WARNING, "Status command timeout. Communication speed test timed out"); + return PM3_ETIMEOUT; + } return PM3_SUCCESS; } static int CmdTia(const char *Cmd) { (void)Cmd; // Cmd is not used so far - clearCommandBuffer(); PrintAndLogEx(INFO, "Triggering new Timing Interval Acquisition (TIA)..."); - PacketResponseNG resp; + clearCommandBuffer(); SendCommandNG(CMD_TIA, NULL, 0); - if (WaitForResponseTimeout(CMD_TIA, &resp, 2000) == false) - PrintAndLogEx(WARNING, "TIA command failed. You probably need to unplug the Proxmark3."); + PacketResponseNG resp; + if (WaitForResponseTimeout(CMD_TIA, &resp, 2000) == false) { + PrintAndLogEx(WARNING, "TIA command timeout. You probably need to unplug the Proxmark3."); + return PM3_ETIMEOUT; + } PrintAndLogEx(INFO, "TIA done."); return PM3_SUCCESS; } From 4529d0a89157523c3dbf6d9d50e93863ba0d976d Mon Sep 17 00:00:00 2001 From: Iceman Date: Tue, 30 Jun 2020 15:13:58 +0200 Subject: [PATCH 78/84] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 940722506..de546a42e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -7,6 +7,18 @@ assignees: '' --- +***Things to try before submitting bug report*** +read the [troubleshooting guide](/doc/md/Installation_Instructions/Troubleshooting.md) + +***Compilation problems*** +Try compiling with verbose. `make VERBOSE=1` with main makefile or `make V=1` with cmake. + +***flashing problems*** +Have you followed the instructions properly? ie, flashed bootrom seperately first if you are going from Offical repo to RRG/Iceman repo. + + +- + **Describe the bug** A clear and concise description of what the bug is. From 86bfdcf260f3a625effccff3c36b9ec68c7f0a79 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 30 Jun 2020 17:43:47 +0200 Subject: [PATCH 79/84] chg: lf em 4x50_read / info - remake output --- client/src/cmdlf.c | 10 +- client/src/cmdlfem4x50.c | 492 +++++++++++++-------------------------- client/src/cmdlfem4x50.h | 5 +- 3 files changed, 181 insertions(+), 326 deletions(-) diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 35ce4c1b7..389d18dad 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -1206,6 +1206,14 @@ static bool CheckChipType(bool getDeviceData) { PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf t55xx`") " commands"); retval = true; } + + // check for em4x50 chips + if (detect_4x50_block()) { + PrintAndLogEx(SUCCESS, "Chipset detection: " _GREEN_("EM4x50")); + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf em 4x50`") " commands"); + retval = true; + goto out; + } out: save_restoreGB(GRAPH_RESTORE); @@ -1252,7 +1260,7 @@ int CmdLFfind(const char *Cmd) { } if (IfPm3EM4x50()) { - if (EM4x50Read("", false) == PM3_SUCCESS) { + if (read_em4x50_uid() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("EM4x50 ID") " found!"); return PM3_SUCCESS; } diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index b38a2cc56..822ed50db 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -24,47 +24,51 @@ int usage_lf_em4x50_info(void) { PrintAndLogEx(NORMAL, " v - verbose output"); PrintAndLogEx(NORMAL, " p - password (hex) (optional)"); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf em 4x50_info"); - PrintAndLogEx(NORMAL, " lf em 4x50_info p fa225de1\n"); - PrintAndLogEx(NORMAL, " lf em 4x50_info v p fa225de1\n"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_info")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_info p fa225de1")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_info v p fa225de1")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } int usage_lf_em4x50_write(void) { PrintAndLogEx(NORMAL, "Write EM4x50 word. Tag must be on antenna. "); PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf em 4x50_write [h] a
w "); + PrintAndLogEx(NORMAL, "Usage: lf em 4x50_write [h] [a
] [w ]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h - this help"); PrintAndLogEx(NORMAL, " a - memory address to write to (dec)"); PrintAndLogEx(NORMAL, " w - word to write (hex)"); PrintAndLogEx(NORMAL, " p - password (hex) (optional)"); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf em 4x50_write a 3 w deadc0de"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_write a 3 w deadc0de")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } int usage_lf_em4x50_write_password(void) { PrintAndLogEx(NORMAL, "Write EM4x50 password. Tag must be on antenna. "); PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf em 4x50_write_password [h] p n "); + PrintAndLogEx(NORMAL, "Usage: lf em 4x50_write_password [h] [p ] [n ]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h - this help"); PrintAndLogEx(NORMAL, " p - password (hex)"); PrintAndLogEx(NORMAL, " n - new password (hex)"); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf em 4x50_write_password p 11223344 n 01020304"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_write_password p 11223344 n 01020304")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } int usage_lf_em4x50_read(void) { PrintAndLogEx(NORMAL, "Read EM4x50 word(s). Tag must be on antenna. "); PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf em 4x50_read [h] a
p "); + PrintAndLogEx(NORMAL, "Usage: lf em 4x50_read [h] [a
] [p ]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h - this help"); PrintAndLogEx(NORMAL, " a - memory address to read (dec) (optional)"); PrintAndLogEx(NORMAL, " p - password (hex) (optional)"); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf em 4x50_read"); - PrintAndLogEx(NORMAL, " lf em 4x50_read a 2 p 00000000"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_read")); + PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_read a 2 p 00000000")); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -121,75 +125,9 @@ static void prepare_result(const uint8_t *byte, int fwr, int lwr, em4x50_word_t if (words[i].stopbit == 1) words[i].stopparity = false; - } } -static void print_bit_table(const em4x50_word_t word) { - - // generate output in table form for each word including parities, stop - // bit, result of parity checks and hex notation of each row in msb/lsb - // notation - // individual parity errors will be highlighted in red - - int bit = 0; - char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; - - // print binary data - for (int j = 0; j < 4; j++) { - - strcat(string, " "); - - // lsb notation - for (int k = 0; k < 8; k++) { - sprintf(pstring, "%i", (word.byte[j] >> (7-k)) & 1); - strcat(string, pstring); - } - - strcat(string, " | "); - - // binary row parities + hex bytes of word - sprintf(pstring, (word.rparity[j]) ? "%i" : _RED_("%i"), word.row_parity[j]); - strcat(string, pstring); - - if (j == 0) - sprintf(pstring, " msb: 0x%02x lsb: 0x%02x", word.byte[j], reflect8(word.byte[j])); - else - sprintf(pstring, " 0x%02x 0x%02x", word.byte[j], reflect8(word.byte[j])); - - strcat(string, pstring); - PrintAndLogEx(NORMAL,string); - - string[0] = '\0'; - } - - strcat(string, " ------------ --------------------\n "); - - // binary column parities - for (int k = 0; k < 8; k++) { - - bit = (word.col_parity >> (7-k)) & 1; - - // if column parity is false -> highlight bit in red - sprintf(pstring, (word.cparity[k]) ? "%i" : _RED_("%i"), bit); - strcat(string, pstring); - } - - // binary stop bit - strcat(string, " | "); - sprintf(pstring, (word.stopparity) ? "%i" : _RED_("%i"), word.stopbit); - strcat(pstring, " parities "); - strcat(string, pstring); - - // parities passed/failed - sprintf(pstring, (word.parity) ? _GREEN_("ok") : _RED_("failed")); - strcat(string, pstring); - - PrintAndLogEx(NORMAL,string); - - string[0] = '\0'; -} - static void print_result(const em4x50_word_t *words, int fwr, int lwr, bool verbose) { // print available information for given word from fwr to lwr, i.e. @@ -201,12 +139,6 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr, bool verb if (verbose) { - // blank line before each bit table - PrintAndLogEx(NORMAL, ""); - - // print bit table - print_bit_table(words[i]); - // final result string[0] = '\0'; sprintf(pstring, "\n word[%i] msb: " _GREEN_("0x"), i); @@ -236,25 +168,19 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr, bool verb } } - PrintAndLogEx(NORMAL,string); + PrintAndLogEx(INFO, string); } } -static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd, bool verbose) { +static void print_info_result(uint8_t *data, bool verbose) { // display all information of info result in structured format - - uint8_t *data = resp->data.asBytes; em4x50_word_t words[EM4X50_NO_WORDS]; - char pstring[NO_CHARS_MAX] = {0}, string[NO_CHARS_MAX] = {0}; - - bool bpwd_given = etd->pwd_given; - bool blogin = resp->status & STATUS_LOGIN; - prepare_result(data, 0, EM4X50_NO_WORDS - 1, words); bool bpwc = words[EM4X50_CONTROL].byte[CONFIG_BLOCK] & PASSWORD_CHECK; bool braw = words[EM4X50_CONTROL].byte[CONFIG_BLOCK] & READ_AFTER_WRITE; + int fwr = reflect8(words[EM4X50_CONTROL].byte[FIRST_WORD_READ]); int lwr = reflect8(words[EM4X50_CONTROL].byte[LAST_WORD_READ]); int fwrp = reflect8(words[EM4X50_PROTECTION].byte[FIRST_WORD_READ_PROTECTED]); @@ -262,8 +188,14 @@ static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd, int fwwi = reflect8(words[EM4X50_PROTECTION].byte[FIRST_WORD_WRITE_INHIBITED]); int lwwi = reflect8(words[EM4X50_PROTECTION].byte[LAST_WORD_WRITE_INHIBITED]); + + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------"); + PrintAndLogEx(INFO, "-------------------------------------------------------------"); + // data section - PrintAndLogEx(NORMAL, _YELLOW_("\n em4x50 data:")); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, _YELLOW_("EM4x50 data:")); if (verbose) { @@ -272,117 +204,82 @@ static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd, } else { + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "idx | word | desc"); + PrintAndLogEx(INFO, "----+-------------+----------------------------------"); + // condensed data section for (int i = 0; i < EM4X50_NO_WORDS; i++) { - - sprintf(pstring, " word[%2i]: ", i); - strcat(string, pstring); - - for (int j = 0; j < 4; j++) { - sprintf(pstring, "%02x", words[i].byte[j]); - strcat(string, pstring); - } - + + char s[50] = {0}; switch(i) { case EM4X50_DEVICE_PASSWORD: - sprintf(pstring, _YELLOW_(" password, write only")); + sprintf(s, _YELLOW_("password, write only")); break; case EM4X50_PROTECTION: - sprintf(pstring, _YELLOW_(" protection word, write inhibited")); + sprintf(s, _YELLOW_("protection cfg (locked)")); break; case EM4X50_CONTROL: - sprintf(pstring, _YELLOW_(" control word, write inhibited")); + sprintf(s, _YELLOW_("control cfg (locked)")); break; case EM4X50_DEVICE_SERIAL: - sprintf(pstring, _YELLOW_(" device serial number, read only")); + sprintf(s, _YELLOW_("device serial number (read only)")); break; case EM4X50_DEVICE_ID: - sprintf(pstring, _YELLOW_(" device identification, read only")); + sprintf(s, _YELLOW_("device identification (read only)")); break; default: - sprintf(pstring, " user data"); + sprintf(s, "user data"); break; } - - strcat(string, pstring); - PrintAndLogEx(NORMAL,"%s", string); - string[0] = '\0'; + PrintAndLogEx(INFO, " %2i | %s| %s", i, sprint_hex(words[i].byte, 4), s); } } + PrintAndLogEx(INFO, "----+-------------+----------------------------------"); + // configuration section - PrintAndLogEx(NORMAL, _YELLOW_("\n em4x50 configuration")); - PrintAndLogEx(NORMAL," control: | protection:"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "---- " _CYAN_("Configuration") " ----"); - sprintf(pstring, " first word read: %3i |", fwr); - strcat(string, pstring); - sprintf(pstring, " first word read protected: %3i", fwrp); - strcat(string, pstring); - PrintAndLogEx(NORMAL,"%s", string); - string[0] = '\0'; + PrintAndLogEx(INFO, "first word read %3i", fwr); + PrintAndLogEx(INFO, "last word read %3i", lwr); + PrintAndLogEx(INFO, "password check %3s", (bpwc) ? _RED_("on"): _GREEN_("off")); + PrintAndLogEx(INFO, "read after write %3s", (braw) ? "on" : "off"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "--------- " _CYAN_("Protection") " ---------"); + PrintAndLogEx(INFO, "first word read protected %3i", fwrp); + PrintAndLogEx(INFO, "last word read protected %3i", lwrp); + PrintAndLogEx(INFO, "first word write inhibited %3i", fwwi); + PrintAndLogEx(INFO, "last word write inhibited %3i", lwwi); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "zero values may indicate read protection"); + PrintAndLogEx(NORMAL, ""); +} - sprintf(pstring, " last word read: %3i |", lwr); - strcat(string, pstring); - sprintf(pstring, " last word read protected: %3i", lwrp); - strcat(string, pstring); - PrintAndLogEx(NORMAL,"%s", string); - string[0] = '\0'; +//quick test for EM4x50 tag +bool detect_4x50_block(void) { + em4x50_data_t etd = { + .pwd_given = false, + .addr_given = true, + .address = EM4X50_DEVICE_ID, + }; + em4x50_word_t words[EM4X50_NO_WORDS] = {0}; + return (em4x50_read(&etd, words, false) == PM3_SUCCESS); +} - sprintf(pstring, " password check: %3s |", (bpwc) ? "on" : "off"); - strcat(string, pstring); - sprintf(pstring, " first word write inhibited: %3i", fwwi); - strcat(string, pstring); - PrintAndLogEx(NORMAL,"%s", string); - string[0] = '\0'; - sprintf(pstring, " read after write: %3s |", (braw) ? "on" : "off"); - strcat(string, pstring); - sprintf(pstring, " last word write inhibited: %3i", lwwi); - strcat(string, pstring); - PrintAndLogEx(NORMAL,"%s", string); - string[0] = '\0'; - - PrintAndLogEx(NORMAL, "\n zero values may indicate read protection!"); - - // status line - sprintf(pstring, " reading "); - strcat(string, pstring); - - sprintf(pstring, _GREEN_("ok ")); - strcat(string, pstring); - - if (blogin) { - - if (bpwd_given) { - - sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)", - etd->password[0], etd->password[1], - etd->password[2], etd->password[3]); - strcat(string, pstring); - - } else { - - sprintf(pstring, "(login with default password 0x00000000)"); - strcat(string, pstring); - - } - - } else { - - if (bpwd_given) { - - sprintf(pstring, "(login failed)"); - strcat(string, pstring); - - } else { - - sprintf(pstring, "(no login)"); - strcat(string, pstring); - - } - } - - PrintAndLogEx(NORMAL,"%s\n", string); +int read_em4x50_uid(void) { + em4x50_data_t etd = { + .pwd_given = false, + .addr_given = true, + .address = EM4X50_DEVICE_SERIAL, + }; + em4x50_word_t words[EM4X50_NO_WORDS] = {0}; + int res = em4x50_read(&etd, words, false); + if (res == PM3_SUCCESS) + PrintAndLogEx(INFO, " Serial: " _GREEN_("%s"), sprint_hex(words[EM4X50_DEVICE_SERIAL].byte, 4)); + return res; } int CmdEM4x50Info(const char *Cmd) { @@ -390,12 +287,9 @@ int CmdEM4x50Info(const char *Cmd) { // envoke reading of a EM4x50 tag which has to be on the antenna because // decoding is done by the device (not on client side) - bool errors = false, verbose = false, success = false; + bool errors = false, verbose = false; uint8_t cmdp = 0; em4x50_data_t etd; - PacketResponseNG resp; - - // init etd.pwd_given = false; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { @@ -429,26 +323,23 @@ int CmdEM4x50Info(const char *Cmd) { if (errors) return usage_lf_em4x50_info(); - // call info command clearCommandBuffer(); SendCommandNG(CMD_LF_EM4X50_INFO, (uint8_t *)&etd, sizeof(etd)); - - // get result + PacketResponseNG resp; if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) { PrintAndLogEx(WARNING, "timeout while waiting for reply."); return PM3_ETIMEOUT; } - success = (resp.status & STATUS_SUCCESS) >> 1; + bool success = (resp.status & STATUS_SUCCESS) >> 1; + if (success) { + print_info_result(resp.data.asBytes, verbose); + return PM3_SUCCESS; + } - // print result - if (success) - print_info_result(&resp, &etd, verbose); - else - PrintAndLogEx(NORMAL,"\nreading " _RED_("failed") "\n"); - - return (success) ? PM3_SUCCESS : PM3_ESOFT; + PrintAndLogEx(FAILED, "reading tag " _RED_("failed")); + return PM3_ESOFT; } static void print_write_result(PacketResponseNG *resp, const em4x50_data_t *etd) { @@ -644,156 +535,109 @@ int CmdEM4x50WritePassword(const char *Cmd) { return (success) ? PM3_SUCCESS : PM3_ESOFT; } -static void print_read_result(PacketResponseNG *resp, const em4x50_data_t *etd, bool verbose) { - - // display result of writing operation in structured format - - bool addr_given = etd->addr_given; - bool pwd_given = etd->pwd_given; - bool login = resp->status & STATUS_LOGIN; - int now = (resp->status & STATUS_NO_WORDS) >> 2; - char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; - uint8_t *data = resp->data.asBytes; - em4x50_word_t words[EM4X50_NO_WORDS]; - - if (addr_given) { - - // selective read mode - - prepare_result(data, etd->address, etd->address, words); - print_result(words, etd->address, etd->address, true); - - string[0] = '\0'; - sprintf(pstring, "\n reading " _GREEN_("ok ")); - strcat(string, pstring); - - if (pwd_given) { - if (login) { - sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)", - etd->password[0], etd->password[1], - etd->password[2], etd->password[3]); - strcat(string, pstring); - } else { - sprintf(pstring, "(login failed)"); - strcat(string, pstring); - } - } else { - sprintf(pstring, "(no login)"); - strcat(string, pstring); - } - - PrintAndLogEx(NORMAL,"%s\n", string); - - } else { - - //standard read mode - - prepare_result(data, 0, now - 1, words); - print_result(words, 0, now - 1, verbose); - - if (verbose) { - - string[0] = '\0'; - sprintf(pstring, "\n reading " _GREEN_("ok ")); - strcat(string, pstring); - - if (pwd_given) { - sprintf(pstring, "(standard read mode, password ignored)"); - strcat(string, pstring); - } else { - sprintf(pstring, "(standard read mode)"); - strcat(string, pstring); - } - - PrintAndLogEx(NORMAL,"%s\n", string); - } - } -} - -int EM4x50Read(const char *Cmd, bool verbose) { +int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose) { // envoke reading // - without option -> standard read mode // - with given address (option a) (and optional password if address is // read protected) -> selective read mode - bool errors = false, success = false; - uint8_t cmdp = 0; - em4x50_data_t etd; - PacketResponseNG resp; - - // init - etd.pwd_given = false; - etd.addr_given = false; - - if (verbose) { - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lf_em4x50_read(); - - case 'p': - if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) { - PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n"); - return PM3_EINVARG; - } - etd.pwd_given = true; - cmdp += 2; - break; - - case 'a': - param_getdec(Cmd, cmdp + 1, &etd.address); - - // validation - if (etd.address <= 0 || etd.address >= EM4X50_NO_WORDS) { - PrintAndLogEx(FAILED, "\n error, address has to be in range [1-33]\n"); - return PM3_EINVARG; - } - etd.addr_given = true; - cmdp += 2; - break; - - default: - PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } - - if (errors) - return usage_lf_em4x50_read(); - + em4x50_data_t edata; + edata.pwd_given = false; + edata.addr_given = false; + + if (etd != NULL) { + edata = *etd; } clearCommandBuffer(); - SendCommandNG(CMD_LF_EM4X50_READ, (uint8_t *)&etd, sizeof(etd)); - + SendCommandNG(CMD_LF_EM4X50_READ, (uint8_t *)&edata, sizeof(edata)); + PacketResponseNG resp; if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) { PrintAndLogEx(WARNING, "timeout while waiting for reply."); return PM3_ETIMEOUT; } - success = (resp.status & STATUS_SUCCESS) >> 1; - - // get, prepare and print response - if (success) - print_read_result(&resp, &etd, verbose); - else if (verbose) - PrintAndLogEx(NORMAL,"\nreading " _RED_("failed") "\n"); + bool isOK = (resp.status & STATUS_SUCCESS) >> 1; + if (isOK == false) { + if (verbose) + PrintAndLogEx(FAILED, "reading " _RED_("failed")); + + return PM3_ESOFT; + } - return (success) ? PM3_SUCCESS : PM3_ESOFT; + if (edata.pwd_given) { + bool login = resp.status & STATUS_LOGIN; + if (login == false) { + PrintAndLogEx(FAILED, "login failed"); + return PM3_ESOFT; + } + PrintAndLogEx(SUCCESS, "login with password " _YELLOW_("%s"), sprint_hex_inrow(etd->password, 4)); + } + + uint8_t *data = resp.data.asBytes; + em4x50_word_t words[EM4X50_NO_WORDS]; + if (edata.addr_given) { + prepare_result(data, etd->address, etd->address, words); + } else { + int now = (resp.status & STATUS_NO_WORDS) >> 2; + prepare_result(data, 0, now - 1, words); + } + if (out != NULL) { + memcpy(out, &words, sizeof(em4x50_word_t) * EM4X50_NO_WORDS); + } + + if (verbose) { + print_result(words, etd->address, etd->address, true); + } + return PM3_SUCCESS; } int CmdEM4x50Read(const char *Cmd) { - // envoke reading function - // verbose = true for manual call - // verbose = false for automatic call (e.g. lf search) - - bool verbose = true; + em4x50_data_t etd; + etd.pwd_given = false; + etd.addr_given = false; - return EM4x50Read(Cmd, verbose); + bool errors = false; + uint8_t cmdp = 0; + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_lf_em4x50_read(); + + case 'p': + if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) { + PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n"); + return PM3_EINVARG; + } + etd.pwd_given = true; + cmdp += 2; + break; + + case 'a': + param_getdec(Cmd, cmdp + 1, &etd.address); + + // validation + if (etd.address <= 0 || etd.address >= EM4X50_NO_WORDS) { + PrintAndLogEx(FAILED, "\n error, address has to be in range [1-33]\n"); + return PM3_EINVARG; + } + etd.addr_given = true; + cmdp += 2; + break; + default: + PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp)); + errors = true; + break; + } + } + + if (errors) + return usage_lf_em4x50_read(); + + return em4x50_read(&etd, NULL, true); } diff --git a/client/src/cmdlfem4x50.h b/client/src/cmdlfem4x50.h index 7b3fb53a0..e426fd460 100644 --- a/client/src/cmdlfem4x50.h +++ b/client/src/cmdlfem4x50.h @@ -12,13 +12,16 @@ #define CMDLFEM4X50_H__ #include"common.h" +#include "em4x50.h" int usage_lf_em4x50_info(void); int usage_lf_em4x50_write(void); int usage_lf_em4x50_write_password(void); int usage_lf_em4x50_read(void); -int EM4x50Read(const char *Cmd, bool verbose); +int read_em4x50_uid(void); +bool detect_4x50_block(void); +int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose); int CmdEM4x50Info(const char *Cmd); int CmdEM4x50Write(const char *Cmd); From aa0b3c67baefb410f7ae89f95deb6714a1f37d52 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 30 Jun 2020 17:59:06 +0200 Subject: [PATCH 80/84] chg: lf em 4x50_write - output flow --- client/src/cmdlfem4x50.c | 120 +++++++++++++++------------------------ 1 file changed, 47 insertions(+), 73 deletions(-) diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index 822ed50db..dae58817a 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -268,7 +268,6 @@ bool detect_4x50_block(void) { return (em4x50_read(&etd, words, false) == PM3_SUCCESS); } - int read_em4x50_uid(void) { em4x50_data_t etd = { .pwd_given = false, @@ -341,62 +340,22 @@ int CmdEM4x50Info(const char *Cmd) { PrintAndLogEx(FAILED, "reading tag " _RED_("failed")); return PM3_ESOFT; } - -static void print_write_result(PacketResponseNG *resp, const em4x50_data_t *etd) { - // display result of writing operation in structured format - - bool pwd_given = etd->pwd_given; - bool login = resp->status & STATUS_LOGIN; - uint8_t *data = resp->data.asBytes; - char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; - em4x50_word_t words[EM4X50_NO_WORDS]; - - prepare_result(data, etd->address, etd->address, words); - print_result(words, etd->address, etd->address, true); - - sprintf(pstring, "\n writing " _GREEN_("ok ")); - strcat(string, pstring); - - if (pwd_given) { - - if (login) { - sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)", - etd->password[0], etd->password[1], - etd->password[2], etd->password[3]); - strcat(string, pstring); - } else { - sprintf(pstring, "(login failed)"); - strcat(string, pstring); - } - - } else { - sprintf(pstring, "(no login)"); - strcat(string, pstring); - } - - PrintAndLogEx(NORMAL,"%s\n", string); -} - int CmdEM4x50Write(const char *Cmd) { // envoke writing a single word (32 bit) to a EM4x50 tag - bool errors = false, bword = false, baddr = false, success = false; + em4x50_data_t etd = { .pwd_given = false }; + + bool errors = false, bword = false, baddr = false; uint8_t cmdp = 0; - em4x50_data_t etd; - PacketResponseNG resp; - - // init - etd.pwd_given = false; - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': + case 'h': { return usage_lf_em4x50_write(); - - case 'p': + } + case 'p': { if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) { PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n"); return PM3_EINVARG; @@ -404,8 +363,8 @@ int CmdEM4x50Write(const char *Cmd) { etd.pwd_given = true; cmdp += 2; break; - - case 'w': + } + case 'w': { if (param_gethex(Cmd, cmdp + 1, etd.word, 8)) { PrintAndLogEx(FAILED, "\n word has to be 8 hex symbols\n"); return PM3_EINVARG; @@ -413,8 +372,8 @@ int CmdEM4x50Write(const char *Cmd) { bword = true; cmdp += 2; break; - - case 'a': + } + case 'a': { param_getdec(Cmd, cmdp + 1, &etd.address); // validation @@ -425,11 +384,12 @@ int CmdEM4x50Write(const char *Cmd) { baddr = true; cmdp += 2; break; - - default: + } + default: { PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp)); errors = true; break; + } } } @@ -438,22 +398,36 @@ int CmdEM4x50Write(const char *Cmd) { clearCommandBuffer(); SendCommandNG(CMD_LF_EM4X50_WRITE, (uint8_t *)&etd, sizeof(etd)); - - + PacketResponseNG resp; if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) { PrintAndLogEx(WARNING, "timeout while waiting for reply."); return PM3_ETIMEOUT; } - - success = (resp.status & STATUS_SUCCESS) >> 1; - // get, prepare and print response - if (success) - print_write_result(&resp, &etd); - else - PrintAndLogEx(NORMAL,"\nwriting " _RED_("failed") "\n"); - - return (success) ? PM3_SUCCESS : PM3_ESOFT; + bool isOK = (resp.status & STATUS_SUCCESS) >> 1; + if (isOK == false) { + PrintAndLogEx(FAILED, "writing " _RED_("failed")); + return PM3_ESOFT; + } + + if (etd.pwd_given) { + bool login = resp.status & STATUS_LOGIN; + if (login == false) { + PrintAndLogEx(FAILED, "login failed"); + return PM3_ESOFT; + } + PrintAndLogEx(SUCCESS, "login with password " _YELLOW_("%s"), sprint_hex_inrow(etd.password, 4)); + } + + // display result of writing operation in structured format + uint8_t *data = resp.data.asBytes; + em4x50_word_t words[EM4X50_NO_WORDS]; + + prepare_result(data, etd.address, etd.address, words); + print_result(words, etd.address, etd.address, true); + PrintAndLogEx(SUCCESS, "Successfully wrote to tag"); + PrintAndLogEx(HINT, "Try `" _YELLOW_("lf em 4x50_read a %u") "` - to read your data", etd.address); + return PM3_SUCCESS; } static void print_write_password_result(PacketResponseNG *resp, const em4x50_data_t *etd) { @@ -542,9 +516,7 @@ int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose) { // - with given address (option a) (and optional password if address is // read protected) -> selective read mode - em4x50_data_t edata; - edata.pwd_given = false; - edata.addr_given = false; + em4x50_data_t edata = { .pwd_given = false, .addr_given = false }; if (etd != NULL) { edata = *etd; @@ -606,10 +578,10 @@ int CmdEM4x50Read(const char *Cmd) { while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': + case 'h': { return usage_lf_em4x50_read(); - - case 'p': + } + case 'p': { if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) { PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n"); return PM3_EINVARG; @@ -617,8 +589,8 @@ int CmdEM4x50Read(const char *Cmd) { etd.pwd_given = true; cmdp += 2; break; - - case 'a': + } + case 'a': { param_getdec(Cmd, cmdp + 1, &etd.address); // validation @@ -629,10 +601,12 @@ int CmdEM4x50Read(const char *Cmd) { etd.addr_given = true; cmdp += 2; break; - default: + } + default: { PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp)); errors = true; break; + } } } From 88d4d037f1793b50e20049512a09b2c7d9c521ad Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 30 Jun 2020 17:59:35 +0200 Subject: [PATCH 81/84] enable EV3 tests --- client/src/cmdhfmfdes.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index fe69d1909..e7a8e3746 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -382,8 +382,8 @@ static char *getVersionStr(uint8_t major, uint8_t minor) { sprintf(retStr, "%x.%x (" _YELLOW_("DESFire EV1") ")", major, minor); else if (major == 0x12 && minor == 0x00) sprintf(retStr, "%x.%x (" _YELLOW_("DESFire EV2") ")", major, minor); -// else if (major == 0x13 && minor == 0x00) -// sprintf(retStr, "%x.%x (" _YELLOW_("DESFire EV3") ")", major, minor); + else if (major == 0x13 && minor == 0x00) + sprintf(retStr, "%x.%x (" _YELLOW_("DESFire EV3") ")", major, minor); else if (major == 0x30 && minor == 0x00) sprintf(retStr, "%x.%x (" _YELLOW_("DESFire Light") ")", major, minor); else @@ -3305,8 +3305,8 @@ static int CmdHF14ADesInfo(const char *Cmd) { PrintAndLogEx(INFO, "\t1.4 - DESFire Ev1 MF3ICD21/41/81, EAL4+"); if (major == 2 && minor == 0) PrintAndLogEx(INFO, "\t2.0 - DESFire Ev2, Originality check, proximity check, EAL5"); -// if (major == 3 && minor == 0) -// PrintAndLogEx(INFO, "\t3.0 - DESFire Ev3, Originality check, proximity check, badass EAL5"); + if (major == 3 && minor == 0) + PrintAndLogEx(INFO, "\t3.0 - DESFire Ev3, Originality check, proximity check, badass EAL6 ?"); if (major == 0 && minor == 2) PrintAndLogEx(INFO, "\t0.2 - DESFire Light, Originality check, "); From 1ec2a83e39b7c1912d8f644a553dc276225a8038 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 30 Jun 2020 18:50:38 +0200 Subject: [PATCH 82/84] style --- client/src/cmdlfem4x50.c | 82 ++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index dae58817a..dad399a36 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -76,43 +76,43 @@ static void prepare_result(const uint8_t *byte, int fwr, int lwr, em4x50_word_t // restructure received result in "em4x50_word_t" structure and check all // parities including stop bit; result of each check is stored in structure - + int p = 0, c[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - + for (int i = fwr; i <= lwr; i++) { - + words[i].stopparity = true; words[i].parity = true; - + for (int j = 0; j < 8; j++) c[j] = 0; for (int j = 0; j < 4; j++) { words[i].byte[j] = byte[i*7+j]; words[i].row_parity[j] = (byte[i*7+4] >> (3-j)) & 1; - + // collect parities p = 0; for (int k = 0; k < 8; k++) { - + // row parity p ^= (words[i].byte[j] >> k) & 1; - + // column parity c[k] ^= (words[i].byte[j] >> (7-k)) & 1; } - + // check row parities words[i].rparity[j] = (words[i].row_parity[j] == p) ? true : false; if (!words[i].rparity[j]) words[i].parity = false; } - + // check column parities words[i].col_parity = byte[i*7+5]; - + for (int j = 0; j < 8; j++) { words[i].cparity[j] = (((words[i].col_parity >> (7-j)) & 1) == c[j]) ? true : false; @@ -122,23 +122,23 @@ static void prepare_result(const uint8_t *byte, int fwr, int lwr, em4x50_word_t // check stop bit words[i].stopbit = byte[i*7+6] & 1; - + if (words[i].stopbit == 1) words[i].stopparity = false; } } static void print_result(const em4x50_word_t *words, int fwr, int lwr, bool verbose) { - + // print available information for given word from fwr to lwr, i.e. // bit table + summary lines with hex notation of word (msb + lsb) - + char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; for (int i = fwr; i <= lwr; i++) { if (verbose) { - + // final result string[0] = '\0'; sprintf(pstring, "\n word[%i] msb: " _GREEN_("0x"), i); @@ -148,7 +148,7 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr, bool verb sprintf(pstring, _GREEN_("%02x"), words[i].byte[j]); strcat(string, pstring); } - + sprintf(pstring, "\n word[%i] lsb: 0x", i); strcat(string, pstring); @@ -157,7 +157,6 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr, bool verb strcat(string, pstring); } } else { - string[0] = '\0'; sprintf(pstring, "[" _GREEN_("+") "] word[%i]: " _YELLOW_("0x"), i); strcat(string, pstring); @@ -167,7 +166,6 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr, bool verb strcat(string, pstring); } } - PrintAndLogEx(INFO, string); } } @@ -187,21 +185,17 @@ static void print_info_result(uint8_t *data, bool verbose) { int lwrp = reflect8(words[EM4X50_PROTECTION].byte[LAST_WORD_READ_PROTECTED]); int fwwi = reflect8(words[EM4X50_PROTECTION].byte[FIRST_WORD_WRITE_INHIBITED]); int lwwi = reflect8(words[EM4X50_PROTECTION].byte[LAST_WORD_WRITE_INHIBITED]); - - + PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------"); - + // data section PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, _YELLOW_("EM4x50 data:")); if (verbose) { - - // detailed data section print_result(words, 0, EM4X50_NO_WORDS - 1, true); - } else { PrintAndLogEx(NORMAL, ""); @@ -210,7 +204,6 @@ static void print_info_result(uint8_t *data, bool verbose) { // condensed data section for (int i = 0; i < EM4X50_NO_WORDS; i++) { - char s[50] = {0}; switch(i) { case EM4X50_DEVICE_PASSWORD: @@ -236,8 +229,7 @@ static void print_info_result(uint8_t *data, bool verbose) { } } PrintAndLogEx(INFO, "----+-------------+----------------------------------"); - - + // configuration section PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "---- " _CYAN_("Configuration") " ----"); @@ -264,7 +256,7 @@ bool detect_4x50_block(void) { .addr_given = true, .address = EM4X50_DEVICE_ID, }; - em4x50_word_t words[EM4X50_NO_WORDS] = {0}; + em4x50_word_t words[EM4X50_NO_WORDS]; return (em4x50_read(&etd, words, false) == PM3_SUCCESS); } @@ -274,7 +266,7 @@ int read_em4x50_uid(void) { .addr_given = true, .address = EM4X50_DEVICE_SERIAL, }; - em4x50_word_t words[EM4X50_NO_WORDS] = {0}; + em4x50_word_t words[EM4X50_NO_WORDS]; int res = em4x50_read(&etd, words, false); if (res == PM3_SUCCESS) PrintAndLogEx(INFO, " Serial: " _GREEN_("%s"), sprint_hex(words[EM4X50_DEVICE_SERIAL].byte, 4)); @@ -290,7 +282,7 @@ int CmdEM4x50Info(const char *Cmd) { uint8_t cmdp = 0; em4x50_data_t etd; etd.pwd_given = false; - + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { @@ -310,7 +302,7 @@ int CmdEM4x50Info(const char *Cmd) { verbose = true; cmdp += 1; break; - + default: PrintAndLogEx(WARNING, " Unknown parameter '%c'", param_getchar(Cmd, cmdp)); errors = true; @@ -330,7 +322,7 @@ int CmdEM4x50Info(const char *Cmd) { PrintAndLogEx(WARNING, "timeout while waiting for reply."); return PM3_ETIMEOUT; } - + bool success = (resp.status & STATUS_SUCCESS) >> 1; if (success) { print_info_result(resp.data.asBytes, verbose); @@ -340,13 +332,13 @@ int CmdEM4x50Info(const char *Cmd) { PrintAndLogEx(FAILED, "reading tag " _RED_("failed")); return PM3_ESOFT; } - + int CmdEM4x50Write(const char *Cmd) { // envoke writing a single word (32 bit) to a EM4x50 tag em4x50_data_t etd = { .pwd_given = false }; - + bool errors = false, bword = false, baddr = false; uint8_t cmdp = 0; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { @@ -409,7 +401,7 @@ int CmdEM4x50Write(const char *Cmd) { PrintAndLogEx(FAILED, "writing " _RED_("failed")); return PM3_ESOFT; } - + if (etd.pwd_given) { bool login = resp.status & STATUS_LOGIN; if (login == false) { @@ -431,7 +423,7 @@ int CmdEM4x50Write(const char *Cmd) { } static void print_write_password_result(PacketResponseNG *resp, const em4x50_data_t *etd) { - + // display result of password changing operation char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0}; @@ -499,7 +491,7 @@ int CmdEM4x50WritePassword(const char *Cmd) { return PM3_ETIMEOUT; } success = (bool)resp.status; - + // get, prepare and print response if (success) print_write_password_result(&resp, &etd); @@ -510,14 +502,14 @@ int CmdEM4x50WritePassword(const char *Cmd) { } int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose) { - + // envoke reading // - without option -> standard read mode // - with given address (option a) (and optional password if address is // read protected) -> selective read mode em4x50_data_t edata = { .pwd_given = false, .addr_given = false }; - + if (etd != NULL) { edata = *etd; } @@ -530,15 +522,15 @@ int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose) { PrintAndLogEx(WARNING, "timeout while waiting for reply."); return PM3_ETIMEOUT; } - + bool isOK = (resp.status & STATUS_SUCCESS) >> 1; if (isOK == false) { if (verbose) PrintAndLogEx(FAILED, "reading " _RED_("failed")); - + return PM3_ESOFT; } - + if (edata.pwd_given) { bool login = resp.status & STATUS_LOGIN; if (login == false) { @@ -547,11 +539,11 @@ int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose) { } PrintAndLogEx(SUCCESS, "login with password " _YELLOW_("%s"), sprint_hex_inrow(etd->password, 4)); } - + uint8_t *data = resp.data.asBytes; em4x50_word_t words[EM4X50_NO_WORDS]; if (edata.addr_given) { - prepare_result(data, etd->address, etd->address, words); + prepare_result(data, etd->address, etd->address, words); } else { int now = (resp.status & STATUS_NO_WORDS) >> 2; prepare_result(data, 0, now - 1, words); @@ -560,7 +552,7 @@ int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose) { if (out != NULL) { memcpy(out, &words, sizeof(em4x50_word_t) * EM4X50_NO_WORDS); } - + if (verbose) { print_result(words, etd->address, etd->address, true); } @@ -574,7 +566,7 @@ int CmdEM4x50Read(const char *Cmd) { etd.addr_given = false; bool errors = false; - uint8_t cmdp = 0; + uint8_t cmdp = 0; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { From c2d92345811f71f0064a2a9274797d8da22a22cc Mon Sep 17 00:00:00 2001 From: tharexde Date: Wed, 1 Jul 2020 00:45:46 +0200 Subject: [PATCH 83/84] speed up "lf search" process --- armsrc/em4x50.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index 0132ff2fd..ddc297591 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -74,6 +74,7 @@ static em4x50_tag_t tag = { #define EM4X50_T_TAG_FULL_PERIOD 64 #define EM4X50_T_TAG_TPP 64 #define EM4X50_T_TAG_TWA 64 +#define EM4X50_T_WAITING_FOR_SNGLLIW 50 #define EM4X50_T_WAITING_FOR_DBLLIW 1550 #define EM4X50_TAG_TOLERANCE 8 @@ -420,6 +421,34 @@ static void em4x50_send_word(const uint8_t bytes[4]) { em4x50_send_bit(0); } +static bool find_single_listen_window(void) { + + // find single listen window + + int cnt_pulses = 0; + + while (cnt_pulses < EM4X50_T_WAITING_FOR_SNGLLIW) { + + // identification of listen window is done via evaluation of + // pulse lengths + if (check_pulse_length(get_pulse_length(), 3 * EM4X50_T_TAG_FULL_PERIOD)) { + + if (check_pulse_length(get_pulse_length(), 2 * EM4X50_T_TAG_FULL_PERIOD)) { + + // listen window found + return true; + + } + } else { + + cnt_pulses++; + + } + } + + return false; +} + static bool find_double_listen_window(bool bcommand) { // find two successive listen windows that indicate the beginning of @@ -482,6 +511,15 @@ static bool find_double_listen_window(bool bcommand) { return false; } +static bool find_em4x50_tag(void) { + + // function is used to check wether a tag on the proxmark is an + // EM4x50 tag or not -> speed up "lf search" process + + return (find_single_listen_window()); + +} + static bool request_receive_mode(void) { // To issue a command we have to find a listen window first. @@ -764,7 +802,7 @@ void em4x50_info(em4x50_data_t *etd) { em4x50_setup_read(); // set gHigh and gLow - if (get_signalproperties()) { + if (get_signalproperties() && find_em4x50_tag()) { if (etd->pwd_given) { @@ -803,7 +841,7 @@ void em4x50_read(em4x50_data_t *etd) { em4x50_setup_read(); // set gHigh and gLow - if (get_signalproperties()) { + if (get_signalproperties() && find_em4x50_tag()) { if (etd->addr_given) { @@ -924,7 +962,7 @@ void em4x50_write(em4x50_data_t *etd) { em4x50_setup_read(); // set gHigh and gLow - if (get_signalproperties()) { + if (get_signalproperties() && find_em4x50_tag()) { // reorder word according to datasheet msb2lsb_word(etd->word); @@ -979,7 +1017,7 @@ void em4x50_write_password(em4x50_data_t *etd) { em4x50_setup_read(); // set gHigh and gLow - if (get_signalproperties()) { + if (get_signalproperties() && find_em4x50_tag()) { // login and change password if (login(etd->password)) { From e6c046e17c7be546bbca76804552a513155c4fa0 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 1 Jul 2020 12:31:57 +0200 Subject: [PATCH 84/84] adapt banner to smaller views --- client/src/proxmark3.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/client/src/proxmark3.c b/client/src/proxmark3.c index 1bf08f1d3..e0dafe480 100644 --- a/client/src/proxmark3.c +++ b/client/src/proxmark3.c @@ -35,8 +35,8 @@ #include "preferences.h" #define BANNERMSG1 " :snowflake: iceman@icesql.net" -#define BANNERMSG2 " https://github.com/rfidresearchgroup/proxmark3/" -#define BANNERMSG3 " bleeding edge :coffee:" +#define BANNERMSG2 " bleeding edge :coffee:" +#define BANNERMSG3 " https://github.com/rfidresearchgroup/proxmark3/" typedef enum LogoMode { UTF8, ANSI, ASCII } LogoMode; @@ -58,11 +58,11 @@ static void showBanner_logo(LogoMode mode) { sq, sq, tl, hl, hl, sq, sq, tr, sq, sq, sq, sq, tr, __, sq, sq, sq, sq, vl, bl, hl, hl, hl, sq, sq, tr); PrintAndLogEx(NORMAL, " " _BLUE_("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"), sq, sq, sq, sq, sq, sq, tl, br, sq, sq, tl, sq, sq, sq, sq, tl, sq, sq, vl, __, sq, sq, sq, sq, tl, br); - PrintAndLogEx(NORMAL, " " _BLUE_("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s")" " BANNERMSG1, + PrintAndLogEx(NORMAL, " " _BLUE_("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"), sq, sq, tl, hl, hl, hl, br, __, sq, sq, vl, bl, sq, sq, tl, br, sq, sq, vl, __, bl, hl, hl, sq, sq, tr); - PrintAndLogEx(NORMAL, " " _BLUE_("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s")" " BANNERMSG2, + PrintAndLogEx(NORMAL, " " _BLUE_("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s")" " BANNERMSG1, sq, sq, vl, __, __, __, __, __, sq, sq, vl, __, bl, hl, br, __, sq, sq, vl, sq, sq, sq, sq, sq, tl, br); - PrintAndLogEx(NORMAL, " " _BLUE_("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s")" " BANNERMSG3, + PrintAndLogEx(NORMAL, " " _BLUE_("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s")" " BANNERMSG2, bl, hl, br, __, __, __, __, __, bl, hl, br, __, __, __, __, __, bl, hl, br, bl, hl, hl, hl, hl, br, __); break; } @@ -70,21 +70,23 @@ static void showBanner_logo(LogoMode mode) { PrintAndLogEx(NORMAL, " " _BLUE_("██████╗ ███╗ ███╗█████╗ ")); PrintAndLogEx(NORMAL, " " _BLUE_("██╔══██╗████╗ ████║╚═══██╗")); PrintAndLogEx(NORMAL, " " _BLUE_("██████╔╝██╔████╔██║ ████╔╝")); - PrintAndLogEx(NORMAL, " " _BLUE_("██╔═══╝ ██║╚██╔╝██║ ╚══██╗") " " BANNERMSG1); - PrintAndLogEx(NORMAL, " " _BLUE_("██║ ██║ ╚═╝ ██║█████╔╝") " " BANNERMSG2); - PrintAndLogEx(NORMAL, " " _BLUE_("╚═╝ ╚═╝ ╚═╝╚════╝ ") " " BANNERMSG3); + PrintAndLogEx(NORMAL, " " _BLUE_("██╔═══╝ ██║╚██╔╝██║ ╚══██╗")); + PrintAndLogEx(NORMAL, " " _BLUE_("██║ ██║ ╚═╝ ██║█████╔╝") " " BANNERMSG1); + PrintAndLogEx(NORMAL, " " _BLUE_("╚═╝ ╚═╝ ╚═╝╚════╝ ") " " BANNERMSG2); break; } case ASCII: { PrintAndLogEx(NORMAL, " ######. ###. ###.#####. "); PrintAndLogEx(NORMAL, " ##...##.####. ####. ...##."); PrintAndLogEx(NORMAL, " ######..##.####.##. ####.."); - PrintAndLogEx(NORMAL, " ##..... ##..##..##. ..##." " " BANNERMSG1); - PrintAndLogEx(NORMAL, " ##. ##. .. ##.#####.." " " BANNERMSG2); - PrintAndLogEx(NORMAL, " .. .. .. ..... " " " BANNERMSG3); + PrintAndLogEx(NORMAL, " ##..... ##..##..##. ..##."); + PrintAndLogEx(NORMAL, " ##. ##. .. ##.#####.. " BANNERMSG1); + PrintAndLogEx(NORMAL, " .. .. .. ..... " BANNERMSG2); break; } } + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, BANNERMSG3); } static void showBanner(void) {