37 lines
823 B
C
37 lines
823 B
C
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <ctype.h>
|
|
|
|
int print_hex_offset(const void *block, int count, int offset, uint32_t start)
|
|
{
|
|
int byte;
|
|
const uint8_t *b = block;
|
|
count += offset;
|
|
b -= offset;
|
|
for ( ; offset < count; offset += 16) {
|
|
printf("%08x", start + offset);
|
|
|
|
for (byte = 0; byte < 16; byte++) {
|
|
if (byte == 8)
|
|
printf(" ");
|
|
printf(" ");
|
|
if (offset + byte < count)
|
|
printf("%02x", b[offset + byte] & 0xff);
|
|
else
|
|
printf(" ");
|
|
}
|
|
|
|
printf(" |");
|
|
for (byte = 0; byte < 16 && byte + offset < count; byte++)
|
|
printf("%c", isprint(b[offset + byte]) ?
|
|
b[offset + byte] :
|
|
'.');
|
|
printf("|\n");
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int print_hex(const void *block, int count, uint32_t start)
|
|
{
|
|
return print_hex_offset(block, count, 0, start);
|
|
} |