FreeCalypso > hg > freecalypso-reveng
annotate objgrep/tables.c @ 401:4b6b595ae0a0
compal/boot/code-deriv: new analysis
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 14 Jan 2023 23:59:23 +0000 |
parents | 77cd647375e5 |
children |
rev | line source |
---|---|
71
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
2 * This C module contains functions for the initial parsing |
71
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * of the section and symbol tables. |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 */ |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <sys/types.h> |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdio.h> |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdlib.h> |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <string.h> |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <strings.h> |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "filestruct.h" |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "intstruct.h" |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "globals.h" |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 extern unsigned get_u16(), get_u32(); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
17 initial_parse_hdr() |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
18 { |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
19 unsigned symtab_offset; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
20 |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
21 filehdr_struct = (struct external_filehdr *) objfilemap; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
22 if (get_u16(filehdr_struct->f_magic) != 0xC2) { |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
23 fprintf(stderr, "error: %s is not a TI COFF2 object\n", |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
24 objfilename); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
25 exit(2); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
26 } |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
27 if (get_u16(filehdr_struct->f_target_id) != 0x97) { |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
28 fprintf(stderr, "error: TI COFF object %s is not for TMS470\n", |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
29 objfilename); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
30 exit(2); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
31 } |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
32 if (get_u16(filehdr_struct->f_opthdr)) { |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
33 fprintf(stderr, |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
34 "error: %s has the \"optional\" header present\n", |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
35 objfilename); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
36 exit(2); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
37 } |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
38 sections_raw = (struct external_scnhdr *) |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
39 (objfilemap + sizeof(struct external_filehdr)); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
40 nsections = get_u16(filehdr_struct->f_nscns); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
41 symtab_offset = get_u32(filehdr_struct->f_symptr); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
42 symtab_raw = (struct external_syment *)(objfilemap + symtab_offset); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
43 nsymtab = get_u32(filehdr_struct->f_nsyms); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
44 strtab_offset = symtab_offset + |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
45 sizeof(struct external_syment) * nsymtab; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
46 } |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
47 |
71
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 static char * |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 get_secorsym_name(ptr) |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 u_char *ptr; |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 { |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 char *alloc; |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 if (ptr[0]) { |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 if (ptr[7]) { |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 alloc = malloc(9); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 if (!alloc) { |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 perror("malloc"); |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
59 exit(2); |
71
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 } |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 bcopy(ptr, alloc, 8); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 alloc[8] = '\0'; |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 return(alloc); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 } else |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 return((char *) ptr); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 } |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 if (ptr[1] || ptr[2] || ptr[3]) { |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 fprintf(stderr, "error: malformed name in %s at offset 0x%x\n", |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
69 objfilename, ptr - objfilemap); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
70 exit(2); |
71
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 } |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
72 return(objfilemap + strtab_offset + get_u32(ptr+4)); |
71
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 } |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 get_int_section_table() |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 { |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 unsigned n; |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 sections = malloc(sizeof(struct internal_scnhdr) * nsections); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 if (!sections) { |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 perror("malloc"); |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
82 exit(2); |
71
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 } |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 for (n = 0; n < nsections; n++) { |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 sections[n].name = get_secorsym_name(sections_raw[n].s_name); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 if (get_u32(sections_raw[n].s_paddr)) |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 fprintf(stderr, |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 "warning: section #%u (%s) has nonzero paddr\n", |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 n, sections[n].name); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 if (get_u32(sections_raw[n].s_vaddr)) |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 fprintf(stderr, |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 "warning: section #%u (%s) has nonzero vaddr\n", |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 n, sections[n].name); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 sections[n].size = get_u32(sections_raw[n].s_size); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 sections[n].data_offset = get_u32(sections_raw[n].s_scnptr); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 sections[n].reloc_offset = get_u32(sections_raw[n].s_relptr); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 sections[n].line_offset = get_u32(sections_raw[n].s_lnnoptr); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 sections[n].nreloc = get_u32(sections_raw[n].s_nreloc); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 sections[n].nlineent = get_u32(sections_raw[n].s_nlnno); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 sections[n].flags = get_u32(sections_raw[n].s_flags); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 if (get_u16(sections_raw[n].s_reserved)) |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 fprintf(stderr, |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 "warning: section #%u (%s): some nonzero value in s_reserved bytes\n", |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 n, sections[n].name); |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 if (get_u16(sections_raw[n].s_page)) |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 fprintf(stderr, |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 "warning: section #%u (%s): some nonzero value in s_page bytes\n", |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 n, sections[n].name); |
80
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
109 sections[n].nsymbols = 0; |
173
77cd647375e5
objgrep -r: dump symbols in other sections recovered through relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
167
diff
changeset
|
110 sections[n].recov_flag = 0; |
71
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 } |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 } |
c15cd3d695c0
tiobjd: successful parsing of the section header table
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 |
73
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
114 get_int_symbol_table() |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
115 { |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
116 unsigned n; |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
117 struct internal_syment *in; |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
118 |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
119 symtab = malloc(sizeof(struct internal_syment *) * nsymtab); |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
120 if (!symtab) { |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
121 perror("malloc"); |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
122 exit(2); |
73
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
123 } |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
124 for (n = 0; n < nsymtab; ) { |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
125 in = malloc(sizeof(struct internal_syment)); |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
126 if (!in) { |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
127 perror("malloc"); |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
128 exit(2); |
73
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
129 } |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
130 symtab[n] = in; |
116
5f4141ee175b
tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
110
diff
changeset
|
131 in->number = n; |
73
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
132 in->name = get_secorsym_name(symtab_raw[n].e_name); |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
133 in->value = get_u32(symtab_raw[n].e_value); |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
134 in->scnum = get_s16(symtab_raw[n].e_scnum); |
80
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
135 if (in->scnum > 0) { |
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
136 if (in->scnum > nsections) { |
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
137 fprintf(stderr, |
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
138 "symtab entry #%u: scnum too big\n", n); |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
139 exit(2); |
80
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
140 } |
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
141 in->section = sections + in->scnum - 1; |
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
142 in->section->nsymbols++; |
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
143 } else if (in->scnum < -2) { |
73
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
144 fprintf(stderr, |
80
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
145 "symtab entry #%u: scnum < -2\n", n); |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
146 exit(2); |
80
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
147 } else |
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
75
diff
changeset
|
148 in->section = 0; |
73
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
149 in->type = get_u16(symtab_raw[n].e_type); |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
150 in->class = symtab_raw[n].e_sclass; |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
151 switch (symtab_raw[n++].e_numaux) { |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
152 case 0: |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
153 in->aux = 0; |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
154 continue; |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
155 case 1: |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
156 if (n >= nsymtab) { |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
157 fprintf(stderr, |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
158 "error: last symbol's aux spills over\n"); |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
159 exit(2); |
73
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
160 } |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
161 symtab[n] = 0; |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
162 in->aux = (u_char *)(symtab_raw + n); |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
163 n++; |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
164 continue; |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
165 default: |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
166 n--; |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
167 fprintf(stderr, "symtab entry #%u: invalid numaux\n", |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
168 n); |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
169 exit(2); |
73
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
170 } |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
171 } |
10f3fbff5e97
tiobjd: symbol table parsing implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
172 } |