Created
August 8, 2016 15:03
-
-
Save elazarl/6640b68891ce340c5c865d0ad9b1b60a to your computer and use it in GitHub Desktop.
C hexdump in objdump -x format
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
#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