From 1cb843a22bbb5c5afc93478f8ab2806792ec6b39 Mon Sep 17 00:00:00 2001 From: team-orangeBlue <63470411+team-orangeBlue@users.noreply.github.com> Date: Sat, 11 Apr 2026 00:38:14 +0300 Subject: [PATCH] Fix bug in ACL block-RO checker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code as-is would bug out like below: ``` (input) --blk 255 -d ...f0f0f0... [=] Sector trailer (ST) write detected [!] ⚠️ Strict ReadOnly Access Conditions on block 240 detected [!] ⚠️ Strict ReadOnly Access Conditions on block 241 detected [!] ⚠️ Strict ReadOnly Access Conditions on block 242 detected ``` This is incorrect. in 16-block sectors, ACLs cover chunks of 5 blocks at once. It should (and now does) look like: ``` [=] Sector trailer (ST) write detected [!] ⚠️ Strict ReadOnly Access Conditions on blocks 240-244 detected [!] ⚠️ Strict ReadOnly Access Conditions on blocks 245-249 detected [!] ⚠️ Strict ReadOnly Access Conditions on blocks 250-254 detected ``` Signed-off-by: team-orangeBlue <63470411+team-orangeBlue@users.noreply.github.com> --- client/src/cmdhfmfp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/src/cmdhfmfp.c b/client/src/cmdhfmfp.c index b21fb2fdf..3ca9d495c 100644 --- a/client/src/cmdhfmfp.c +++ b/client/src/cmdhfmfp.c @@ -1195,10 +1195,16 @@ static int mfp_analyse_st_block(uint8_t blockno, uint8_t *block, bool force) { } bool ro_detected = false; - uint8_t bar = mfNumBlocksPerSector(mfSectorNum(blockno)); + //uint8_t bar = mfNumBlocksPerSector(mfSectorNum(blockno)); + uint8_t bar = 4; for (uint8_t foo = 0; foo < bar; foo++) { if (mfReadOnlyAccessConditions(foo, &block[6])) { - PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on block " _YELLOW_("%u") " detected", blockno - bar + 1 + foo); + // WARNING: Sectors 33+ assume ACLs apply to groups of 4 blocks, not 1 block. + // The code as-is is bugged and actually wastes iterations. If you have 16 blocks, it'll run all 16 but only error out like it's a 4-block sector. + if (blockno<127) + PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on block " _YELLOW_("%u") " detected", blockno - bar + 1 + foo); + else + PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on blocks " _YELLOW_("%u-%u") " detected", blockno - bar*4 + 1 + foo*5, blockno - bar*4 + 1 + foo*5 + 4); ro_detected = true; } }