From 210d2847aeb2019d15ae69eadff68771a4b656ef Mon Sep 17 00:00:00 2001 From: nvx Date: Tue, 22 Aug 2023 07:32:07 +1000 Subject: [PATCH 1/4] Adds `hf iclass esetblk`, equivalent to `hf mf esetblk` Also some minor tweaks to make commands.json and commands.md properly on Windows. --- Makefile | 2 +- client/pyscripts/pm3_help2list.py | 2 +- client/src/cmdhficlass.c | 55 ++++++++++++++++++++++++++++--- client/src/cmdhftexkom.c | 8 ++--- client/src/pm3line_vocabulary.h | 1 + doc/commands.json | 28 ++++++++++++---- doc/commands.md | 1 + 7 files changed, 81 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 8ca441faf..64b0aa6ab 100644 --- a/Makefile +++ b/Makefile @@ -327,7 +327,7 @@ style: # Make sure python3 is installed @command -v python3 >/dev/null || ( echo "Please install 'python3' package first" ; exit 1 ) # Update commands.json, patch port in case it was run under Windows - [ -x client/proxmark3 ] && client/proxmark3 --fulltext | sed 's#com[0-9]#/dev/ttyacm0#'|python3 client/pyscripts/pm3_help2json.py - doc/commands.json + [ -x client/proxmark3 ] && client/proxmark3 --fulltext | sed 's#com[0-9]#/dev/ttyACM0#'|python3 client/pyscripts/pm3_help2json.py - doc/commands.json # Update the readline autocomplete autogenerated code [ -x client/proxmark3 ] && client/proxmark3 --fulltext | python3 client/pyscripts/pm3_help2list.py - client/src/pm3line_vocabulary.h diff --git a/client/pyscripts/pm3_help2list.py b/client/pyscripts/pm3_help2list.py index 7355bca46..a896e5546 100755 --- a/client/pyscripts/pm3_help2list.py +++ b/client/pyscripts/pm3_help2list.py @@ -88,7 +88,7 @@ const static vocabulary_t vocabulary[] = {\n""") cmd = values['command'] - args.output_file.write(' {{ {}, "{}" }}, \n'.format(offline, cmd)) + args.output_file.write(' {{ {}, "{}" }},\n'.format(offline, cmd)) args.output_file.write(""" {0, NULL}\n}; diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 131944f6e..4a4ac3289 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -129,7 +129,7 @@ static inline uint32_t leadingzeros(uint64_t a) { #endif } -static void iclass_upload_emul(uint8_t *d, uint16_t n, uint16_t *bytes_sent) { +static void iclass_upload_emul(uint8_t *d, uint16_t n, uint16_t offset, uint16_t *bytes_sent) { struct p { uint16_t offset; @@ -155,7 +155,7 @@ static void iclass_upload_emul(uint8_t *d, uint16_t n, uint16_t *bytes_sent) { } struct p *payload = calloc(4 + bytes_in_packet, sizeof(uint8_t)); - payload->offset = *bytes_sent; + payload->offset = offset + *bytes_sent; payload->len = bytes_in_packet; memcpy(payload->data, d + *bytes_sent, bytes_in_packet); @@ -424,7 +424,7 @@ static int generate_config_card(const iclass_config_card_item_t *o, uint8_t *ke //Send to device PrintAndLogEx(INFO, "Uploading to device... "); uint16_t bytes_sent = 0; - iclass_upload_emul(data, tot_bytes, &bytes_sent); + iclass_upload_emul(data, tot_bytes, 0, &bytes_sent); free(data); PrintAndLogEx(NORMAL, ""); @@ -1092,7 +1092,7 @@ static int CmdHFiClassELoad(const char *Cmd) { //Send to device uint16_t bytes_sent = 0; - iclass_upload_emul(dump, bytes_read, &bytes_sent); + iclass_upload_emul(dump, bytes_read, 0, &bytes_sent); free(dump); PrintAndLogEx(SUCCESS, "uploaded " _YELLOW_("%d") " bytes to emulator memory", bytes_sent); PrintAndLogEx(HINT, "You are ready to simulate. See " _YELLOW_("`hf iclass sim -h`")); @@ -1222,6 +1222,52 @@ static int CmdHFiClassEView(const char *Cmd) { return PM3_SUCCESS; } +static int CmdHFiClassESetBlk(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf iclass esetblk", + "Display emulator memory.\n" + "Number of bytes to download defaults to 256. Other value is 2048.", + "hf iclass eview\n" + "hf iclass eview -s 2048\n" + "hf iclass eview -s 2048 -v"); + + void *argtable[] = { + arg_param_begin, + arg_int1("b", "blk", "", "block number"), + arg_str0("d", "data", "", "bytes to write, 16 hex bytes"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + + int blk = arg_get_int_def(ctx, 1, 0); + + if (blk > 255) { + PrintAndLogEx(WARNING, "block number must be between 0 and 255. Got %i", blk); + return PM3_EINVARG; + } + + uint8_t data[PICOPASS_BLOCK_SIZE] = {0x00}; + int datalen = 0; + int res = CLIParamHexToBuf(arg_get_str(ctx, 2), data, sizeof(data), &datalen); + CLIParserFree(ctx); + if (res) { + PrintAndLogEx(FAILED, "Error parsing bytes"); + return PM3_EINVARG; + } + + if (datalen != sizeof(data)) { + PrintAndLogEx(WARNING, "block data must include 8 HEX bytes. Got %i", datalen); + return PM3_EINVARG; + } + + CLIParserFree(ctx); + + uint16_t bytes_sent = 0; + iclass_upload_emul(data, sizeof(data), blk * PICOPASS_BLOCK_SIZE, &bytes_sent); + + return PM3_SUCCESS; +} + static void iclass_decode_credentials(uint8_t *data) { BLOCK79ENCRYPTION encryption = (data[(6 * 8) + 7] & 0x03); bool has_values = (memcmp(data + (8 * 7), empty, 8) != 0) && (memcmp(data + (8 * 7), zeros, 8) != 0); @@ -4226,6 +4272,7 @@ static command_t CommandTable[] = { {"sim", CmdHFiClassSim, IfPm3Iclass, "Simulate iCLASS tag"}, {"eload", CmdHFiClassELoad, IfPm3Iclass, "Load Picopass / iCLASS dump file into emulator memory"}, {"esave", CmdHFiClassESave, IfPm3Iclass, "Save emulator memory to file"}, + {"esetblk", CmdHFiClassESetBlk, IfPm3Iclass, "Set emulator memory block data"}, {"eview", CmdHFiClassEView, IfPm3Iclass, "View emulator memory"}, {"-----------", CmdHelp, AlwaysAvailable, "---------------------- " _CYAN_("utils") " ----------------------"}, {"configcard", CmdHFiClassConfigCard, AlwaysAvailable, "Reader configuration card"}, diff --git a/client/src/cmdhftexkom.c b/client/src/cmdhftexkom.c index 4164060f7..6cb77a54e 100644 --- a/client/src/cmdhftexkom.c +++ b/client/src/cmdhftexkom.c @@ -850,10 +850,10 @@ static int CmdHFTexkomSim(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf texkom sim", "Simulate a texkom tag", - "hf texkom sim \r\n" - "hf texkom sim --raw FFFF638C7DC45553 -> simulate TK13 tag with id 8C7DC455\r\n" - "hf texkom sim --tk17 --raw FFFFCA17F31EC512 -> simulate TK17 tag with id 17F31EC5\r\n" - "hf texkom sim --id 8C7DC455 -> simulate TK13 tag with id 8C7DC455\r\n" + "hf texkom sim \n" + "hf texkom sim --raw FFFF638C7DC45553 -> simulate TK13 tag with id 8C7DC455\n" + "hf texkom sim --tk17 --raw FFFFCA17F31EC512 -> simulate TK17 tag with id 17F31EC5\n" + "hf texkom sim --id 8C7DC455 -> simulate TK13 tag with id 8C7DC455\n" "hf texkom sim --id 8C7DC455 --tk17 -> simulate TK17 tag with id 17F31EC5"); void *argtable[] = { diff --git a/client/src/pm3line_vocabulary.h b/client/src/pm3line_vocabulary.h index 0f617ef0d..8926ffb94 100644 --- a/client/src/pm3line_vocabulary.h +++ b/client/src/pm3line_vocabulary.h @@ -282,6 +282,7 @@ const static vocabulary_t vocabulary[] = { { 0, "hf iclass sim" }, { 0, "hf iclass eload" }, { 0, "hf iclass esave" }, + { 0, "hf iclass esetblk" }, { 0, "hf iclass eview" }, { 1, "hf iclass configcard" }, { 1, "hf iclass calcnewkey" }, diff --git a/doc/commands.json b/doc/commands.json index 858cc02cd..f92263843 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -215,10 +215,9 @@ "offline": true, "options": [ "-h, --help This help", - "-d ASN1 encoded byte array", - "-t, --test perform selftest" + "-d ASN1 encoded byte array" ], - "usage": "data atr [-ht] [-d ]" + "usage": "data atr [-h] [-d ]" }, "data autocorr": { "command": "data autocorr", @@ -3150,6 +3149,22 @@ ], "usage": "hf iclass esave [-h] [-f ] [-s <256|2048>]" }, + "hf iclass esetblk": { + "command": "hf iclass esetblk", + "description": "Display emulator memory. Number of bytes to download defaults to 256. Other value is 2048.", + "notes": [ + "hf iclass eview", + "hf iclass eview -s 2048", + "hf iclass eview -s 2048 -v" + ], + "offline": false, + "options": [ + "-h, --help This help", + "-b, --blk block number", + "-d, --data bytes to write, 16 hex bytes" + ], + "usage": "hf iclass esetblk [-h] -b [-d ]" + }, "hf iclass eview": { "command": "hf iclass eview", "description": "Display emulator memory. Number of bytes to download defaults to 256. Other value is 2048.", @@ -6986,6 +7001,7 @@ "description": "Simulate a texkom tag", "notes": [ "hf texkom sim", + "", "hf texkom sim --raw FFFF638C7DC45553 -> simulate TK13 tag with id 8C7DC455", "hf texkom sim --tk17 --raw FFFFCA17F31EC512 -> simulate TK17 tag with id 17F31EC5", "hf texkom sim --id 8C7DC455 -> simulate TK13 tag with id 8C7DC455", @@ -8770,7 +8786,7 @@ "-1, --ht1 Card type Hitag 1", "-2, --ht2 Card type Hitag 2", "-s, --hts Card type Hitag S", - "-m, --htm Card type Hitag \u03bc" + "-m, --htm Card type Hitag \u00ce\u00bc" ], "usage": "lf hitag eload [-h12sm] -f " }, @@ -11819,8 +11835,8 @@ } }, "metadata": { - "commands_extracted": 685, + "commands_extracted": 686, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2023-08-02T20:39:48" + "extracted_on": "2023-08-21T21:25:03" } } \ No newline at end of file diff --git a/doc/commands.md b/doc/commands.md index 27d6a05b4..919ce3f8e 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -421,6 +421,7 @@ Check column "offline" for their availability. |`hf iclass sim `|N |`Simulate iCLASS tag` |`hf iclass eload `|N |`Load Picopass / iCLASS dump file into emulator memory` |`hf iclass esave `|N |`Save emulator memory to file` +|`hf iclass esetblk `|N |`Set emulator memory block data` |`hf iclass eview `|N |`View emulator memory` |`hf iclass configcard `|Y |`Reader configuration card` |`hf iclass calcnewkey `|Y |`Calc diversified keys (blocks 3 & 4) to write new keys` From d183944bb16b9bb0a4a7702c5723084c0de635b2 Mon Sep 17 00:00:00 2001 From: nvx Date: Tue, 22 Aug 2023 07:53:57 +1000 Subject: [PATCH 2/4] Add CHANGELOG entry for hf iclass esetblk command --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e773482db..cf9c6f192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Added `hf iclass esetblk` - set iClass emulator memory block data (@nvx) - Added cryptorf regressiontests (@iceman1001) - Fixed `cryptorf/sma_multi` - local state used in multithread (@iceman1001) - Changed `fpga_compress` - better deallocation of memory and closing of file handles (@iceman1001) From bc8761500885f5c1a644712392b376dd5ea2a49a Mon Sep 17 00:00:00 2001 From: nvx Date: Wed, 23 Aug 2023 02:43:18 +1000 Subject: [PATCH 3/4] Fix help text for hf iclass esetblk --- client/src/cmdhficlass.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 4a4ac3289..92df71046 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -1225,16 +1225,13 @@ static int CmdHFiClassEView(const char *Cmd) { static int CmdHFiClassESetBlk(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf iclass esetblk", - "Display emulator memory.\n" - "Number of bytes to download defaults to 256. Other value is 2048.", - "hf iclass eview\n" - "hf iclass eview -s 2048\n" - "hf iclass eview -s 2048 -v"); + "Sets an individual block in emulator memory.", + "hf iclass esetblk -b 7 -d 0000000000000000"); void *argtable[] = { arg_param_begin, arg_int1("b", "blk", "", "block number"), - arg_str0("d", "data", "", "bytes to write, 16 hex bytes"), + arg_str0("d", "data", "", "bytes to write, 8 hex bytes"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); From 9fdf314347778511ff2323670e440f805fad6220 Mon Sep 17 00:00:00 2001 From: nvx Date: Wed, 23 Aug 2023 03:15:21 +1000 Subject: [PATCH 4/4] regenerate doc/commands.json --- doc/commands.json | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/doc/commands.json b/doc/commands.json index f92263843..12509b1e7 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -3151,17 +3151,15 @@ }, "hf iclass esetblk": { "command": "hf iclass esetblk", - "description": "Display emulator memory. Number of bytes to download defaults to 256. Other value is 2048.", + "description": "Sets an individual block in emulator memory.", "notes": [ - "hf iclass eview", - "hf iclass eview -s 2048", - "hf iclass eview -s 2048 -v" + "hf iclass esetblk -b 7 -d 0000000000000000" ], "offline": false, "options": [ "-h, --help This help", "-b, --blk block number", - "-d, --data bytes to write, 16 hex bytes" + "-d, --data bytes to write, 8 hex bytes" ], "usage": "hf iclass esetblk [-h] -b [-d ]" }, @@ -7001,7 +6999,6 @@ "description": "Simulate a texkom tag", "notes": [ "hf texkom sim", - "", "hf texkom sim --raw FFFF638C7DC45553 -> simulate TK13 tag with id 8C7DC455", "hf texkom sim --tk17 --raw FFFFCA17F31EC512 -> simulate TK17 tag with id 17F31EC5", "hf texkom sim --id 8C7DC455 -> simulate TK13 tag with id 8C7DC455", @@ -11837,6 +11834,6 @@ "metadata": { "commands_extracted": 686, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2023-08-21T21:25:03" + "extracted_on": "2023-08-22T17:13:49" } } \ No newline at end of file