Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1051 | tullio | 1 | //////////////////////////////////////////////////////////////////////// |
2 | // elf.h |
||
3 | // |
||
4 | // DynaLink for S.H.A.R.K |
||
5 | // Dynamic ELF object linker. |
||
6 | // |
||
7 | // Original code written by Luca Abeni. |
||
8 | // Adapted by Lex Nahumury 19-7-2006. |
||
9 | // |
||
10 | // This is free software; see GPL.txt |
||
11 | //////////////////////////////////////////////////////////////////////// |
||
12 | #ifndef __ELF_HDR__ |
||
13 | #define __ELF_HDR__ |
||
14 | |||
15 | #define ELFCLASS32 1 |
||
16 | #define ELFDATA2LSB 1 |
||
17 | #define ET_EXEC 2 |
||
18 | #define EM_386 3 |
||
19 | |||
20 | /* This info is needed when parsing the symbol table */ |
||
21 | #define STB_LOCAL 0 |
||
22 | #define STB_GLOBAL 1 |
||
23 | #define STB_WEAK 2 |
||
24 | |||
25 | #define STT_NOTYPE 0 |
||
26 | #define STT_OBJECT 1 |
||
27 | #define STT_FUNC 2 |
||
28 | #define STT_SECTION 3 |
||
29 | #define STT_FILE 4 |
||
30 | |||
31 | #define ELF_ST_BIND(info) ((info) >> 4) |
||
32 | #define ELF_ST_TYPE(info) (((unsigned int) info) & 0xf) |
||
33 | |||
34 | /* sh_type */ |
||
35 | #define SHT_NULL 0 |
||
36 | #define SHT_SYMTAB 2 |
||
37 | #define SHT_RELA 4 |
||
38 | #define SHT_NOBITS 8 |
||
39 | #define SHT_REL 9 |
||
40 | #define SHT_DYNSYM 11 |
||
41 | |||
42 | #define R_386_32 1 |
||
43 | #define R_386_PC32 2 |
||
44 | |||
45 | /* special section indexes */ |
||
46 | #define SHN_UNDEF 0 |
||
47 | #define SHN_COMMON 0xFFF2 |
||
48 | |||
49 | /* e_ident[] indexes */ |
||
50 | #define EI_MAG0 0 |
||
51 | #define EI_MAG1 1 |
||
52 | #define EI_MAG2 2 |
||
53 | #define EI_MAG3 3 |
||
54 | #define EI_CLASS 4 |
||
55 | #define EI_DATA 5 |
||
56 | |||
57 | #define EI_NIDENT 16 |
||
58 | |||
59 | /* EI_MAG */ |
||
60 | #define ELFMAG0 0x7f |
||
61 | #define ELFMAG1 'E' |
||
62 | #define ELFMAG2 'L' |
||
63 | #define ELFMAG3 'F' |
||
64 | |||
65 | #define PT_LOAD 1 |
||
66 | #define PF_W 0x02 |
||
67 | |||
68 | struct elf_header{ |
||
69 | BYTE e_ident[EI_NIDENT]; |
||
70 | WORD e_type; |
||
71 | WORD e_machine; |
||
72 | DWORD e_version; |
||
73 | DWORD e_entry; /* Entry point */ |
||
74 | DWORD e_phoff; |
||
75 | DWORD e_shoff; |
||
76 | DWORD e_flags; |
||
77 | WORD e_ehsize; |
||
78 | WORD e_phentsize; |
||
79 | WORD e_phnum; |
||
80 | WORD e_shentsize; |
||
81 | WORD e_shnum; |
||
82 | WORD e_shstrndx; |
||
83 | }; |
||
84 | |||
85 | /* FIXME!!! */ |
||
86 | typedef struct { |
||
87 | DWORD p_type; |
||
88 | DWORD p_offset; |
||
89 | DWORD p_vaddr; |
||
90 | DWORD p_paddr; |
||
91 | DWORD p_filesz; |
||
92 | DWORD p_memsz; |
||
93 | DWORD p_flags; |
||
94 | DWORD p_align; |
||
95 | } Elf32_Phdr; |
||
96 | |||
97 | struct elf_section_header { |
||
98 | DWORD sh_name; |
||
99 | DWORD sh_type; /* Type of section */ |
||
100 | DWORD sh_flags; /* Miscellaneous section attributes */ |
||
101 | DWORD sh_addr; /* Section virtual addr at execution */ |
||
102 | DWORD sh_offset; /* Section file offset */ |
||
103 | DWORD sh_size; /* Size of section in bytes */ |
||
104 | DWORD sh_link; /* Index of another section */ |
||
105 | DWORD sh_info; /* Additional section information */ |
||
106 | DWORD sh_addralign; /* Section alignment */ |
||
107 | DWORD sh_entsize; /* Entry size if section holds table */ |
||
108 | }; |
||
109 | |||
110 | struct elf_symbol_info { |
||
111 | DWORD st_name; |
||
112 | DWORD st_value; |
||
113 | DWORD st_size; |
||
114 | BYTE st_info; |
||
115 | BYTE st_other; |
||
116 | WORD st_shndx; |
||
117 | }; |
||
118 | |||
119 | struct elf_rel_info { |
||
120 | DWORD r_offset; |
||
121 | DWORD r_info; |
||
122 | }; |
||
123 | |||
124 | struct elf_rela_info { |
||
125 | DWORD r_offset; |
||
126 | DWORD r_info; |
||
127 | DWORD r_addend; |
||
128 | }; |
||
129 | |||
130 | int Elf_check(struct file_ops *kf); |
||
131 | |||
132 | int ELF_read_symbols(struct file_ops *kf, |
||
133 | struct table_info *tables, |
||
134 | struct symbol_info *syms); |
||
135 | |||
136 | int ELF_read_section_headers(struct file_ops *kf, |
||
137 | struct table_info *tables, |
||
138 | struct section_info *scndata); |
||
139 | |||
140 | DWORD ELF_read_headers(struct file_ops *kf, |
||
141 | struct table_info *tables); |
||
142 | |||
143 | |||
144 | int ELF_relocate_section(struct file_ops *kf, DWORD base, |
||
145 | struct table_info *tables, |
||
146 | int n, |
||
147 | struct section_info *s, |
||
148 | int sect, |
||
149 | struct symbol_info *syms, |
||
150 | struct symbol *import); |
||
151 | |||
152 | DWORD ELF_import_symbol(struct file_ops *kf, |
||
153 | int n, |
||
154 | struct symbol_info *syms, |
||
155 | char *name, |
||
156 | int *sect); |
||
157 | |||
158 | DWORD ELF_load_relocatable(struct file_ops *kf, |
||
159 | struct table_info *tables, |
||
160 | int n, |
||
161 | struct section_info *s, |
||
162 | DWORD *size); |
||
163 | |||
164 | void ELF_free_tables(struct file_ops *kf, |
||
165 | struct table_info *tables, |
||
166 | struct symbol_info *syms, |
||
167 | struct section_info *scndata); |
||
168 | #endif |
||
169 | |||
170 | |||
171 | |||
172 | |||
173 | |||
174 | |||
175 | |||
176 | |||
177 |