Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
C hexdump in objdump -x format
#include <ctype.h>
#include <stdio.h>
struct buf {
unsigned char *p;
uint64_t len;
};
void hexdump(struct buf buf) {
int i = 0;
printf(" 0x%08x ", i);
for (; i < buf.len; i++) {
if (i && (i % 16) == 0) {
int j;
printf(" ");
for (j = i - 16; j < i; j++)
printf("%c", isprint(buf.p[j]) ? buf.p[j] : '.');
printf("\n 0x%08x ", i);
} else if (i && (i % 4) == 0)
printf(" ");
printf("%02x", buf.p[i]);
}
puts("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment