36 lines
833 B
C
36 lines
833 B
C
#include <ctype.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
void hexdump(const void *data, const size_t size, const size_t width) {
|
|
const unsigned char *p = (const unsigned char *)data;
|
|
size_t i, j;
|
|
|
|
for (i = 0; i < size; i += width) {
|
|
printf("%08zx ", i);
|
|
|
|
for (j = 0; j < width; j++) {
|
|
if (i + j < size) {
|
|
printf("%02X ", p[i + j]);
|
|
} else {
|
|
printf(" ");
|
|
}
|
|
|
|
if ((j + 1) % 8 == 0)
|
|
printf(" ");
|
|
}
|
|
|
|
printf(" |");
|
|
|
|
for (j = 0; j < width && i + j < size; j++) {
|
|
unsigned char c = p[i + j];
|
|
printf("%c", isprint(c) ? c : '.');
|
|
}
|
|
|
|
printf("|\n");
|
|
}
|
|
}
|