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