From c546b70d12a89d65c04d8a4345f19a42041675a5 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 12 Nov 2026 21:20:43 +0700 Subject: [PATCH] hf 15 dump: don't show or save unread blocks as data After two failed reads of a block the dump loop ends, but the table was still printed for every block the tag reports, from a buffer that is zero where nothing was read, the command returned PM3_SUCCESS, and without --ns that table was saved as the dump. A card with genuine zero blocks makes the difference impossible to see. On a PM5 before 05c21a33b every dump of an EM4233 read block 0, failed on block 1 and printed all 52 rows. A dump that stops early now prints only the blocks it read, says "Dump incomplete, read X of Y blocks, not saved", saves nothing and returns PM3_EPARTIAL. The tag answering 0x0F/0x10 is different: that is the existing end of memory heuristic, used when SYSINFO gave no size and 128 blocks were assumed. The block count now becomes what the tag actually holds, so the dump stays complete and no rows past the real end are shown. Behaviour change: an interrupted dump exits PM3_EPARTIAL instead of 0 and writes no file. A complete dump is unchanged. Tested on a PM5 with an EM4233 (52 blocks), the pre-05c21a33b firmware serving as a source of genuine read failures: - fixed firmware, 1-of-4 and 1-of-256: 20/20 complete, exit 0 - failing firmware, 1-of-4: 15/15 "read 2..14 of 52 blocks, not saved", only those rows printed, exit PM3_EPARTIAL; without --ns no file - the end of memory path was not reached: this tag reports its size in SYSINFO Builds clean with gcc and clang. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + client/src/cmdhf15.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1343ba002..73607d32c 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 `hf 15 dump` - a dump that stops early no longer prints and saves the unread blocks as zeros; it shows the blocks it read, says how many of the total, saves nothing and returns PM3_EPARTIAL. A tag that ends before the default 128 blocks is shown at its real size (@iceman1001) - Fixed `hf mf brute` - Enter or a chunk timeout stops it, no division by zero on a stage under 1 s (@matrix) - Fixed `hf mf brute` - `--emu` checks the trailer read, `--dump` keeps the keys when the card is gone and reports a failed save (@matrix) - Fixed `hf mf fchk` - Enter or a timeout during a chunk stops it, `--emu` checks the trailer read (@matrix) diff --git a/client/src/cmdhf15.c b/client/src/cmdhf15.c index aaf4fb901..e428cfe3a 100644 --- a/client/src/cmdhf15.c +++ b/client/src/cmdhf15.c @@ -2450,6 +2450,7 @@ static int CmdHF15Dump(const char *Cmd) { PrintAndLogEx(SUCCESS, "Reading memory"); int blocknum = 0; + bool end_of_memory = false; for (int retry = 0; (retry < 2 && blocknum < tag->pagesCount); retry++) { if (used_uid) { @@ -2483,6 +2484,7 @@ static int CmdHF15Dump(const char *Cmd) { // heuristic determine end of available memory if (d[1] == 0x0F || d[1] == 0x10) { + end_of_memory = true; break; } @@ -2508,6 +2510,19 @@ static int CmdHF15Dump(const char *Cmd) { // done reading tag memory + // The tag has no more blocks than this, the rest of the default range doesn't exist + if (end_of_memory) { + tag->pagesCount = blocknum; + } + + // Anything else that ended the loop early left the remaining blocks unread. They + // must not be shown as data, nor saved as a dump + bool incomplete = (blocknum < tag->pagesCount); + uint32_t expected = tag->pagesCount; + if (incomplete) { + tag->pagesCount = blocknum; + } + if (tag->bytesPerPage != blocksize) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, _YELLOW_("%u") " bytes block length detected, called with " _YELLOW_("%d"), tag->bytesPerPage, blocksize); @@ -2516,6 +2531,14 @@ static int CmdHF15Dump(const char *Cmd) { print_tag_15693(tag, dense_output, verbose); + if (incomplete) { + PrintAndLogEx(WARNING, "Dump " _RED_("incomplete") ", read %d of %u blocks, not saved", blocknum, expected); + PrintAndLogEx(HINT, "Hint: reposition the card and run the dump again"); + PrintAndLogEx(NORMAL, ""); + free(tag); + return PM3_EPARTIAL; + } + if (no_save) { PrintAndLogEx(INFO, "Called with no save option"); PrintAndLogEx(NORMAL, "");