From 3616f145e1c4a29cd8d1d743e247a7f672c4755e Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 19 Oct 2020 10:33:45 +0200 Subject: [PATCH 01/35] textual --- client/src/cmdhficlass.c | 91 ++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index dd025852f..e9aaa1880 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -428,51 +428,51 @@ static void fuse_config(const picopass_hdr *hdr) { uint16_t otp = (hdr->conf.otp[1] << 8 | hdr->conf.otp[0]); PrintAndLogEx(INFO, " Raw: " _YELLOW_("%s"), sprint_hex((uint8_t*)&hdr->conf, 8)); - PrintAndLogEx(INFO, " " _YELLOW_("%02X") "..................... App limit", hdr->conf.app_limit); + PrintAndLogEx(INFO, " " _YELLOW_("%02X") "..................... app limit", hdr->conf.app_limit); PrintAndLogEx(INFO, " " _YELLOW_("%04X") " ( %5u )...... OTP", otp, otp); - PrintAndLogEx(INFO, " " _YELLOW_("%02X") "............ Block write lock", hdr->conf.block_writelock); - PrintAndLogEx(INFO, " " _YELLOW_("%02X") "......... Chip", hdr->conf.chip_config); - PrintAndLogEx(INFO, " " _YELLOW_("%02X") "...... Mem", hdr->conf.mem_config); + PrintAndLogEx(INFO, " " _YELLOW_("%02X") "............ block write lock", hdr->conf.block_writelock); + PrintAndLogEx(INFO, " " _YELLOW_("%02X") "......... chip", hdr->conf.chip_config); + PrintAndLogEx(INFO, " " _YELLOW_("%02X") "...... mem", hdr->conf.mem_config); PrintAndLogEx(INFO, " " _YELLOW_("%02X") "... EAS", hdr->conf.eas); - PrintAndLogEx(INFO, " " _YELLOW_("%02X") " Fuses", hdr->conf.fuses); + PrintAndLogEx(INFO, " " _YELLOW_("%02X") " fuses", hdr->conf.fuses); uint8_t fuses = hdr->conf.fuses; PrintAndLogEx(INFO, " 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"); + PrintAndLogEx(SUCCESS, " coding...... RFU"); } else { if (isset(fuses, FUSE_CODING0)) - PrintAndLogEx(SUCCESS, " coding... " _YELLOW_("ISO 14443-2 B / 15693")); + PrintAndLogEx(SUCCESS, " coding....... " _YELLOW_("ISO 14443-2 B / 15693")); else - PrintAndLogEx(SUCCESS, " coding... " _YELLOW_("ISO 14443-B only")); + PrintAndLogEx(SUCCESS, " coding....... " _YELLOW_("ISO 14443-B only")); } uint8_t pagemap = get_pagemap(hdr); switch (pagemap) { case 0x0: - PrintAndLogEx(INFO, " crypt.... No auth possible. Read only if RA is enabled"); + PrintAndLogEx(INFO, " crypt........ No auth possible. Read only if RA is enabled"); break; case 0x1: - PrintAndLogEx(SUCCESS, " crypt.... Non secured page"); + PrintAndLogEx(SUCCESS, " crypt........ Non secured page"); break; case 0x2: - PrintAndLogEx(INFO, " crypt.... Secured page, keys locked"); + PrintAndLogEx(INFO, " crypt........ Secured page, keys locked"); break; case 0x03: - PrintAndLogEx(SUCCESS, " crypt.... Secured page, " _GREEN_("keys not locked")); + PrintAndLogEx(SUCCESS, " crypt........ Secured page, " _GREEN_("keys not locked")); break; } if (isset(fuses, FUSE_RA)) - PrintAndLogEx(SUCCESS, " RA....... Read access enabled (non-secure mode)"); + PrintAndLogEx(SUCCESS, " RA........... Read access enabled (non-secure mode)"); else - PrintAndLogEx(INFO, " RA....... Read access not enabled"); + PrintAndLogEx(INFO, " RA........... Read access not enabled"); } static void getMemConfig(uint8_t mem_cfg, uint8_t chip_cfg, uint8_t *app_areas, uint8_t *kb) { @@ -545,23 +545,23 @@ static void mem_app_config(const picopass_hdr *hdr) { PrintAndLogEx(INFO, " AA1 blocks %u { 0x06 - 0x%02X (06 - %02d) }", app1_limit, app1_limit + 5, app1_limit + 5); PrintAndLogEx(INFO, " AA2 blocks %u { 0x%02X - 0x%02X (%02d - %02d) }", app2_limit - app1_limit, app1_limit + 5 + 1, app2_limit, app1_limit + 5 + 1, app2_limit); - PrintAndLogEx(INFO, "------------------------ " _CYAN_("KeyAccess") " -------------------------"); - PrintAndLogEx(INFO, " Kd = Debit key (AA1), Kc = Credit key (AA2)"); + 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"); - PrintAndLogEx(INFO, " Read B - Kc"); - PrintAndLogEx(INFO, " Write A - Kd"); - PrintAndLogEx(INFO, " Write B - Kc"); - PrintAndLogEx(INFO, " Debit - Kd or Kc"); - PrintAndLogEx(INFO, " Credit - Kc"); + PrintAndLogEx(INFO, " Read A....... debit"); + PrintAndLogEx(INFO, " Read B....... credit"); + PrintAndLogEx(INFO, " Write A...... debit"); + PrintAndLogEx(INFO, " Write B...... credit"); + PrintAndLogEx(INFO, " Debit........ debit or credit"); + PrintAndLogEx(INFO, " Credit....... credit"); } else { - PrintAndLogEx(INFO, " Read A - Kd or Kc"); - PrintAndLogEx(INFO, " Read B - Kd or Kc"); - PrintAndLogEx(INFO, " Write A - Kc"); - PrintAndLogEx(INFO, " Write B - Kc"); - PrintAndLogEx(INFO, " Debit - Kd or Kc"); - PrintAndLogEx(INFO, " Credit - Kc"); + PrintAndLogEx(INFO, " Read A....... debit or credit"); + PrintAndLogEx(INFO, " Read B....... debit or credit"); + PrintAndLogEx(INFO, " Write A...... credit"); + PrintAndLogEx(INFO, " Write B...... credit"); + PrintAndLogEx(INFO, " Debit........ debit or credit"); + PrintAndLogEx(INFO, " redit........ credit"); } } @@ -3539,33 +3539,33 @@ int info_iclass(void) { picopass_ns_hdr *ns_hdr = (picopass_ns_hdr *)resp.data.asBytes; PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " --------------------------"); - PrintAndLogEx(INFO, "-------------------------------------------------------------"); + PrintAndLogEx(INFO, "--------------------- " _CYAN_("Tag Information") " ----------------------"); + PrintAndLogEx(INFO, "------------------------------------------------------------"); if (readStatus & FLAG_ICLASS_CSN) { - PrintAndLogEx(SUCCESS, " CSN: " _GREEN_("%s") " (uid)", sprint_hex(hdr->csn, sizeof(hdr->csn))); + PrintAndLogEx(SUCCESS, " CSN: " _GREEN_("%s") " uid", sprint_hex(hdr->csn, sizeof(hdr->csn))); } if (readStatus & FLAG_ICLASS_CONF) { - PrintAndLogEx(SUCCESS, " Config: %s (Card configuration)", sprint_hex((uint8_t *)&hdr->conf, sizeof(hdr->conf))); + PrintAndLogEx(SUCCESS, " Config: %s card configuration", sprint_hex((uint8_t *)&hdr->conf, sizeof(hdr->conf))); } // page mapping. If fuse0|1 == 0x01, card is in non-secure mode, with CSN, CONF, AIA as top 3 blocks. // page9 in http://www.proxmark.org/files/Documents/13.56%20MHz%20-%20iClass/DS%20Picopass%202KS%20V1-0.pdf uint8_t pagemap = get_pagemap(hdr); if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) { - PrintAndLogEx(SUCCESS, " AIA: %s (Application Issuer area)", sprint_hex(ns_hdr->app_issuer_area, sizeof(ns_hdr->app_issuer_area))); + PrintAndLogEx(SUCCESS, " AIA: %s application issuer area", sprint_hex(ns_hdr->app_issuer_area, sizeof(ns_hdr->app_issuer_area))); } else { if (readStatus & FLAG_ICLASS_CC) { - PrintAndLogEx(SUCCESS, "E-purse: %s (Card challenge, CC)", sprint_hex(hdr->epurse, sizeof(hdr->epurse))); + 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))); + 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_AIA) { - PrintAndLogEx(SUCCESS, " AIA: %s (Application Issuer area)", sprint_hex(hdr->app_issuer_area, sizeof(hdr->app_issuer_area))); + PrintAndLogEx(SUCCESS, " AIA: %s application issuer area", sprint_hex(hdr->app_issuer_area, sizeof(hdr->app_issuer_area))); } } @@ -3573,7 +3573,7 @@ int info_iclass(void) { print_picopass_info(hdr); } - PrintAndLogEx(INFO, "------ " _CYAN_("Fingerprint") " ------"); + PrintAndLogEx(INFO, "------------------------ " _CYAN_("Fingerprint") " -----------------------"); uint8_t aia[8]; if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) @@ -3588,18 +3588,17 @@ int info_iclass(void) { bool se_enabled = (memcmp(aia, "\xff\xff\xff\x00\x06\xff\xff\xff", 8) == 0); if (isHidRange) { - PrintAndLogEx(SUCCESS, "CSN is in HID range"); + PrintAndLogEx(SUCCESS, " CSN.......... " _YELLOW_("HID range")); if (legacy) - PrintAndLogEx(SUCCESS, "Credential : " _GREEN_("iCLASS legacy")); + PrintAndLogEx(SUCCESS, " Credential... " _GREEN_("iCLASS legacy")); if (se_enabled) - PrintAndLogEx(SUCCESS, "Credential : " _GREEN_("iCLASS SE")); - + PrintAndLogEx(SUCCESS, " Credential... " _GREEN_("iCLASS SE")); } else { - PrintAndLogEx(SUCCESS, _YELLOW_("PicoPass")" (CSN is not in HID range)"); + PrintAndLogEx(SUCCESS, " CSN..-....... " _YELLOW_("outside HID range")); } uint8_t cardtype = get_mem_config(hdr); - PrintAndLogEx(SUCCESS, " Card type : " _GREEN_("%s"), card_types[cardtype]); + PrintAndLogEx(SUCCESS, " Card type.... " _GREEN_("%s"), card_types[cardtype]); } DropField(); From 0e4a9fbc346e88ae8ddd8d1d45bf213a7126471d Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 19 Oct 2020 12:42:26 +0200 Subject: [PATCH 02/35] text --- client/src/cmdhw.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index f2eff6966..7ad1ba5b8 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -792,18 +792,18 @@ void pm3_version(bool verbose, bool oneliner) { PrintAndLogEx(NORMAL, "\n [ " _YELLOW_("PROXMARK3") " ]"); if (IfPm3Rdv4Fw() == false) { - PrintAndLogEx(NORMAL, " firmware.........................%s", _GREEN_("PM3OTHER")); + PrintAndLogEx(NORMAL, " firmware.................. %s", _YELLOW_("PM3OTHER")); if (IfPm3FpcUsartHost()) { - PrintAndLogEx(NORMAL, " FPC USART for BT add-on..........%s", _GREEN_("present")); + PrintAndLogEx(NORMAL, " FPC USART for BT add-on... %s", _GREEN_("present")); } } else { - PrintAndLogEx(NORMAL, " firmware.........................%s", _GREEN_("PM3RDV4")); - PrintAndLogEx(NORMAL, " external flash...................%s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent")); - PrintAndLogEx(NORMAL, " smartcard reader.................%s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent")); - PrintAndLogEx(NORMAL, " FPC USART for BT add-on..........%s", IfPm3FpcUsartHost() ? _GREEN_("present") : _YELLOW_("absent")); + PrintAndLogEx(NORMAL, " firmware.................. %s", _YELLOW_("PM3RDV4")); + PrintAndLogEx(NORMAL, " external flash............ %s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent")); + PrintAndLogEx(NORMAL, " smartcard reader.......... %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent")); + PrintAndLogEx(NORMAL, " FPC USART for BT add-on... %s", IfPm3FpcUsartHost() ? _GREEN_("present") : _YELLOW_("absent")); } if (IfPm3FpcUsartDevFromUsb()) { - PrintAndLogEx(NORMAL, " FPC USART for developer..........%s", _GREEN_("present")); + PrintAndLogEx(NORMAL, " FPC USART for developer... %s", _GREEN_("present")); } PrintAndLogEx(NORMAL, ""); From f1d39f7e53718951d9f7923c4a81ccd87c9f08a5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 19 Oct 2020 15:48:45 +0200 Subject: [PATCH 03/35] fix support for waveshare 1.54 --- client/src/cmdhf14a.c | 10 ++++++++-- client/src/cmdhfwaveshare.c | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index e9ddbf6c5..837311062 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -1681,10 +1681,16 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { } getTagLabel(card.uid[0], card.uid[1]); break; - case 0x57: // Qualcomm + case 0x46: + if (memcmp(card.uid, "FSTN10m", 7) == 0) { + isMifareClassic = false; + printTag("Waveshare NFC-Powered e-Paper 1.54\" (please disregard MANUFACTURER mapping above)"); + } + break; + case 0x57: if (memcmp(card.uid, "WSDZ10m", 7) == 0) { isMifareClassic = false; - printTag("Waveshare NFC-Powered e-Paper"); + printTag("Waveshare NFC-Powered e-Paper (please disregard MANUFACTURER mapping above)"); } break; default: diff --git a/client/src/cmdhfwaveshare.c b/client/src/cmdhfwaveshare.c index 4e5728e7f..1ea7013a1 100644 --- a/client/src/cmdhfwaveshare.c +++ b/client/src/cmdhfwaveshare.c @@ -693,11 +693,21 @@ static int start_drawing(uint8_t model_nr, uint8_t *black, uint8_t *red) { return PM3_ESOFT; } - if ((card.uidlen != 7) || (memcmp(card.uid, "WSDZ10m", 7) != 0)) { + if ((card.uidlen != 7) || ((memcmp(card.uid, "FSTN10m", 7) != 0) && (memcmp(card.uid, "WSDZ10m", 7) != 0))) { PrintAndLogEx(WARNING, "Card doesn't look like Waveshare tag"); DropField(); return PM3_ESOFT; } + if (((model_nr != M1in54B) && (memcmp(card.uid, "FSTN10m", 7) == 0))) { + PrintAndLogEx(WARNING, "Card is a Waveshare tag 1.54\", not %s", models[model_nr].desc); + DropField(); + return PM3_ESOFT; + } + if (((model_nr == M1in54B) && (memcmp(card.uid, "FSTN10m", 7) != 0))) { + PrintAndLogEx(WARNING, "Card is not a Waveshare tag 1.54\", check your model number"); + DropField(); + return PM3_ESOFT; + } PrintAndLogEx(DEBUG, "model_nr = %d", model_nr); int ret; PrintAndLogEx(DEBUG, "Step0"); @@ -921,6 +931,7 @@ static int start_drawing(uint8_t model_nr, uint8_t *black, uint8_t *red) { msleep(200); } PrintAndLogEx(DEBUG, "Step11: Wait tag to be ready"); + PrintAndLogEx(INPLACE, "E-paper Reflashing, Waiting"); if (model_nr == M2in13B || model_nr == M1in54B) { // Black, white and red screen refresh time is longer, wait first msleep(9000); } else if (model_nr == M7in5HD) { @@ -950,7 +961,7 @@ static int start_drawing(uint8_t model_nr, uint8_t *black, uint8_t *red) { } else { fail_num++; PrintAndLogEx(INPLACE, "E-paper Reflashing, Waiting"); - msleep(100); + msleep(400); } } } From daabdf2e31cde2f8f91bb5e10452f05eb08bbdbc Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 19 Oct 2020 21:21:24 +0200 Subject: [PATCH 04/35] Avoid spurious GCC10 stringop-overflow errors I already got them at several occasions --- Makefile.defs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile.defs b/Makefile.defs index 06eb2e36f..4045fb711 100644 --- a/Makefile.defs +++ b/Makefile.defs @@ -27,6 +27,9 @@ LD = g++ SH = sh BASH = bash PERL = perl +CCC =foo +CC_VERSION = $(shell $(CC) -dumpversion 2>/dev/null|sed 's/\..*//') +CC_VERSION := $(or $(strip $(CC_VERSION)),0) PATHSEP=/ PREFIX ?= /usr/local @@ -62,7 +65,11 @@ DEFCFLAGS += -Wbad-function-cast -Wredundant-decls -Wmissing-prototypes -Wchar-s # Some more warnings we need first to eliminate, so temporarely tolerated: DEFCFLAGS += -Wcast-align -Wno-error=cast-align DEFCFLAGS += -Wswitch-enum -Wno-error=switch-enum - +# GCC 10 has issues with false positives on stringop-overflow, let's disable them for now (cf https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92955, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94335) +# beware these flags didn't exist for GCC < 7 +ifeq ($(shell expr $(CC_VERSION) \>= 10), 1) + DEFCFLAGS += -Wno-stringop-overflow -Wno-error=stringop-overflow +endif ifeq ($(platform),Darwin) # their readline has strict-prototype issues DEFCFLAGS += -Wno-strict-prototypes From 8d14b46232b59a451973e67eeaa02266ad97a0d6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 19 Oct 2020 21:25:24 +0200 Subject: [PATCH 05/35] waveshare: tolerate (but ignore) alpha channel --- client/src/cmdhfwaveshare.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/client/src/cmdhfwaveshare.c b/client/src/cmdhfwaveshare.c index 1ea7013a1..b47043be2 100644 --- a/client/src/cmdhfwaveshare.c +++ b/client/src/cmdhfwaveshare.c @@ -351,7 +351,7 @@ static void map8to1(uint8_t *colormap, uint16_t width, uint16_t height, uint8_t static int read_bmp_rgb(uint8_t *bmp, const size_t bmpsize, uint8_t model_nr, uint8_t **black, uint8_t **red, char *filename, bool save_conversions) { BMP_HEADER *pbmpheader = (BMP_HEADER *)bmp; // check file is full color - if (pbmpheader->bpp != 24) { + if ((pbmpheader->bpp != 24) && (pbmpheader->bpp != 32)) { return PM3_ESOFT; } @@ -400,6 +400,8 @@ static int read_bmp_rgb(uint8_t *bmp, const size_t bmpsize, uint8_t model_nr, ui chanB[X + (height - Y - 1) * width] = bmp[offset++]; chanG[X + (height - Y - 1) * width] = bmp[offset++]; chanR[X + (height - Y - 1) * width] = bmp[offset++]; + if (pbmpheader->bpp == 32) // Skip Alpha chan + offset++; } // Skip line padding offset += width % 4; @@ -436,6 +438,8 @@ static int read_bmp_rgb(uint8_t *bmp, const size_t bmpsize, uint8_t model_nr, ui bmp[offset++] = chanB[X + (height - Y - 1) * width] & 0xFF; bmp[offset++] = chanG[X + (height - Y - 1) * width] & 0xFF; bmp[offset++] = chanR[X + (height - Y - 1) * width] & 0xFF; + if (pbmpheader->bpp == 32) // Fill Alpha chan + bmp[offset++] = 0xFF; } // Skip line padding offset += width % 4; @@ -500,6 +504,8 @@ static int read_bmp_rgb(uint8_t *bmp, const size_t bmpsize, uint8_t model_nr, ui bmp[offset++] = chanGrey[X + (height - Y - 1) * width] & 0xFF; bmp[offset++] = chanGrey[X + (height - Y - 1) * width] & 0xFF; bmp[offset++] = chanGrey[X + (height - Y - 1) * width] & 0xFF; + if (pbmpheader->bpp == 32) // Fill Alpha chan + bmp[offset++] = 0xFF; } // Skip line padding offset += width % 4; @@ -1059,11 +1065,13 @@ static int CmdHF14AWSLoadBmp(const char *Cmd) { return PM3_ESOFT; } } else if (depth == 32) { - PrintAndLogEx(ERR, "Error, BMP color depth %i not supported. Remove alpha channel.", depth); - free(bmp); - return PM3_ESOFT; + PrintAndLogEx(DEBUG, "BMP file is a RGBA, we will ignore the Alpha channel"); + if (read_bmp_rgb(bmp, bytes_read, model_nr, &black, &red, filename, save_conversions) != PM3_SUCCESS) { + free(bmp); + return PM3_ESOFT; + } } else { - PrintAndLogEx(ERR, "Error, BMP color depth %i not supported. Must be 1 (BW) or 24 (RGB)", depth); + PrintAndLogEx(ERR, "Error, BMP color depth %i not supported. Must be 1 (BW), 24 (RGB) or 32 (RGBA)", depth); free(bmp); return PM3_ESOFT; } From 86ff6aebefeed0759e4529035f05f1758fed8b73 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 20 Oct 2020 00:45:03 +0200 Subject: [PATCH 06/35] vscode --- .vscode/launch.json | 55 ++++++++++++++++++++++++++++++++++ .vscode/tasks.json | 73 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..f115c5c7e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,55 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Attach", + "type": "cppdbg", + "request": "attach", + "program": "${cwd}/client/proxmark3", + //"processId": "${command:pickProcess}", + "processId": "${input:ProcessID}", + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + },{ + "name": "(gdb) Build & Launch", + "type": "cppdbg", + "request": "launch", + "program": "${cwd}/client/proxmark3", + "args": ["/dev/ttyACM0"], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "Debug: clean & make client", + "miDebuggerPath": "/usr/bin/gdb" + } + ], + "inputs": [ + { + // Using Extension "Tasks Shell Input" https://marketplace.visualstudio.com/items?itemName=augustocdias.tasks-shell-input + "id": "ProcessID", + "type": "command", + "command": "shellCommand.execute", + "args": { + "command": "pgrep -n proxmark3", + } + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 20b68be0e..352f22a42 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,24 +4,85 @@ "version": "2.0.0", "tasks": [ { - "label": "build", + "label": "Make all & run", "type": "shell", - "command": "make clean && make all -j$(nproc --all)", + "command": "make -j && ./pm3", "problemMatcher": [ "$gcc" - ] + ], + "group": { + "kind": "build", + "isDefault": true + } }, { - "label": "flash fullimage", + "label": "Make TARGET", "type": "shell", - "command": "sudo ./pm3-flash-fullimage", + "command": "make ${input:componentType} -j", + "problemMatcher": [ + "$gcc" + ], + "group": "build", + }, + { + "label": "Debug: make client", + "type": "shell", + "command": "make client -j DEBUG=1", + "problemMatcher": [ + "$gcc" + ], + "group": "build", + }, + { + "label": "Debug: clean & make client", + "type": "shell", + "command": "make client/clean && make client -j DEBUG=1", + "problemMatcher": [ + "$gcc" + ], + "group": "build", + }, + { + "label": "Flash fullimage", + "type": "shell", + "command": "./pm3-flash-fullimage", "problemMatcher": [] }, { "label": "FLASH BOOTROM", "type": "shell", - "command": "sudo ./pm3-flash-bootrom", + "command": "./pm3-flash-bootrom", "problemMatcher": [] + }, + { + "label": "Run client", + "type": "shell", + "command": "./pm3", + "problemMatcher": [], + "dependsOn": [ + "Release: build client" + ] + } + ], + "inputs": [ + { + "type": "pickString", + "id": "componentType", + "description": "What Makefile target do you want to execute?", + "options": [ + "all", + "client", + "bootrom", + "fullimage", + "recovery", + "clean", + "install", + "uninstall", + "style", + "miscchecks", + "check", + ], + "default": "all" } ] } \ No newline at end of file From ec820db997af8c9a7508d21b204a72a2debb0204 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 20 Oct 2020 01:00:00 +0200 Subject: [PATCH 07/35] Add DEBUG flag to Makefile --- Makefile.defs | 12 +++++++++--- doc/md/Development/Makefile-vs-CMake.md | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Makefile.defs b/Makefile.defs index 4045fb711..a06cbb31e 100644 --- a/Makefile.defs +++ b/Makefile.defs @@ -51,9 +51,15 @@ else RANLIB= ranlib endif -DEFCXXFLAGS = -Wall -Werror -O3 -pipe -DEFCFLAGS = -Wall -Werror -O3 -fstrict-aliasing -pipe -DEFLDFLAGS = +ifeq ($(DEBUG),1) + DEFCXXFLAGS = -g -O0 -pipe + DEFCFLAGS = -g -O0 -fstrict-aliasing -pipe + DEFLDFLAGS = +else + DEFCXXFLAGS = -Wall -Werror -O3 -pipe + DEFCFLAGS = -Wall -Werror -O3 -fstrict-aliasing -pipe + DEFLDFLAGS = +endif # Next ones are activated only if SANITIZE=1 ifeq ($(SANITIZE),1) DEFCFLAGS += -g -fsanitize=address -fno-omit-frame-pointer diff --git a/doc/md/Development/Makefile-vs-CMake.md b/doc/md/Development/Makefile-vs-CMake.md index 314cd1e7a..6fa95066c 100644 --- a/doc/md/Development/Makefile-vs-CMake.md +++ b/doc/md/Development/Makefile-vs-CMake.md @@ -13,7 +13,8 @@ At the moment both are maintained because they don't perfectly overlap yet. | Feature | Makefile | CMake | Remarks | |-----|---|---|---| -| verbose | V=1 | VERBOSE=1 | | +| verbose | `V=1` | `VERBOSE=1` | | +| debug build | `DEBUG=1` | `-DCMAKE_BUILD_TYPE=Debug` | client only | | warnings management | yes (1) | **no** | (1) cf Makefile.defs | | extra GCC warnings | GCCEXTRA=1 | **no** | | | extra Clang warnings | CLANGEXTRA=1 | **no** | only on host | @@ -32,7 +33,7 @@ At the moment both are maintained because they don't perfectly overlap yet. | bzip2 detection | **none** | find_package, Cross:gitclone | | | dep cliparser | in_deps | in_deps | | | dep hardnested | in_deps | in_deps | | -| hardn arch autodetect | `uname -m` =? 86 or amd64; `$(CC) -E -mavx512f`? +AVX512` | `CMAKE_SYSTEM_PROCESSOR` =? x86 or x86_64 or i686 or AMD64 (1) | (1) currently it always includes AVX512 on Intel arch | +| hardn arch autodetect | `uname -m` =? 86 or amd64; `$(CC) -E -mavx512f`? +`AVX512` | `CMAKE_SYSTEM_PROCESSOR` =? x86 or x86_64 or i686 or AMD64 (1) | (1) currently it always includes AVX512 on Intel arch | | `cpu_arch` | yes | **no/auto?** | e.g. `cpu_arch=generic` for cross-compilation | dep jansson | sys / in_deps | sys / in_deps | | | jansson detection | pc | pc/find* | | From 29f1147aadc64bf9bbcaf9bafcb856da4ece1e68 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 20 Oct 2020 01:00:23 +0200 Subject: [PATCH 08/35] make style --- armsrc/appmain.c | 20 ++-- armsrc/em4x50.c | 22 ++-- armsrc/iclass.c | 30 +++--- armsrc/iso14443a.c | 2 +- armsrc/iso15693.c | 12 +-- armsrc/mifarecmd.c | 18 ++-- client/deps/cliparser/cliparser.c | 16 +-- client/src/cmdhf14a.c | 22 ++-- client/src/cmdhf14b.c | 2 +- client/src/cmdhf15.c | 22 ++-- client/src/cmdhficlass.c | 70 ++++++------- client/src/cmdhfmfp.c | 4 +- client/src/cmdhfmfu.c | 80 +++++++------- client/src/cmdhfst.c | 6 +- client/src/cmdlf.c | 2 +- client/src/cmdlfdestron.c | 8 +- client/src/cmdlfem4x05.c | 168 +++++++++++++++--------------- client/src/cmdlfem4x50.c | 2 +- client/src/cmdlffdxb.c | 6 +- client/src/cmdlfindala.c | 4 +- client/src/cmdlfmotorola.c | 8 +- client/src/scripting.c | 18 ++-- doc/commands.md | 25 ++++- include/pm3_cmd.h | 2 +- 24 files changed, 292 insertions(+), 277 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 02d6f1d23..6b127c831 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1481,12 +1481,12 @@ static void PacketReceived(PacketCommandNG *packet) { MifareU_Otp_Tearoff(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes); break; } - case CMD_HF_MFU_COUNTER_TEAROFF: { + case CMD_HF_MFU_COUNTER_TEAROFF: { struct p { uint8_t counter; uint32_t tearoff_time; } PACKED; - struct p *payload = (struct p *) packet->data.asBytes; + struct p *payload = (struct p *) packet->data.asBytes; MifareU_Counter_Tearoff(payload->counter, payload->tearoff_time); break; } @@ -1520,13 +1520,13 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_HF_ICLASS_SIMULATE: { -/* - struct p { - uint8_t reader[4]; - uint8_t mac[4]; - } PACKED; - struct p *payload = (struct p *) packet->data.asBytes; -*/ + /* + struct p { + uint8_t reader[4]; + uint8_t mac[4]; + } PACKED; + struct p *payload = (struct p *) packet->data.asBytes; + */ SimulateIClass(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes); break; @@ -1562,7 +1562,7 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_HF_ICLASS_RESTORE: { - iClass_Restore( (iclass_restore_req_t *)packet->data.asBytes); + iClass_Restore((iclass_restore_req_t *)packet->data.asBytes); break; } #endif diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index bce422908..9ab8dcf35 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -889,18 +889,18 @@ static int write(uint8_t word[4], uint8_t address) { return PM3_ETEAROFF; } else { - // wait for T0 * EM4X50_T_TAG_TWA (write access time) - wait_timer(FPGA_TIMER_0, T0 * EM4X50_T_TAG_TWA); + // wait for T0 * EM4X50_T_TAG_TWA (write access time) + wait_timer(FPGA_TIMER_0, T0 * EM4X50_T_TAG_TWA); - // look for ACK sequence - if (check_ack(false)) { + // look for ACK sequence + if (check_ack(false)) { - // now EM4x50 needs T0 * EM4X50_T_TAG_TWEE (EEPROM write time) - // for saving data and should return with ACK - if (check_ack(false)) - return PM3_SUCCESS; + // now EM4x50 needs T0 * EM4X50_T_TAG_TWEE (EEPROM write time) + // for saving data and should return with ACK + if (check_ack(false)) + return PM3_SUCCESS; - } + } } } else { @@ -985,7 +985,7 @@ void em4x50_write(em4x50_data_t *etd) { lf_finalize(); return; } - + if (res == PM3_SUCCESS) { // to verify result reset EM4x50 if (reset()) { @@ -1033,7 +1033,7 @@ void em4x50_write_password(em4x50_data_t *etd) { // login and change password if (login(etd->password)) { - + int res = write_password(etd->password, etd->new_password); if (res == PM3_ETEAROFF) { lf_finalize(); diff --git a/armsrc/iclass.c b/armsrc/iclass.c index 204cd9ea1..03f7dcbba 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -1367,7 +1367,7 @@ static bool select_iclass_tag_ex(picopass_hdr *hdr, bool use_credit_key, uint32_ *status |= FLAG_ICLASS_CC; } else { - + // on NON_SECURE_PAGEMODE cards, AIA is on block2.. // read App Issuer Area block 2 @@ -1443,7 +1443,7 @@ void ReaderIClass(uint8_t flags) { // with 0xFF:s in block 3 and 4. LED_B_ON(); - reply_mix(CMD_ACK, result_status, 0, 0, (uint8_t*)&hdr, sizeof(hdr)); + reply_mix(CMD_ACK, result_status, 0, 0, (uint8_t *)&hdr, sizeof(hdr)); //Send back to client, but don't bother if we already sent this - // only useful if looping in arm (not try_once && not abort_after_read) @@ -1489,9 +1489,9 @@ bool authenticate_iclass_tag(iclass_auth_req_t *payload, picopass_hdr *hdr, uint memcpy(ccnr, hdr->epurse, sizeof(hdr->epurse)); - if ( payload->use_replay) { + if (payload->use_replay) { - memcpy(pmac, payload->key + 4, 4); + memcpy(pmac, payload->key + 4, 4); memcpy(cmd_check + 1, payload->key, 8); } else { @@ -1780,7 +1780,7 @@ static bool iclass_writeblock_ext(uint8_t blockno, uint8_t *data, uint8_t *mac) // write command: cmd, 1 blockno, 8 data, 4 mac uint8_t write[16] = { 0x80 | ICLASS_CMD_UPDATE, blockno }; - memcpy(write + 2, data, 8); + memcpy(write + 2, data, 8); memcpy(write + 10, mac, 4); AddCrc(write + 1, 13); @@ -1872,11 +1872,11 @@ void iClass_WriteBlock(uint8_t *msg) { iclass_send_as_reader(write, sizeof(write), &start_time, &eof_time); if (tearoff_hook() == PM3_ETEAROFF) { // tearoff occured - res = false; - switch_off(); - if (payload->req.send_reply) - reply_ng(CMD_HF_ICLASS_WRITEBL, PM3_ETEAROFF, (uint8_t *)&res, sizeof(uint8_t)); - return; + res = false; + switch_off(); + if (payload->req.send_reply) + reply_ng(CMD_HF_ICLASS_WRITEBL, PM3_ETEAROFF, (uint8_t *)&res, sizeof(uint8_t)); + return; } else { if (GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_UPDATE, &eof_time) == 10) { @@ -1885,7 +1885,7 @@ void iClass_WriteBlock(uint8_t *msg) { } } } - + if (tries == 0) { res = false; goto out; @@ -1932,7 +1932,7 @@ void iClass_Restore(iclass_restore_req_t *msg) { if (msg->req.send_reply) { reply_ng(CMD_HF_ICLASS_RESTORE, PM3_ESOFT, NULL, 0); } - return; + return; } LED_A_ON(); @@ -1942,7 +1942,7 @@ void iClass_Restore(iclass_restore_req_t *msg) { uint32_t eof_time = 0; picopass_hdr hdr = {0}; - // select + // select bool res = select_iclass_tag(&hdr, msg->req.use_credit_key, &eof_time); if (res == false) { goto out; @@ -1974,7 +1974,7 @@ void iClass_Restore(iclass_restore_req_t *msg) { doMAC_N(wb, sizeof(wb), hdr.key_c, mac); else doMAC_N(wb, sizeof(wb), hdr.key_d, mac); - + // data + mac if (iclass_writeblock_ext(item.blockno, item.data, mac)) { Dbprintf("Write block [%02x] " _GREEN_("successful"), item.blockno); @@ -1983,7 +1983,7 @@ void iClass_Restore(iclass_restore_req_t *msg) { Dbprintf("Write block [%02x] " _RED_("failed"), item.blockno); } } - + out: switch_off(); diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index d40080ae1..6e1e22738 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -2629,7 +2629,7 @@ int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *p_card, uint32 AddCrc14A(rats, 2); ReaderTransmit(rats, sizeof(rats), NULL); int len = ReaderReceive(resp, resp_par); - if (len == 0) + if (len == 0) return 0; if (p_card) { diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index 00af14c4f..bacceb165 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -1474,13 +1474,13 @@ int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t int res = 0; tosend_t *ts = get_tosend(); TransmitTo15693Tag(ts->buf, ts->max, &start_time); - + if (tearoff_hook() == PM3_ETEAROFF) { // tearoff occured res = PM3_ETEAROFF; } else { - + *eof_time = start_time + 32 * ((8 * ts->max) - 4); // substract the 4 padding bits after EOF LogTrace_ISO15693(send, sendlen, (start_time * 4), (*eof_time * 4), NULL, true); if (recv != NULL) { @@ -1595,11 +1595,11 @@ void ReaderIso15693(uint32_t parameter) { uint32_t start_time = 0; uint32_t eof_time; int recvlen = SendDataTag(cmd, sizeof(cmd), true, true, answer, ISO15693_MAX_RESPONSE_LENGTH, start_time, ISO15693_READER_TIMEOUT, &eof_time); - + if (recvlen == PM3_ETEAROFF) { // tearoff occured reply_mix(CMD_ACK, recvlen, 0, 0, NULL, 0); } else { - + start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER; // we should do a better check than this @@ -1634,7 +1634,7 @@ void ReaderIso15693(uint32_t parameter) { } } else { DbpString("Failed to select card"); - reply_mix(CMD_ACK, 0, 0, 0, NULL, 0); + reply_mix(CMD_ACK, 0, 0, 0, NULL, 0); } } switch_off(); @@ -1869,7 +1869,7 @@ void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint } if (recv) { - recvlen = MIN(recvlen,ISO15693_MAX_RESPONSE_LENGTH); + recvlen = MIN(recvlen, ISO15693_MAX_RESPONSE_LENGTH); reply_mix(CMD_ACK, recvlen, 0, 0, recvbuf, recvlen); } else { reply_mix(CMD_ACK, 1, 0, 0, NULL, 0); diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index f442166f4..11c89a98b 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -2752,15 +2752,15 @@ void MifareU_Counter_Tearoff(uint8_t counter, uint32_t tearoff_time) { // Send MFU counter increase cmd uint8_t cmd[] = { - MIFARE_ULEV1_INCR_CNT, - counter, - 0, // lsb - 0, - 0, // msb - 0, // rfu - 0, - 0, - }; + MIFARE_ULEV1_INCR_CNT, + counter, + 0, // lsb + 0, + 0, // msb + 0, // rfu + 0, + 0, + }; AddCrc14A(cmd, sizeof(cmd) - 2); // anticollision / select card diff --git a/client/deps/cliparser/cliparser.c b/client/deps/cliparser/cliparser.c index a601e6490..258346c00 100644 --- a/client/deps/cliparser/cliparser.c +++ b/client/deps/cliparser/cliparser.c @@ -205,9 +205,9 @@ int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int int tmplen = 0; uint8_t tmpstr[(256 * 2) + 1] = {0}; - + // concat all strings in argstr into tmpstr[] - // + // int res = CLIParamStrToBuf(argstr, tmpstr, sizeof(tmpstr), &tmplen); if (res) { return res; @@ -216,7 +216,7 @@ int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int return res; } - res = param_gethex_to_eol((char*)tmpstr, 0, data, maxdatalen, datalen); + res = param_gethex_to_eol((char *)tmpstr, 0, data, maxdatalen, datalen); switch (res) { case 1: printf("Parameter error: Invalid HEX value\n"); @@ -241,20 +241,20 @@ int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int int ibuf = 0; for (int i = 0; i < argstr->count; i++) { - + int len = strlen(argstr->sval[i]); - - if (len > ( (sizeof(tmpstr) / 2 ) - ibuf)) { + + if (len > ((sizeof(tmpstr) / 2) - ibuf)) { printf("Parameter error: string too long (%i chars), expect MAX %zu chars\n", len + ibuf, (sizeof(tmpstr) / 2)); fflush(stdout); return 2; } - + memcpy(&tmpstr[ibuf], argstr->sval[i], len); ibuf += len; } - + ibuf = MIN(ibuf, (sizeof(tmpstr) / 2)); tmpstr[ibuf] = 0; diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index 837311062..dac2193c6 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -1843,30 +1843,30 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { if (memcmp(card.ats + pos, "\xC1\x05\x2F\x2F\x01\xBC\xD6", 7) == 0) { tip = "-> MIFARE Plus X 2K/4K (SL3)"; } else if (memcmp(card.ats + pos, "\xC1\x05\x2F\x2F\x00\x35\xC7", 7) == 0) { - + if ((card.atqa[0] & 0x02) == 0x02) tip = "-> MIFARE Plus S 2K (SL3)"; else if ((card.atqa[0] & 0x04) == 0x04) tip = "-> MIFARE Plus S 4K (SL3)"; - + } else if (memcmp(card.ats + pos, "\xC1\x05\x21\x30\x00\xF6\xD1", 7) == 0) { tip = "-> MIFARE Plus SE 1K (17pF)"; - } else if (memcmp(card.ats + pos, "\xC1\x05\x21\x30\x10\xF6\xD1", 7) == 0) { + } else if (memcmp(card.ats + pos, "\xC1\x05\x21\x30\x10\xF6\xD1", 7) == 0) { tip = "-> MIFARE Plus SE 1K (70pF)"; } - - } else { //SAK B4,5,6 - - if ((card.sak & 0x20) == 0x20) { // and no GetVersion().. - - + + } else { //SAK B4,5,6 + + if ((card.sak & 0x20) == 0x20) { // and no GetVersion().. + + if (memcmp(card.ats + pos, "\xC1\x05\x2F\x2F\x01\xBC\xD6", 7) == 0) { tip = "-> MIFARE Plus X 2K (SL1)"; } else if (memcmp(card.ats + pos, "\xC1\x05\x2F\x2F\x00\x35\xC7", 7) == 0) { tip = "-> MIFARE Plus S 2K (SL1)"; } else if (memcmp(card.ats + pos, "\xC1\x05\x21\x30\x00\xF6\xD1", 7) == 0) { tip = "-> MIFARE Plus SE 1K (17pF)"; - } else if (memcmp(card.ats + pos, "\xC1\x05\x21\x30\x10\xF6\xD1", 7) == 0) { + } else if (memcmp(card.ats + pos, "\xC1\x05\x21\x30\x10\xF6\xD1", 7) == 0) { tip = "-> MIFARE Plus SE 1K (70pF)"; } } else { @@ -1874,7 +1874,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { tip = "-> MIFARE Plus X 4K (SL1)"; } else if (memcmp(card.ats + pos, "\xC1\x05\x2F\x2F\x00\x35\xC7", 7) == 0) { tip = "-> MIFARE Plus S 4K (SL1)"; - } + } } } diff --git a/client/src/cmdhf14b.c b/client/src/cmdhf14b.c index 85898fe04..73f8c2a8f 100644 --- a/client/src/cmdhf14b.c +++ b/client/src/cmdhf14b.c @@ -149,7 +149,7 @@ static int CmdHF14BSim(const char *Cmd) { PrintAndLogEx(FAILED, "failed to read pupi"); return PM3_EINVARG; } - + PrintAndLogEx(INFO, "Simulate with PUPI : " _GREEN_("%s"), sprint_hex_inrow(pupi, sizeof(pupi))); PrintAndLogEx(INFO, "Press pm3-button to abort simulation"); clearCommandBuffer(); diff --git a/client/src/cmdhf15.c b/client/src/cmdhf15.c index b4cde234f..6d276617c 100644 --- a/client/src/cmdhf15.c +++ b/client/src/cmdhf15.c @@ -656,13 +656,13 @@ static int CmdHF15Demod(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); - + // The sampling rate is 106.353 ksps/s, for T = 18.8 us int i, j; int max = 0, maxPos = 0; int skip = 4; - if (GraphTraceLen < 1000) { + if (GraphTraceLen < 1000) { PrintAndLogEx(FAILED, "Too few samples in GraphBuffer. Need more than 1000"); PrintAndLogEx(HINT, "Run " _YELLOW_("`hf 15 samples`") " to collect and download data"); return PM3_ESOFT; @@ -733,8 +733,8 @@ static int CmdHF15Demod(const char *Cmd) { PrintAndLogEx(WARNING, "Warning, uneven octet! (discard extra bits!)"); PrintAndLogEx(INFO, " mask = %02x", mask); } - - if ( k == 0 ) { + + if (k == 0) { return PM3_SUCCESS; } @@ -744,7 +744,7 @@ static int CmdHF15Demod(const char *Cmd) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(SUCCESS, " idx | data"); PrintAndLogEx(SUCCESS, "-----+-------------------------------------------------"); - if ( k / 16 > 0) { + if (k / 16 > 0) { for (; i < k; i += 16) { PrintAndLogEx(SUCCESS, " %3i | %s", i, sprint_hex(outBuf + i, 16)); } @@ -824,7 +824,7 @@ static int NxpSysInfo(uint8_t *uid) { if (status == PM3_ETEAROFF) { return status; } - + if (status < 2) { PrintAndLogEx(WARNING, "iso15693 card doesn't answer to NXP systeminfo command"); return PM3_EWRONGANSWER; @@ -1058,7 +1058,7 @@ static int CmdHF15Sniff(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); - + PacketResponseNG resp; clearCommandBuffer(); SendCommandNG(CMD_HF_ISO15693_SNIFF, NULL, 0); @@ -1111,7 +1111,7 @@ static int CmdHF15Sim(const char *Cmd) { struct { uint8_t uid[8]; } PACKED payload; - + int uidlen = 0; CLIGetHexWithReturn(ctx, 1, payload.uid, &uidlen); CLIParserFree(ctx); @@ -1904,11 +1904,11 @@ static int CmdHF15CSetUID(const char *Cmd) { struct { uint8_t uid[8]; } PACKED payload; - + int uidlen = 0; CLIGetHexWithReturn(ctx, 1, payload.uid, &uidlen); CLIParserFree(ctx); - + if (uidlen != 8) { PrintAndLogEx(WARNING, "UID must include 16 HEX symbols got "); return PM3_EINVARG; @@ -1936,7 +1936,7 @@ static int CmdHF15CSetUID(const char *Cmd) { if (WaitForResponseTimeout(CMD_HF_ISO15693_CSETUID, &resp, 2000) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); DropField(); - return PM3_ESOFT; + return PM3_ESOFT; } PrintAndLogEx(INFO, "getting updated card details..."); diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index e9aaa1880..782e782eb 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -427,7 +427,7 @@ static void fuse_config(const picopass_hdr *hdr) { uint16_t otp = (hdr->conf.otp[1] << 8 | hdr->conf.otp[0]); - PrintAndLogEx(INFO, " Raw: " _YELLOW_("%s"), sprint_hex((uint8_t*)&hdr->conf, 8)); + PrintAndLogEx(INFO, " Raw: " _YELLOW_("%s"), sprint_hex((uint8_t *)&hdr->conf, 8)); PrintAndLogEx(INFO, " " _YELLOW_("%02X") "..................... app limit", hdr->conf.app_limit); PrintAndLogEx(INFO, " " _YELLOW_("%04X") " ( %5u )...... OTP", otp, otp); PrintAndLogEx(INFO, " " _YELLOW_("%02X") "............ block write lock", hdr->conf.block_writelock); @@ -1540,7 +1540,7 @@ static int CmdHFiClassDump(const char *Cmd) { PrintAndLogEx(SUCCESS, "Using " _YELLOW_("replay NR/MAC mode")); use_replay = true; cmdp++; - break; + break; default: PrintAndLogEx(WARNING, "Unknown parameter '%c'\n", param_getchar(Cmd, cmdp)); errors = true; @@ -1552,7 +1552,7 @@ static int CmdHFiClassDump(const char *Cmd) { PrintAndLogEx(FAILED, "Can not use a combo of 'e', 'r', 'n'"); errors = true; } - + if (errors) return usage_hf_iclass_dump(); uint32_t flags = (FLAG_ICLASS_READER_INIT | FLAG_ICLASS_READER_CLEARTRACE); @@ -1788,7 +1788,7 @@ write_dump: } static int iclass_write_block(uint8_t blockno, uint8_t *bldata, uint8_t *KEY, bool use_credit_key, bool elite, bool rawkey, bool replay, bool verbose) { - + iclass_writeblock_req_t payload = { .req.use_raw = rawkey, .req.use_elite = elite, @@ -1882,13 +1882,13 @@ static int CmdHFiClass_WriteBlock(const char *Cmd) { rawkey = true; cmdp++; break; -/* - case 'n': - PrintAndLogEx(SUCCESS, "Using " _YELLOW_("replay NR/MAC mode")); - use_replay = true; - cmdp++; - break; -*/ + /* + case 'n': + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("replay NR/MAC mode")); + use_replay = true; + cmdp++; + break; + */ case 'v': verbose = true; cmdp++; @@ -1910,7 +1910,7 @@ static int CmdHFiClass_WriteBlock(const char *Cmd) { if (errors || cmdp < 6) return usage_hf_iclass_writeblock(); int isok = iclass_write_block(blockno, bldata, KEY, use_credit_key, elite, rawkey, use_replay, verbose); - switch(isok) { + switch (isok) { case PM3_SUCCESS: PrintAndLogEx(SUCCESS, "Wrote block %02X successful", blockno); break; @@ -2043,24 +2043,24 @@ static int CmdHFiClassRestore(const char *Cmd) { return PM3_EFILE; } - if (bytes_read < ((endblock - startblock + 1) * 8 )) { + if (bytes_read < ((endblock - startblock + 1) * 8)) { PrintAndLogEx(ERR, "file is smaller than your suggested block range ( " _RED_("0x%02x..0x%02x")" )", - startblock, endblock - ); + startblock, endblock + ); free(dump); return PM3_EFILE; } iclass_restore_req_t *payload = calloc(1, payload_size); payload->req.use_raw = rawkey, - payload->req.use_elite = elite, - payload->req.use_credit_key = use_credit_key, - payload->req.use_replay = false, - payload->req.blockno = startblock, - payload->req.send_reply = true, - payload->req.do_auth = true, - memcpy(payload->req.key, KEY, 8); - + payload->req.use_elite = elite, + payload->req.use_credit_key = use_credit_key, + payload->req.use_replay = false, + payload->req.blockno = startblock, + payload->req.send_reply = true, + payload->req.do_auth = true, + memcpy(payload->req.key, KEY, 8); + payload->item_cnt = (endblock - startblock + 1); // read data from file from block 6 --- 19 @@ -2068,21 +2068,21 @@ static int CmdHFiClassRestore(const char *Cmd) { // then copy to usbcommand->asbytes; // max is 32 - 6 = 28 block. 28 x 12 bytes gives 336 bytes - for (uint8_t i = 0; i < payload->item_cnt; i++) { + for (uint8_t i = 0; i < payload->item_cnt; i++) { payload->blocks[i].blockno = startblock + i; - memcpy(payload->blocks[i].data, dump + (startblock * 8) + (i * 8) , sizeof(payload->blocks[i].data)); + memcpy(payload->blocks[i].data, dump + (startblock * 8) + (i * 8), sizeof(payload->blocks[i].data)); } free(dump); if (verbose) { PrintAndLogEx(INFO, "Preparing to restore block range 0x%02x..0x%02x", startblock, endblock); - + PrintAndLogEx(INFO, "------+----------------------"); PrintAndLogEx(INFO, "block | data"); PrintAndLogEx(INFO, "------+----------------------"); - for (uint8_t i = 0; i < payload->item_cnt; i++) { + for (uint8_t i = 0; i < payload->item_cnt; i++) { iclass_restore_item_t item = payload->blocks[i]; PrintAndLogEx(INFO, " %02X | %s", item.blockno, sprint_hex_inrow(item.data, sizeof(item.data))); } @@ -2233,7 +2233,7 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) { } if (got_blockno == false) errors = true; - + if ((use_replay + rawkey + elite) > 1) { PrintAndLogEx(FAILED, "Can not use a combo of 'e', 'r', 'n'"); errors = true; @@ -2405,7 +2405,7 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e PrintAndLogEx(INFO, " blk| data | ascii |lck| info"); PrintAndLogEx(INFO, "----+-------------------------+----------+---+--------------"); PrintAndLogEx(INFO, "0x00| " _GREEN_("%s") " | | CSN ", sprint_hex_ascii(iclass_dump, 8)); - + if (i != 1) PrintAndLogEx(INFO, "...."); @@ -2455,8 +2455,8 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e const char *s = info_nonks[3]; if (i < 3) { s = info_nonks[i]; - } - + } + PrintAndLogEx(INFO, "0x%02X| %s | %s | %s ", i, sprint_hex_ascii(blk, 8), lockstr, s); } else { const char *info_ks[] = {"CSN", "Config", "E-purse", "Debit", "Credit", "AIA", "User"}; @@ -2978,8 +2978,8 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { free(keyBlock); return res; } - - // Get CSN / UID and CCNR + + // Get CSN / UID and CCNR PrintAndLogEx(SUCCESS, "Reading tag CSN / CCNR..."); for (uint8_t i = 0; i < ICLASS_AUTH_RETRY && !got_csn; i++) { got_csn = select_only(CSN, CCNR, false); @@ -2993,7 +2993,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { DropField(); return PM3_ESOFT; } - + iclass_premac_t *pre = calloc(keycount, sizeof(iclass_premac_t)); if (pre == NULL) { return PM3_EMALLOC; @@ -3449,7 +3449,7 @@ static int CmdHFiClassAutopwn(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); - + // Check keys. // dump diff --git a/client/src/cmdhfmfp.c b/client/src/cmdhfmfp.c index 7d9c077fb..fd0f6c93a 100644 --- a/client/src/cmdhfmfp.c +++ b/client/src/cmdhfmfp.c @@ -294,9 +294,9 @@ static int CmdHFMFPInfo(const char *Cmd) { } else { // info about 14a part infoHF14A(false, false, false); - + // Historical bytes. - + } diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index c472b8d59..55e03a848 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -242,7 +242,7 @@ static int usage_hf_mfu_otp_tearoff(void) { PrintAndLogEx(NORMAL, " s