From b013532b3061cc661ee9d0b141efbc86cda5c320 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 8 Sep 2007 18:21:23 +0000 Subject: *** empty log message *** --- src/util.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/util.c (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..32071fd --- /dev/null +++ b/src/util.c @@ -0,0 +1,55 @@ +#include "project.h" + +void +hexdump (FILE * f, uint8_t * data, int s, int l) +{ + int e = s + l - 1; + int b = s & ~15; + int a = (e | 15) + 1; + int i, j; + + for (i = b; i < a; i += 16) + { + fprintf (f, " %04x: ", i); + for (j = i; j < (i + 16); ++j) + { + if (j == (i + 8)) + fprintf (f, " "); + + if ((j >= s) && (j <= e)) + { + fprintf (f, "%02x ", data[j]); + } + else + { + fprintf (f, " "); + } + } + + for (j = i; j < (i + 16); ++j) + { + + if (j == (i + 8)) + fprintf (f, " "); + + + if ((j >= s) && (j <= e)) + { + uint8_t c = data[j]; + if ((c < ' ') || (c > 126)) + c = '.'; + fprintf (f, "%c", c); + } + else + { + fprintf (f, " "); + } + } + + + fprintf (f, "\n"); + } + +} + + -- cgit v1.2.3