diff --git a/CHANGELOG.md b/CHANGELOG.md index eec2ac775..06254cec2 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) 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..92df71046 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,49 @@ static int CmdHFiClassEView(const char *Cmd) { return PM3_SUCCESS; } +static int CmdHFiClassESetBlk(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf iclass esetblk", + "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, 8 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 +4269,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..12509b1e7 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,20 @@ ], "usage": "hf iclass esave [-h] [-f ] [-s <256|2048>]" }, + "hf iclass esetblk": { + "command": "hf iclass esetblk", + "description": "Sets an individual block in emulator memory.", + "notes": [ + "hf iclass esetblk -b 7 -d 0000000000000000" + ], + "offline": false, + "options": [ + "-h, --help This help", + "-b, --blk block number", + "-d, --data bytes to write, 8 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.", @@ -8770,7 +8783,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 +11832,8 @@ } }, "metadata": { - "commands_extracted": 685, + "commands_extracted": 686, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2023-08-02T20:39:48" + "extracted_on": "2023-08-22T17:13:49" } } \ 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`