FreeCalypso > hg > freecalypso-reveng
comparison miscprog/ftmdump.c @ 221:9f2e0c34fe33
ftmdump (C1xx factory data reverse eng) tool written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 17 Nov 2017 19:58:07 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
220:2cc7a17c3859 | 221:9f2e0c34fe33 |
---|---|
1 /* | |
2 * This program parses the record structure in Compal's FTM sector (or at least | |
3 * that's what I *think* it is called) and dumps each record in hex for further | |
4 * human analysis. | |
5 */ | |
6 | |
7 #include <sys/types.h> | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <strings.h> | |
12 | |
13 char *infname; | |
14 FILE *inf; | |
15 u_char header[8]; | |
16 u_char endmarker[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; | |
17 unsigned hdr_words[4]; | |
18 | |
19 main(argc, argv) | |
20 char **argv; | |
21 { | |
22 if (argc < 2 || argc > 3) { | |
23 fprintf(stderr, "usage: %s binfile [offset]\n", argv[0]); | |
24 exit(1); | |
25 } | |
26 infname = argv[1]; | |
27 inf = fopen(infname, "r"); | |
28 if (!inf) { | |
29 perror(infname); | |
30 exit(1); | |
31 } | |
32 if (argc == 3) | |
33 fseek(inf, strtoul(argv[2], 0, 0), SEEK_SET); | |
34 for (;;) { | |
35 fread(header, 1, 8, inf); | |
36 if (!bcmp(header, endmarker, 8)) | |
37 break; | |
38 process_record(); | |
39 } | |
40 exit(0); | |
41 } | |
42 | |
43 process_record() | |
44 { | |
45 u_char readbuf[16]; | |
46 int pos, chunk, i, c; | |
47 | |
48 for (i = 0; i < 4; i++) | |
49 hdr_words[i] = header[i*2] | (header[i*2+1] << 8); | |
50 printf("%04X %04X %04X %04X:\n\n", hdr_words[0], hdr_words[1], | |
51 hdr_words[2], hdr_words[3]); | |
52 for (pos = 0; pos < hdr_words[3]; pos += chunk) { | |
53 chunk = hdr_words[3] - pos; | |
54 if (chunk > 16) | |
55 chunk = 16; | |
56 fread(readbuf, 1, chunk, inf); | |
57 printf("%04X:", pos); | |
58 for (i = 0; i < 16; i++) { | |
59 if (i == 0 || i == 8) | |
60 putchar(' '); | |
61 if (i < chunk) | |
62 printf(" %02X", readbuf[i]); | |
63 else | |
64 fputs(" ", stdout); | |
65 } | |
66 fputs(" ", stdout); | |
67 for (i = 0; i < chunk; i++) { | |
68 c = readbuf[i]; | |
69 if (c < ' ' || c > '~') | |
70 c = '.'; | |
71 putchar(c); | |
72 } | |
73 putchar('\n'); | |
74 } | |
75 putchar('\n'); | |
76 } |