From 5b31211971ae593679a1d17c992895fef5b1f25b Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 16 Jan 2024 11:53:42 +0100 Subject: [PATCH] style --- armsrc/Standalone/hf_cardhopper.c | 6 +- armsrc/iso14443b.c | 8 +- armsrc/iso14443b.h | 2 +- armsrc/iso15693.c | 22 ++--- client/src/cmdhf14a.c | 12 +-- client/src/cmdhf14b.c | 12 +-- client/src/cmdtrace.c | 4 +- client/src/iso7816/iso7816core.c | 40 ++++---- client/src/pm3line_vocabulary.h | 7 +- client/src/scripting.c | 2 +- doc/commands.json | 150 ++++++++++++++++-------------- doc/commands.md | 7 +- 12 files changed, 143 insertions(+), 129 deletions(-) diff --git a/armsrc/Standalone/hf_cardhopper.c b/armsrc/Standalone/hf_cardhopper.c index 2949ada78..45181b0d9 100644 --- a/armsrc/Standalone/hf_cardhopper.c +++ b/armsrc/Standalone/hf_cardhopper.c @@ -369,7 +369,7 @@ static void cook_ats(packet_t *ats, uint8_t fwi, uint8_t sfgi) { } packet_t cooked_ats = { 0 }; - cooked_ats.len = 5+historical_len; + cooked_ats.len = 5 + historical_len; cooked_ats.dat[0] = cooked_ats.len; cooked_ats.dat[1] = t0; cooked_ats.dat[2] = ta; @@ -377,7 +377,7 @@ static void cook_ats(packet_t *ats, uint8_t fwi, uint8_t sfgi) { cooked_ats.dat[4] = tc; if (historical_len > 0) { - memcpy(cooked_ats.dat+5, historical_bytes, historical_len); + memcpy(cooked_ats.dat + 5, historical_bytes, historical_len); } memcpy(ats, &cooked_ats, sizeof(packet_t)); @@ -479,7 +479,7 @@ static void read_packet(packet_t *packet) { DbpString(_CYAN_("[@]") " PM3 NG packet recieved - ignoring"); // clear any remaining buffered data - while(cardhopper_data_available()) { + while (cardhopper_data_available()) { cardhopper_read(packet->dat, 255); } diff --git a/armsrc/iso14443b.c b/armsrc/iso14443b.c index ad2cff161..950f13ecb 100644 --- a/armsrc/iso14443b.c +++ b/armsrc/iso14443b.c @@ -466,7 +466,7 @@ static void iso14b_set_fwt(uint8_t fwt) { s_iso14b_fwt = fwt; if (g_dbglevel >= DBG_DEBUG) { Dbprintf("ISO14443B FWT Timeout set to %ld fwt", s_iso14b_fwt); - } + } iso14b_set_timeout(32 << fwt); } @@ -1412,7 +1412,7 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, uint32_t (Demod.len * (8 + 2)) // time for byte transfers + (10 + 2) // time for SOF transfer + (10) // time for EOF transfer - ) + ) ; LogTrace(Demod.output, Demod.len, sof_time, *eof_time, NULL, false); } @@ -1672,7 +1672,7 @@ int iso14443b_apdu(uint8_t const *msg, size_t msg_len, bool send_chaining, void if ((len >= 3) && // PCB + CRC = 3 bytes (((data_bytes[0] & 0xC0) == 0) || (data_bytes[0] & 0xD0) == 0x80) && // I-Block OR R-Block with ACK bit set to 0 - ((data_bytes[0] & 0x01) == s_iso14b_pcb_blocknum)) { // equal block numbers + ((data_bytes[0] & 0x01) == s_iso14b_pcb_blocknum)) { // equal block numbers s_iso14b_pcb_blocknum ^= 1; @@ -1689,7 +1689,7 @@ int iso14443b_apdu(uint8_t const *msg, size_t msg_len, bool send_chaining, void } } - // cut frame byte + // cut frame byte if (len) { len -= 1; diff --git a/armsrc/iso14443b.h b/armsrc/iso14443b.h index c737a369d..bf0ac0bc6 100644 --- a/armsrc/iso14443b.h +++ b/armsrc/iso14443b.h @@ -35,7 +35,7 @@ #endif void iso14443b_setup(void); -int iso14443b_apdu(uint8_t const *msg, size_t msg_len, bool send_chaining, void *rxdata, uint16_t rxmaxlen, uint8_t *res, uint16_t * responselen); +int iso14443b_apdu(uint8_t const *msg, size_t msg_len, bool send_chaining, void *rxdata, uint16_t rxmaxlen, uint8_t *res, uint16_t *responselen); int iso14443b_select_card(iso14b_card_select_t *card); diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index af404a5ce..868b1f6f4 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -2680,17 +2680,17 @@ void SetTag15693Uid(const uint8_t *uid) { for (int i = 0; i < 4; i++) { res = SendDataTag( - cmd[i], - sizeof(cmd[i]), - (i == 0) ? true : false, - true, - buf, - sizeof(buf), - start_time, - ISO15693_READER_TIMEOUT_WRITE, - &eof_time, - &recvlen - ); + cmd[i], + sizeof(cmd[i]), + (i == 0) ? true : false, + true, + buf, + sizeof(buf), + start_time, + ISO15693_READER_TIMEOUT_WRITE, + &eof_time, + &recvlen + ); start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER; } diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index c0c9d6c14..1fd33f921 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -1259,14 +1259,14 @@ static int CmdHF14AAPDU(const char *Cmd) { "Sends an ISO 7816-4 APDU via ISO 14443-4 block transmission protocol (T=CL).\n" "Works with all APDU types from ISO 7816-4:2013\n" "\n" - "note:\n" - " `-m` and `-d` goes hand in hand\n" - " -m -d 325041592E5359532E4444463031\n" + "note:\n" + " `-m` and `-d` goes hand in hand\n" + " -m -d 325041592E5359532E4444463031\n" "\n" - " OR\n" + " OR\n" "\n" - " use `-d` with complete APDU data\n" - " -d 00A404000E325041592E5359532E444446303100", + " use `-d` with complete APDU data\n" + " -d 00A404000E325041592E5359532E444446303100", "hf 14a apdu -st -d 00A404000E325041592E5359532E444446303100\n" "hf 14a apdu -sd -d 00A404000E325041592E5359532E444446303100 -> decode apdu\n" "hf 14a apdu -sm 00A40400 -d 325041592E5359532E4444463031 -l 256 -> encode standard apdu\n" diff --git a/client/src/cmdhf14b.c b/client/src/cmdhf14b.c index c3a840349..cd69563af 100644 --- a/client/src/cmdhf14b.c +++ b/client/src/cmdhf14b.c @@ -1840,11 +1840,11 @@ static uint32_t srix4k_get_magicbytes(uint64_t uid, uint32_t block6, uint32_t bl } static int CmdSRIX4kValid(const char *Cmd) { - CLIParserContext *ctx; + CLIParserContext *ctx; CLIParserInit(&ctx, "hf 14b valid", "SRIX checksum test", "hf 14b valid\n" - ); + ); void *argtable[] = { arg_param_begin, @@ -2220,10 +2220,10 @@ static int CmdHF14BAPDU(const char *Cmd) { PrintAndLogEx(INFO, "<<<< %s", sprint_hex(data, datalen)); PrintAndLogEx(SUCCESS, "APDU response: " _YELLOW_("%02x %02x") " - %s" - , data[datalen - 2] - , data[datalen - 1] - , GetAPDUCodeDescription(data[datalen - 2], data[datalen - 1]) - ); + , data[datalen - 2] + , data[datalen - 1] + , GetAPDUCodeDescription(data[datalen - 2], data[datalen - 1]) + ); // TLV decoder if (decode_TLV && datalen > 4) { diff --git a/client/src/cmdtrace.c b/client/src/cmdtrace.c index afd4343f8..b5e0d98db 100644 --- a/client/src/cmdtrace.c +++ b/client/src/cmdtrace.c @@ -1086,7 +1086,7 @@ static int CmdTraceExtract(const char *Cmd) { return PM3_EINVARG; } - PrintAndLogEx(SUCCESS, "Recorded activity ( " _YELLOW_("%u") " bytes )" , gs_traceLen); + PrintAndLogEx(SUCCESS, "Recorded activity ( " _YELLOW_("%u") " bytes )", gs_traceLen); if (gs_traceLen == 0) { return PM3_SUCCESS; } @@ -1320,7 +1320,7 @@ int CmdTraceList(const char *Cmd) { return PM3_EINVARG; } - PrintAndLogEx(SUCCESS, "Recorded activity ( " _YELLOW_("%u") " bytes )" , gs_traceLen); + PrintAndLogEx(SUCCESS, "Recorded activity ( " _YELLOW_("%u") " bytes )", gs_traceLen); if (gs_traceLen == 0) { return PM3_SUCCESS; } diff --git a/client/src/iso7816/iso7816core.c b/client/src/iso7816/iso7816core.c index 24e5964a1..9eafaa599 100644 --- a/client/src/iso7816/iso7816core.c +++ b/client/src/iso7816/iso7816core.c @@ -189,30 +189,30 @@ int Iso7816ExchangeEx(Iso7816CommandChannel channel, bool activate_field, bool l int Iso7816Exchange(Iso7816CommandChannel channel, bool leave_field_on, sAPDU_t apdu, uint8_t *result, size_t max_result_len, size_t *result_len, uint16_t *sw) { return Iso7816ExchangeEx(channel - , false - , leave_field_on - , apdu - , false - , 0 - , result - , max_result_len - , result_len - , sw - ); + , false + , leave_field_on + , apdu + , false + , 0 + , result + , max_result_len + , result_len + , sw + ); } int Iso7816Select(Iso7816CommandChannel channel, bool activate_field, bool leave_field_on, uint8_t *aid, size_t aid_len, uint8_t *result, size_t max_result_len, size_t *result_len, uint16_t *sw) { return Iso7816ExchangeEx(channel - , activate_field - , leave_field_on - , (sAPDU_t) {0x00, 0xa4, 0x04, 0x00, aid_len, aid} - , (channel == CC_CONTACTLESS) - , 0 - , result - , max_result_len - , result_len - , sw - ); + , activate_field + , leave_field_on + , (sAPDU_t) {0x00, 0xa4, 0x04, 0x00, aid_len, aid} + , (channel == CC_CONTACTLESS) + , 0 + , result + , max_result_len + , result_len + , sw + ); } diff --git a/client/src/pm3line_vocabulary.h b/client/src/pm3line_vocabulary.h index 6f8f07a7f..eb45dba91 100644 --- a/client/src/pm3line_vocabulary.h +++ b/client/src/pm3line_vocabulary.h @@ -157,18 +157,19 @@ const static vocabulary_t vocabulary[] = { { 0, "hf 14a ndefread" }, { 0, "hf 14a ndefwrite" }, { 1, "hf 14b help" }, + { 1, "hf 14b list" }, { 0, "hf 14b apdu" }, { 0, "hf 14b dump" }, { 0, "hf 14b info" }, - { 1, "hf 14b list" }, { 0, "hf 14b ndefread" }, { 0, "hf 14b raw" }, + { 0, "hf 14b rdbl" }, { 0, "hf 14b reader" }, { 0, "hf 14b sim" }, { 0, "hf 14b sniff" }, - { 0, "hf 14b rdbl" }, - { 0, "hf 14b sriwrite" }, + { 0, "hf 14b wrbl" }, { 1, "hf 14b view" }, + { 1, "hf 14b valid" }, { 1, "hf 15 help" }, { 1, "hf 15 list" }, { 1, "hf 15 demod" }, diff --git a/client/src/scripting.c b/client/src/scripting.c index 37213a68b..0896fd550 100644 --- a/client/src/scripting.c +++ b/client/src/scripting.c @@ -1333,7 +1333,7 @@ static int l_cwd(lua_State *L) { while (GetCurrentDir(cwd, path_len) == NULL) { if (errno == ERANGE) { // Need bigger buffer path_len += 10; // if buffer was too small add 10 characters and try again - char* cwdNew = realloc(cwd, path_len); + char *cwdNew = realloc(cwd, path_len); if (cwdNew == NULL) { free(cwd); return returnToLuaWithError(L, "Failed to allocate memory"); diff --git a/doc/commands.json b/doc/commands.json index f16af3fa5..c1b8ec03c 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -1112,26 +1112,26 @@ }, "hf 14a apdu": { "command": "hf 14a apdu", - "description": "Sends an ISO 7816-4 APDU via ISO 14443-4 block transmission protocol (T=CL). works with all apdu types from ISO 7816-4:2013", + "description": "Sends an ISO 7816-4 APDU via ISO 14443-4 block transmission protocol (T=CL). Works with all APDU types from ISO 7816-4:2013 note: `-m` and `-d` goes hand in hand -m -d 325041592E5359532E4444463031 OR use `-d` with complete APDU data -d 00A404000E325041592E5359532E444446303100", "notes": [ - "hf 14a apdu -st 00A404000E325041592E5359532E444446303100", - "hf 14a apdu -sd 00A404000E325041592E5359532E444446303100 -> decode apdu", - "hf 14a apdu -sm 00A40400 325041592E5359532E4444463031 -l 256 -> encode standard apdu", - "hf 14a apdu -sm 00A40400 325041592E5359532E4444463031 -el 65536 -> encode extended apdu" + "hf 14a apdu -st -d 00A404000E325041592E5359532E444446303100", + "hf 14a apdu -sd -d 00A404000E325041592E5359532E444446303100 -> decode apdu", + "hf 14a apdu -sm 00A40400 -d 325041592E5359532E4444463031 -l 256 -> encode standard apdu", + "hf 14a apdu -sm 00A40400 -d 325041592E5359532E4444463031 -el 65536 -> encode extended apdu" ], "offline": false, "options": [ "-h, --help This help", "-s, --select activate field and select card", "-k, --keep keep signal field ON after receive", - "-t, --tlv executes TLV decoder if it possible", - "-d, --decapdu decode apdu request if it possible", - "-m, --make make apdu with head from this field and data from data field. Must be 4 bytes length: ", + "-t, --tlv decode TLV", + "-d, --decapdu decode APDU request", + "-m, --make APDU header, 4 bytes ", "-e, --extended make extended length apdu if `m` parameter included", - "-l, --le Le apdu parameter if `m` parameter included", - " data if `m` parameter included" + "-l, --le Le APDU parameter if `m` parameter included", + "-d, --data full APDU package or data if `m` parameter included" ], - "usage": "hf 14a apdu [-hsktde] [-m ] [-l ] []..." + "usage": "hf 14a apdu [-hsktde] [-m ] [-l ] -d [-d ]..." }, "hf 14a apdufind": { "command": "hf 14a apdufind", @@ -1358,6 +1358,31 @@ ], "usage": "hf 14a sniff [-hcr]" }, + "hf 14b apdu": { + "command": "hf 14b apdu", + "description": "Sends an ISO 7816-4 APDU via ISO 14443-4 block transmission protocol (T=CL). works with all apdu types from ISO 7816-4:2013", + "notes": [ + "hf 14b apdu -s -d 94a40800043f000002", + "hf 14b apdu -s --decode -d 00A404000E325041592E5359532E444446303100 -> decode apdu", + "hf 14b apdu -sm 00A40400 -l 256 -d 325041592E5359532E4444463031 -> encode standard apdu", + "hf 14b apdu -sm 00A40400 -el 65536 -d 325041592E5359532E4444463031 -> encode extended apdu" + ], + "offline": false, + "options": [ + "-h, --help This help", + "-s, --select activate field and select card", + "-k, --keep leave the signal field ON after receive response", + "-t, --tlv executes TLV decoder if it possible", + "--decode decode apdu request if it possible", + "-m, --make make apdu with head from this field and data from data field.", + "must be 4 bytes: ", + "-e, --extended make extended length apdu if `m` parameter included", + "-l, --le Le apdu parameter if `m` parameter included", + "-d, --data if `m` parameter included", + "--timeout timeout in ms" + ], + "usage": "hf 14b apdu [-hskte] [--decode] [-m ] [-l ] -d [--timeout ]" + }, "hf 14b dump": { "command": "hf 14b dump", "description": "This command dumps the contents of a ISO-14443-B tag and save it to file Tries to autodetect cardtype, memory size defaults to SRI4K", @@ -1375,46 +1400,7 @@ }, "hf 14b help": { "command": "hf 14b help", - "description": "help This help list List ISO-14443-B history view Display content from tag dump file --------------------------------------------------------------------------------------- hf 14b apdu available offline: no Sends an ISO 7816-4 APDU via ISO 14443-4 block transmission protocol (T=CL). works with all apdu types from ISO 7816-4:2013", - "notes": [ - "hf 14b apdu -s -d 94a40800043f000002", - "hf 14b apdu -s --decode -d 00A404000E325041592E5359532E444446303100 -> decode apdu", - "hf 14b apdu -sm 00A40400 -l 256 -d 325041592E5359532E4444463031 -> encode standard apdu", - "hf 14b apdu -sm 00A40400 -el 65536 -d 325041592E5359532E4444463031 -> encode extended apdu" - ], - "offline": true, - "options": [ - "-h, --help This help", - "-s, --select activate field and select card", - "-k, --keep leave the signal field ON after receive response", - "-t, --tlv executes TLV decoder if it possible", - "--decode decode apdu request if it possible", - "-m, --make make apdu with head from this field and data from data field.", - "must be 4 bytes: ", - "-e, --extended make extended length apdu if `m` parameter included", - "-l, --le Le apdu parameter if `m` parameter included", - "-d, --data if `m` parameter included", - "--timeout timeout in ms" - ], - "usage": "hf 14b apdu [-hskte] [--decode] [-m ] [-l ] -d [--timeout ]" - }, - "hf 14b info": { - "command": "hf 14b info", - "description": "Tag information for ISO/IEC 14443 type B based tags", - "notes": [ - "hf 14b info" - ], - "offline": false, - "options": [ - "-h, --help This help", - "-s, --aidsearch checks if AIDs from aidlist.json is present on the card and prints information about found AIDs", - "-v, --verbose verbose output" - ], - "usage": "hf 14b info [-hsv]" - }, - "hf 14b list": { - "command": "hf 14b list", - "description": "Alias of `trace list -t 14b -c` with selected protocol data to annotate trace buffer You can load a trace from file (see `trace load -h`) or it be downloaded from device by default It accepts all other arguments of `trace list`. Note that some might not be relevant for this specific protocol", + "description": "help This help list List ISO-14443-B history --------- ----------------------- general ----------------------- view Display content from tag dump file valid SRIX4 checksum test --------------------------------------------------------------------------------------- hf 14b list available offline: yes Alias of `trace list -t 14b -c` with selected protocol data to annotate trace buffer You can load a trace from file (see `trace load -h`) or it be downloaded from device by default It accepts all other arguments of `trace list`. Note that some might not be relevant for this specific protocol", "notes": [ "hf 14b list --frame -> show frame delay times", "hf 14b list -1 -> use trace buffer" @@ -1433,6 +1419,20 @@ ], "usage": "hf 14b list [-h1crux] [--frame] [-f ]" }, + "hf 14b info": { + "command": "hf 14b info", + "description": "Tag information for ISO/IEC 14443 type B based tags", + "notes": [ + "hf 14b info" + ], + "offline": false, + "options": [ + "-h, --help This help", + "-s, --aidsearch checks if AIDs from aidlist.json is present on the card and prints information about found AIDs", + "-v, --verbose verbose output" + ], + "usage": "hf 14b info [-hsv]" + }, "hf 14b ndefread": { "command": "hf 14b ndefread", "description": "Print NFC Data Exchange Format (NDEF)", @@ -1525,26 +1525,17 @@ ], "usage": "hf 14b sniff [-h]" }, - "hf 14b sriwrite": { - "command": "hf 14b sriwrite", - "description": "Write data to a SRI512 or SRIX4K block If writing to a block out-of-range, use --force to override checks", + "hf 14b valid": { + "command": "hf 14b valid", + "description": "SRIX checksum test", "notes": [ - "hf 14b sriwrite --4k -b 100 -d 11223344", - "hf 14b sriwrite --4k --sb -d 11223344 -> special block write", - "hf 14b sriwrite --512 -b 15 -d 11223344", - "hf 14b sriwrite --512 --sb -d 11223344 -> special block write" + "hf 14b valid" ], - "offline": false, + "offline": true, "options": [ - "-h, --help This help", - "-b, --block block number", - "-d, --data 4 hex bytes", - "--512 target SRI 512 tag", - "--4k target SRIX 4k tag", - "--sb special block write at end of memory (0xFF)", - "--force overrides block range checks" + "-h, --help This help" ], - "usage": "hf 14b sriwrite [-h] [-b ] -d [--512] [--4k] [--sb] [--force]" + "usage": "hf 14b valid [-h]" }, "hf 14b view": { "command": "hf 14b view", @@ -1560,6 +1551,27 @@ ], "usage": "hf 14b view [-hv] -f " }, + "hf 14b wrbl": { + "command": "hf 14b wrbl", + "description": "Write data to a SRI512 or SRIX4K block If writing to a block out-of-range, use `--force` to override checks Special block at end denots OTP and lock bits among others", + "notes": [ + "hf 14b wrbl --4k -b 100 -d 11223344", + "hf 14b wrbl --4k --sb -d 11223344 -> special block write", + "hf 14b wrbl --512 -b 15 -d 11223344", + "hf 14b wrbl --512 --sb -d 11223344 -> special block write" + ], + "offline": false, + "options": [ + "-h, --help This help", + "-b, --block block number", + "-d, --data 4 hex bytes", + "--512 target SRI 512 tag", + "--4k target SRIX 4k tag", + "--sb special block write at end of memory (0xFF)", + "--force overrides block range checks" + ], + "usage": "hf 14b wrbl [-h] [-b ] -d [--512] [--4k] [--sb] [--force]" + }, "hf 15 csetuid": { "command": "hf 15 csetuid", "description": "Set UID for magic Chinese card (only works with such cards)", @@ -12228,8 +12240,8 @@ } }, "metadata": { - "commands_extracted": 706, + "commands_extracted": 707, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2024-01-15T12:04:30" + "extracted_on": "2024-01-16T10:52:42" } } \ No newline at end of file diff --git a/doc/commands.md b/doc/commands.md index 83a968779..e4259edea 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -208,18 +208,19 @@ Check column "offline" for their availability. |command |offline |description |------- |------- |----------- |`hf 14b help `|Y |`This help` +|`hf 14b list `|Y |`List ISO-14443-B history` |`hf 14b apdu `|N |`Send ISO 14443-4 APDU to tag` |`hf 14b dump `|N |`Read all memory pages of an ISO-14443-B tag, save to file` |`hf 14b info `|N |`Tag information` -|`hf 14b list `|Y |`List ISO-14443-B history` |`hf 14b ndefread `|N |`Read NDEF file on tag` |`hf 14b raw `|N |`Send raw hex data to tag` +|`hf 14b rdbl `|N |`Read SRI512/SRIX4 block` |`hf 14b reader `|N |`Act as a ISO-14443-B reader to identify a tag` |`hf 14b sim `|N |`Fake ISO ISO-14443-B tag` |`hf 14b sniff `|N |`Eavesdrop ISO-14443-B` -|`hf 14b rdbl `|N |`Read SRI512/SRIX4x block` -|`hf 14b sriwrite `|N |`Write data to a SRI512 or SRIX4K tag` +|`hf 14b wrbl `|N |`Write data to a SRI512/SRIX4 tag` |`hf 14b view `|Y |`Display content from tag dump file` +|`hf 14b valid `|Y |`SRIX4 checksum test` ### hf 15