FreeCalypso > hg > freecalypso-reveng
comparison ticoff/tables.c @ 71:c15cd3d695c0
tiobjd: successful parsing of the section header table
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sat, 22 Mar 2014 05:53:02 +0000 |
parents | |
children | 10f3fbff5e97 |
comparison
equal
deleted
inserted
replaced
70:6799a5c57a49 | 71:c15cd3d695c0 |
---|---|
1 /* | |
2 * This C module will contain functions for the initial parsing | |
3 * of the section and symbol tables. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include "filestruct.h" | |
12 #include "intstruct.h" | |
13 #include "globals.h" | |
14 | |
15 extern unsigned get_u16(), get_u32(); | |
16 | |
17 static char * | |
18 get_secorsym_name(ptr) | |
19 u_char *ptr; | |
20 { | |
21 char *alloc; | |
22 | |
23 if (ptr[0]) { | |
24 if (ptr[7]) { | |
25 alloc = malloc(9); | |
26 if (!alloc) { | |
27 perror("malloc"); | |
28 exit(1); | |
29 } | |
30 bcopy(ptr, alloc, 8); | |
31 alloc[8] = '\0'; | |
32 return(alloc); | |
33 } else | |
34 return((char *) ptr); | |
35 } | |
36 if (ptr[1] || ptr[2] || ptr[3]) { | |
37 fprintf(stderr, "error: malformed name in %s at offset 0x%x\n", | |
38 objfilename, ptr - filemap); | |
39 exit(1); | |
40 } | |
41 return(filemap + strtab_offset + get_u32(ptr+4)); | |
42 } | |
43 | |
44 get_int_section_table() | |
45 { | |
46 unsigned n; | |
47 | |
48 sections = malloc(sizeof(struct internal_scnhdr) * nsections); | |
49 if (!sections) { | |
50 perror("malloc"); | |
51 exit(1); | |
52 } | |
53 for (n = 0; n < nsections; n++) { | |
54 sections[n].name = get_secorsym_name(sections_raw[n].s_name); | |
55 if (get_u32(sections_raw[n].s_paddr)) | |
56 fprintf(stderr, | |
57 "warning: section #%u (%s) has nonzero paddr\n", | |
58 n, sections[n].name); | |
59 if (get_u32(sections_raw[n].s_vaddr)) | |
60 fprintf(stderr, | |
61 "warning: section #%u (%s) has nonzero vaddr\n", | |
62 n, sections[n].name); | |
63 sections[n].size = get_u32(sections_raw[n].s_size); | |
64 sections[n].data_offset = get_u32(sections_raw[n].s_scnptr); | |
65 sections[n].reloc_offset = get_u32(sections_raw[n].s_relptr); | |
66 sections[n].line_offset = get_u32(sections_raw[n].s_lnnoptr); | |
67 sections[n].nreloc = get_u32(sections_raw[n].s_nreloc); | |
68 sections[n].nlineent = get_u32(sections_raw[n].s_nlnno); | |
69 sections[n].flags = get_u32(sections_raw[n].s_flags); | |
70 if (get_u16(sections_raw[n].s_reserved)) | |
71 fprintf(stderr, | |
72 "warning: section #%u (%s): some nonzero value in s_reserved bytes\n", | |
73 n, sections[n].name); | |
74 if (get_u16(sections_raw[n].s_page)) | |
75 fprintf(stderr, | |
76 "warning: section #%u (%s): some nonzero value in s_page bytes\n", | |
77 n, sections[n].name); | |
78 } | |
79 } | |
80 | |
81 cmd_sechdr() | |
82 { | |
83 unsigned n; | |
84 struct internal_scnhdr *inf; | |
85 | |
86 get_int_section_table(); | |
87 for (n = 0; n < nsections; n++) { | |
88 inf = sections + n; | |
89 printf("#%d: %s size=%u, flags=0x%x\n", n, inf->name, | |
90 inf->size, inf->flags); | |
91 printf("\t%u reloc, %u line entries\n", | |
92 inf->nreloc, inf->nlineent); | |
93 } | |
94 exit(0); | |
95 } |