1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include "qemu/osdep.h"
17#include "qemu-common.h"
18
19void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
20{
21 unsigned int b, len, i, c;
22
23 for (b = 0; b < size; b += 16) {
24 len = size - b;
25 if (len > 16) {
26 len = 16;
27 }
28 fprintf(fp, "%s: %04x:", prefix, b);
29 for (i = 0; i < 16; i++) {
30 if ((i % 4) == 0) {
31 fprintf(fp, " ");
32 }
33 if (i < len) {
34 fprintf(fp, " %02x", (unsigned char)buf[b + i]);
35 } else {
36 fprintf(fp, " ");
37 }
38 }
39 fprintf(fp, " ");
40 for (i = 0; i < len; i++) {
41 c = buf[b + i];
42 if (c < ' ' || c > '~') {
43 c = '.';
44 }
45 fprintf(fp, "%c", c);
46 }
47 fprintf(fp, "\n");
48 }
49}
50