-
Notifications
You must be signed in to change notification settings - Fork 1
/
convertmem.c
72 lines (62 loc) · 1.69 KB
/
convertmem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//utility to convert dumped mem to C array format
#include <stdio.h>
#include <stdint.h>
void main(int argc, char* argv[]) {
if(argc < 3) {
printf("Usage: %s <source> <destination>\n", argv[0]);
return;
}
FILE* mem_in;
FILE* vals_out;
if((mem_in = fopen(argv[1], "r")) == NULL) {
printf("couldn't open first source %s for writing\n", argv[1]);
return;
}
if((vals_out = fopen(argv[2], "w")) == NULL) {
printf("couldn't open destination %s for writing\n", argv[2]);
return;
}
int c1, c2, c3, c4;
int count = 0;
fputc(' ', vals_out);
fputc(' ', vals_out);
fputc(' ', vals_out);
fputc(' ', vals_out);
while((c1 = fgetc(mem_in)) != EOF ) {
if((c2 = fgetc(mem_in)) != EOF) {
if((c3 = fgetc(mem_in)) != EOF) {
if((c4 = fgetc(mem_in)) != EOF) {
}
else {
printf("unexpected end at char 4\n");
break;
}
}
else {
printf("unexpected end at char 3\n");
break;
}
}
else {
printf("unexpected end at char 2\n");
break;
}
fputc('0', vals_out);
fputc('x', vals_out);
fputc(c3, vals_out);
fputc(c4, vals_out);
fputc(c1, vals_out);
fputc(c2, vals_out);
fputc(',', vals_out);
fputc(' ', vals_out);
count++;
if(count >= 10) {
count = 0;
fputc('\n', vals_out);
fputc(' ', vals_out);
fputc(' ', vals_out);
fputc(' ', vals_out);
fputc(' ', vals_out);
}
}
}