aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c55
1 files changed, 55 insertions, 0 deletions
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");
+ }
+
+}
+
+