From f8f135a3b723136615959e11065c74fb4c867c52 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 18 Dec 2023 10:11:11 +0100 Subject: [PATCH] style --- armsrc/Standalone/hf_unisniff.c | 32 ++--- client/src/cmdanalyse.c | 4 +- client/src/cmdhf14a.c | 2 +- client/src/cmdhflist.c | 244 ++++++++++++++++---------------- client/src/cmdhfmfp.c | 62 ++++---- client/src/cmdhw.c | 2 +- client/src/cmdlf.c | 22 +-- client/src/cmdtrace.c | 20 +-- client/src/mifare/mifare4.c | 14 +- client/src/pm3line_vocabulary.h | 1 + client/src/preferences.c | 8 +- client/src/preferences.h | 4 +- client/src/util.c | 6 +- common/generator.c | 4 +- common_arm/usb_cdc.c | 6 +- doc/commands.json | 34 +++-- doc/commands.md | 1 + 17 files changed, 240 insertions(+), 226 deletions(-) diff --git a/armsrc/Standalone/hf_unisniff.c b/armsrc/Standalone/hf_unisniff.c index 6d2a6ee54..e1882ba8c 100644 --- a/armsrc/Standalone/hf_unisniff.c +++ b/armsrc/Standalone/hf_unisniff.c @@ -151,20 +151,20 @@ void ModInfo(void) { } void RunMod(void) { - char *protocols[]=HF_UNISNIFF_PROTOCOLS; + char *protocols[] = HF_UNISNIFF_PROTOCOLS; uint8_t sniff_protocol, default_sniff_protocol; StandAloneMode(); Dbprintf(_YELLOW_("HF UNISNIFF started")); - for (sniff_protocol=0; sniff_protocol HF_UNISNIFF_CONFIG_SIZE) config_size = HF_UNISNIFF_CONFIG_SIZE; rdv40_spiffs_read_as_filetype(HF_UNISNIFF_CONFIG, (uint8_t *)config_buffer, - config_size, RDV40_SPIFFS_SAFETY_SAFE); + config_size, RDV40_SPIFFS_SAFETY_SAFE); // This parser is terrible but I think fairly memory efficient? Maybe better to use JSON? char *x = config_buffer; char *y = x; // strip out all the whitespace and Windows line-endings - do { + do { while (*y == 0x20 || *y == 0x09 || *y == 0x0D) { ++y; } @@ -197,10 +197,10 @@ void RunMod(void) { char *tag = strtok(config_buffer, "="); char *value = strtok(NULL, "\n"); if (tag != NULL && value != NULL) { - if (!strcmp(tag,"protocol")) { + if (!strcmp(tag, "protocol")) { // If we got a selection here, override compile-time selection uint8_t conf_protocol; - for (conf_protocol=0; conf_protocol= HF_UNISNIFF_PROTO_USER) sniff_protocol=0; + if (sniff_protocol >= HF_UNISNIFF_PROTO_USER) sniff_protocol = 0; SpinDelay(100); Dbprintf("Selected protocol: '%s'", protocols[sniff_protocol]); } else if (button_pressed == BUTTON_HOLD) { Dbprintf("Executing protocol %s", protocols[sniff_protocol]); - for (uint8_t i=0; i<4; i++) { - LED(15,0); + for (uint8_t i = 0; i < 4; i++) { + LED(15, 0); SpinDelay(100); LEDsoff(); SpinDelay(100); @@ -262,7 +262,7 @@ void RunMod(void) { } } - switch(sniff_protocol) { + switch (sniff_protocol) { case HF_UNISNIFF_PROTO_14a: SniffIso14443a(0); break; @@ -300,11 +300,11 @@ void RunMod(void) { sprintf(filename, "%s_%s%s", HF_UNISNIFF_LOGFILE, protocols[sniff_protocol], HF_UNISNIFF_LOGEXT); if (save_mode == HF_UNISNIFF_SAVE_MODE_NEW) { - uint16_t file_index=0; + uint16_t file_index = 0; while (exists_in_spiffs(filename)) { if (file_index++ == 1000) break; sprintf(filename, "%s_%s-%03d%s", HF_UNISNIFF_LOGFILE, protocols[sniff_protocol], - file_index, HF_UNISNIFF_LOGEXT); + file_index, HF_UNISNIFF_LOGEXT); } if (file_index > 999) { Dbprintf("[!] Too many files! Trace not saved. Clean up your SPIFFS."); diff --git a/client/src/cmdanalyse.c b/client/src/cmdanalyse.c index a6a4b737c..780107953 100644 --- a/client/src/cmdanalyse.c +++ b/client/src/cmdanalyse.c @@ -970,8 +970,8 @@ static int CmdAnalyseFreq(const char *Cmd) { PrintAndLogEx(INFO, " 13.56 mHz has %f m, rf range %f m", len_1356, rf_range_1356); PrintAndLogEx(INFO, "Antenna lengths"); - PrintAndLogEx(INFO, " 125 kHz 1/2 = %f m, 1/4 = %f m", (len_125 / 2), (len_125 / 4) ); - PrintAndLogEx(INFO, " 134 kHz 1/2 = %f m, 1/4 = %f m", (len_134 / 2), (len_134 / 4) ); + PrintAndLogEx(INFO, " 125 kHz 1/2 = %f m, 1/4 = %f m", (len_125 / 2), (len_125 / 4)); + PrintAndLogEx(INFO, " 134 kHz 1/2 = %f m, 1/4 = %f m", (len_134 / 2), (len_134 / 4)); PrintAndLogEx(INFO, " 13.56 mHz 1/2 = %f m, 1/4 = %f m", (len_1356 / 2), (len_1356 / 4)); diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index e99d709ac..5fe74d6b9 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -922,7 +922,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav uint8_t data[PM3_CMD_DATA_SIZE] = { 0x0a | gs_frames_num, 0x00}; gs_frames_num ^= 1; - int min = MIN( (PM3_CMD_DATA_SIZE - 2), (datainlen & 0x1FF)); + int min = MIN((PM3_CMD_DATA_SIZE - 2), (datainlen & 0x1FF)); memcpy(&data[2], datain, min); SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | cmdc, (datainlen & 0xFFFF) + 2, 0, data, min + 2); diff --git a/client/src/cmdhflist.c b/client/src/cmdhflist.c index ccedc5c66..aaecb3e52 100644 --- a/client/src/cmdhflist.c +++ b/client/src/cmdhflist.c @@ -1332,54 +1332,54 @@ void annotateMfPlus(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) { if (data_size > 1) { // key : uint16_t uKeyNum = 0x4000 + sectorNum * 2 + (keyB ? 1 : 0); uint16_t uKeyNum = MemLeToUint2byte(data); - switch (uKeyNum & 0xf000){ - const char* stringdata; - default: - stringdata = "FIRST AUTH (Keynr 0x%04X: Key not identified)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uKeyNum); - break; - case 0x4000: - snprintf(exp, size, "FIRST AUTH (Keynr 0x%04X: %c sector %d)", uKeyNum, uKeyNum & 0x0001 ? 'B' : 'A', (uKeyNum - 0x4000) / 2); - break; - case 0xA000: // There are virtual card encryption and MACing keys, but this is NOT their place! - stringdata = "FIRST AUTH(Keynr 0x%04X: Proximity Check Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uKeyNum); - break; - case 0x9000: - switch (uKeyNum & 0xf){ - case 0x0: - stringdata = "FIRST AUTH (Keynr 0x%04X: Card Master Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uKeyNum); - break; - case 0x1: - stringdata = "FIRST AUTH (Keynr 0x%04X: Card Configuration Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uKeyNum); - break; - case 0x2: - stringdata = "FIRST AUTH(Keynr 0x%04X: SL2 Switch Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uKeyNum); - break; - case 0x3: - stringdata = "FIRST AUTH(Keynr 0x%04X: SL3 Switch Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uKeyNum); - break; - case 0x4: - stringdata = "FIRST AUTH(Keynr 0x%04X: SL1 Additional Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uKeyNum); - break; - case 0x6: - stringdata = "FIRST AUTH(Keynr 0x%04X: SL3 Sector Switch Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uKeyNum); - break; - case 0x7: - stringdata = "FIRST AUTH(Keynr 0x%04X: SL1SL3Mix Sector Switch Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uKeyNum); - break; - default: - stringdata = "FIRST AUTH(Keynr 0x%04X: Management Key not identified)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uKeyNum); - break; - } + switch (uKeyNum & 0xf000) { + const char *stringdata; + default: + stringdata = "FIRST AUTH (Keynr 0x%04X: Key not identified)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uKeyNum); + break; + case 0x4000: + snprintf(exp, size, "FIRST AUTH (Keynr 0x%04X: %c sector %d)", uKeyNum, uKeyNum & 0x0001 ? 'B' : 'A', (uKeyNum - 0x4000) / 2); + break; + case 0xA000: // There are virtual card encryption and MACing keys, but this is NOT their place! + stringdata = "FIRST AUTH(Keynr 0x%04X: Proximity Check Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uKeyNum); + break; + case 0x9000: + switch (uKeyNum & 0xf) { + case 0x0: + stringdata = "FIRST AUTH (Keynr 0x%04X: Card Master Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uKeyNum); + break; + case 0x1: + stringdata = "FIRST AUTH (Keynr 0x%04X: Card Configuration Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uKeyNum); + break; + case 0x2: + stringdata = "FIRST AUTH(Keynr 0x%04X: SL2 Switch Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uKeyNum); + break; + case 0x3: + stringdata = "FIRST AUTH(Keynr 0x%04X: SL3 Switch Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uKeyNum); + break; + case 0x4: + stringdata = "FIRST AUTH(Keynr 0x%04X: SL1 Additional Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uKeyNum); + break; + case 0x6: + stringdata = "FIRST AUTH(Keynr 0x%04X: SL3 Sector Switch Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uKeyNum); + break; + case 0x7: + stringdata = "FIRST AUTH(Keynr 0x%04X: SL1SL3Mix Sector Switch Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uKeyNum); + break; + default: + stringdata = "FIRST AUTH(Keynr 0x%04X: Management Key not identified)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uKeyNum); + break; + } } } else { snprintf(exp, size, "FIRST AUTH") ; @@ -1430,80 +1430,80 @@ void annotateMfPlus(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) { if (data_size > 1) { uint16_t uBlockNum = MemLeToUint2byte(data); - switch (uBlockNum & 0xF000){ - const char* stringdata; - default: - stringdata = "WRITE %s(%u) %s"; - snprintf(exp, size, stringdata, encrypted, uBlockNum, responseMaced); - break; - case 0x4000: - snprintf(exp, size, "WRITE (Keynr 0x%04X: %c sector %d)", uBlockNum, uBlockNum & 0x0001 ? 'B' : 'A', (uBlockNum - 0x4000) / 2); - break; - case 0xA000: // There are virtual card encryption and MACing keys, but this is NOT their place! - stringdata = "WRITE(Keynr 0x%04X: Proximity Check Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - case 0xB000: - case 0x9000: - if ((uBlockNum & 0x2000) == 0x2000){ - switch (uBlockNum & 0xf){ - default: - stringdata = "WRITE(Config %04X: Unidentified)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - case 0x0: - stringdata = "WRITE(Config %04X: Config)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - case 0x1: - stringdata = "WRITE(Config %04X: Virtual Card Installation ID)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - case 0x2: - stringdata = "WRITE(Config %04X: ATS)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - case 0x3: - stringdata = "WRITE(Config %04X: Field configuration)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - } - } else { - switch (uBlockNum & 0xf){ - default: - stringdata = "WRITE(Keynr 0x%04X: Management Key not identified)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - case 0x0: - stringdata = "WRITE(Keynr 0x%04X: Card Master Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - case 0x1: - stringdata = "WRITE(Keynr 0x%04X: Card Configuration Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - case 0x2: - stringdata = "WRITE(Keynr 0x%04X: SL2 Switch Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - case 0x3: - stringdata = "WRITE(Keynr 0x%04X: SL3 Switch Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - case 0x4: - stringdata = "WRITE(Keynr 0x%04X: SL1 Additional Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - case 0x6: - stringdata = "WRITE(Keynr 0x%04X: SL3 Sector Switch Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - case 0x7: - stringdata = "WRITE(Keynr 0x%04X: SL1SL3Mix Sector Switch Key)"; - snprintf(exp, strlen(stringdata)+1, stringdata, uBlockNum); - break; - } - } + switch (uBlockNum & 0xF000) { + const char *stringdata; + default: + stringdata = "WRITE %s(%u) %s"; + snprintf(exp, size, stringdata, encrypted, uBlockNum, responseMaced); + break; + case 0x4000: + snprintf(exp, size, "WRITE (Keynr 0x%04X: %c sector %d)", uBlockNum, uBlockNum & 0x0001 ? 'B' : 'A', (uBlockNum - 0x4000) / 2); + break; + case 0xA000: // There are virtual card encryption and MACing keys, but this is NOT their place! + stringdata = "WRITE(Keynr 0x%04X: Proximity Check Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + case 0xB000: + case 0x9000: + if ((uBlockNum & 0x2000) == 0x2000) { + switch (uBlockNum & 0xf) { + default: + stringdata = "WRITE(Config %04X: Unidentified)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + case 0x0: + stringdata = "WRITE(Config %04X: Config)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + case 0x1: + stringdata = "WRITE(Config %04X: Virtual Card Installation ID)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + case 0x2: + stringdata = "WRITE(Config %04X: ATS)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + case 0x3: + stringdata = "WRITE(Config %04X: Field configuration)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + } + } else { + switch (uBlockNum & 0xf) { + default: + stringdata = "WRITE(Keynr 0x%04X: Management Key not identified)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + case 0x0: + stringdata = "WRITE(Keynr 0x%04X: Card Master Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + case 0x1: + stringdata = "WRITE(Keynr 0x%04X: Card Configuration Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + case 0x2: + stringdata = "WRITE(Keynr 0x%04X: SL2 Switch Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + case 0x3: + stringdata = "WRITE(Keynr 0x%04X: SL3 Switch Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + case 0x4: + stringdata = "WRITE(Keynr 0x%04X: SL1 Additional Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + case 0x6: + stringdata = "WRITE(Keynr 0x%04X: SL3 Sector Switch Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + case 0x7: + stringdata = "WRITE(Keynr 0x%04X: SL1SL3Mix Sector Switch Key)"; + snprintf(exp, strlen(stringdata) + 1, stringdata, uBlockNum); + break; + } + } } } else { snprintf(exp, size, "WRITE %s %s ?", encrypted, responseMaced); diff --git a/client/src/cmdhfmfp.c b/client/src/cmdhfmfp.c index c8feeb044..868f65aab 100644 --- a/client/src/cmdhfmfp.c +++ b/client/src/cmdhfmfp.c @@ -681,28 +681,28 @@ static int CmdHFMFPAuth(const char *Cmd) { return MifareAuth4(NULL, keyn, key, true, false, true, verbose, false); } -static int data_crypt(mf4Session_t *mf4session, uint8_t *dati, uint8_t *dato, bool rev){ -uint8_t kenc[16]; - memcpy(kenc, mf4session->Kenc, 16); - uint8_t ti[4]; - memcpy(ti, mf4session->TI, 4); - uint8_t ctr[1]; - uint8_t IV[16] ={0,0,0x00,0x00,0x00,0,0x00,0x00,0x00,0}; - if (rev){ - ctr[0] = (uint8_t)(mf4session->R_Ctr & 0xff); - for (int i = 0; i<9; i+=4){memcpy(&IV[i], ctr, 1);} - memcpy(&IV[12], ti, 4); // For reads TI is LS - } else { - ctr[0] = (uint8_t)(mf4session->W_Ctr & 0xff); - for (int i = 3; i<16; i+=4){memcpy(&IV[i], ctr, 1);} - memcpy(&IV[0], ti, 4); // For writes TI is MS - } - if (rev){ - aes_decode(IV, kenc, dati, dato, 16); - } else { - aes_encode(IV, kenc, dati, dato, 16); - } - return 0; +static int data_crypt(mf4Session_t *mf4session, uint8_t *dati, uint8_t *dato, bool rev) { + uint8_t kenc[16]; + memcpy(kenc, mf4session->Kenc, 16); + uint8_t ti[4]; + memcpy(ti, mf4session->TI, 4); + uint8_t ctr[1]; + uint8_t IV[16] = {0, 0, 0x00, 0x00, 0x00, 0, 0x00, 0x00, 0x00, 0}; + if (rev) { + ctr[0] = (uint8_t)(mf4session->R_Ctr & 0xff); + for (int i = 0; i < 9; i += 4) {memcpy(&IV[i], ctr, 1);} + memcpy(&IV[12], ti, 4); // For reads TI is LS + } else { + ctr[0] = (uint8_t)(mf4session->W_Ctr & 0xff); + for (int i = 3; i < 16; i += 4) {memcpy(&IV[i], ctr, 1);} + memcpy(&IV[0], ti, 4); // For writes TI is MS + } + if (rev) { + aes_decode(IV, kenc, dati, dato, 16); + } else { + aes_encode(IV, kenc, dati, dato, 16); + } + return 0; } static int CmdHFMFPRdbl(const char *Cmd) { CLIParserContext *ctx; @@ -905,7 +905,7 @@ static int CmdHFMFPRdsc(const char *Cmd) { return PM3_ESOFT; } - if (datalen != 1 + MFBLOCK_SIZE + (nomacres? 0 : 8) + 2) { + if (datalen != 1 + MFBLOCK_SIZE + (nomacres ? 0 : 8) + 2) { PrintAndLogEx(ERR, "Error return length:%d", datalen); DropField(); return PM3_ESOFT; @@ -1097,14 +1097,14 @@ static int CmdHFMFPChKey(const char *Cmd) { } mf4Session_t mf4session; keyn[0] = ki[0]; - if (ki[0] == 0x40){ // Only if we are working with sector keys - if (usekeyb){ - keyn[1] = (ki[1] % 2 ==0) ? ki[1] + 1 : ki[1]; // If we change using key B, check if KI is key A - } else { - keyn[1] = (ki[1] % 2 ==0) ? ki[1] : ki[1] -1; // If we change using key A, check if KI is key A - } + if (ki[0] == 0x40) { // Only if we are working with sector keys + if (usekeyb) { + keyn[1] = (ki[1] % 2 == 0) ? ki[1] + 1 : ki[1]; // If we change using key B, check if KI is key A + } else { + keyn[1] = (ki[1] % 2 == 0) ? ki[1] : ki[1] - 1; // If we change using key A, check if KI is key A + } } else {keyn[1] = ki[1];} - if (verbose){ + if (verbose) { PrintAndLogEx(INFO, "--key index:", sprint_hex(keyn, 2)); } int res = MifareAuth4(&mf4session, keyn, key, true, true, true, verbose, false); @@ -1216,7 +1216,7 @@ static int CmdHFMFPChConf(const char *Cmd) { mf4Session_t mf4session; keyn[0] = 0x90; keyn[1] = usecck ? 0x01 : 0x00; - if (verbose){ + if (verbose) { PrintAndLogEx(INFO, "--key index:", sprint_hex(keyn, 2)); } int res = MifareAuth4(&mf4session, keyn, key, true, true, true, verbose, false); diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index 273ed384b..8c2757249 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -1142,7 +1142,7 @@ static command_t CommandTable[] = { {"-------------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Hardware") " -----------------------"}, {"help", CmdHelp, AlwaysAvailable, "This help"}, {"break", CmdBreak, IfPm3Present, "Send break loop usb command"}, - {"bootloader", CmdBootloader, IfPm3Present, "Reboot Proxmark3 into bootloader mode"}, + {"bootloader", CmdBootloader, IfPm3Present, "Reboot Proxmark3 into bootloader mode"}, {"connect", CmdConnect, AlwaysAvailable, "Connect Proxmark3 to serial port"}, {"dbg", CmdDbg, IfPm3Present, "Set Proxmark3 debug level"}, {"detectreader", CmdDetectReader, IfPm3Present, "Detect external reader field"}, diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 7f7c95edc..a097c19ac 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -1564,12 +1564,12 @@ static int check_autocorrelate(const char *prefix, int clock) { if (ans == -1) { continue; } - + if (ans > 1) { PrintAndLogEx(SUCCESS, " " _YELLOW_("%d") " repeating samples", ans); // If we got a field clock / bit rate from before - // we can use it for predict number of repeating bytes + // we can use it for predict number of repeating bytes // this signal contain. if (clock > 0) { int bytes = ans / (8 * clock); @@ -1586,7 +1586,7 @@ static int check_autocorrelate(const char *prefix, int clock) { return PM3_SUCCESS; } } - PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, ""); return PM3_EFAILED; } @@ -1915,7 +1915,7 @@ int CmdLFfind(const char *Cmd) { PrintAndLogEx(INFO, "FSK clock.......... " NOLF); int clock = GetFskClock("", false); if (clock) { - PrintAndLogEx(NORMAL, _GREEN_("detected")); + PrintAndLogEx(NORMAL, _GREEN_("detected")); if (FSKrawDemod(0, 0, 0, 0, true) == PM3_SUCCESS) { PrintAndLogEx(INFO, _GREEN_("FSK") " modulation detected!"); check_autocorrelate("FSK", clock); @@ -1927,9 +1927,9 @@ int CmdLFfind(const char *Cmd) { } } else { PrintAndLogEx(INFO, "FSK demodulation... " _RED_("failed")); - } + } } else { - PrintAndLogEx(NORMAL, _RED_("no")); + PrintAndLogEx(NORMAL, _RED_("no")); } // ASK @@ -1953,7 +1953,7 @@ int CmdLFfind(const char *Cmd) { PrintAndLogEx(INFO, "ASK demodulation... " _RED_("failed")); } } else { - PrintAndLogEx(NORMAL, _RED_("no")); + PrintAndLogEx(NORMAL, _RED_("no")); } // NZR @@ -1972,15 +1972,15 @@ int CmdLFfind(const char *Cmd) { } } else { PrintAndLogEx(INFO, "NRZ demodulation... " _RED_("failed")); - } + } } else { - PrintAndLogEx(NORMAL, _RED_("no")); + PrintAndLogEx(NORMAL, _RED_("no")); } // PSK PrintAndLogEx(INFO, "PSK clock.......... " NOLF); clock = GetPskClock("", false); - if (clock) { + if (clock) { PrintAndLogEx(NORMAL, _GREEN_("detected")); if (CmdPSK1rawDemod("") == PM3_SUCCESS) { PrintAndLogEx(INFO, "Possible " _GREEN_("PSK1") " modulation detected!"); @@ -1998,7 +1998,7 @@ int CmdLFfind(const char *Cmd) { PrintAndLogEx(INFO, "PSK demodulation... " _RED_("failed")); } } else { - PrintAndLogEx(NORMAL, _RED_("no")); + PrintAndLogEx(NORMAL, _RED_("no")); } if (found == 0) { diff --git a/client/src/cmdtrace.c b/client/src/cmdtrace.c index 8cc8795f3..c4d278c0a 100644 --- a/client/src/cmdtrace.c +++ b/client/src/cmdtrace.c @@ -927,16 +927,16 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr if (hdr->isResponse) { PrintAndLogEx(NORMAL, " | | * |%-*s | %-4s| %s", - str_padder, - sprint_hex_inrow_spaces(mfData + j, plen, 2), - (crcc == 0 ? _RED_(" !! ") : (crcc == 1 ? _GREEN_(" ok ") : " ")), - explanation); + str_padder, + sprint_hex_inrow_spaces(mfData + j, plen, 2), + (crcc == 0 ? _RED_(" !! ") : (crcc == 1 ? _GREEN_(" ok ") : " ")), + explanation); } else { PrintAndLogEx(NORMAL, " | | * |" _YELLOW_("%-*s")" | " _YELLOW_("%s") "| " _YELLOW_("%s"), - str_padder, - sprint_hex_inrow_spaces(mfData + j, plen, 2), - (crcc == 0 ? _RED_(" !! ") : (crcc == 1 ? _GREEN_(" ok ") : " ")), - explanation); + str_padder, + sprint_hex_inrow_spaces(mfData + j, plen, 2), + (crcc == 0 ? _RED_(" !! ") : (crcc == 1 ? _GREEN_(" ok ") : " ")), + explanation); } } } @@ -1106,7 +1106,7 @@ static int CmdTraceLoad(const char *Cmd) { if (gs_trace) { free(gs_trace); // maybe better to not clobber this until we have successful load? gs_trace = NULL; - gs_traceLen = 0; + gs_traceLen = 0; } size_t len = 0; @@ -1293,7 +1293,7 @@ int CmdTraceList(const char *Cmd) { if (use_buffer == false) { download_trace(); - } else if (gs_traceLen == 0 || gs_trace ==NULL) { + } else if (gs_traceLen == 0 || gs_trace == NULL) { PrintAndLogEx(FAILED, "You requested a trace list in offline mode but there is no trace."); PrintAndLogEx(FAILED, "Consider using " _YELLOW_("`trace load`") " or removing parameter " _YELLOW_("`-1`")); return PM3_EINVARG; diff --git a/client/src/mifare/mifare4.c b/client/src/mifare/mifare4.c index 8186b27d5..f7d9980a9 100644 --- a/client/src/mifare/mifare4.c +++ b/client/src/mifare/mifare4.c @@ -258,7 +258,7 @@ int MifareAuth4(mf4Session_t *mf4session, uint8_t *keyn, uint8_t *key, bool acti memmove(&raw[16], &RndB[1], 16); aes_encode(NULL, key, raw, &cmd2[1], 32); - if (verbose){ + if (verbose) { PrintAndLogEx(INFO, ">phase2: %s", sprint_hex(cmd2, 33)); } res = ExchangeRAW14a(cmd2, sizeof(cmd2), false, true, data, sizeof(data), &datalen, silentMode); @@ -374,16 +374,16 @@ int MFPCommitPerso(bool activateField, bool leaveSignalON, uint8_t *dataout, int int MFPReadBlock(mf4Session_t *mf4session, bool plain, bool nomaccmd, bool nomacres, uint8_t blockNum, uint8_t blockCount, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, uint8_t *mac) { int cmdb = 0x31; - if (nomacres){cmdb = cmdb ^ 0x01;} // If we do not want MAC in reply, remove 0x01 - if (plain){cmdb = cmdb ^ 0x02;} // If we do not need an encrypted transmission, add 0x02 - if (nomaccmd){cmdb = cmdb ^ 0x04;} // If we do not want to send a MAC, remove 0x04 + if (nomacres) {cmdb = cmdb ^ 0x01;} // If we do not want MAC in reply, remove 0x01 + if (plain) {cmdb = cmdb ^ 0x02;} // If we do not need an encrypted transmission, add 0x02 + if (nomaccmd) {cmdb = cmdb ^ 0x04;} // If we do not want to send a MAC, remove 0x04 uint8_t rcmd1[4] = {cmdb, blockNum, 0x00, blockCount}; uint8_t maccmddat[8] = {0}; uint8_t rcmd[nomaccmd ? 4 : 12]; if (!nomaccmd && mf4session) CalculateMAC(mf4session, mtypReadCmd, blockNum, blockCount, rcmd1, 4, &maccmddat[0], g_verbose_mode); memmove(rcmd, rcmd1, 4); - if (!nomaccmd){memmove(&rcmd[4], maccmddat, 8);} + if (!nomaccmd) {memmove(&rcmd[4], maccmddat, 8);} int res = intExchangeRAW14aPlus(rcmd, sizeof(rcmd), activateField, leaveSignalON, dataout, maxdataoutlen, dataoutlen); if (res) return res; @@ -397,8 +397,8 @@ int MFPReadBlock(mf4Session_t *mf4session, bool plain, bool nomaccmd, bool nomac int MFPWriteBlock(mf4Session_t *mf4session, bool plain, bool nomacres, uint8_t blockNum, uint8_t blockHdr, uint8_t *data, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, uint8_t *mac) { int cmdb = 0xA1; - if (nomacres){cmdb = cmdb ^ 0x01;} // If we do not want MAC in reply, remove 0x01 - if (plain){cmdb = cmdb ^ 0x02;} // If we do not need an encrypted transmission, add 0x02 + if (nomacres) {cmdb = cmdb ^ 0x01;} // If we do not want MAC in reply, remove 0x01 + if (plain) {cmdb = cmdb ^ 0x02;} // If we do not need an encrypted transmission, add 0x02 uint8_t rcmd[1 + 2 + 16 + 8] = {cmdb, blockNum, blockHdr}; memmove(&rcmd[3], data, 16); if (mf4session) diff --git a/client/src/pm3line_vocabulary.h b/client/src/pm3line_vocabulary.h index df1c8ec75..17c9c03e7 100644 --- a/client/src/pm3line_vocabulary.h +++ b/client/src/pm3line_vocabulary.h @@ -509,6 +509,7 @@ const static vocabulary_t vocabulary[] = { { 0, "hf xerox dump" }, { 1, "hw help" }, { 0, "hw break" }, + { 0, "hw bootloader" }, { 1, "hw connect" }, { 0, "hw dbg" }, { 0, "hw detectreader" }, diff --git a/client/src/preferences.c b/client/src/preferences.c index 4effb1bef..8ceab2bb5 100644 --- a/client/src/preferences.c +++ b/client/src/preferences.c @@ -762,7 +762,7 @@ static int setCmdDeviceDebug (const char *Cmd) } */ -int getDeviceDebugLevel (uint8_t *debug_level) { +int getDeviceDebugLevel(uint8_t *debug_level) { if (!g_session.pm3_present) return PM3_EFAILED; @@ -780,19 +780,19 @@ int getDeviceDebugLevel (uint8_t *debug_level) { return PM3_SUCCESS; } -int setDeviceDebugLevel (uint8_t debug_level, bool verbose) { +int setDeviceDebugLevel(uint8_t debug_level, bool verbose) { if (!g_session.pm3_present) return PM3_EFAILED; if (verbose) - PrintAndLogEx (INFO,"setting device debug loglevel to %u", debug_level); + PrintAndLogEx(INFO, "setting device debug loglevel to %u", debug_level); uint8_t cdata[] = {debug_level, verbose}; clearCommandBuffer(); SendCommandNG(CMD_SET_DBGMODE, cdata, sizeof(cdata)); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_SET_DBGMODE, &resp, 2000) == false) { - PrintAndLogEx (WARNING,"failed to set device debug loglevel"); + PrintAndLogEx(WARNING, "failed to set device debug loglevel"); return PM3_EFAILED; } diff --git a/client/src/preferences.h b/client/src/preferences.h index 74e3bc2a8..e49b64d9c 100644 --- a/client/src/preferences.h +++ b/client/src/preferences.h @@ -31,7 +31,7 @@ int preferences_save(void); void preferences_save_callback(json_t *root); void preferences_load_callback(json_t *root); -int getDeviceDebugLevel (uint8_t *debug_level); -int setDeviceDebugLevel (uint8_t debug_level, bool verbose); +int getDeviceDebugLevel(uint8_t *debug_level); +int setDeviceDebugLevel(uint8_t debug_level, bool verbose); #endif diff --git a/client/src/util.c b/client/src/util.c index ad6b4f447..0e2e27151 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -1233,7 +1233,7 @@ size_t str_nlen(const char *src, size_t maxlen) { } void str_reverse(char *buf, size_t len) { - for (size_t i = 0; i < (len>>1); i++) { + for (size_t i = 0; i < (len >> 1); i++) { char tmp = buf[i]; buf[i] = buf[len - i - 1]; buf[len - i - 1] = tmp; @@ -1241,7 +1241,7 @@ void str_reverse(char *buf, size_t len) { } void str_inverse_hex(char *buf, size_t len) { - for (size_t i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { buf[i] = inv_b2s(buf[i], true); } } @@ -1252,7 +1252,7 @@ void str_inverse_bin(char *buf, size_t len) { char c = buf[i]; if (c == '1') buf[i] = '0'; - else if ( c == '0') + else if (c == '0') buf[i] = '1'; else buf[i] = '.'; diff --git a/common/generator.c b/common/generator.c index 28c8a5fa2..25832710a 100644 --- a/common/generator.c +++ b/common/generator.c @@ -329,8 +329,8 @@ int mfc_algo_saflok_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t if (keytype == 0 && sector == 2) { *key = 0xFFFFFFFFFFFF; - return PM3_SUCCESS; -} + return PM3_SUCCESS; + } if (keytype == 0 && sector == 1) { *key = 0x2a2c13cc242a; diff --git a/common_arm/usb_cdc.c b/common_arm/usb_cdc.c index 3f3db2a5a..f0050bd90 100644 --- a/common_arm/usb_cdc.c +++ b/common_arm/usb_cdc.c @@ -669,7 +669,7 @@ uint32_t usb_read(uint8_t *data, size_t len) { uint32_t time_out = 0; while (len) { - if (!usb_check()) + if (!usb_check()) break; if (pUdp->UDP_CSR[AT91C_EP_OUT] & bank) { @@ -690,7 +690,7 @@ uint32_t usb_read(uint8_t *data, size_t len) { bank = AT91C_UDP_RX_DATA_BK0; } - if (time_out++ == 0x1fff) + if (time_out++ == 0x1fff) break; } @@ -735,7 +735,7 @@ uint32_t usb_read_ng(uint8_t *data, size_t len) { } while (len) { - if (!usb_check()) + if (!usb_check()) break; if ((pUdp->UDP_CSR[AT91C_EP_OUT] & bank)) { diff --git a/doc/commands.json b/doc/commands.json index 277e54e91..edebe62b9 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -2320,13 +2320,13 @@ "notes": [ "hf emrtd dump", "hf emrtd dump --dir ../dump", - "hf emrtd dump -n 123456789 -d 19890101 -e 20250401" + "hf emrtd dump -n 123456789 -d 890101 -e 250401" ], "offline": false, "options": [ "-h, --help This help", - "-n, --documentnumber document number, up to 9 chars", - "-d, --dateofbirth date of birth in YYMMDD format", + "-n, --doc document number, up to 9 chars", + "-d, --date date of birth in YYMMDD format", "-e, --expiry expiry in YYMMDD format", "-m, --mrz <[0-9A-Z<]> 2nd line of MRZ, 44 chars", "--dir save dump to the given dirpath" @@ -2339,14 +2339,14 @@ "notes": [ "hf emrtd info", "hf emrtd info --dir ../dumps", - "hf emrtd info -n 123456789 -d 19890101 -e 20250401", - "hf emrtd info -n 123456789 -d 19890101 -e 20250401 -i" + "hf emrtd info -n 123456789 -d 890101 -e 250401", + "hf emrtd info -n 123456789 -d 890101 -e 250401 -i" ], "offline": true, "options": [ "-h, --help This help", - "-n, --documentnumber document number, up to 9 chars", - "-d, --dateofbirth date of birth in YYMMDD format", + "-n, --doc document number, up to 9 chars", + "-d, --date date of birth in YYMMDD format", "-e, --expiry expiry in YYMMDD format", "-m, --mrz <[0-9A-Z<]> 2nd line of MRZ, 44 chars (passports only)", "--dir display info from offline dump stored in dirpath", @@ -4712,7 +4712,7 @@ "description": "Information and check vulnerabilities in a MIFARE Classic card Some cards in order to extract information you need to specify key and/or specific keys in the copmmand line", "notes": [ "hf mf info", - "hf mf info -k ffffffff -n -v" + "hf mf info -k FFFFFFFFFFFF -n -v" ], "offline": false, "options": [ @@ -7601,6 +7601,18 @@ ], "usage": "hints [-h10]" }, + "hw bootloader": { + "command": "hw bootloader", + "description": "Reboot Proxmark3 into bootloader mode", + "notes": [ + "hw bootloader" + ], + "offline": false, + "options": [ + "-h, --help This help" + ], + "usage": "hw bootloader [-h]" + }, "hw break": { "command": "hw break", "description": "send break loop package", @@ -9055,7 +9067,7 @@ "-1, --ht1 Card type Hitag 1", "-2, --ht2 Card type Hitag 2", "-s, --hts Card type Hitag S", - "-m, --htm Card type Hitag \u041e\u0458" + "-m, --htm Card type Hitag \u03bc" ], "usage": "lf hitag eload [-h12sm] -f " }, @@ -12146,8 +12158,8 @@ } }, "metadata": { - "commands_extracted": 702, + "commands_extracted": 703, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2023-12-11T23:10:13" + "extracted_on": "2023-12-18T09:05:00" } } \ No newline at end of file diff --git a/doc/commands.md b/doc/commands.md index 447478cfa..8478e3205 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -784,6 +784,7 @@ Check column "offline" for their availability. |------- |------- |----------- |`hw help `|Y |`This help` |`hw break `|N |`Send break loop usb command` +|`hw bootloader `|N |`Reboot Proxmark3 into bootloader mode` |`hw connect `|Y |`Connect Proxmark3 to serial port` |`hw dbg `|N |`Set Proxmark3 debug level` |`hw detectreader `|N |`Detect external reader field`