From 3e582b246a4557b1fa939be9958c826d83e22e3a Mon Sep 17 00:00:00 2001 From: DidierA Date: Tue, 20 Sep 2022 23:01:25 +0200 Subject: [PATCH 1/2] print_sr_blocks(): don't assume uid is at begining of dump --- client/src/cmdhf14b.c | 32 ++++++++++++++++++++++++++------ client/src/cmdhf14b.h | 1 + 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/client/src/cmdhf14b.c b/client/src/cmdhf14b.c index 7288c3251..1f6d62523 100644 --- a/client/src/cmdhf14b.c +++ b/client/src/cmdhf14b.c @@ -787,11 +787,11 @@ static void print_ct_blocks(uint8_t *data, size_t len) { } */ -static void print_sr_blocks(uint8_t *data, size_t len) { +static void print_sr_blocks(uint8_t *data, size_t len, const uint8_t *uid) { size_t blocks = (len / ST25TB_SR_BLOCK_SIZE) -1 ; uint8_t * systemblock = data + blocks * ST25TB_SR_BLOCK_SIZE ; - uint8_t chipid = get_st_chipid(data); + uint8_t chipid = get_st_chipid(uid); PrintAndLogEx(SUCCESS, _GREEN_("%s") " tag", get_st_chip_model(chipid)); PrintAndLogEx(DEBUG, "systemblock : %s", sprint_hex(systemblock, ST25TB_SR_BLOCK_SIZE)); @@ -1426,7 +1426,6 @@ static int CmdHF14BDump(const char *Cmd) { // detect blocksize from card :) PrintAndLogEx(INFO, "reading tag memory from UID " _GREEN_("%s"), sprint_hex_inrow(SwapEndian64(card.uid, card.uidlen, 8), card.uidlen)); - iso14b_raw_cmd_t *packet = (iso14b_raw_cmd_t *)calloc(1, sizeof(iso14b_raw_cmd_t) + 2); if (packet == NULL) { PrintAndLogEx(FAILED, "failed to allocate memory"); @@ -1513,7 +1512,7 @@ static int CmdHF14BDump(const char *Cmd) { return switch_off_field_14b(); } - print_sr_blocks(data, cardsize); + print_sr_blocks(data, cardsize, card.uid); // save to file if (fnlen < 1) { @@ -2104,6 +2103,28 @@ out: return res; } +/* extract uid from filename + * filename must match '^hf-14b-[0-9A-F]{16}' + */ +uint8_t * get_uid_from_filename(const char *filename) { + static uint8_t uid[8] ; + memset(uid, 0, 8) ; + char uidinhex[17] ; + if (strlen(filename)<23 || strncmp(filename, "hf-14b-", 7)) { + PrintAndLogEx(ERR, "can't get uid from filename '%s'. Expected format is hf-14b-...", filename); + return uid ; + } + // extract uid part from filename + strncpy(uidinhex, filename+7, 16) ; uidinhex[16]='\0' ; + int len=hex_to_bytes(uidinhex, uid, 8); + if (len == 8) + return SwapEndian64(uid , 8, 8); + else { + PrintAndLogEx(ERR, "get_uid_from_filename failed: hex_to_bytes returned %d", len); + memset(uid, 0, 8); + } + return uid ; +} static int CmdHF14BView(const char *Cmd) { @@ -2142,8 +2163,7 @@ static int CmdHF14BView(const char *Cmd) { // figure out a way to identify the different dump files. // STD/SR/CT is difference - - print_sr_blocks(dump, bytes_read); + print_sr_blocks(dump, bytes_read, get_uid_from_filename(filename)); //print_std_blocks(dump, bytes_read); //print_ct_blocks(dump, bytes_read); diff --git a/client/src/cmdhf14b.h b/client/src/cmdhf14b.h index b81149722..06cd637b9 100644 --- a/client/src/cmdhf14b.h +++ b/client/src/cmdhf14b.h @@ -25,6 +25,7 @@ int CmdHF14B(const char *Cmd); int CmdHF14BNdefRead(const char *Cmd); +uint8_t * get_uid_from_filename(const char *filename); int exchange_14b_apdu(uint8_t *datain, int datainlen, bool activate_field, bool leave_signal_on, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, int user_timeout); int select_card_14443b_4(bool disconnect, iso14b_card_select_t *card); From a3b530108adbe40eef85b05df36e0f21660b1626 Mon Sep 17 00:00:00 2001 From: DidierA Date: Tue, 20 Sep 2022 23:18:40 +0200 Subject: [PATCH 2/2] forgot to update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2023e24bc..824c19966 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 14b dump, view` to get correct chip type in case of SRT512 and friends (@DidierA) - Added `hf 15 eview` and `hf 15 esave` - Retrieve emulator image for ISO15693 simulation (@markus-oehme-pg40) - Changed `hf 15 sim` - now supports reader writes (@markus-oehme-pg40) - Added `hf 15 eload` - specify memory image for ISO15693 simulation (@markus-oehme-pg40)