From 451ce54bedadf9286fe352ca1fee38cb7c627eb7 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sat, 7 Nov 2026 00:03:58 +0100 Subject: [PATCH 1/6] lf indala: --fc/--cn parity and checksum as on genuine cards PR #2453 computed the parity bits over stream positions and PR #2947 inverted the checksum, so --fc/--cn clones did not match the genuine cards on record, from issue #2939 and the DangerousThings forum. Both carry the 26-bit Wiegand parity of getIndalaBits4041x and the checksum from before #2947, and the encoder now reproduces them. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + client/src/cmdlfindala.c | 26 ++++++++------------------ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1bedd944..4da21423d 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] +- Fixed `lf indala clone`, `sim` and `brute` with `--fc`/`--cn` - parity and checksum bits as on genuine cards (@matrix) - Fixed flashing with redirected output - the progress animation is drawn only when stdout is a terminal (@matrix) - Fixed `proxmark3 --flash`, `--dumpmem` and `--reboot-to-bootloader` exit status - a failure exits 1, a failed flash no longer ends with `All done` (@matrix) - Fixed `data rawdemod` - `--max`, `--samples` and the `--p2` clock no longer wrap above 255, `--fs` refuses values above 255 (@matrix) diff --git a/client/src/cmdlfindala.c b/client/src/cmdlfindala.c index 2843b43cf..dd49ed167 100644 --- a/client/src/cmdlfindala.c +++ b/client/src/cmdlfindala.c @@ -1163,12 +1163,13 @@ int getIndalaBits(uint8_t fc, uint16_t cn, uint8_t *bits) { chk += ((cn >> 2) & 1); //y14 == 89 - 30 = 59 chk += (cn & 1); //y16 == 71 - 30 = 41 - if ((chk & 1) == 0) { // If the sum is even, checksum is '10' (binary) = 2. - bits[62] = 1; - bits[63] = 0; - } else { // If the sum is odd, checksum is '01' (binary) = 1. + // as on genuine cards, see issue #2939 + if ((chk & 1) == 0) { // If the sum is even, checksum is '01' (binary) = 1. bits[62] = 0; bits[63] = 1; + } else { // If the sum is odd, checksum is '10' (binary) = 2. + bits[62] = 1; + bits[63] = 0; } // add parity @@ -1178,20 +1179,9 @@ int getIndalaBits(uint8_t fc, uint16_t cn, uint8_t *bits) { // 92 = 62 // 93 = 63 - bits[34] = 0; // parity for odd bits - bits[38] = 0; // parity for even bits - uint8_t p1 = 1; - uint8_t p2 = 1; - - for (int i = 33; i < 64; i++) { - if (i % 2) - p1 ^= bits[i]; - else - p2 ^= bits[i]; - } - - bits[34] = p1; // parity for odd bits - bits[38] = p2; // parity for even bits + // 26-bit wiegand parity, as in getIndalaBits4041x + bits[34] = evenparity16((fc << 4) | (cn >> 12)); + bits[38] = oddparity16(cn & 0x0fff); return PM3_SUCCESS; } From ae6e9be0a4d760332a47bf35708cbf484cf8e63e Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sat, 7 Nov 2026 01:42:49 +0100 Subject: [PATCH 2/6] lf indala: count fc bit 6 in the --fc/--cn checksum Three more genuine cards came to light in the repository traces. The checksum over the card number bits alone matched three of the five, with fc bit 6 in the sum it matches all five. Co-Authored-By: Claude Mythos 5.1 --- client/src/cmdlfindala.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/cmdlfindala.c b/client/src/cmdlfindala.c index dd49ed167..059fc45b6 100644 --- a/client/src/cmdlfindala.c +++ b/client/src/cmdlfindala.c @@ -1162,8 +1162,9 @@ int getIndalaBits(uint8_t fc, uint16_t cn, uint8_t *bits) { chk += ((cn >> 5) & 1); //y11 == 67 - 30 = 37 chk += ((cn >> 2) & 1); //y14 == 89 - 30 = 59 chk += (cn & 1); //y16 == 71 - 30 = 41 + chk += ((fc >> 6) & 1); // fc b7 == 49, the five genuine cards on record need it - // as on genuine cards, see issue #2939 + // as on the five genuine cards on record if ((chk & 1) == 0) { // If the sum is even, checksum is '01' (binary) = 1. bits[62] = 0; bits[63] = 1; From 6c1545cb5fa1710cc96e9c109201cfb1c8d3c53f Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sat, 7 Nov 2026 02:39:31 +0100 Subject: [PATCH 3/6] lf indala: --fc/--cn checksum fitted to twelve genuine cards The sum of y2, y4, y7, y8, y10, y11, y14 and y16 comes from a 2014 forum post that says "I believe", and with fc bit 6 added it still missed one of the seven genuine Indala cards now on record (FC 20 CN 9045). The same post gives Keri 26-bit W as the same calculation with "11" and "00", and five such cards are on record. Adding fc bits x1, x2, x3, x5, x6 and x7 fits all twelve. With these card number bits and "01" for an even sum, no other fc set does. Co-Authored-By: Claude Opus 5.5 --- client/src/cmdlfindala.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/cmdlfindala.c b/client/src/cmdlfindala.c index 059fc45b6..ae47c3872 100644 --- a/client/src/cmdlfindala.c +++ b/client/src/cmdlfindala.c @@ -1162,9 +1162,9 @@ int getIndalaBits(uint8_t fc, uint16_t cn, uint8_t *bits) { chk += ((cn >> 5) & 1); //y11 == 67 - 30 = 37 chk += ((cn >> 2) & 1); //y14 == 89 - 30 = 59 chk += (cn & 1); //y16 == 71 - 30 = 41 - chk += ((fc >> 6) & 1); // fc b7 == 49, the five genuine cards on record need it + chk += evenparity8(fc & 0xEE); // x1 x2 x3 x5 x6 x7 - // as on the five genuine cards on record + // fitted to the genuine Indala and Keri W cards on record if ((chk & 1) == 0) { // If the sum is even, checksum is '01' (binary) = 1. bits[62] = 0; bits[63] = 1; From 5bc67a0d1c011ef7227fd470fec137c979da7f8b Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sat, 7 Nov 2026 20:01:51 +0100 Subject: [PATCH 4/6] lf destron: implement sim, refuse uids the frame can't carry lf destron sim only printed "To be implemented". It now sends the frame that lf destron clone writes, FSK2 RF/50 as in the clone's T5577 config. Both take 5 bytes of 00-7F: clone wrote a byte above 7F without its top bit and padded a short uid with FF of bad parity. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 + client/src/cmdlfdestron.c | 98 +++++++++++++++++++++++++++++++-------- doc/commands.json | 13 +++--- tools/pm3_tests.sh | 1 + 4 files changed, 89 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df0841f18..3768a6797 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ 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 `lf destron sim` - simulates the FDX-A frame that `lf destron clone` writes (@matrix) +- Fixed `lf destron clone` - a uid that is not 5 bytes of 00-7F is refused instead of written as another id or with bad parity (@matrix) - Fixed `hf thinfilm sim` - a second simulation in the same client no longer ends at once with `Done!` (@matrix) - Added `hf mf supercard -u` - UID change on super card generation 2 (@mishamyte) - Changed `hf mf supercard` - a refused `-r`/`-u` now exits non-zero instead of reporting success (@mishamyte) diff --git a/client/src/cmdlfdestron.c b/client/src/cmdlfdestron.c index a9c6b1bd2..f9f1b06e3 100644 --- a/client/src/cmdlfdestron.c +++ b/client/src/cmdlfdestron.c @@ -17,6 +17,7 @@ //----------------------------------------------------------------------------- #include "cmdlfdestron.h" #include // tolower +#include // calloc #include // memcpy #include "commonutil.h" // ARRAYLEN #include "common.h" @@ -134,6 +135,37 @@ static int CmdDestronReader(const char *Cmd) { return PM3_SUCCESS; } +// a uid is five bytes of 7 bits, the top bit of each carries its parity +static int checkDestronUid(const uint8_t *data, int datalen) { + if (datalen != 5) { + PrintAndLogEx(FAILED, "Uid must include 5 hex bytes (10 hex symbols), got " _YELLOW_("%d"), datalen); + return PM3_EINVARG; + } + + for (int i = 0; i < datalen; i++) { + if (data[i] & 0x80) { + PrintAndLogEx(FAILED, "Uid byte %d is " _YELLOW_("%02X") ", each byte holds 7 bits (00-7F)", i + 1, data[i]); + return PM3_EINVARG; + } + } + return PM3_SUCCESS; +} + +// the three data blocks of a frame, as cloned and simulated +static void getDestronBlocks(const uint8_t *data, int datalen, uint32_t *blocks) { + uint8_t data_ex[12 + 24] = {0}; // ManchesterEncode need extra room + for (int i = 0; i < datalen; i++) { + data_ex[i + 1] = ~(data [i] | (oddparity8(data[i]) << 7)); + } + + // manchester encode it + for (int i = 0; i < 3; i++) { + blocks[i] = manchesterEncode2Bytes((data_ex[i * 2] << 8) + data_ex[i * 2 + 1]); + } + // inject preamble + blocks[0] = (blocks[0] & 0xFFFF) | 0xAAE20000; +} + static int CmdDestronClone(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "lf destron clone", @@ -145,7 +177,7 @@ static int CmdDestronClone(const char *Cmd) { void *argtable[] = { arg_param_begin, - arg_str1("u", "uid", "", "5 bytes max"), + arg_str1("u", "uid", "", "5 hex bytes, 00-7F each"), arg_lit0(NULL, "q5", "optional - specify writing to Q5/T5555 tag"), arg_lit0(NULL, "em", "optional - specify writing to EM4305/4469 tag"), arg_param_end @@ -166,8 +198,7 @@ static int CmdDestronClone(const char *Cmd) { return PM3_EINVARG; } - if (datalen > 5) { - PrintAndLogEx(FAILED, "Uid is max 5 bytes. (got %u)", datalen); + if (checkDestronUid(data, datalen) != PM3_SUCCESS) { return PM3_EINVARG; } @@ -187,17 +218,7 @@ static int CmdDestronClone(const char *Cmd) { snprintf(cardtype, sizeof(cardtype), "EM4305/4469"); } - uint8_t data_ex[12 + 24] = {0}; // ManchesterEncode need extra room - for (int i = 0; i < datalen; i++) { - data_ex[i + 1] = ~(data [i] | (oddparity8(data[i]) << 7)); - } - - // manchester encode it - for (int i = 0; i < 3; i++) { - blocks[i + 1] = manchesterEncode2Bytes((data_ex[i * 2] << 8) + data_ex[i * 2 + 1]); - } - // inject preamble - blocks[1] = (blocks[1] & 0xFFFF) | 0xAAE20000; + getDestronBlocks(data, datalen, blocks + 1); PrintAndLogEx(INFO, "Preparing to clone Destron tag to " _YELLOW_("%s") " with ID: " _YELLOW_("%s") , cardtype @@ -220,18 +241,57 @@ static int CmdDestronClone(const char *Cmd) { static int CmdDestronSim(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "lf destron sim", - "Try to find Destron preamble, if found decode / descramble data", - "lf destron sim" + "Enables simulation of Destron card with specified uid.\n" + "Simulation runs until the button is pressed or another USB command is issued.", + "lf destron sim --uid 1A2B3C4D5E" ); void *argtable[] = { arg_param_begin, + arg_str1("u", "uid", "", "5 hex bytes, 00-7F each"), arg_param_end }; - CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIExecWithReturn(ctx, Cmd, argtable, false); + + uint8_t data[8]; + int datalen = 0; + CLIGetHexWithReturn(ctx, 1, data, &datalen); CLIParserFree(ctx); - PrintAndLogEx(INFO, " To be implemented, feel free to contribute!"); - return PM3_ENOTIMPL; + + if (checkDestronUid(data, datalen) != PM3_SUCCESS) { + return PM3_EINVARG; + } + + uint32_t blocks[3] = {0}; + getDestronBlocks(data, datalen, blocks); + + PrintAndLogEx(SUCCESS, "Simulating Destron - ID: " _YELLOW_("%s") ", Raw: " _YELLOW_("%08X%08X%08X") + , sprint_hex_inrow(data, datalen) + , blocks[0], blocks[1], blocks[2] + ); + + uint8_t bs[96]; + for (size_t i = 0; i < ARRAYLEN(blocks); i++) { + num_to_bytebits(blocks[i], 32, bs + (i * 32)); + } + + // FSK2 as in clone: 1 is fc/8, 0 is fc/10 + lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + sizeof(bs)); + if (payload == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); + return PM3_EMALLOC; + } + payload->fchigh = 8; + payload->fclow = 10; + payload->separator = 0; + payload->clock = 50; + memcpy(payload->data, bs, sizeof(bs)); + + clearCommandBuffer(); + SendCommandNG(CMD_LF_FSK_SIMULATE, (uint8_t *)payload, sizeof(lf_fsksim_t) + sizeof(bs)); + free(payload); + + return lfsim_wait_check(CMD_LF_FSK_SIMULATE); } static command_t CommandTable[] = { diff --git a/doc/commands.json b/doc/commands.json index 9c22c6718..49b6eb863 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -11796,7 +11796,7 @@ "offline": false, "options": [ "-h, --help This help", - "-u, --uid 5 bytes max", + "-u, --uid 5 hex bytes, 00-7F each", "--q5 optional - specify writing to Q5/T5555 tag", "--em optional - specify writing to EM4305/4469 tag" ], @@ -11829,15 +11829,16 @@ }, "lf destron sim": { "command": "lf destron sim", - "description": "Try to find Destron preamble, if found decode / descramble data", + "description": "Enables simulation of Destron card with specified uid. Simulation runs until the button is pressed or another USB command is issued.", "notes": [ - "lf destron sim" + "lf destron sim --uid 1A2B3C4D5E" ], "offline": false, "options": [ - "-h, --help This help" + "-h, --help This help", + "-u, --uid 5 hex bytes, 00-7F each" ], - "usage": "lf destron sim [-h]" + "usage": "lf destron sim [-h] -u " }, "lf em 410x brute": { "command": "lf em 410x brute", @@ -16812,6 +16813,6 @@ "metadata": { "commands_extracted": 936, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2026-11-06T22:34:07+00:00" + "extracted_on": "2026-11-07T18:51:39+00:00" } } diff --git a/tools/pm3_tests.sh b/tools/pm3_tests.sh index 74a45e0b4..ab21ab98e 100755 --- a/tools/pm3_tests.sh +++ b/tools/pm3_tests.sh @@ -577,6 +577,7 @@ while true; do if ! CheckExecute "lf EM4x70 recover test 2/3" "$CLIENTBIN -c 'lf em 4x70 recover --key 022A028C02BE --rnd 7D5167003571F8 --frn 982DBCC0 --grn 36C0E0'" "022a028c02be366866191b60"; then break; fi if ! CheckExecute "lf EM4x70 recover test 3/3" "$CLIENTBIN -c 'lf em 4x70 recover --key 022A028C02BE --rnd 7D5167003571F8 --frn 982DBCC0 --grn 36C0E0'" "022a028c02bef1e352c2718d"; then break; fi if ! CheckExecute "lf FDX-A FECAVA test" "$CLIENTBIN -c 'data load -f traces/lf_EM4305_fdxa_destron.pm3;lf search -1'" "FDX-A FECAVA Destron ID found"; then break; fi + if ! CheckExecute "lf destron sim help" "$CLIENTBIN -c 'lf destron sim -h'" "lf destron sim --uid 1A2B3C4D5E"; then break; fi if ! CheckExecute "lf FDX-B test" "$CLIENTBIN -c 'data load -f traces/lf_HomeAgain1600.pm3;lf search -1'" "FDX-B ID found"; then break; fi if ! CheckExecute "lf FDX/BioThermo test" "$CLIENTBIN -c 'data load -f traces/lf_FDXB_Bio-Thermo.pm3; lf fdxb demod'" "95.2 F / 35.1 C"; then break; fi if ! CheckExecute "lf GPROXII test" "$CLIENTBIN -c 'data load -f traces/lf_GProx_36_30_14489.pm3; lf search -1'" "Guardall G-Prox II ID found"; then break; fi From 96ad2981bda075acdaba4633d86d1644675a7e79 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sun, 8 Nov 2026 02:08:02 +0100 Subject: [PATCH 5/6] lf hitag: refuse bad pages and data, fix eview, Paxton and LCK1 output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The page check covers the Hitag 2, S and µ `wrbl`, the data check S and µ. `htu rdbl -c` stops at the 55 blocks the reply holds, `hts -m` above 3 is refused, `ta -h` shows its help and argument errors free the parser. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ client/src/cmdlfhitag.c | 16 +++++++++++++--- client/src/cmdlfhitaghts.c | 20 ++++++++++++++++---- client/src/cmdlfhitagu.c | 19 ++++++++++++++++--- tools/pm3_tests.sh | 1 + 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f8f9eea1..892f5e95d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ 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] +- Fixed `lf hitag wrbl`, `hts wrbl` and `htu wrbl` - a page out of range or data shorter than 4 bytes is refused (@matrix) +- Fixed `lf hitag eview -1/-s/-m` and `htu rdbl -c` - no read past the label table or the reply (@matrix) +- Fixed `lf hitag` and `lf search` Paxton id - no garbage before the form factor (@matrix) +- Fixed `lf hitag hts rdbl`, `hts -m` and `ta -h` - page 32 under LCK1, mode above 3 refused, help shown (@matrix) - Added `lf destron sim` - simulates the FDX-A frame that `lf destron clone` writes (@matrix) - Fixed `lf destron clone` - a uid that is not 5 bytes of 00-7F is refused instead of written as another id or with bad parity (@matrix) - Fixed `lf fdxb` decoding - ISO 11784:2024 and ISO 24631-6 fields and names, and many more fixes. See commit message (@matrix) diff --git a/client/src/cmdlfhitag.c b/client/src/cmdlfhitag.c index c7aa90f08..321e9353a 100644 --- a/client/src/cmdlfhitag.c +++ b/client/src/cmdlfhitag.c @@ -250,7 +250,7 @@ static void print_hitag2_paxton(bool show_header, const uint8_t *data) { // [=] 4/0x04 | 39 04 21 1C | 9.!. | RW | User // [=] 5/0x05 | AC 3F 00 06 | .?.. | RW | User - char formfactor[16]; + char formfactor[16] = {0}; switch (data[23]) { case 0x06: { strcat(formfactor, "isocard"); @@ -332,7 +332,7 @@ static void print_hitag2_configuration(uint32_t uid, uint8_t config) { PrintAndLogEx(NORMAL, ""); } -const char *annotation[] = { +static const char *annotation[] = { "UID", "Pwd", "Key/Pwd", "Config", "User", "User", "User", "User", "User", "User", "User", "User" @@ -410,7 +410,7 @@ static void print_hitag2_blocks(uint8_t *d, uint16_t n) { , sprint_hex(d + (i * HITAG_BLOCK_SIZE), HITAG_BLOCK_SIZE) , sprint_ascii(d + (i * HITAG_BLOCK_SIZE), HITAG_BLOCK_SIZE) , lckstr - , annotation[i] + , (i < ARRAYLEN(annotation)) ? annotation[i] : "User" ); } PrintAndLogEx(INFO, "--------+-------------+-------+-----+---------"); @@ -1225,6 +1225,11 @@ static int CmdLFHitag2CheckChallenges(const char *Cmd) { "Test recorded authentications (replay?)", "lf hitag ta" ); + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); lf_hitag_data_t packet; @@ -1333,6 +1338,11 @@ static int CmdLFHitagWriter(const char *Cmd) { return PM3_EINVARG; } + if ((page < 0) || (page >= HITAG2_MAX_BLOCKS)) { + PrintAndLogEx(WARNING, "Page address out-of-range. Max is %d, got %d", HITAG2_MAX_BLOCKS - 1, page); + return PM3_EINVARG; + } + if (nalen != 0 && nalen != 8) { PrintAndLogEx(WARNING, "Wrong NR/AR len expected 0 or 8, got %d", nalen); return PM3_EINVARG; diff --git a/client/src/cmdlfhitaghts.c b/client/src/cmdlfhitaghts.c index 2f52823f8..a9e1afa05 100644 --- a/client/src/cmdlfhitaghts.c +++ b/client/src/cmdlfhitaghts.c @@ -229,9 +229,9 @@ static int process_hitags_common_args(CLIParserContext *ctx, lf_hitag_data_t *co return PM3_EINVARG; } - uint8_t mode = arg_get_int_def(ctx, 5, 3); + int mode = arg_get_int_def(ctx, 5, 3); - if (mode > 3) { + if ((mode < 0) || (mode > 3)) { PrintAndLogEx(WARNING, "Wrong response protocol mode, expected 0, 1, 2 or 3, got %d", mode); return PM3_EINVARG; } @@ -416,6 +416,7 @@ static int CmdLFHitagSRead(const char *Cmd) { if (page > 255) { PrintAndLogEx(WARNING, "Page address Invalid."); + CLIParserFree(ctx); return PM3_EINVARG; } @@ -423,6 +424,7 @@ static int CmdLFHitagSRead(const char *Cmd) { if (count > HITAGS_MAX_PAGES) { PrintAndLogEx(WARNING, "No more than 64 pages can be read at once."); + CLIParserFree(ctx); return PM3_EINVARG; } @@ -480,7 +482,6 @@ static int CmdLFHitagSRead(const char *Cmd) { // access right if (page_addr == HITAGS_UID_PADR) { PrintAndLogEx(NORMAL, _RED_("RO ")NOLF); - \ } else if (packet.cmd == HTSF_82xx && page_addr > 40) { // using an 82xx (pages>40 are RO) PrintAndLogEx(NORMAL, _RED_("RO ")NOLF); } else if (page_addr == HITAGS_CONFIG_PADR) { @@ -524,7 +525,7 @@ static int CmdLFHitagSRead(const char *Cmd) { PrintAndLogEx(NORMAL, _RED_("RO ")NOLF); else PrintAndLogEx(NORMAL, _GREEN_("RW ")NOLF); - } else if (24 <= page_addr && page_addr <= 32) { + } else if (24 <= page_addr && page_addr <= 31) { if (card->config_page.s.LCK2) PrintAndLogEx(NORMAL, _RED_("RO ")NOLF); else @@ -701,6 +702,7 @@ static int CmdLFHitagSRestore(const char *Cmd) { int fnlen = 0; char filename[FILE_PATH_SIZE] = {0}; CLIParamStrToBuf(arg_get_str(ctx, 6), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); + CLIParserFree(ctx); if (fnlen == 0) { PrintAndLogEx(ERR, "Must specify a file"); @@ -930,6 +932,16 @@ static int CmdLFHitagSWrite(const char *Cmd) { CLIParserFree(ctx); + if ((page < 0) || (page > 255)) { + PrintAndLogEx(WARNING, "Page address Invalid."); + return PM3_EINVARG; + } + + if (data_len != sizeof(data)) { + PrintAndLogEx(WARNING, "Wrong DATA len expected 4, got %d", data_len); + return PM3_EINVARG; + } + packet.page = page; memcpy(packet.data, data, sizeof(packet.data)); diff --git a/client/src/cmdlfhitagu.c b/client/src/cmdlfhitagu.c index 5d0ec275f..1430823df 100644 --- a/client/src/cmdlfhitagu.c +++ b/client/src/cmdlfhitagu.c @@ -349,13 +349,16 @@ static int CmdLFHitagURead(const char *Cmd) { if (page >= HITAGU_MAX_BLOCKS) { PrintAndLogEx(WARNING, "Block address out-of-range. Max is 255, got %u", page); + CLIParserFree(ctx); return PM3_EINVARG; } uint32_t count = arg_get_int_def(ctx, 4, 1); - if (count > HITAGU_MAX_BLOCKS) { - PrintAndLogEx(WARNING, "No more than %d blocks can be read at once", HITAGU_MAX_BLOCKS); + // the read response holds HITAGU_MAX_PAGE_ADVANCED_PLUS blocks + if (count > HITAGU_MAX_PAGE_ADVANCED_PLUS) { + PrintAndLogEx(WARNING, "No more than %d blocks can be read at once", HITAGU_MAX_PAGE_ADVANCED_PLUS); + CLIParserFree(ctx); return PM3_EINVARG; } @@ -422,7 +425,7 @@ static int CmdLFHitagURead(const char *Cmd) { count = (user_blocks > page) ? (user_blocks - page) : HITAGU_MAX_BLOCKS; } - for (int i = 0; i < count; ++i) { + for (int i = 0; (i < count) && (i < HITAGU_MAX_PAGE_ADVANCED_PLUS); ++i) { int page_addr = page + i; if (page_addr >= HITAGU_MAX_BLOCKS) { @@ -645,6 +648,16 @@ static int CmdLFHitagUWrite(const char *Cmd) { CLIParserFree(ctx); + if ((page < 0) || (page >= HITAGU_MAX_BLOCKS)) { + PrintAndLogEx(WARNING, "Block address out-of-range. Max is 255, got %d", page); + return PM3_EINVARG; + } + + if (data_len != sizeof(data)) { + PrintAndLogEx(WARNING, "Wrong DATA len expected 4, got %d", data_len); + return PM3_EINVARG; + } + packet.page = page; memcpy(packet.data, data, sizeof(packet.data)); diff --git a/tools/pm3_tests.sh b/tools/pm3_tests.sh index 893040143..10f1f7815 100755 --- a/tools/pm3_tests.sh +++ b/tools/pm3_tests.sh @@ -561,6 +561,7 @@ while true; do echo -e "\n${C_BLUE}Testing LF:${C_NC}" if ! CheckExecute "lf hitag2 test" "$CLIENTBIN -c 'lf hitag test'" "Tests \( ok"; then break; fi + if ! CheckExecute "lf hitag ta help" "$CLIENTBIN -c 'lf hitag ta -h'" "Test recorded authentications"; then break; fi if ! CheckExecute "lf cotag demod test 1/4" "$CLIENTBIN -c 'data load -f traces/lf_cotag_220_8331.pm3; lf cotag demod -c 272 -v'" \ "data hex: 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 5 8 2 4 E 0 0 0 0 8 0 2 3 D F 7 7"; then break; fi if ! CheckExecute "lf cotag demod test 2/4" "$CLIENTBIN -c 'data load -f traces/cotag/lf_cotag_passive_02402447_700000.pm3; lf cotag demod -v'" \ From a70f0adec86e6263ca493069145a637e731df798 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sun, 8 Nov 2026 03:55:51 +0100 Subject: [PATCH 6/6] lf noralsy demod: stop losing reads to one demod error, accept BB0314FF ASKDemod_ext() was called with maxErr 0. The error is most often the cut first bit of the read, outside every frame. cmdlfgallagher.c passes 100 in the same call since dfb7eaf06, and a frame still has to pass both checksums. A 0xBB0314FF first block, which getnoralsyBits() notes as seen, no longer gets the unknown bits warning. The example in the comment is such a card, its hex column said BB0214FF. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 ++ client/src/cmdlfnoralsy.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f8f9eea1..281326c62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ 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] +- Fixed `lf noralsy demod` - one demod error outside the frame, like a cut first bit, no longer loses the read (@matrix) +- Fixed `lf noralsy demod` - a card with the 0xBB0314FF first block no longer gets the unknown bits warning (@matrix) - Added `lf destron sim` - simulates the FDX-A frame that `lf destron clone` writes (@matrix) - Fixed `lf destron clone` - a uid that is not 5 bytes of 00-7F is refused instead of written as another id or with bad parity (@matrix) - Fixed `lf fdxb` decoding - ISO 11784:2024 and ISO 24631-6 fields and names, and many more fixes. See commit message (@matrix) diff --git a/client/src/cmdlfnoralsy.c b/client/src/cmdlfnoralsy.c index b10ee7f97..e3278ddfb 100644 --- a/client/src/cmdlfnoralsy.c +++ b/client/src/cmdlfnoralsy.c @@ -46,7 +46,7 @@ int demodNoralsy(bool verbose) { (void) verbose; // unused so far //ASK / Manchester bool st = true; - if (ASKDemod_ext(32, 0, 0, 0, false, false, false, 1, &st) != PM3_SUCCESS) { + if (ASKDemod_ext(32, 0, 100, 0, false, false, false, 1, &st) != PM3_SUCCESS) { if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - Noralsy: ASK/Manchester Demod failed"); return PM3_ESOFT; } @@ -104,8 +104,8 @@ int demodNoralsy(bool verbose) { } PrintAndLogEx(SUCCESS, "Noralsy - Card: " _GREEN_("%u")", Year: " _GREEN_("%u") ", Raw: %08X%08X%08X", cardid, year, raw1, raw2, raw3); - if (raw1 != 0xBB0214FF) { - PrintAndLogEx(WARNING, "Unknown bits set in first block! Expected 0xBB0214FF, Found: 0x%08X", raw1); + if ((raw1 != 0xBB0214FF) && (raw1 != 0xBB0314FF)) { + PrintAndLogEx(WARNING, "Unknown bits set in first block! Expected 0xBB0214FF or 0xBB0314FF, Found: 0x%08X", raw1); PrintAndLogEx(WARNING, "Please post this output in forum to further research on this format"); } return PM3_SUCCESS; @@ -346,7 +346,7 @@ int detectNoralsy(uint8_t *dest, size_t *size) { } /* * -* 2520116 | BB0214FF2529900116360000 | 10111011 00000011 00010100 11111111 00100101 00101001 10010000 00000001 00010110 00110110 00000000 00000000 +* 2520116 | BB0314FF2529900116360000 | 10111011 00000011 00010100 11111111 00100101 00101001 10010000 00000001 00010110 00110110 00000000 00000000 * aaa*aaaaiiiYY*iiiicc---- **** iiiiiiii iiiiYYYY YYYY**** iiiiiiii iiiiiiii cccccccc * * a = fixed value BB0*14FF