Merge pull request #3828 from matrix/fix-hf15-dump

hf 15 dump: fix field offsets, buffer overflow and short block answers
This commit is contained in:
Iceman authored and GitHub committed 2026-11-14 11:45:18 +08:00
commit 8dfbcba70e
2 files changed
+38 -9

No files matched your search

+1
View File
@@ -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` - wrong block size on tags without DSFID or AFI, buffer overflow on large memories, short block answers copied as full blocks (@matrix)
- Added `configure_environment.sh` / `make configure` - first-run check of a fresh clone: host and ARM toolchains, required and optional client libraries, the `PLATFORM` / `PLATFORM_EXTRAS` in `Makefile.platform`, Python venv and requirements, and device access rights; reports only, with `--install` to fix what it can (@iceman1001)
- Changed `hw status` - PM5 Battery, BWM and Power sections are down to 7 lines with colour coded charge, health and temperature; charger profile, chip details and idle / sleep counters moved to debug level (@iceman1001)
- Changed `hw bwm` - `autooff`, `charge`, `powersave`, `wifi`, `wifipower` and `ble pairing` take dash options (`--on`/`--off`, `--status`/`--stop`, `-m <mode>`) instead of bare words, so they show in the help; their output is aligned and colour codes the state, `autooff` and `ble status` are shorter and flag a default passkey (@iceman1001)
+37 -9
View File
@@ -2316,6 +2316,12 @@ static int CmdHF15Dump(const char *Cmd) {
blocksize = 4;
}
// ISO15693 block size field is 5 bits
if (blocksize > 32) {
PrintAndLogEx(WARNING, "Blocksize too large, using maximum 32 bytes");
blocksize = 32;
}
// default fallback to scan for tag.
if (uidlen != ISO15693_UID_LENGTH && !unaddressed) {
scan = true;
@@ -2403,30 +2409,30 @@ static int CmdHF15Dump(const char *Cmd) {
if (res == PM3_SUCCESS) {
memcpy(tag->uid, d + 2, 8);
// optional fields follow the UID in flag order, only when their flag is set
if (d[1] & 0x01) {
tag->dsfid = d[dCpt];
tag->dsfid = d[dCpt++];
}
dCpt++;
if (d[1] & 0x02) {
tag->afi = d[dCpt];
tag->afi = d[dCpt++];
}
dCpt++;
if (d[1] & 0x04) {
tag->pagesCount = d[dCpt] + 1;
tag->bytesPerPage = d[dCpt + 1] + 1;
// block size in b5-b1, b8-b6 RFU
tag->bytesPerPage = (d[dCpt + 1] & 0x1F) + 1;
dCpt += 2;
} else {
// Set tag memory layout values (if can't be read in SYSINFO)
tag->bytesPerPage = blocksize;
tag->pagesCount = 128;
// 128 blocks, fewer when large blocks would not fit
tag->pagesCount = MIN(128, ISO15693_TAG_MAX_SIZE / blocksize);
}
dCpt += 2;
if (d[1] & 0x08) {
tag->ic = d[dCpt];
}
dCpt++;
} else {
tag->uid[0] = 0xE0;
@@ -2434,7 +2440,22 @@ static int CmdHF15Dump(const char *Cmd) {
tag->afi = 0;
// Set tag memory layout values (if can't be read in SYSINFO)
tag->bytesPerPage = blocksize;
tag->pagesCount = 128;
tag->pagesCount = MIN(128, ISO15693_TAG_MAX_SIZE / blocksize);
}
if ((tag->pagesCount > ISO15693_TAG_MAX_PAGES) ||
((tag->pagesCount * tag->bytesPerPage) > ISO15693_TAG_MAX_SIZE) ||
(tag->pagesCount == 0) ||
(tag->bytesPerPage == 0)) {
PrintAndLogEx(FAILED, "Tag size error: pagesCount=%d, bytesPerPage=%d",
tag->pagesCount,
tag->bytesPerPage
);
free(packet);
free(tag);
DropField();
return PM3_EINVARG;
}
// add length for blockno (1)
@@ -2493,6 +2514,13 @@ static int CmdHF15Dump(const char *Cmd) {
break;
}
// flags, lock status, block data, CRC
if (resp.length < (2 + tag->bytesPerPage + 2)) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(FAILED, "block %d answer too short ( %d bytes, block size %u )", blocknum, resp.length, tag->bytesPerPage);
continue;
}
tag->locks[blocknum] = d[1];
// copy read data