From 1acecc29b1e2b1efccbd3e1648970a3aa93ca8cd Mon Sep 17 00:00:00 2001 From: nvx Date: Fri, 22 Jul 2022 14:01:13 +1000 Subject: [PATCH] Changed `hf iclass view` to suppress consecutive blocks with repeated contents --- CHANGELOG.md | 1 + client/src/cmdhficlass.c | 51 +++++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9757a2952..b71ef48e0 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] + - Changed `hf iclass view` to suppress consecutive blocks with repeated contents (@nvx) - Added `hf gallagher decode` command and fix Gallagher diversification for card master key (@nvx) - Added mmbit-002 (kibi-002, kb5004xk1) russian tag to `hf texkom read` command (@merlokk) - Added `hf sniff --smode` skip/group adc data to consume less memory. Now it can sniff very long signals (@merlokk) diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index ea16de75c..f687807c4 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -2553,6 +2553,7 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e if (i != 1) PrintAndLogEx(INFO, " ......"); + bool in_repeated_block = false; while (i <= endblock) { uint8_t *blk = iclass_dump + (i * 8); @@ -2594,21 +2595,17 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e const char *lockstr = (bl_lock) ? _RED_("x") : " "; + const char *block_info; + bool regular_print_block = false; if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) { const char *info_nonks[] = {"CSN", "Config", "AIA", "User"}; - const char *s = info_nonks[3]; if (i < 3) { - s = info_nonks[i]; + block_info = info_nonks[i]; + } else { + block_info = info_nonks[3]; } - PrintAndLogEx(INFO, "%3d/0x%02X | %s | %s | %s " - , i - , i - , sprint_hex_ascii(blk, 8) - , lockstr - , s - ); - + regular_print_block = true; } else { const char *info_ks[] = {"CSN", "Config", "E-purse", "Debit", "Credit", "AIA", "User"}; @@ -2640,13 +2637,40 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e , lockstr ); } else { - const char *s = info_ks[6]; if (i < 6) { - s = info_ks[i]; + block_info = info_ks[i]; + } else { + block_info = info_ks[6]; } - PrintAndLogEx(INFO, "%3d/0x%02X | %s | %s | %s ", i, i, sprint_hex_ascii(blk, 8), lockstr, s); + + regular_print_block = true; } } + + if (regular_print_block) { + // suppress repeating blocks, truncate as such that the first and last block with the same data is shown + // but the blocks in between are replaced with a single line of "*" + if (i > 6 && i < (endblock - 1) && !in_repeated_block && !memcmp(blk, blk - 8, 8) && + !memcmp(blk, blk + 8, 8) && !memcmp(blk, blk + 16, 8)) { + // we're in a user block that isn't the first user block nor last two user blocks, + // and the current block data is the same as the previous and next two block + in_repeated_block = true; + PrintAndLogEx(INFO, "*"); + } else if (in_repeated_block && (memcmp(blk, blk + 8, 8) || i == endblock)) { + // in a repeating block, but the next block doesn't match anymore, or we're at the end block + in_repeated_block = false; + } + if (!in_repeated_block) { + PrintAndLogEx(INFO, + "%3d/0x%02X | %s | %s | %s ", + i, + i, + sprint_hex_ascii(blk, 8), + lockstr, + block_info); + } + } + i++; } PrintAndLogEx(INFO, "---------+-------------------------+----------+---+----------------"); @@ -4127,4 +4151,3 @@ int info_iclass(void) { return PM3_SUCCESS; } -