34 lines
855 B
C
34 lines
855 B
C
#include <stddef.h>
|
|
#include <ctype.h>
|
|
#include <stdio.h>
|
|
|
|
void hexdump(const void *data, size_t size) {
|
|
const unsigned char *p = (const unsigned char *)data;
|
|
size_t i, j;
|
|
|
|
for (i = 0; i < size; i += 16) {
|
|
// Print offset
|
|
kprintf("%08x ", i);
|
|
|
|
// Print hex bytes
|
|
for (j = 0; j < 16; j++) {
|
|
if (i + j < size) {
|
|
kprintf("%02X ", p[i + j]);
|
|
} else {
|
|
kprintf(" "); // padding for incomplete lines
|
|
}
|
|
if (j == 7)
|
|
kprintf(" "); // extra space in middle
|
|
}
|
|
|
|
kprintf(" |");
|
|
|
|
// Print ASCII characters
|
|
for (j = 0; j < 16 && i + j < size; j++) {
|
|
unsigned char c = p[i + j];
|
|
kprintf("%c", isprint(c) ? c : '.');
|
|
}
|
|
|
|
kprintf("|\n");
|
|
}
|
|
}
|