Download | Plain Text | No Line Numbers
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
-
- void hex_dump(void *data, int size)
- {
- /* dumps size bytes of *data to stdout. Looks like:
- * [0000] 75 6E 6B 6E 6F 77 6E 20
- * 30 FF 00 00 00 00 39 00 unknown 0.....9.
- * (in a single line of course)
- */
-
- unsigned char *p = data;
- unsigned char c;
- int n;
- char bytestr[20] = {0};
- char addrstr[10] = {0};
- char hexstr[ 16*3 + 5 + 20] = {0};
- char charstr[16*1 + 5] = {0};
- for (n=1;n<=size;n++)
- {
- if (n%8 == 1)
- {
- /* store address for this line */
- ((unsigned int)p-(unsigned int)data) );
- }
-
- c = *p;
- c = '.';
-
- /* store hex str (for left side) */
-
- /* store char str (for right side) */
-
- if (n%8 == 0)
- {
- /* line completed */
- hexstr[0] = 0;
- charstr[0] = 0;
- }
- else if (n%8 == 0)
- {
- /* half line: add whitespaces */
- }
- p++; /* next byte */
- }
-
- {
- /* print rest of buffer if not empty */
- }
- }
-
-