From 9a822ea0879aa4ddcfe8882802d921bcf0145019 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Tue, 27 Jul 2021 17:50:22 +0300 Subject: [PATCH] add offset print buffer to util --- client/src/util.c | 14 ++++++++++++++ client/src/util.h | 1 + 2 files changed, 15 insertions(+) diff --git a/client/src/util.c b/client/src/util.c index ed6ca6e7c..829af8d7a 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -249,6 +249,20 @@ void print_buffer(const uint8_t *data, const size_t len, int level) { print_buffer_ex(data, len, level, 16); } +void print_buffer_with_offset(const uint8_t *data, const size_t len, int offset) { + PrintAndLogEx(INFO, " Offset | Data | Ascii"); + PrintAndLogEx(INFO, "----------------------------------------------------------------------------"); + + for (uint32_t i = 0; i < len; i += 16) { + uint32_t l = len - i; + PrintAndLogEx(INFO, "%3d/0x%02X | %s" NOLF, offset + i, offset + i, sprint_hex(&data[i], l > 16 ? 16 : l)); + if (l < 16) + PrintAndLogEx(NORMAL, "%*s" NOLF, 3 * (16 - l), " "); + PrintAndLogEx(NORMAL, "| %s", sprint_ascii(&data[i], l > 16 ? 16 : l)); + } +} + + void print_blocks(uint32_t *data, size_t len) { PrintAndLogEx(SUCCESS, "Blk | Data "); PrintAndLogEx(SUCCESS, "----+------------"); diff --git a/client/src/util.h b/client/src/util.h index 9357eb1d0..14795773a 100644 --- a/client/src/util.h +++ b/client/src/util.h @@ -52,6 +52,7 @@ char *sprint_hex_ascii(const uint8_t *data, const size_t len); char *sprint_ascii(const uint8_t *data, const size_t len); char *sprint_ascii_ex(const uint8_t *data, const size_t len, const size_t min_str_len); +void print_buffer_with_offset(const uint8_t *data, const size_t len, int offset); void print_buffer(const uint8_t *data, const size_t len, int level); void print_blocks(uint32_t *data, size_t len);