From 9c2ef4e0da09e8f13830ac292526064c34b98630 Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Sat, 26 Oct 2019 13:17:33 +1100 Subject: [PATCH 01/16] 2nd Win10 Color Reg. Key Check --- client/proxmark3.c | 29 +++++++++++++++++-- .../Windows-Installation-Instructions.md | 10 ++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index fde2af91e..53ce6e203 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -473,11 +473,16 @@ finish2: // Check if windows AnsiColor Support is enabled in the registery // [HKEY_CURRENT_USER\Console] // "VirtualTerminalLevel"=dword:00000001 +// 2nd Key needs to be enabled... This key takes the console out of legacy mode. +// [HKEY_CURRENT_USER\Console] +// "ForceV2"=dword:00000001 static bool DetectWindowsAnsiSupport(void) { bool ret = false; #if defined(_WIN32) HKEY hKey = NULL; - + bool virtualTerminalLevelSet = false; + bool forceV2Set = false; + if (RegOpenKeyA(HKEY_CURRENT_USER, "Console", &hKey) == ERROR_SUCCESS) { DWORD dwType = REG_SZ; BYTE KeyValue[sizeof(dwType)]; @@ -490,11 +495,31 @@ static bool DetectWindowsAnsiSupport(void) { Data += KeyValue[i] << (8 * i); if (Data == 1) { // Reg key is set to 1, Ansi Color Enabled - ret = true; + virtualTerminalLevelSet = true; } } RegCloseKey(hKey); } + + if (RegOpenKeyA(HKEY_CURRENT_USER, "Console", &hKey) == ERROR_SUCCESS) { + DWORD dwType = REG_SZ; + BYTE KeyValue[sizeof(dwType)]; + DWORD len = sizeof(KeyValue); + + if (RegQueryValueEx(hKey, "ForceV2", NULL, &dwType, KeyValue, &len) != ERROR_FILE_NOT_FOUND) { + uint8_t i; + uint32_t Data = 0; + for (i = 0; i < 4; i++) + Data += KeyValue[i] << (8 * i); + + if (Data == 1) { // Reg key is set to 1, Not using legacy Mode. + forceV2Set = true; + } + } + RegCloseKey(hKey); + } + // If both VirtualTerminalLevel and ForceV2 is set, AnsiColor should work + ret = virtualTerminalLevelSet && forceV2Set; #endif return ret; } diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index dfbea55c4..d77a2dfae 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -135,4 +135,12 @@ In later versions of windows 10 you may be able to get color to work by setting [HKEY_CURRENT_USER\Console] "VirtualTerminalLevel"=dword:00000001 ``` -If after setting this key (and restarting proxmark3.exe) you get extra characters and no color text, either delete the key or set the value to 0 +You also need to disable "use legacy console" in the cmd.exe properties, or set the following registry key +``` +[HKEY_CURRENT_USER\Console] + "ForceV2"=dword:00000001 +``` +After making these changes, you will need to start a new command prompt (cmd.exe) to ensure its using the new settings. + +If after making these changes (and restarting proxmark3.exe) you get extra characters and no color text, set either key to 0 or enable legacy mode again (and restart the command prompt). + From c613a758b267679da57af9643594f527969ab52c Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 18:06:52 +0200 Subject: [PATCH 02/16] mfkey64: fix sscanf uint8_t clang warning --- tools/mfkey/mfkey64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mfkey/mfkey64.c b/tools/mfkey/mfkey64.c index dbf0bea9f..04126c7cf 100644 --- a/tools/mfkey/mfkey64.c +++ b/tools/mfkey/mfkey64.c @@ -38,7 +38,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < encc; i++) { enclen[i] = strlen(argv[i + 6]) / 2; for (int i2 = 0; i2 < enclen[i]; i2++) { - sscanf(argv[i + 6] + i2 * 2, "%2x", (unsigned int *)&enc[i][i2]); + sscanf(argv[i + 6] + i2 * 2, "%2hhx", &enc[i][i2]); } } From c6220dc7beac979b4479653a09f35f3cfecc0f42 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 18:32:17 +0200 Subject: [PATCH 03/16] fpga_compress: unused parameter warning --- tools/fpga_compress/fpga_compress.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/fpga_compress/fpga_compress.c b/tools/fpga_compress/fpga_compress.c index 2174571d6..56dab1865 100644 --- a/tools/fpga_compress/fpga_compress.c +++ b/tools/fpga_compress/fpga_compress.c @@ -53,11 +53,13 @@ static void usage(void) { static voidpf fpga_deflate_malloc(voidpf opaque, uInt items, uInt size) { + (void) opaque; return calloc(items * size, sizeof(uint8_t)); } static void fpga_deflate_free(voidpf opaque, voidpf address) { + (void) opaque; free(address); } From 5ef4d6dbbb0548de88c1f6a5a51f0ab17bd60469 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 18:32:38 +0200 Subject: [PATCH 04/16] fpga_compress: no previous prototype warning --- tools/fpga_compress/fpga_compress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/fpga_compress/fpga_compress.c b/tools/fpga_compress/fpga_compress.c index 56dab1865..0992c53ca 100644 --- a/tools/fpga_compress/fpga_compress.c +++ b/tools/fpga_compress/fpga_compress.c @@ -74,7 +74,7 @@ static bool all_feof(FILE *infile[], uint8_t num_infiles) { } -int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, bool hardnested_mode) { +static int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, bool hardnested_mode) { uint8_t *fpga_config; uint32_t i; int32_t ret; @@ -184,7 +184,7 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, bool hardn } -int zlib_decompress(FILE *infile, FILE *outfile) { +static int zlib_decompress(FILE *infile, FILE *outfile) { #define DECOMPRESS_BUF_SIZE 1024 uint8_t outbuf[DECOMPRESS_BUF_SIZE]; uint8_t inbuf[DECOMPRESS_BUF_SIZE]; From c523980d99689e91bf0f66e4bc4c1b89c7ce6f01 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 18:34:04 +0200 Subject: [PATCH 05/16] zlib: enumeration values not explicitly handled in switch warning --- common/zlib/inflate.h | 4 ++++ common/zlib/inftrees.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/common/zlib/inflate.h b/common/zlib/inflate.h index f48620e08..f91e0aa78 100644 --- a/common/zlib/inflate.h +++ b/common/zlib/inflate.h @@ -19,6 +19,7 @@ /* Possible inflate modes between inflate() calls */ typedef enum { HEAD = 16180, /* i: waiting for magic header */ +#ifdef GUNZIP FLAGS, /* i: waiting for method and flags (gzip) */ TIME, /* i: waiting for modification time (gzip) */ OS, /* i: waiting for extra flags and operating system (gzip) */ @@ -27,6 +28,7 @@ typedef enum { NAME, /* i: waiting for end of file name (gzip) */ COMMENT, /* i: waiting for end of comment (gzip) */ HCRC, /* i: waiting for header crc (gzip) */ +#endif DICTID, /* i: waiting for dictionary check value */ DICT, /* waiting for inflateSetDictionary() call */ TYPE, /* i: waiting for type bits, including last-flag bit */ @@ -45,7 +47,9 @@ typedef enum { MATCH, /* o: waiting for output space to copy string */ LIT, /* o: waiting for output space to write literal */ CHECK, /* i: waiting for 32-bit check value */ +#ifdef GUNZIP LENGTH, /* i: waiting for 32-bit length (gzip) */ +#endif DONE, /* finished check, done -- remain here until reset */ BAD, /* got a data error -- remain here until reset */ MEM, /* got an inflate() memory error -- remain here until reset */ diff --git a/common/zlib/inftrees.c b/common/zlib/inftrees.c index 49672650c..3dae7e534 100644 --- a/common/zlib/inftrees.c +++ b/common/zlib/inftrees.c @@ -191,7 +191,8 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, extra = lext; match = 257; break; - default: /* DISTS */ + case DISTS: + default: base = dbase; extra = dext; match = 0; From a869ae9687839b08a44c2ec25ea92f424db34e6b Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 18:34:25 +0200 Subject: [PATCH 06/16] zlib: unused parameter warning --- common/zlib/trees.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/zlib/trees.c b/common/zlib/trees.c index 8d230426e..1ef49d00d 100644 --- a/common/zlib/trees.c +++ b/common/zlib/trees.c @@ -923,6 +923,10 @@ charf *buf; /* input block, or NULL if too old */ ulg stored_len; /* length of input block */ int last; /* one if this is the last block for a file */ { +#ifdef ZLIB_PM3_TUNED + (void) buf; + (void) stored_len; +#endif int max_blindex = 0; /* index of last bit length code of non zero freq */ #ifndef ZLIB_PM3_TUNED ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ From af75c70c2735010a460462e8576dce13c1750493 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 18:49:25 +0200 Subject: [PATCH 07/16] wiegand: no previous prototype warnings --- client/proxmark3.c | 2 +- client/wiegand_formats.c | 72 ++++++++++++++++++++-------------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index 53ce6e203..91d130fb2 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -90,7 +90,7 @@ static FILE *current_cmdscriptfile() { return cmdscriptfile[cmdscriptfile_idx]; } -bool pop_cmdscriptfile() { +static bool pop_cmdscriptfile() { fclose(cmdscriptfile[cmdscriptfile_idx]); cmdscriptfile[cmdscriptfile_idx--] = NULL; if (cmdscriptfile_idx == 0) diff --git a/client/wiegand_formats.c b/client/wiegand_formats.c index 613f68e20..a535bc614 100644 --- a/client/wiegand_formats.c +++ b/client/wiegand_formats.c @@ -10,7 +10,7 @@ #include "wiegand_formats.h" #include "commonutil.h" -bool Pack_H10301(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_H10301(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0xFF) return false; // Can't encode FC. @@ -26,7 +26,7 @@ bool Pack_H10301(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_H10301(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_H10301(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 26) return false; // Wrong length? Stop here. @@ -38,7 +38,7 @@ bool Unpack_H10301(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_Tecom27(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_Tecom27(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0x7FF) return false; // Can't encode FC. @@ -52,7 +52,7 @@ bool Pack_Tecom27(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_Tecom27(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_Tecom27(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 27) return false; // Wrong length? Stop here. @@ -62,7 +62,7 @@ bool Unpack_Tecom27(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_2804W(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_2804W(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0x0FF) return false; // Can't encode FC. @@ -85,7 +85,7 @@ bool Pack_2804W(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_2804W(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_2804W(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 28) return false; // Wrong length? Stop here. @@ -99,7 +99,7 @@ bool Unpack_2804W(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_ATSW30(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_ATSW30(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0xFFF) return false; // Can't encode FC. @@ -119,7 +119,7 @@ bool Pack_ATSW30(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_ATSW30(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_ATSW30(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 30) return false; // Wrong length? Stop here. @@ -132,7 +132,7 @@ bool Unpack_ATSW30(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_ADT31(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_ADT31(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0x0F) return false; // Can't encode FC. @@ -147,7 +147,7 @@ bool Pack_ADT31(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_ADT31(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_ADT31(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 31) return false; // Wrong length? Stop here. @@ -156,7 +156,7 @@ bool Unpack_ADT31(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_Kastle(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_Kastle(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0x00FF) return false; // Can't encode FC. @@ -174,7 +174,7 @@ bool Pack_Kastle(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_Kastle(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_Kastle(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 32) return false; // Wrong length? Stop here. @@ -189,7 +189,7 @@ bool Unpack_Kastle(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_D10202(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_D10202(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0x007F) return false; // Can't encode FC. @@ -205,7 +205,7 @@ bool Pack_D10202(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_D10202(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_D10202(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 33) return false; // Wrong length? Stop here. @@ -218,7 +218,7 @@ bool Unpack_D10202(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_H10306(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_H10306(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0xFFFF) return false; // Can't encode FC. @@ -235,7 +235,7 @@ bool Pack_H10306(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_H10306(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_H10306(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 34) return false; // Wrong length? Stop here. @@ -248,7 +248,7 @@ bool Unpack_H10306(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_N10002(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_N10002(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0xFF) return false; // Can't encode FC. @@ -262,7 +262,7 @@ bool Pack_N10002(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_N10002(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_N10002(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 34) return false; // Wrong length? Stop here. @@ -272,7 +272,7 @@ bool Unpack_N10002(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_C1k35s(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_C1k35s(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0xFFF) return false; // Can't encode FC. @@ -290,7 +290,7 @@ bool Pack_C1k35s(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_C1k35s(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_C1k35s(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 35) return false; // Wrong length? Stop here. @@ -304,7 +304,7 @@ bool Unpack_C1k35s(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_H10320(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_H10320(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0) return false; // Can't encode FC. (none in this format) @@ -332,7 +332,7 @@ bool Pack_H10320(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_H10320(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_H10320(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 36) return false; // Wrong length? Stop here. @@ -356,7 +356,7 @@ bool Unpack_H10320(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_S12906(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_S12906(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0xFF) return false; // Can't encode FC. @@ -373,7 +373,7 @@ bool Pack_S12906(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_S12906(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_S12906(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 36) return false; // Wrong length? Stop here. @@ -387,7 +387,7 @@ bool Unpack_S12906(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_Sie36(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_Sie36(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0x0003FFFF) return false; // Can't encode FC. @@ -407,7 +407,7 @@ bool Pack_Sie36(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_Sie36(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_Sie36(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 36) return false; // Wrong length? Stop here. @@ -420,7 +420,7 @@ bool Unpack_Sie36(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_C15001(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_C15001(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0x000000FF) return false; // Can't encode FC. @@ -437,7 +437,7 @@ bool Pack_C15001(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_C15001(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_C15001(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 36) return false; // Wrong length? Stop here. @@ -451,7 +451,7 @@ bool Unpack_C15001(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_H10302(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_H10302(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0) return false; // Can't encode FC. (none in this format) @@ -466,7 +466,7 @@ bool Pack_H10302(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_H10302(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_H10302(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 37) return false; // Wrong length? Stop here. @@ -478,7 +478,7 @@ bool Unpack_H10302(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_H10304(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_H10304(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); if (card->FacilityCode > 0x0000FFFF) return false; // Can't encode FC. @@ -495,7 +495,7 @@ bool Pack_H10304(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_H10304(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_H10304(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 37) return false; // Wrong length? Stop here. @@ -508,7 +508,7 @@ bool Unpack_H10304(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_P10001(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_P10001(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); @@ -530,7 +530,7 @@ bool Pack_P10001(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_P10001(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_P10001(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); @@ -547,7 +547,7 @@ bool Unpack_P10001(wiegand_message_t *packed, wiegand_card_t *card) { return true; } -bool Pack_C1k48s(wiegand_card_t *card, wiegand_message_t *packed) { +static bool Pack_C1k48s(wiegand_card_t *card, wiegand_message_t *packed) { memset(packed, 0, sizeof(wiegand_message_t)); @@ -566,7 +566,7 @@ bool Pack_C1k48s(wiegand_card_t *card, wiegand_message_t *packed) { return add_HID_header(packed); } -bool Unpack_C1k48s(wiegand_message_t *packed, wiegand_card_t *card) { +static bool Unpack_C1k48s(wiegand_message_t *packed, wiegand_card_t *card) { memset(card, 0, sizeof(wiegand_card_t)); if (packed->Length != 48) return false; // Wrong length? Stop here. From 129b1c4b1f7a2c65587aabed546e68de227b43d3 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 18:56:36 +0200 Subject: [PATCH 08/16] make sure all .c include their own .h --- armsrc/{fonts.c => fonts_disabled.c} | 2 ++ armsrc/{fonts.h => fonts_disabled.h} | 0 armsrc/hfsnoop.c | 1 + armsrc/legicrfsim.c | 1 + client/loclass/hash1_brute.c | 3 ++- 5 files changed, 6 insertions(+), 1 deletion(-) rename armsrc/{fonts.c => fonts_disabled.c} (99%) rename armsrc/{fonts.h => fonts_disabled.h} (100%) diff --git a/armsrc/fonts.c b/armsrc/fonts_disabled.c similarity index 99% rename from armsrc/fonts.c rename to armsrc/fonts_disabled.c index 78b96e238..97079f48a 100644 --- a/armsrc/fonts.c +++ b/armsrc/fonts_disabled.c @@ -6,6 +6,8 @@ // Fonts for the LCD //----------------------------------------------------------------------------- +#include "fonts.h" + const char FONT6x8[97][8] = { {0x06, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00}, // columns, rows, bytes per char {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // space diff --git a/armsrc/fonts.h b/armsrc/fonts_disabled.h similarity index 100% rename from armsrc/fonts.h rename to armsrc/fonts_disabled.h diff --git a/armsrc/hfsnoop.c b/armsrc/hfsnoop.c index 994d76e51..2c96ec218 100644 --- a/armsrc/hfsnoop.c +++ b/armsrc/hfsnoop.c @@ -1,3 +1,4 @@ +#include "hfsnoop.h" #include "proxmark3_arm.h" #include "BigBuf.h" #include "fpgaloader.h" diff --git a/armsrc/legicrfsim.c b/armsrc/legicrfsim.c index 111c4940b..34f8458ce 100644 --- a/armsrc/legicrfsim.c +++ b/armsrc/legicrfsim.c @@ -9,6 +9,7 @@ //----------------------------------------------------------------------------- // LEGIC RF simulation code //----------------------------------------------------------------------------- +#include "legicrfsim.h" #include "legicrf.h" #include "crc.h" /* legic crc-4 */ diff --git a/client/loclass/hash1_brute.c b/client/loclass/hash1_brute.c index 29430a2a6..e381c5a3a 100644 --- a/client/loclass/hash1_brute.c +++ b/client/loclass/hash1_brute.c @@ -1,3 +1,4 @@ +#include "hash1_brute.h" #include #include "cipherutils.h" #include @@ -54,7 +55,7 @@ static void calc_score(uint8_t *csn, uint8_t *k) { } } -static void brute_hash1(void) { +void brute_hash1(void) { uint16_t a, b, c, d; uint8_t csn[8] = {0, 0, 0, 0, 0xf7, 0xff, 0x12, 0xe0}; uint8_t k[8] = {0, 0, 0, 0, 0, 0, 0, 0}; From d5a68ac2922173be8a0824f0e1f01c0b6819804f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 19:37:36 +0200 Subject: [PATCH 09/16] check_crc: add CRC_KERMIT --- common/crc16.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/crc16.c b/common/crc16.c index 729c15cf4..57b984773 100644 --- a/common/crc16.c +++ b/common/crc16.c @@ -230,7 +230,7 @@ uint16_t Crc16ex(CrcType_t ct, const uint8_t *d, size_t n) { // n length (including crc) // // This function uses the message + crc bytes in order to compare the "residue" afterwards. -// crc16 algos like CRC-A become 0x000 +// crc16 algos like CRC-A become 0x0000 // while CRC-15693 become 0x0F47 // If calculated with crc bytes, the residue should be 0xF0B8 bool check_crc(CrcType_t ct, const uint8_t *d, size_t n) { @@ -254,6 +254,8 @@ bool check_crc(CrcType_t ct, const uint8_t *d, size_t n) { return (crc16_xmodem(d, n) == 0); case CRC_CCITT: return (crc16_ccitt(d, n) == 0); + case CRC_KERMIT: + return (crc16_kermit(d, n) == 0); case CRC_LEGIC: // TODO return false; From 11b954b6bdbcd7beb6d9e6344e654f8c0dc6779a Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 19:40:32 +0200 Subject: [PATCH 10/16] proxmark.c: warnings discarded qualifiers --- client/proxmark3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index 91d130fb2..c1d6a5dc7 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -151,7 +151,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { // loops every time enter is pressed... while (1) { bool printprompt = false; - char *prompt = PROXPROMPT; + const char *prompt = PROXPROMPT; check_script: // If there is a script file @@ -321,7 +321,7 @@ static void set_my_executable_path(void) { } } -static char *my_user_directory = NULL; +static const char *my_user_directory = NULL; const char *get_my_user_directory(void) { return my_user_directory; From cc902fb4d85ef4523f881cb98c644621df6ca778 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 19:40:59 +0200 Subject: [PATCH 11/16] ui.c: warnings discarded qualifiers --- client/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ui.c b/client/ui.c index d12713b9b..0cd2c589a 100644 --- a/client/ui.c +++ b/client/ui.c @@ -134,7 +134,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) { char *token = NULL; char *tmp_ptr = NULL; FILE *stream = stdout; - char *spinner[] = {_YELLOW_("[\\]"), _YELLOW_("[|]"), _YELLOW_("[/]"), _YELLOW_("[-]")}; + const char *spinner[] = {_YELLOW_("[\\]"), _YELLOW_("[|]"), _YELLOW_("[/]"), _YELLOW_("[-]")}; switch (level) { case ERR: strncpy(prefix, _RED_("[!!]"), sizeof(prefix) - 1); From c084862e07c64a6b968b68b5ab3521dd1b5bf8e2 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 19:41:30 +0200 Subject: [PATCH 12/16] crc16: all enumerates in switch --- common/crc16.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/crc16.c b/common/crc16.c index 57b984773..22445beda 100644 --- a/common/crc16.c +++ b/common/crc16.c @@ -218,6 +218,7 @@ uint16_t Crc16ex(CrcType_t ct, const uint8_t *d, size_t n) { case CRC_LEGIC: // TODO return 0; + case CRC_NONE: default: break; } @@ -259,6 +260,7 @@ bool check_crc(CrcType_t ct, const uint8_t *d, size_t n) { case CRC_LEGIC: // TODO return false; + case CRC_NONE: default: break; } From 6c048c5026b2deaaf0a377658542227974e71b1f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 19:49:46 +0200 Subject: [PATCH 13/16] comms.c dl_it: remove unused arg --- client/comms.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/comms.c b/client/comms.c index 1ccdb4d05..d39680c6c 100644 --- a/client/comms.c +++ b/client/comms.c @@ -60,7 +60,7 @@ static uint64_t timeout_start_time; static uint64_t last_packet_time; -static bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, PacketResponseNG *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd); +static bool dl_it(uint8_t *dest, uint32_t bytes, PacketResponseNG *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd); // Simple alias to track usages linked to the Bootloader, these commands must not be migrated. // - commands sent to enter bootloader mode as we might have to talk to old firmwares @@ -778,30 +778,30 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3 switch (memtype) { case BIG_BUF: { SendCommandMIX(CMD_DOWNLOAD_BIGBUF, start_index, bytes, 0, NULL, 0); - return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_BIGBUF); + return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_DOWNLOADED_BIGBUF); } case BIG_BUF_EML: { SendCommandMIX(CMD_DOWNLOAD_EML_BIGBUF, start_index, bytes, 0, NULL, 0); - return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_EML_BIGBUF); + return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_DOWNLOADED_EML_BIGBUF); } case SPIFFS: { SendCommandMIX(CMD_SPIFFS_DOWNLOAD, start_index, bytes, 0, data, datalen); - return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_SPIFFS_DOWNLOADED); + return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_SPIFFS_DOWNLOADED); } case FLASH_MEM: { SendCommandMIX(CMD_FLASHMEM_DOWNLOAD, start_index, bytes, 0, NULL, 0); - return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_FLASHMEM_DOWNLOADED); + return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_FLASHMEM_DOWNLOADED); } case SIM_MEM: { //SendCommandMIX(CMD_DOWNLOAD_SIM_MEM, start_index, bytes, 0, NULL, 0); - //return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_SIMMEM); + //return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_DOWNLOADED_SIMMEM); return false; } } return false; } -static bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, PacketResponseNG *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd) { +static bool dl_it(uint8_t *dest, uint32_t bytes, PacketResponseNG *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd) { uint32_t bytes_completed = 0; __atomic_store_n(&timeout_start_time, msclock(), __ATOMIC_SEQ_CST); From 900184b600629f0edd528bd8ba77cb06794eb91a Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 26 Oct 2019 20:37:48 +0200 Subject: [PATCH 14/16] ikeys: "declaration shadows a variable in the global scope" warning --- client/loclass/ikeys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/loclass/ikeys.c b/client/loclass/ikeys.c index 2f3a6c067..339ea91f7 100644 --- a/client/loclass/ikeys.c +++ b/client/loclass/ikeys.c @@ -422,7 +422,7 @@ typedef struct { uint8_t div_key[8]; } Testcase; -static int testDES(Testcase testcase, mbedtls_des_context ctx_enc, mbedtls_des_context ctx_dec) { +static int testDES(Testcase testcase) { uint8_t des_encrypted_csn[8] = {0}; uint8_t decrypted[8] = {0}; uint8_t div_key[8] = {0}; @@ -562,7 +562,7 @@ static int testKeyDiversificationWithMasterkeyTestcases() { PrintAndLogEx(INFO, "Testing encryption/decryption"); for (i = 0; memcmp(testcases + i, empty, 8); i++) - error += testDES(testcases[i], ctx_enc, ctx_dec); + error += testDES(testcases[i]); if (error) PrintAndLogEx(FAILED, "%d errors occurred (%d testcases)", error, i); From 377ead8e62a539203ec500fa13c21a05984eae31 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 27 Oct 2019 00:31:37 +0200 Subject: [PATCH 15/16] arm: honor CFLAGS and LDFLAGS --- common_arm/Makefile.common | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common_arm/Makefile.common b/common_arm/Makefile.common index 52ec2ebd2..586901354 100644 --- a/common_arm/Makefile.common +++ b/common_arm/Makefile.common @@ -39,8 +39,10 @@ VPATH = . ../common_arm ../common ../common/crapto1 ../common/mbedtls ../common/ INCLUDES = ../include/proxmark3_arm.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/pm3_cmd.h -CFLAGS = -c $(INCLUDE) -Wall -Werror -pedantic -Wunused -std=c99 $(APP_CFLAGS) -Os -LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-gc-sections -n +CFLAGS ?= -Wall -Werror -pedantic -Wunused -Os +CFLAGS += -c $(INCLUDE) -std=c99 $(APP_CFLAGS) + +LDFLAGS += -nostartfiles -nodefaultlibs -Wl,-gc-sections -n LIBS = -lgcc # Flags to generate temporary dependency files From 2a0bc9c07b39b8c5f0c5f612acdba0349af09d48 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 27 Oct 2019 01:28:07 +0200 Subject: [PATCH 16/16] arm: move mthumb-interwork to CFLAGS for clang compatibility --- common_arm/Makefile.common | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common_arm/Makefile.common b/common_arm/Makefile.common index 586901354..36887707c 100644 --- a/common_arm/Makefile.common +++ b/common_arm/Makefile.common @@ -39,7 +39,7 @@ VPATH = . ../common_arm ../common ../common/crapto1 ../common/mbedtls ../common/ INCLUDES = ../include/proxmark3_arm.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/pm3_cmd.h -CFLAGS ?= -Wall -Werror -pedantic -Wunused -Os +CFLAGS ?= -Wall -Werror -pedantic -Wunused -Os -mthumb-interwork CFLAGS += -c $(INCLUDE) -std=c99 $(APP_CFLAGS) LDFLAGS += -nostartfiles -nodefaultlibs -Wl,-gc-sections -n @@ -57,21 +57,21 @@ VERSIONOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(VERSIONSRC))) $(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) $(info [-] CC $<) - $(Q)$(CC) $(CFLAGS) $(DEPFLAGS) -mthumb -mthumb-interwork -o $@ $< + $(Q)$(CC) $(CFLAGS) $(DEPFLAGS) -mthumb -o $@ $< $(Q)$(POSTCOMPILE) $(ARMOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) $(info [-] CC $<) - $(Q)$(CC) $(CFLAGS) $(DEPFLAGS) -mthumb-interwork -o $@ $< + $(Q)$(CC) $(CFLAGS) $(DEPFLAGS) -o $@ $< $(Q)$(POSTCOMPILE) $(ASMOBJ): $(OBJDIR)/%.o: %.s $(info [-] CC $<) - $(Q)$(CC) $(CFLAGS) -mthumb-interwork -o $@ $< + $(Q)$(CC) $(CFLAGS) -o $@ $< $(VERSIONOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) $(info [-] CC $<) - $(Q)$(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $< + $(Q)$(CC) $(CFLAGS) -mthumb -o $@ $< # This objcopy call translates physical flash addresses to logical addresses # without touching start address or RAM addresses (.bss and .data sections)