FreeCalypso > hg > freecalypso-reveng
annotate leo-obj/tool/basics.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 | ed533d469838 |
children |
rev | line source |
---|---|
70 | 1 /* |
74
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
2 * This C module implements some "basic" dump commands |
70 | 3 */ |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <time.h> | |
9 #include "filestruct.h" | |
74
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
10 #include "intstruct.h" |
70 | 11 #include "globals.h" |
12 | |
74
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
13 extern unsigned get_u16(), get_u32(); |
70 | 14 |
15 dump_filehdr_info() | |
16 { | |
17 time_t timestamp; | |
18 struct tm *timedec; | |
19 | |
20 timestamp = get_u32(filehdr_struct->f_timdat); | |
21 timedec = gmtime(×tamp); | |
22 printf("timestamp: %d-%02d-%02dT%02d:%02d:%02dZ\n", | |
23 timedec->tm_year + 1900, timedec->tm_mon + 1, timedec->tm_mday, | |
24 timedec->tm_hour, timedec->tm_min, timedec->tm_sec); | |
25 printf("file flags: 0x%x\n", get_u16(filehdr_struct->f_flags)); | |
26 printf("%u sections, %u symtab entries\n", nsections, nsymtab); | |
27 return(0); | |
28 } | |
74
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
29 |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
30 dump_sechdr() |
74
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
31 { |
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
32 unsigned n; |
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
33 struct internal_scnhdr *inf; |
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
34 |
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
35 for (n = 0; n < nsections; n++) { |
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
36 inf = sections + n; |
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
37 printf("#%d: %s size=%u, flags=0x%x\n", n, inf->name, |
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
38 inf->size, inf->flags); |
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
39 printf("\t%u reloc, %u line entries\n", |
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
40 inf->nreloc, inf->nlineent); |
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
41 } |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
42 return(0); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
43 } |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
44 |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
45 cmd_sechdr() |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
46 { |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
47 get_int_section_table(); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
48 dump_sechdr(); |
74
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
49 exit(0); |
2eef88395908
tiobjd: a little refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
73
diff
changeset
|
50 } |
75
1a23ff9a81de
tiobjd: dumpsym implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
74
diff
changeset
|
51 |
142
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
52 cmd_symtab(argc, argv) |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
53 char **argv; |
75
1a23ff9a81de
tiobjd: dumpsym implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
74
diff
changeset
|
54 { |
142
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
55 int c, show_aux = 0; |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
56 |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
57 while ((c = getopt(argc, argv, "a")) != EOF) |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
58 switch (c) { |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
59 case 'a': |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
60 show_aux++; |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
61 continue; |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
62 default: |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
63 /* error msg already printed */ |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
64 exit(1); |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
65 } |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
66 |
75
1a23ff9a81de
tiobjd: dumpsym implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
74
diff
changeset
|
67 get_int_section_table(); |
1a23ff9a81de
tiobjd: dumpsym implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
74
diff
changeset
|
68 get_int_symbol_table(); |
142
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
69 dump_symtab(show_aux); |
75
1a23ff9a81de
tiobjd: dumpsym implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
74
diff
changeset
|
70 exit(0); |
1a23ff9a81de
tiobjd: dumpsym implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
74
diff
changeset
|
71 } |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
72 |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
73 cmd_basics() |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
74 { |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
75 printf("%s:\n", objfilename); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
76 dump_filehdr_info(); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
77 putchar('\n'); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
78 get_int_section_table(); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
79 printf("Sections:\n\n"); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
80 dump_sechdr(); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
81 putchar('\n'); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
82 get_int_symbol_table(); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
83 printf("Symbol table:\n\n"); |
142
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
84 dump_symtab(0); |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
85 putchar('\n'); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
86 exit(0); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
87 } |