Last active
November 8, 2023 14:58
-
-
Save a2800276/4e3eb5edc2af9071ee9aab67d97216cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simple helper to dump bytes in hex format | |
static void dump_bytes(uint8_t *bytes, size_t len) { | |
char buf[16 * 3 + 1]; | |
buf[16 * 3] = '\0'; | |
size_t i = 0; | |
for (i = 0; i < len; i++) { | |
if (i % 16 == 0) { | |
if (i > 0) { | |
printf("\n%s", buf); | |
} | |
printf("\n"); | |
} | |
printf("%02x ", bytes[i]); | |
buf[(i % 16) * 3] = ' '; | |
buf[(i % 16) * 3 +1] = isprint(bytes[i]) ? bytes[i] : '.'; | |
buf[(i % 16) * 3 +2] = ' '; | |
} | |
printf("\n%.*s (%d)", i%16 * 3, buf, i); | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment