From afe2e71c014e291b9915271d45c1fd933f2fa55f Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 29 Mar 2026 07:21:08 +0100 Subject: util/nvmutil: better hexdump this is a more generic one that i implemented for "lottery.c" (which is really just a tester of my rset function in lib/rand.c) i could probably actually write a full hexdump program in libreboot-utils to be honest. Signed-off-by: Leah Rowe --- util/libreboot-utils/lib/num.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'util/libreboot-utils/lib/num.c') diff --git a/util/libreboot-utils/lib/num.c b/util/libreboot-utils/lib/num.c index 66fc26f1..e4d0ce6b 100644 --- a/util/libreboot-utils/lib/num.c +++ b/util/libreboot-utils/lib/num.c @@ -16,8 +16,10 @@ defined(__NetBSD__) || defined(__APPLE__)) #include /* if not arc4random: /dev/urandom */ #endif +#include #include #include +#include #include #include @@ -47,6 +49,48 @@ hextonum(char ch_s) return 16; } +/* basically hexdump -C */ +void +spew_hex(const void *data, size_t len) +{ + const unsigned char *buf = (const unsigned char *)data; + unsigned char c; + size_t i; + size_t j; + + if (buf == NULL || + len == 0) + return; + + for (i = 0; i < len; i += 16) { + + printf("%08zx ", i); + + for (j = 0; j < 16; j++) { + + if (i + j < len) + printf("%02x ", buf[i + j]); + else + printf(" "); + + if (j == 7) + printf(" "); + } + + printf(" |"); + + for (j = 0; j < 16 && i + j < len; j++) { + + c = buf[i + j]; + printf("%c", isprint(c) ? c : '.'); + } + + printf("|\n"); + } + + printf("%08zx\n", len); +} + void check_bin(size_t a, const char *a_name) { -- cgit v1.2.1