2008-12-30 23:45:08 -05:00
|
|
|
#include <stdlib.h>
|
2010-02-24 23:37:33 -05:00
|
|
|
#include <stdarg.h>
|
2008-12-30 23:45:08 -05:00
|
|
|
#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
|
|
|
{
|
|
|
|
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 {
|
|
|
|
ios_printf(dest, "%.8x ", offs+startoffs);
|
|
|
|
pos = 10;
|
2009-03-13 10:54:48 -04:00
|
|
|
for(i=0; i < 16 && offs < len; i++, offs++) {
|
|
|
|
ch = buffer[offs];
|
2008-12-30 23:45:08 -05:00
|
|
|
linebuffer[i] = (ch<32 || ch>=0x7f) ? '.' : ch;
|
|
|
|
hexc[0] = hexdig[((unsigned char)ch)>>4];
|
|
|
|
hexc[1] = hexdig[ch&0x0f];
|
2009-03-13 10:54:48 -04:00
|
|
|
pos += ios_write(dest, hexc, (i==7 || i==15) ? 4 : 3);
|
2008-12-30 23:45:08 -05:00
|
|
|
}
|
|
|
|
for(; i < 16; i++)
|
|
|
|
linebuffer[i] = ' ';
|
2009-03-13 10:54:48 -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);
|
|
|
|
}
|