2008-12-30 23:45:08 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "dtypes.h"
|
|
|
|
#include "ios.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
static char hexdig[] = "0123456789abcdef";
|
|
|
|
|
|
|
|
/*
|
|
|
|
display a given number of bytes from a buffer, with the first
|
|
|
|
address label being startoffs
|
|
|
|
*/
|
2010-05-02 14:28:53 -04:00
|
|
|
void hexdump(ios_t *dest, const char *buffer, size_t len, size_t startoffs)
|
2008-12-30 23:45:08 -05:00
|
|
|
{
|
2019-08-09 07:02:02 -04:00
|
|
|
size_t offs = 0;
|
2009-03-13 10:54:48 -04:00
|
|
|
size_t i, pos;
|
2008-12-30 23:45:08 -05:00
|
|
|
char ch, linebuffer[16];
|
|
|
|
char hexc[4];
|
2009-03-13 10:54:48 -04:00
|
|
|
static char *spc50 = " ";
|
2008-12-30 23:45:08 -05:00
|
|
|
|
|
|
|
hexc[2] = hexc[3] = ' ';
|
|
|
|
do {
|
2019-08-09 07:02:02 -04:00
|
|
|
ios_printf(dest, "%.8x ", offs + startoffs);
|
2008-12-30 23:45:08 -05:00
|
|
|
pos = 10;
|
2019-08-09 07:02:02 -04:00
|
|
|
for (i = 0; i < 16 && offs < len; i++, offs++) {
|
2009-03-13 10:54:48 -04:00
|
|
|
ch = buffer[offs];
|
2019-08-09 07:02:02 -04:00
|
|
|
linebuffer[i] = (ch < 32 || ch >= 0x7f) ? '.' : ch;
|
|
|
|
hexc[0] = hexdig[((unsigned char)ch) >> 4];
|
|
|
|
hexc[1] = hexdig[ch & 0x0f];
|
|
|
|
pos += ios_write(dest, hexc, (i == 7 || i == 15) ? 4 : 3);
|
2008-12-30 23:45:08 -05:00
|
|
|
}
|
2019-08-09 07:02:02 -04:00
|
|
|
for (; i < 16; i++)
|
2008-12-30 23:45:08 -05:00
|
|
|
linebuffer[i] = ' ';
|
2019-08-09 07:02:02 -04:00
|
|
|
ios_write(dest, spc50, 60 - pos);
|
2008-12-30 23:45:08 -05:00
|
|
|
ios_putc('|', dest);
|
|
|
|
ios_write(dest, linebuffer, 16);
|
|
|
|
ios_write(dest, "|\n", 2);
|
|
|
|
} while (offs < len);
|
|
|
|
}
|