1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,45 @@ |
1 |
+/*! |
|
2 |
+ * @file dumpcode.c |
|
3 |
+ * @author Kang IkSeon (ikseon1026@gmail.com) |
|
4 |
+ * |
|
5 |
+ * @internal |
|
6 |
+ * Created: 2018년 01월 30일 |
|
7 |
+ * Copyright: Copyright (c) 2018, Kang IkSeon |
|
8 |
+ */ |
|
9 |
+ |
|
10 |
+#include <stdio.h> |
|
11 |
+#include <ctype.h> |
|
12 |
+ |
|
13 |
+#include "src/dumpcode.h" |
|
14 |
+ |
|
15 |
+void printchar(unsigned char c) { |
|
16 |
+ if (isprint(c)) |
|
17 |
+ printf("%c", c); |
|
18 |
+ else |
|
19 |
+ printf("."); |
|
20 |
+} |
|
21 |
+ |
|
22 |
+void dumpcode(void *ptr, int len) { |
|
23 |
+ int i; |
|
24 |
+ for (i=0; i < len; i++) { |
|
25 |
+ if (i%16 == 0) |
|
26 |
+ printf("%p ", ((unsigned char *)ptr + i)); |
|
27 |
+ printf("%02x ", ((unsigned char *)ptr)[i]); |
|
28 |
+ if (i%16-15 == 0) { |
|
29 |
+ int j; |
|
30 |
+ printf(" "); |
|
31 |
+ for (j=i-15; j <= i; j++) |
|
32 |
+ printchar(((unsigned char *)ptr)[j]); |
|
33 |
+ printf("\n"); |
|
34 |
+ } |
|
35 |
+ } |
|
36 |
+ if (i%16 != 0) { |
|
37 |
+ int j; |
|
38 |
+ int spaces = (len-i+16-i%16)*3+2; |
|
39 |
+ for (j=0; j < spaces; j++) |
|
40 |
+ printf(" "); |
|
41 |
+ for (j=i-i%16; j < len; j++) |
|
42 |
+ printchar(((unsigned char *)ptr)[j]); |
|
43 |
+ } |
|
44 |
+ printf("\n"); |
|
45 |
+} |