mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-16 23:08:49 +02:00
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 <leah@libreboot.org>
This commit is contained in:
@@ -13,9 +13,6 @@
|
||||
static void
|
||||
exit_cleanup(void);
|
||||
|
||||
static void
|
||||
spew_buf(const void *data, size_t len);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@@ -35,53 +32,13 @@ main(int argc, char **argv)
|
||||
same = 1;
|
||||
|
||||
if (argc < 2) /* no spew */
|
||||
spew_buf(buf, BUFSIZ);
|
||||
spew_hex(buf, BUFSIZ);
|
||||
free(buf);
|
||||
|
||||
fprintf(stderr, "\n%s\n", same ? "You win!" : "You lose!");
|
||||
return same ^ 1;
|
||||
}
|
||||
|
||||
static void
|
||||
spew_buf(const void *data, size_t len)
|
||||
{
|
||||
const unsigned char *buf = data;
|
||||
unsigned char c;
|
||||
size_t i, 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);
|
||||
}
|
||||
|
||||
static void
|
||||
exit_cleanup(void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user