FreeList hexdump now takes width argument
This commit is contained in:
parent
80825e620c
commit
ac6abd7c10
3 changed files with 14 additions and 13 deletions
|
|
@ -2,30 +2,31 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void hexdump(const void *data, size_t size) {
|
||||
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 += 16) {
|
||||
// Print offset
|
||||
for (i = 0; i < size; i += width) {
|
||||
printf("%08zx ", i);
|
||||
|
||||
// Print hex bytes
|
||||
for (j = 0; j < 16; j++) {
|
||||
for (j = 0; j < width; j++) {
|
||||
if (i + j < size) {
|
||||
printf("%02X ", p[i + j]);
|
||||
} else {
|
||||
printf(" "); // padding for incomplete lines
|
||||
printf(" ");
|
||||
}
|
||||
if (j == 7)
|
||||
printf(" "); // extra space in middle
|
||||
|
||||
if ((j + 1) % 8 == 0)
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
printf(" |");
|
||||
|
||||
// Print ASCII characters
|
||||
for (j = 0; j < 16 && i + j < size; j++) {
|
||||
for (j = 0; j < width && i + j < size; j++) {
|
||||
unsigned char c = p[i + j];
|
||||
printf("%c", isprint(c) ? c : '.');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue