diff --git a/client/src/cmdhfcalypso.c b/client/src/cmdhfcalypso.c index 8dc37ceea..e28985899 100644 --- a/client/src/cmdhfcalypso.c +++ b/client/src/cmdhfcalypso.c @@ -1739,13 +1739,6 @@ static bool calypso_ef_list_contains_lid(const calypso_ef_list_t *ef_list, uint1 return false; } -static void calypso_print_get_data_hex_block(const uint8_t *data, size_t data_len) { - for (size_t pos = 0; pos < data_len; pos += CALYPSO_GET_DATA_HEX_BREAK) { - size_t chunk_len = MIN(data_len - pos, CALYPSO_GET_DATA_HEX_BREAK); - PrintAndLogEx(INFO, CALYPSO_GET_DATA_HEX_INDENT _YELLOW_("%s"), sprint_hex(data + pos, chunk_len)); - } -} - static void calypso_print_get_data_object(const calypso_get_data_probe_t *probe, const uint8_t *data, size_t data_len) { if (data_len <= CALYPSO_GET_DATA_INLINE_MAX) { PrintAndLogEx(SUCCESS, " %04X %-24s : " _YELLOW_("%s"), probe->tag, probe->name, sprint_hex(data, data_len)); @@ -1753,7 +1746,7 @@ static void calypso_print_get_data_object(const calypso_get_data_probe_t *probe, } PrintAndLogEx(SUCCESS, " %04X %-24s : " _YELLOW_("%zu bytes"), probe->tag, probe->name, data_len); - calypso_print_get_data_hex_block(data, data_len); + print_hex_noascii_break_ex(data, data_len, CALYPSO_GET_DATA_HEX_BREAK, CALYPSO_GET_DATA_HEX_INDENT "\x1b[33m", ' ', AEND); } static void calypso_print_info_data_objects(void) { diff --git a/client/src/util.c b/client/src/util.c index 8f4b5589a..2e7627892 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -339,6 +339,38 @@ void print_hex_noascii_break(const uint8_t *data, const size_t len, uint8_t brea } } +void print_hex_noascii_break_ex(const uint8_t *data, const size_t len, uint8_t breaks, const char *prefix, char separator, const char *suffix) { + if (data == NULL || len == 0 || breaks == 0) return; + + if (prefix == NULL) { + prefix = ""; + } + if (suffix == NULL) { + suffix = ""; + } + char sep[2] = {separator, '\0'}; + + for (size_t pos = 0; pos < len; pos += breaks) { + char buf[UTIL_BUFFER_SIZE_SPRINT + 3] = {0}; + size_t chunk_len = len - pos; + if (chunk_len > breaks) { + chunk_len = breaks; + } + + char *p = buf; + size_t remaining = sizeof(buf); + for (size_t i = 0; i < chunk_len; i++) { + int written = snprintf(p, remaining, "%s%02X", (i > 0 && separator != '\0') ? sep : "", data[pos + i]); + if (written < 0 || (size_t)written >= remaining) { + break; + } + p += written; + remaining -= (size_t)written; + } + PrintAndLogEx(INFO, "%s%s%s", prefix, buf, suffix); + } +} + static void print_buffer_ex(const uint8_t *data, const size_t len, int level, uint8_t breaks) { // sanity checks diff --git a/client/src/util.h b/client/src/util.h index 75cd7c9b3..727c95545 100644 --- a/client/src/util.h +++ b/client/src/util.h @@ -84,6 +84,7 @@ void hex_to_buffer(uint8_t *buf, const uint8_t *hex_data, const size_t hex_len, void print_hex(const uint8_t *data, const size_t len); void print_hex_break(const uint8_t *data, const size_t len, const uint8_t breaks); void print_hex_noascii_break(const uint8_t *data, const size_t len, uint8_t breaks); +void print_hex_noascii_break_ex(const uint8_t *data, const size_t len, uint8_t breaks, const char *prefix, char separator, const char *suffix); char *sprint_hex(const uint8_t *data, const size_t len); char *sprint_hex_inrow(const uint8_t *data, const size_t len);