@@ -1,1068 +1,1068 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the SocExplorer Software |
|
3 | 3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 2 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | -------------------------------------------------------------------------------*/ |
|
19 | 19 | /*-- Author : |
|
20 | 20 | Alexis Jeandet |
|
21 | 21 | -- Mail : |
|
22 | 22 | alexis.jeandet@member.fsf.org |
|
23 | 23 | ----------------------------------------------------------------------------*/ |
|
24 | 24 | #include "elffile.h" |
|
25 | 25 | #include "srec/srecfile.h" |
|
26 | #include <stdint.h> | |
|
26 | 27 | |
|
27 | 28 | ElfFile::ElfFile() |
|
28 | 29 | :abstractBinFile() |
|
29 | 30 | { |
|
30 | 31 | this->opened = false; |
|
31 | 32 | this->type_elf = false; |
|
32 | 33 | this->elfFile = (int)NULL; |
|
33 | 34 | this->e = NULL; |
|
34 | 35 | } |
|
35 | 36 | |
|
36 | 37 | ElfFile::ElfFile(const QString &File) |
|
37 | 38 | :abstractBinFile() |
|
38 | 39 | { |
|
39 | 40 | this->opened = false; |
|
40 | 41 | this->type_elf = false; |
|
41 | 42 | this->elfFile = (int)NULL; |
|
42 | 43 | this->e = NULL; |
|
43 | 44 | this->p_fileName = File; |
|
44 | 45 | openFile(File); |
|
45 | 46 | } |
|
46 | 47 | |
|
47 | 48 | ElfFile::~ElfFile() |
|
48 | 49 | { |
|
49 | 50 | closeFile(); |
|
50 | 51 | if(scn)free(scn); |
|
51 | 52 | if(data)free(data); |
|
52 | 53 | for(int i=0;i<this->sections.count();i++) |
|
53 | 54 | { |
|
54 | 55 | delete this->sections.at(i); |
|
55 | 56 | } |
|
56 | 57 | this->sections.clear(); |
|
57 | 58 | for(int i=0;i<this->Segments.count();i++) |
|
58 | 59 | { |
|
59 | 60 | free(this->Segments.at(i)); |
|
60 | 61 | } |
|
61 | 62 | this->Segments.clear(); |
|
62 | 63 | for(int i=0;i<symbols.count();i++) |
|
63 | 64 | { |
|
64 | 65 | delete this->symbols.at(i); |
|
65 | 66 | } |
|
66 | 67 | this->symbols.clear(); |
|
67 | 68 | } |
|
68 | 69 | |
|
69 | 70 | bool ElfFile::openFile(const QString &File) |
|
70 | 71 | { |
|
71 | 72 | this->p_fileName = File; |
|
72 | 73 | this->closeFile(); |
|
73 | 74 | if(elf_version(EV_CURRENT)==EV_NONE)return 0; |
|
74 | 75 | #ifdef _ELF_WINDOWS_ |
|
75 | 76 | this->elfFile = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0); |
|
76 | 77 | #else |
|
77 | 78 | this->elfFile = open(File.toStdString().c_str(),O_RDONLY ,0); |
|
78 | 79 | #endif |
|
79 | 80 | if(this->elfFile==(int)NULL)return 0; |
|
80 | 81 | this->e = elf_begin(this->elfFile,ELF_C_READ,NULL); |
|
81 | 82 | if(this->e==NULL)return 0; |
|
82 | 83 | this->ek = elf_kind(this->e); |
|
83 | 84 | gelf_getehdr (this->e, &this->ehdr ); |
|
84 | 85 | elf_getshdrstrndx (this->e, &this->shstrndx); |
|
85 | 86 | this->updateSegments(); |
|
86 | 87 | this->updateSections(); |
|
87 | 88 | this->updateSymbols(); |
|
88 | 89 | this->opened = true; |
|
89 | 90 | return 1; |
|
90 | 91 | } |
|
91 | 92 | |
|
92 | 93 | bool ElfFile::isopened() |
|
93 | 94 | { |
|
94 | 95 | return this->opened; |
|
95 | 96 | } |
|
96 | 97 | |
|
97 | 98 | int ElfFile::closeFile() |
|
98 | 99 | { |
|
99 | 100 | if(this->elfFile!=(int)NULL) |
|
100 | 101 | { |
|
101 | 102 | if(this->e!=NULL) |
|
102 | 103 | { |
|
103 | 104 | elf_end(this->e); |
|
104 | 105 | this->e = NULL; |
|
105 | 106 | } |
|
106 | 107 | close(this->elfFile); |
|
107 | 108 | this->elfFile = (int)NULL; |
|
108 | 109 | } |
|
109 | 110 | this->opened = false; |
|
110 | 111 | return 0; |
|
111 | 112 | } |
|
112 | 113 | |
|
113 | 114 | |
|
114 | 115 | QList<codeFragment*> ElfFile::getFragments(QStringList fragmentList) |
|
115 | 116 | { |
|
116 | 117 | QList<codeFragment*> fragments; |
|
117 | 118 | if (isopened()) |
|
118 | 119 | { |
|
119 | 120 | for(int i =0;i<fragmentList.count();i++) |
|
120 | 121 | { |
|
121 | 122 | fragments.append(getFragment(fragmentList.at(i))); |
|
122 | 123 | } |
|
123 | 124 | } |
|
124 | 125 | return fragments; |
|
125 | 126 | } |
|
126 | 127 | |
|
127 | 128 | QList<codeFragment*> ElfFile::getFragments() |
|
128 | 129 | { |
|
129 | 130 | return getFragments(QStringList()<<".data"<<".text"); |
|
130 | 131 | } |
|
131 | 132 | |
|
132 | 133 | codeFragment *ElfFile::getFragment(const QString &name) |
|
133 | 134 | { |
|
134 | 135 | codeFragment* fragment= new codeFragment(); |
|
135 | 136 | for(int i=0;i<getSectionCount();i++) |
|
136 | 137 | { |
|
137 | 138 | if(getSectionName(i) == name) |
|
138 | 139 | { |
|
139 | 140 | fragment->data =NULL; |
|
140 | 141 | fragment->size = getSectionDatasz(i); |
|
141 | 142 | fragment->address = getSectionPaddr(i); |
|
142 | 143 | getSectionData(i,&fragment->data); |
|
143 | 144 | } |
|
144 | 145 | } |
|
145 | 146 | return fragment; |
|
146 | 147 | } |
|
147 | 148 | |
|
148 | 149 | |
|
149 | 150 | |
|
150 | 151 | |
|
151 | 152 | |
|
152 | 153 | |
|
153 | 154 | |
|
154 | 155 | QString elfresolveMachine(Elf64_Half e_machine) |
|
155 | 156 | { |
|
156 | 157 | QString machineName; |
|
157 | 158 | //Update from with bash script don't write it by yourself! |
|
158 | 159 | switch(e_machine) |
|
159 | 160 | { |
|
160 | 161 | case EM_NONE: |
|
161 | 162 | machineName = " No machine "; |
|
162 | 163 | break; |
|
163 | 164 | case EM_M32: |
|
164 | 165 | machineName = " AT&T WE 32100 "; |
|
165 | 166 | break; |
|
166 | 167 | case EM_SPARC: |
|
167 | 168 | machineName = " SUN SPARC "; |
|
168 | 169 | break; |
|
169 | 170 | case EM_386: |
|
170 | 171 | machineName = " Intel 80386 "; |
|
171 | 172 | break; |
|
172 | 173 | case EM_68K: |
|
173 | 174 | machineName = " Motorola m68k family "; |
|
174 | 175 | break; |
|
175 | 176 | case EM_88K: |
|
176 | 177 | machineName = " Motorola m88k family "; |
|
177 | 178 | break; |
|
178 | 179 | case EM_860: |
|
179 | 180 | machineName = " Intel 80860 "; |
|
180 | 181 | break; |
|
181 | 182 | case EM_MIPS: |
|
182 | 183 | machineName = " MIPS R3000 big-endian "; |
|
183 | 184 | break; |
|
184 | 185 | case EM_S370: |
|
185 | 186 | machineName = " IBM System/370 "; |
|
186 | 187 | break; |
|
187 | 188 | case EM_MIPS_RS3_LE: |
|
188 | 189 | machineName = " MIPS R3000 little-endian "; |
|
189 | 190 | break; |
|
190 | 191 | case EM_PARISC: |
|
191 | 192 | machineName = " HPPA "; |
|
192 | 193 | break; |
|
193 | 194 | case EM_VPP500: |
|
194 | 195 | machineName = " Fujitsu VPP500 "; |
|
195 | 196 | break; |
|
196 | 197 | case EM_SPARC32PLUS: |
|
197 | 198 | machineName = " Sun's \"v8plus\" "; |
|
198 | 199 | break; |
|
199 | 200 | case EM_960: |
|
200 | 201 | machineName = " Intel 80960 "; |
|
201 | 202 | break; |
|
202 | 203 | case EM_PPC: |
|
203 | 204 | machineName = " PowerPC "; |
|
204 | 205 | break; |
|
205 | 206 | case EM_PPC64: |
|
206 | 207 | machineName = " PowerPC 64-bit "; |
|
207 | 208 | break; |
|
208 | 209 | case EM_S390: |
|
209 | 210 | machineName = " IBM S390 "; |
|
210 | 211 | break; |
|
211 | 212 | case EM_V800: |
|
212 | 213 | machineName = " NEC V800 series "; |
|
213 | 214 | break; |
|
214 | 215 | case EM_FR20: |
|
215 | 216 | machineName = " Fujitsu FR20 "; |
|
216 | 217 | break; |
|
217 | 218 | case EM_RH32: |
|
218 | 219 | machineName = " TRW RH-32 "; |
|
219 | 220 | break; |
|
220 | 221 | case EM_RCE: |
|
221 | 222 | machineName = " Motorola RCE "; |
|
222 | 223 | break; |
|
223 | 224 | case EM_ARM: |
|
224 | 225 | machineName = " ARM "; |
|
225 | 226 | break; |
|
226 | 227 | case EM_FAKE_ALPHA: |
|
227 | 228 | machineName = " Digital Alpha "; |
|
228 | 229 | break; |
|
229 | 230 | case EM_SH: |
|
230 | 231 | machineName = " Hitachi SH "; |
|
231 | 232 | break; |
|
232 | 233 | case EM_SPARCV9: |
|
233 | 234 | machineName = " SPARC v9 64-bit "; |
|
234 | 235 | break; |
|
235 | 236 | case EM_TRICORE: |
|
236 | 237 | machineName = " Siemens Tricore "; |
|
237 | 238 | break; |
|
238 | 239 | case EM_ARC: |
|
239 | 240 | machineName = " Argonaut RISC Core "; |
|
240 | 241 | break; |
|
241 | 242 | case EM_H8_300: |
|
242 | 243 | machineName = " Hitachi H8/300 "; |
|
243 | 244 | break; |
|
244 | 245 | case EM_H8_300H: |
|
245 | 246 | machineName = " Hitachi H8/300H "; |
|
246 | 247 | break; |
|
247 | 248 | case EM_H8S: |
|
248 | 249 | machineName = " Hitachi H8S "; |
|
249 | 250 | break; |
|
250 | 251 | case EM_H8_500: |
|
251 | 252 | machineName = " Hitachi H8/500 "; |
|
252 | 253 | break; |
|
253 | 254 | case EM_IA_64: |
|
254 | 255 | machineName = " Intel Merced "; |
|
255 | 256 | break; |
|
256 | 257 | case EM_MIPS_X: |
|
257 | 258 | machineName = " Stanford MIPS-X "; |
|
258 | 259 | break; |
|
259 | 260 | case EM_COLDFIRE: |
|
260 | 261 | machineName = " Motorola Coldfire "; |
|
261 | 262 | break; |
|
262 | 263 | case EM_68HC12: |
|
263 | 264 | machineName = " Motorola M68HC12 "; |
|
264 | 265 | break; |
|
265 | 266 | case EM_MMA: |
|
266 | 267 | machineName = " Fujitsu MMA Multimedia Accelerator"; |
|
267 | 268 | break; |
|
268 | 269 | case EM_PCP: |
|
269 | 270 | machineName = " Siemens PCP "; |
|
270 | 271 | break; |
|
271 | 272 | case EM_NCPU: |
|
272 | 273 | machineName = " Sony nCPU embeeded RISC "; |
|
273 | 274 | break; |
|
274 | 275 | case EM_NDR1: |
|
275 | 276 | machineName = " Denso NDR1 microprocessor "; |
|
276 | 277 | break; |
|
277 | 278 | case EM_STARCORE: |
|
278 | 279 | machineName = " Motorola Start*Core processor "; |
|
279 | 280 | break; |
|
280 | 281 | case EM_ME16: |
|
281 | 282 | machineName = " Toyota ME16 processor "; |
|
282 | 283 | break; |
|
283 | 284 | case EM_ST100: |
|
284 | 285 | machineName = " STMicroelectronic ST100 processor "; |
|
285 | 286 | break; |
|
286 | 287 | case EM_TINYJ: |
|
287 | 288 | machineName = " Advanced Logic Corp. Tinyj emb.fam"; |
|
288 | 289 | break; |
|
289 | 290 | case EM_X86_64: |
|
290 | 291 | machineName = " AMD x86-64 architecture "; |
|
291 | 292 | break; |
|
292 | 293 | case EM_PDSP: |
|
293 | 294 | machineName = " Sony DSP Processor "; |
|
294 | 295 | break; |
|
295 | 296 | case EM_FX66: |
|
296 | 297 | machineName = " Siemens FX66 microcontroller "; |
|
297 | 298 | break; |
|
298 | 299 | case EM_ST9PLUS: |
|
299 | 300 | machineName = " STMicroelectronics ST9+ 8/16 mc "; |
|
300 | 301 | break; |
|
301 | 302 | case EM_ST7: |
|
302 | 303 | machineName = " STmicroelectronics ST7 8 bit mc "; |
|
303 | 304 | break; |
|
304 | 305 | case EM_68HC16: |
|
305 | 306 | machineName = " Motorola MC68HC16 microcontroller "; |
|
306 | 307 | break; |
|
307 | 308 | case EM_68HC11: |
|
308 | 309 | machineName = " Motorola MC68HC11 microcontroller "; |
|
309 | 310 | break; |
|
310 | 311 | case EM_68HC08: |
|
311 | 312 | machineName = " Motorola MC68HC08 microcontroller "; |
|
312 | 313 | break; |
|
313 | 314 | case EM_68HC05: |
|
314 | 315 | machineName = " Motorola MC68HC05 microcontroller "; |
|
315 | 316 | break; |
|
316 | 317 | case EM_SVX: |
|
317 | 318 | machineName = " Silicon Graphics SVx "; |
|
318 | 319 | break; |
|
319 | 320 | case EM_ST19: |
|
320 | 321 | machineName = " STMicroelectronics ST19 8 bit mc "; |
|
321 | 322 | break; |
|
322 | 323 | case EM_VAX: |
|
323 | 324 | machineName = " Digital VAX "; |
|
324 | 325 | break; |
|
325 | 326 | case EM_CRIS: |
|
326 | 327 | machineName = " Axis Communications 32-bit embedded processor "; |
|
327 | 328 | break; |
|
328 | 329 | case EM_JAVELIN: |
|
329 | 330 | machineName = " Infineon Technologies 32-bit embedded processor "; |
|
330 | 331 | break; |
|
331 | 332 | case EM_FIREPATH: |
|
332 | 333 | machineName = " Element 14 64-bit DSP Processor "; |
|
333 | 334 | break; |
|
334 | 335 | case EM_ZSP: |
|
335 | 336 | machineName = " LSI Logic 16-bit DSP Processor "; |
|
336 | 337 | break; |
|
337 | 338 | case EM_MMIX: |
|
338 | 339 | machineName = " Donald Knuth's educational 64-bit processor "; |
|
339 | 340 | break; |
|
340 | 341 | case EM_HUANY: |
|
341 | 342 | machineName = " Harvard University machine-independent object files "; |
|
342 | 343 | break; |
|
343 | 344 | case EM_PRISM: |
|
344 | 345 | machineName = " SiTera Prism "; |
|
345 | 346 | break; |
|
346 | 347 | case EM_AVR: |
|
347 | 348 | machineName = " Atmel AVR 8-bit microcontroller "; |
|
348 | 349 | break; |
|
349 | 350 | case EM_FR30: |
|
350 | 351 | machineName = " Fujitsu FR30 "; |
|
351 | 352 | break; |
|
352 | 353 | case EM_D10V: |
|
353 | 354 | machineName = " Mitsubishi D10V "; |
|
354 | 355 | break; |
|
355 | 356 | case EM_D30V: |
|
356 | 357 | machineName = " Mitsubishi D30V "; |
|
357 | 358 | break; |
|
358 | 359 | case EM_V850: |
|
359 | 360 | machineName = " NEC v850 "; |
|
360 | 361 | break; |
|
361 | 362 | case EM_M32R: |
|
362 | 363 | machineName = " Mitsubishi M32R "; |
|
363 | 364 | break; |
|
364 | 365 | case EM_MN10300: |
|
365 | 366 | machineName = " Matsushita MN10300 "; |
|
366 | 367 | break; |
|
367 | 368 | case EM_MN10200: |
|
368 | 369 | machineName = " Matsushita MN10200 "; |
|
369 | 370 | break; |
|
370 | 371 | case EM_PJ: |
|
371 | 372 | machineName = " picoJava "; |
|
372 | 373 | break; |
|
373 | 374 | case EM_OPENRISC: |
|
374 | 375 | machineName = " OpenRISC 32-bit embedded processor "; |
|
375 | 376 | break; |
|
376 | 377 | case EM_ARC_A5: |
|
377 | 378 | machineName = " ARC Cores Tangent-A5 "; |
|
378 | 379 | break; |
|
379 | 380 | case EM_XTENSA: |
|
380 | 381 | machineName = " Tensilica Xtensa Architecture "; |
|
381 | 382 | break; |
|
382 | 383 | case EM_AARCH64: |
|
383 | 384 | machineName = " ARM AARCH64 "; |
|
384 | 385 | break; |
|
385 | 386 | case EM_TILEPRO: |
|
386 | 387 | machineName = " Tilera TILEPro "; |
|
387 | 388 | break; |
|
388 | 389 | case EM_MICROBLAZE: |
|
389 | 390 | machineName = " Xilinx MicroBlaze "; |
|
390 | 391 | break; |
|
391 | 392 | case EM_TILEGX: |
|
392 | 393 | machineName = " Tilera TILE-Gx "; |
|
393 | 394 | break; |
|
394 | 395 | case EM_NUM: |
|
395 | 396 | machineName = ""; |
|
396 | 397 | break; |
|
397 | 398 | default: |
|
398 | 399 | machineName ="Unknow Machine"; |
|
399 | 400 | break; |
|
400 | 401 | } |
|
401 | 402 | return machineName; |
|
402 | 403 | } |
|
403 | 404 | |
|
404 | 405 | |
|
405 | 406 | |
|
406 | 407 | |
|
407 | 408 | QString ElfFile::getClass() |
|
408 | 409 | { |
|
409 | 410 | if(this->e!=NULL) |
|
410 | 411 | { |
|
411 | 412 | int eclass = gelf_getclass(this->e); |
|
412 | 413 | if(eclass==ELFCLASS32)return "ELF32"; |
|
413 | 414 | if(eclass==ELFCLASS64)return "ELF64"; |
|
414 | 415 | } |
|
415 | 416 | return "none"; |
|
416 | 417 | } |
|
417 | 418 | |
|
418 | 419 | |
|
419 | 420 | bool ElfFile::iself() |
|
420 | 421 | { |
|
421 | 422 | return (this->getType()!="Unknow"); |
|
422 | 423 | } |
|
423 | 424 | |
|
424 | 425 | QString ElfFile::getArchitecture() |
|
425 | 426 | { |
|
426 | 427 | if(this->e!=NULL) |
|
427 | 428 | { |
|
428 | 429 | return elfresolveMachine(this->ehdr.e_machine); |
|
429 | 430 | } |
|
430 | 431 | return ""; |
|
431 | 432 | } |
|
432 | 433 | |
|
433 | 434 | |
|
434 | 435 | QString ElfFile::getType() |
|
435 | 436 | { |
|
436 | 437 | QString kind(""); |
|
437 | 438 | if(this->e!=NULL) |
|
438 | 439 | { |
|
439 | 440 | switch(this->ek) |
|
440 | 441 | { |
|
441 | 442 | case ELF_K_AR: |
|
442 | 443 | kind = "Archive"; |
|
443 | 444 | break; |
|
444 | 445 | case ELF_K_ELF: |
|
445 | 446 | kind = "Elf"; |
|
446 | 447 | break; |
|
447 | 448 | case ELF_K_COFF: |
|
448 | 449 | kind = "COFF"; |
|
449 | 450 | break; |
|
450 | 451 | case ELF_K_NUM: |
|
451 | 452 | kind = "NUM"; |
|
452 | 453 | break; |
|
453 | 454 | case ELF_K_NONE: |
|
454 | 455 | kind = "Data"; |
|
455 | 456 | break; |
|
456 | 457 | default: |
|
457 | 458 | kind = "Unknow"; |
|
458 | 459 | break; |
|
459 | 460 | } |
|
460 | 461 | } |
|
461 | 462 | return kind; |
|
462 | 463 | } |
|
463 | 464 | |
|
464 | 465 | QString ElfFile::getEndianness() |
|
465 | 466 | { |
|
466 | 467 | if(this->e!=NULL) |
|
467 | 468 | { |
|
468 | 469 | if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return "2's complement, little endian"; |
|
469 | 470 | if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return "2's complement, big endian"; |
|
470 | 471 | } |
|
471 | 472 | return "none"; |
|
472 | 473 | } |
|
473 | 474 | |
|
474 | 475 | QString ElfFile::getABI() |
|
475 | 476 | { |
|
476 | 477 | if(this->e!=NULL) |
|
477 | 478 | { |
|
478 | 479 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NONE)return "UNIX System V ABI"; |
|
479 | 480 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SYSV)return "Alias"; |
|
480 | 481 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_HPUX)return "HP-UX"; |
|
481 | 482 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NETBSD)return "NetBSD"; |
|
482 |
if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ |
|
|
483 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_LINUX)return "Compatibility alias"; | |
|
483 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_LINUX)return "Object uses GNU ELF extensions"; | |
|
484 | 484 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SOLARIS)return "Sun Solaris"; |
|
485 | 485 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_AIX)return "IBM AIX"; |
|
486 | 486 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_IRIX)return "SGI Irix"; |
|
487 | 487 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_FREEBSD)return "FreeBSD"; |
|
488 | 488 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_TRU64)return "Compaq TRU64 UNIX"; |
|
489 | 489 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_MODESTO)return " Novell Modesto"; |
|
490 | 490 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_OPENBSD)return "OpenBSD"; |
|
491 | 491 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM_AEABI)return "ARM EABI"; |
|
492 | 492 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM)return "ARM"; |
|
493 | 493 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_STANDALONE)return "Standalone (embedded) application"; |
|
494 | 494 | } |
|
495 | 495 | return "none"; |
|
496 | 496 | } |
|
497 | 497 | |
|
498 | 498 | |
|
499 | 499 | qint64 ElfFile::getVersion() |
|
500 | 500 | { |
|
501 | 501 | if(this->e!=NULL) |
|
502 | 502 | { |
|
503 | 503 | return this->ehdr.e_version; |
|
504 | 504 | } |
|
505 | 505 | return -1; |
|
506 | 506 | } |
|
507 | 507 | |
|
508 | 508 | qint64 ElfFile::getEntryPointAddress() |
|
509 | 509 | { |
|
510 | 510 | if(this->e!=NULL) |
|
511 | 511 | { |
|
512 | 512 | return this->ehdr.e_entry; |
|
513 | 513 | } |
|
514 | 514 | return -1; |
|
515 | 515 | } |
|
516 | 516 | |
|
517 | 517 | |
|
518 | 518 | int ElfFile::getSectionCount() |
|
519 | 519 | { |
|
520 | 520 | return (int)this->SectionCount; |
|
521 | 521 | } |
|
522 | 522 | |
|
523 | 523 | int ElfFile::getSymbolCount() |
|
524 | 524 | { |
|
525 | 525 | return (int)this->SymbolCount; |
|
526 | 526 | } |
|
527 | 527 | |
|
528 | 528 | |
|
529 | 529 | int ElfFile::getSegmentCount() |
|
530 | 530 | { |
|
531 | 531 | return (int)this->SegmentCount; |
|
532 | 532 | } |
|
533 | 533 | |
|
534 | 534 | |
|
535 | 535 | QString ElfFile::getSegmentType(int index) |
|
536 | 536 | { |
|
537 | 537 | QString type(""); |
|
538 | 538 | if(this->e!=NULL) |
|
539 | 539 | { |
|
540 | 540 | if(index < this->Segments.count()) |
|
541 | 541 | { |
|
542 | 542 | switch(this->Segments.at(index)->p_type) |
|
543 | 543 | { |
|
544 | 544 | case PT_NULL: |
|
545 | 545 | type = "Program header table entry unused"; |
|
546 | 546 | break; |
|
547 | 547 | case PT_LOAD: |
|
548 | 548 | type = "Loadable program segment"; |
|
549 | 549 | break; |
|
550 | 550 | case PT_DYNAMIC : |
|
551 | 551 | type = "Dynamic linking information"; |
|
552 | 552 | break; |
|
553 | 553 | case PT_INTERP: |
|
554 | 554 | type ="Program interpreter"; |
|
555 | 555 | break; |
|
556 | 556 | case PT_NOTE: |
|
557 | 557 | type = "Auxiliary information"; |
|
558 | 558 | break; |
|
559 | 559 | case PT_SHLIB: |
|
560 | 560 | type = "Reserved"; |
|
561 | 561 | break; |
|
562 | 562 | case PT_PHDR: |
|
563 | 563 | type = "Entry for header table itself"; |
|
564 | 564 | break; |
|
565 | 565 | case PT_TLS: |
|
566 | 566 | type = "Thread-local storage segment"; |
|
567 | 567 | break; |
|
568 | 568 | case PT_NUM: |
|
569 | 569 | type = "Number of defined types"; |
|
570 | 570 | break; |
|
571 | 571 | case PT_LOOS: |
|
572 | 572 | type = "Start of OS-specific"; |
|
573 | 573 | break; |
|
574 | 574 | case PT_SUNWSTACK: |
|
575 | 575 | type = "Stack segment"; |
|
576 | 576 | break; |
|
577 | 577 | case PT_LOPROC: |
|
578 | 578 | type = "Start of processor-specific"; |
|
579 | 579 | break; |
|
580 | 580 | case PT_HIPROC: |
|
581 | 581 | type = "End of processor-specific"; |
|
582 | 582 | break; |
|
583 | 583 | default: |
|
584 | 584 | type = "Unknow Section Type"; |
|
585 | 585 | break; |
|
586 | 586 | } |
|
587 | 587 | } |
|
588 | 588 | } |
|
589 | 589 | |
|
590 | 590 | return type; |
|
591 | 591 | } |
|
592 | 592 | |
|
593 | 593 | |
|
594 | 594 | qint64 ElfFile::getSegmentOffset(int index) |
|
595 | 595 | { |
|
596 | 596 | qint64 Offset = -1; |
|
597 | 597 | if(this->e!=NULL) |
|
598 | 598 | { |
|
599 | 599 | if(index < this->Segments.count()) |
|
600 | 600 | { |
|
601 | 601 | Offset = (qint64)this->Segments.at(index)->p_offset; |
|
602 | 602 | } |
|
603 | 603 | } |
|
604 | 604 | return Offset; |
|
605 | 605 | } |
|
606 | 606 | |
|
607 | 607 | |
|
608 | 608 | qint64 ElfFile::getSegmentVaddr(int index) |
|
609 | 609 | { |
|
610 | 610 | int64_t Vaddr = 0; |
|
611 | 611 | if(this->e!=NULL) |
|
612 | 612 | { |
|
613 | 613 | if(index < this->Segments.count()) |
|
614 | 614 | { |
|
615 | 615 | Vaddr = (int64_t)this->Segments.at(index)->p_vaddr; |
|
616 | 616 | } |
|
617 | 617 | } |
|
618 | 618 | return Vaddr; |
|
619 | 619 | } |
|
620 | 620 | |
|
621 | 621 | |
|
622 | 622 | qint64 ElfFile::getSegmentPaddr(int index) |
|
623 | 623 | { |
|
624 | 624 | int64_t Paddr=0; |
|
625 | 625 | if(this->e!=NULL) |
|
626 | 626 | { |
|
627 | 627 | if(index < this->Segments.count()) |
|
628 | 628 | { |
|
629 | 629 | Paddr = (int64_t)this->Segments.at(index)->p_paddr; |
|
630 | 630 | } |
|
631 | 631 | } |
|
632 | 632 | return Paddr; |
|
633 | 633 | } |
|
634 | 634 | |
|
635 | 635 | qint64 ElfFile::getSectionPaddr(int index) |
|
636 | 636 | { |
|
637 | 637 | int64_t Paddr=0; |
|
638 | 638 | if(this->e!=NULL) |
|
639 | 639 | { |
|
640 | 640 | if(index < this->sections.count()) |
|
641 | 641 | { |
|
642 | 642 | Paddr = (int64_t)this->sections.at(index)->section_header->sh_addr; |
|
643 | 643 | } |
|
644 | 644 | } |
|
645 | 645 | return Paddr; |
|
646 | 646 | } |
|
647 | 647 | |
|
648 | 648 | |
|
649 | 649 | qint64 ElfFile::getSegmentFilesz(int index) |
|
650 | 650 | { |
|
651 | 651 | int64_t FileSz=0; |
|
652 | 652 | if(this->e!=NULL) |
|
653 | 653 | { |
|
654 | 654 | if(index < this->Segments.count()) |
|
655 | 655 | { |
|
656 | 656 | FileSz = (int64_t)this->Segments.at(index)->p_filesz; |
|
657 | 657 | } |
|
658 | 658 | } |
|
659 | 659 | return FileSz; |
|
660 | 660 | } |
|
661 | 661 | |
|
662 | 662 | qint64 ElfFile::getSectionDatasz(int index) |
|
663 | 663 | { |
|
664 | 664 | int64_t DataSz=0; |
|
665 | 665 | if(this->e!=NULL) |
|
666 | 666 | { |
|
667 | 667 | if(index < this->sections.count()) |
|
668 | 668 | { |
|
669 | 669 | if(this->sections.at(index)->section_header->sh_type==SHT_NOBITS) |
|
670 | 670 | { |
|
671 | 671 | DataSz=0; |
|
672 | 672 | } |
|
673 | 673 | else |
|
674 | 674 | { |
|
675 | 675 | DataSz = (int64_t)this->sections.at(index)->data->d_size; |
|
676 | 676 | } |
|
677 | 677 | } |
|
678 | 678 | } |
|
679 | 679 | return DataSz; |
|
680 | 680 | } |
|
681 | 681 | |
|
682 | 682 | bool ElfFile::getSectionData(int index, char **buffer) |
|
683 | 683 | { |
|
684 | 684 | if(this->e!=NULL) |
|
685 | 685 | { |
|
686 | 686 | if(index < this->sections.count()) |
|
687 | 687 | { |
|
688 | 688 | *buffer = (char *)this->sections.at(index)->data->d_buf; |
|
689 | 689 | return true; |
|
690 | 690 | } |
|
691 | 691 | } |
|
692 | 692 | return false; |
|
693 | 693 | } |
|
694 | 694 | |
|
695 | 695 | |
|
696 | 696 | qint64 ElfFile::getSegmentMemsz(int index) |
|
697 | 697 | { |
|
698 | 698 | int64_t MemSz=0; |
|
699 | 699 | if(this->e!=NULL) |
|
700 | 700 | { |
|
701 | 701 | if(index < this->Segments.count()) |
|
702 | 702 | { |
|
703 | 703 | MemSz = (int64_t)this->Segments.at(index)->p_memsz; |
|
704 | 704 | } |
|
705 | 705 | } |
|
706 | 706 | return MemSz; |
|
707 | 707 | } |
|
708 | 708 | |
|
709 | 709 | qint64 ElfFile::getSectionMemsz(int index) |
|
710 | 710 | { |
|
711 | 711 | int64_t MemSz=0; |
|
712 | 712 | if(this->e!=NULL) |
|
713 | 713 | { |
|
714 | 714 | if(index < this->sections.count()) |
|
715 | 715 | { |
|
716 | 716 | MemSz = (int64_t)this->sections.at(index)->section_header->sh_size; |
|
717 | 717 | } |
|
718 | 718 | } |
|
719 | 719 | return MemSz; |
|
720 | 720 | } |
|
721 | 721 | |
|
722 | 722 | |
|
723 | 723 | QString ElfFile::getSegmentFlags(int index) |
|
724 | 724 | { |
|
725 | 725 | QString flags(""); |
|
726 | 726 | if(this->e!=NULL) |
|
727 | 727 | { |
|
728 | 728 | if(index < this->Segments.count()) |
|
729 | 729 | { |
|
730 | 730 | if((this->Segments.at(index)->p_flags&PF_X) == PF_X)flags+="x"; |
|
731 | 731 | if((this->Segments.at(index)->p_flags&PF_W) == PF_W)flags+="w"; |
|
732 | 732 | if((this->Segments.at(index)->p_flags&PF_R) == PF_R)flags+="r"; |
|
733 | 733 | if((this->Segments.at(index)->p_flags&PF_MASKOS) == PF_MASKOS)flags+=" OS-specific"; |
|
734 | 734 | if((this->Segments.at(index)->p_flags&PF_MASKPROC) == PF_MASKPROC)flags+=" Processor-specific"; |
|
735 | 735 | } |
|
736 | 736 | } |
|
737 | 737 | return flags; |
|
738 | 738 | } |
|
739 | 739 | |
|
740 | 740 | |
|
741 | 741 | QString ElfFile::getSectionName(int index) |
|
742 | 742 | { |
|
743 | 743 | if((index<sections.count()) && (index>=0)) |
|
744 | 744 | { |
|
745 | 745 | char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name); |
|
746 | 746 | return QString(nameChr); |
|
747 | 747 | } |
|
748 | 748 | return ""; |
|
749 | 749 | } |
|
750 | 750 | |
|
751 | 751 | |
|
752 | 752 | void ElfFile::updateSections() |
|
753 | 753 | { |
|
754 | 754 | for(int i=0;i<this->sections.count();i++) |
|
755 | 755 | { |
|
756 | 756 | delete this->sections.at(i); |
|
757 | 757 | } |
|
758 | 758 | this->sections.clear(); |
|
759 | 759 | this->scn = elf_nextscn (this->e , NULL ); |
|
760 | 760 | this->SectionCount = 0; |
|
761 | 761 | while( this->scn != NULL ) |
|
762 | 762 | { |
|
763 | 763 | GElf_Shdr* shdr = (GElf_Shdr*)malloc(sizeof(GElf_Shdr)); |
|
764 | 764 | gelf_getshdr ( this->scn , shdr ); |
|
765 | 765 | Elf_Data* data = elf_getdata(this->scn, NULL); |
|
766 | 766 | this->sections.append(new Elf_Section(data,shdr)); |
|
767 | 767 | this->SectionCount+=1; |
|
768 | 768 | this->scn = elf_nextscn(e , scn); |
|
769 | 769 | } |
|
770 | 770 | } |
|
771 | 771 | |
|
772 | 772 | |
|
773 | 773 | void ElfFile::updateSegments() |
|
774 | 774 | { |
|
775 | 775 | elf_getphdrnum (this->e , &this->SegmentCount); |
|
776 | 776 | for(int i=0;i<this->Segments.count();i++) |
|
777 | 777 | { |
|
778 | 778 | free(this->Segments.at(i)); |
|
779 | 779 | } |
|
780 | 780 | this->Segments.clear(); |
|
781 | 781 | for(int i=0;i<(int)this->SegmentCount;i++) |
|
782 | 782 | { |
|
783 | 783 | GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr)); |
|
784 | 784 | gelf_getphdr (this->e , i , header ); |
|
785 | 785 | this->Segments.append(header); |
|
786 | 786 | } |
|
787 | 787 | } |
|
788 | 788 | |
|
789 | 789 | void ElfFile::updateSymbols() |
|
790 | 790 | { |
|
791 | 791 | for(int i=0;i<symbols.count();i++) |
|
792 | 792 | { |
|
793 | 793 | delete this->symbols.at(i); |
|
794 | 794 | } |
|
795 | 795 | this->symbols.clear(); |
|
796 | 796 | updateSections(); //Useless in most case but safer to do it |
|
797 | 797 | for(int i=0;i<(int)SectionCount;i++) |
|
798 | 798 | { |
|
799 | 799 | //First find Symbol table |
|
800 | 800 | if(this->getSectionName(i)==".symtab") |
|
801 | 801 | { |
|
802 | 802 | Elf_Section* sec = sections.at(i); |
|
803 | 803 | this->SymbolCount = sec->section_header->sh_size / sec->section_header->sh_entsize; |
|
804 | 804 | //Then list all symbols |
|
805 | 805 | for(int j=0;j<(int)this->SymbolCount;j++) |
|
806 | 806 | { |
|
807 | 807 | GElf_Sym* esym = (GElf_Sym*)malloc(sizeof(GElf_Sym)); |
|
808 | 808 | gelf_getsym(sec->data, j, esym); |
|
809 | 809 | QString name = elf_strptr(this->e,sec->section_header->sh_link,esym->st_name); |
|
810 | 810 | Elf_Symbol* sym = new Elf_Symbol(name,esym); |
|
811 | 811 | symbols.append(sym); |
|
812 | 812 | } |
|
813 | 813 | } |
|
814 | 814 | } |
|
815 | 815 | |
|
816 | 816 | } |
|
817 | 817 | |
|
818 | 818 | |
|
819 | 819 | |
|
820 | 820 | QString ElfFile::getSectionType(int index) |
|
821 | 821 | { |
|
822 | 822 | QString type(""); |
|
823 | 823 | if(this->e!=NULL) |
|
824 | 824 | { |
|
825 | 825 | if(index < this->sections.count()) |
|
826 | 826 | { |
|
827 | 827 | switch(this->sections.at(index)->section_header->sh_type) |
|
828 | 828 | { |
|
829 | 829 | case SHT_NULL : type = "Section header table entry unused"; break; |
|
830 | 830 | case SHT_PROGBITS : type = "Program data"; break; |
|
831 | 831 | case SHT_SYMTAB : type = "Symbol table"; break; |
|
832 | 832 | case SHT_STRTAB : type = "String table"; break; |
|
833 | 833 | case SHT_RELA : type = "Relocation entries with addends"; break; |
|
834 | 834 | case SHT_HASH : type = "Symbol hash table"; break; |
|
835 | 835 | case SHT_DYNAMIC : type = "Dynamic linking information"; break; |
|
836 | 836 | case SHT_NOTE : type = "Notes"; break; |
|
837 | 837 | case SHT_NOBITS :type = "Program space with no data (bss)"; break; |
|
838 | 838 | case SHT_REL :type = "Relocation entries, no addends"; break; |
|
839 | 839 | case SHT_SHLIB : type = "Reserved"; break; |
|
840 | 840 | case SHT_DYNSYM : type = "Dynamic linker symbol table"; break; |
|
841 | 841 | case SHT_INIT_ARRAY : type = "Array of constructors"; break; |
|
842 | 842 | case SHT_FINI_ARRAY : type = "Array of destructors"; break; |
|
843 | 843 | case SHT_PREINIT_ARRAY : type = "Array of pre-constructors"; break; |
|
844 | 844 | case SHT_GROUP : type = "Section group"; break; |
|
845 | 845 | case SHT_SYMTAB_SHNDX : type = "Extended section indeces"; break; |
|
846 | 846 | case SHT_NUM : type = "Number of defined types. "; break; |
|
847 | 847 | case SHT_LOOS : type = "Start OS-specific. "; break; |
|
848 | 848 | case SHT_LOSUNW : type = "Sun-specific low bound. "; break; |
|
849 | 849 | case SHT_SUNW_COMDAT : type = " "; break; |
|
850 | 850 | case SHT_SUNW_syminfo : type = " "; break; |
|
851 | 851 | case SHT_GNU_verdef : type = "Version definition section. "; break; |
|
852 | 852 | case SHT_GNU_verneed : type = "Version needs section. "; break; |
|
853 | 853 | case SHT_GNU_versym : type = "Version symbol table. "; break; |
|
854 | 854 | case SHT_LOPROC : type = "Start of processor-specific"; break; |
|
855 | 855 | case SHT_HIPROC : type = "End of processor-specific"; break; |
|
856 | 856 | case SHT_HIUSER : type = "End of application-specific"; break; |
|
857 | 857 | } |
|
858 | 858 | } |
|
859 | 859 | } |
|
860 | 860 | return type; |
|
861 | 861 | } |
|
862 | 862 | |
|
863 | 863 | int ElfFile::getSectionIndex(QString name) |
|
864 | 864 | { |
|
865 | 865 | if(this->e!=NULL) |
|
866 | 866 | { |
|
867 | 867 | for(int i=0;i<sections.count();i++) |
|
868 | 868 | { |
|
869 | 869 | if(getSectionName(i)==name) |
|
870 | 870 | return i; |
|
871 | 871 | } |
|
872 | 872 | } |
|
873 | 873 | return -1; |
|
874 | 874 | } |
|
875 | 875 | |
|
876 | 876 | bool ElfFile::sectionIsNobits(int index) |
|
877 | 877 | { |
|
878 | 878 | if(this->e!=NULL) |
|
879 | 879 | { |
|
880 | 880 | if(index < this->sections.count()) |
|
881 | 881 | { |
|
882 | 882 | return this->sections.at(index)->section_header->sh_type== SHT_NOBITS; |
|
883 | 883 | } |
|
884 | 884 | } |
|
885 | 885 | return false; |
|
886 | 886 | } |
|
887 | 887 | |
|
888 | 888 | QString ElfFile::getSymbolName(int index) |
|
889 | 889 | { |
|
890 | 890 | if(this->e!=NULL) |
|
891 | 891 | { |
|
892 | 892 | if(index < this->symbols.count()) |
|
893 | 893 | { |
|
894 | 894 | return symbols.at(index)->name; |
|
895 | 895 | } |
|
896 | 896 | } |
|
897 | 897 | return ""; |
|
898 | 898 | } |
|
899 | 899 | |
|
900 | 900 | QString ElfFile::getSymbolType(int index) |
|
901 | 901 | { |
|
902 | 902 | if(this->e!=NULL) |
|
903 | 903 | { |
|
904 | 904 | if(index < this->symbols.count()) |
|
905 | 905 | { |
|
906 | 906 | int type = GELF_ST_TYPE(symbols.at(index)->sym->st_info); |
|
907 | 907 | switch(type) |
|
908 | 908 | { |
|
909 | 909 | case STT_NOTYPE: |
|
910 | 910 | return "No Type"; |
|
911 | 911 | break; |
|
912 | 912 | case STT_OBJECT: |
|
913 | 913 | return "Object"; |
|
914 | 914 | break; |
|
915 | 915 | case STT_FUNC: |
|
916 | 916 | return "Function"; |
|
917 | 917 | break; |
|
918 | 918 | case STT_SECTION: |
|
919 | 919 | return "Section"; |
|
920 | 920 | break; |
|
921 | 921 | case STT_FILE: |
|
922 | 922 | return "File"; |
|
923 | 923 | break; |
|
924 | 924 | case STT_COMMON: |
|
925 | 925 | return "Common data object"; |
|
926 | 926 | break; |
|
927 | 927 | case STT_TLS: |
|
928 | 928 | return "Thread-local data object"; |
|
929 | 929 | break; |
|
930 | 930 | case STT_NUM: |
|
931 | 931 | return "Number of defined types"; |
|
932 | 932 | break; |
|
933 | 933 | case STT_LOOS: |
|
934 | 934 | return "Start of OS-specific"; |
|
935 | 935 | break; |
|
936 | 936 | case STT_HIOS: |
|
937 | 937 | return "End of OS-specific"; |
|
938 | 938 | break; |
|
939 | 939 | case STT_LOPROC: |
|
940 | 940 | return "Start of processor-specific"; |
|
941 | 941 | break; |
|
942 | 942 | case STT_HIPROC: |
|
943 | 943 | return "End of processor-specific"; |
|
944 | 944 | break; |
|
945 | 945 | default: |
|
946 | 946 | return "none"; |
|
947 | 947 | break; |
|
948 | 948 | } |
|
949 | 949 | } |
|
950 | 950 | } |
|
951 | 951 | return "none"; |
|
952 | 952 | } |
|
953 | 953 | |
|
954 | 954 | quint64 ElfFile::getSymbolSize(int index) |
|
955 | 955 | { |
|
956 | 956 | if(this->e!=NULL) |
|
957 | 957 | { |
|
958 | 958 | if((index < this->symbols.count()) && (index>=0)) |
|
959 | 959 | { |
|
960 | 960 | return symbols.at(index)->sym->st_size; |
|
961 | 961 | } |
|
962 | 962 | } |
|
963 | 963 | return 0; |
|
964 | 964 | } |
|
965 | 965 | |
|
966 | 966 | QString ElfFile::getSymbolSectionName(int index) |
|
967 | 967 | { |
|
968 | 968 | if(this->e!=NULL) |
|
969 | 969 | { |
|
970 | 970 | if((index < this->symbols.count()) && (index>=0)) |
|
971 | 971 | { |
|
972 | 972 | return getSectionName(symbols.at(index)->sym->st_shndx-1); |
|
973 | 973 | } |
|
974 | 974 | } |
|
975 | 975 | return "none"; |
|
976 | 976 | } |
|
977 | 977 | |
|
978 | 978 | int ElfFile::getSymbolSectionIndex(int index) |
|
979 | 979 | { |
|
980 | 980 | if(this->e!=NULL) |
|
981 | 981 | { |
|
982 | 982 | if((index < this->symbols.count()) && (index>=0)) |
|
983 | 983 | { |
|
984 | 984 | return symbols.at(index)->sym->st_shndx; |
|
985 | 985 | } |
|
986 | 986 | } |
|
987 | 987 | return 0; |
|
988 | 988 | } |
|
989 | 989 | |
|
990 | 990 | quint64 ElfFile::getSymbolAddress(int index) |
|
991 | 991 | { |
|
992 | 992 | if(this->e!=NULL) |
|
993 | 993 | { |
|
994 | 994 | if((index < this->symbols.count()) && (index>=0)) |
|
995 | 995 | { |
|
996 | 996 | return symbols.at(index)->sym->st_value; |
|
997 | 997 | } |
|
998 | 998 | } |
|
999 | 999 | return 0; |
|
1000 | 1000 | } |
|
1001 | 1001 | |
|
1002 | 1002 | QString ElfFile::getSymbolLinkType(int index) |
|
1003 | 1003 | { |
|
1004 | 1004 | if(this->e!=NULL) |
|
1005 | 1005 | { |
|
1006 | 1006 | if(index < this->symbols.count()) |
|
1007 | 1007 | { |
|
1008 | 1008 | int btype = GELF_ST_BIND(symbols.at(index)->sym->st_info); |
|
1009 | 1009 | switch(btype) |
|
1010 | 1010 | { |
|
1011 | 1011 | case STB_LOCAL: |
|
1012 | 1012 | return "Local"; |
|
1013 | 1013 | break; |
|
1014 | 1014 | case STB_GLOBAL: |
|
1015 | 1015 | return "Global"; |
|
1016 | 1016 | break; |
|
1017 | 1017 | case STB_WEAK: |
|
1018 | 1018 | return "Weak"; |
|
1019 | 1019 | break; |
|
1020 | 1020 | case STB_NUM: |
|
1021 | 1021 | return "Number of defined types"; |
|
1022 | 1022 | break; |
|
1023 | 1023 | case STB_LOOS: |
|
1024 | 1024 | return "Start of OS-specific"; |
|
1025 | 1025 | break; |
|
1026 | 1026 | case STB_HIOS: |
|
1027 | 1027 | return "End of OS-specific"; |
|
1028 | 1028 | break; |
|
1029 | 1029 | case STB_LOPROC: |
|
1030 | 1030 | return "Start of processor-specific"; |
|
1031 | 1031 | break; |
|
1032 | 1032 | case STB_HIPROC: |
|
1033 | 1033 | return "End of processor-specific"; |
|
1034 | 1034 | break; |
|
1035 | 1035 | default: |
|
1036 | 1036 | return "none"; |
|
1037 | 1037 | break; |
|
1038 | 1038 | } |
|
1039 | 1039 | } |
|
1040 | 1040 | } |
|
1041 | 1041 | return "none"; |
|
1042 | 1042 | } |
|
1043 | 1043 | |
|
1044 | 1044 | bool ElfFile::isElf(const QString &File) |
|
1045 | 1045 | { |
|
1046 | 1046 | int file =0; |
|
1047 | 1047 | #ifdef _ELF_WINDOWS_ |
|
1048 | 1048 | file = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0); |
|
1049 | 1049 | #else |
|
1050 | 1050 | file = open(File.toStdString().c_str(),O_RDONLY ,0); |
|
1051 | 1051 | #endif |
|
1052 | 1052 | char Magic[4]; |
|
1053 | 1053 | if(file!=-1) |
|
1054 | 1054 | { |
|
1055 | 1055 | size_t res = read(file,Magic,4); |
|
1056 | 1056 | close(file); |
|
1057 | 1057 | if((res==4) && (Magic[0]==0x7f) && (Magic[1]==0x45) && (Magic[2]==0x4c) && (Magic[3]==0x46)) |
|
1058 | 1058 | { |
|
1059 | 1059 | return true; |
|
1060 | 1060 | } |
|
1061 | 1061 | } |
|
1062 | 1062 | return false; |
|
1063 | 1063 | } |
|
1064 | 1064 | |
|
1065 | 1065 | bool ElfFile::toSrec(const QString &File) |
|
1066 | 1066 | { |
|
1067 | 1067 | return srecFile::toSrec(this->getFragments(),File); |
|
1068 | 1068 | } |
@@ -1,523 +1,522 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the SocExplorer Software |
|
3 | 3 | -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | -------------------------------------------------------------------------------*/ |
|
19 | 19 | /*-- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
21 | 21 | ----------------------------------------------------------------------------*/ |
|
22 | 22 | #include "elfparser.h" |
|
23 | 23 | #include <sys/types.h> |
|
24 | 24 | #include <sys/stat.h> |
|
25 | 25 | #include <fcntl.h> |
|
26 | 26 | #include <unistd.h> |
|
27 | 27 | |
|
28 | 28 | extern QString elfresolveMachine(Elf64_Half e_machine); |
|
29 | 29 | |
|
30 | 30 | |
|
31 | 31 | elfparser::elfparser() |
|
32 | 32 | { |
|
33 | 33 | this->opened = false; |
|
34 | 34 | this->type_elf = false; |
|
35 | 35 | this->elfFile = (int)NULL; |
|
36 | 36 | this->e = NULL; |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | |
|
40 | 40 | int elfparser::setFilename(const QString &name) |
|
41 | 41 | { |
|
42 | 42 | this->closeFile(); |
|
43 | 43 | if(elf_version(EV_CURRENT)==EV_NONE)return 0; |
|
44 | 44 | #ifdef _ELF_WINDOWS_ |
|
45 | 45 | this->elfFile = open(name.toStdString().c_str(),O_RDONLY|O_BINARY ,0); |
|
46 | 46 | #else |
|
47 | 47 | this->elfFile = open(name.toStdString().c_str(),O_RDONLY ,0); |
|
48 | 48 | #endif |
|
49 | 49 | if(this->elfFile==(int)NULL)return 0; |
|
50 | 50 | this->e = elf_begin(this->elfFile,ELF_C_READ,NULL); |
|
51 | 51 | if(this->e==NULL)return 0; |
|
52 | 52 | this->ek = elf_kind(this->e); |
|
53 | 53 | gelf_getehdr (this->e, &this->ehdr ); |
|
54 | 54 | elf_getshdrstrndx (this->e, &this->shstrndx); |
|
55 | 55 | this->updateSegments(); |
|
56 | 56 | this->updateSections(); |
|
57 | 57 | return 1; |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | |
|
61 | 61 | int elfparser::closeFile() |
|
62 | 62 | { |
|
63 | 63 | if(this->elfFile!=(int)NULL) |
|
64 | 64 | { |
|
65 | 65 | if(this->e!=NULL) |
|
66 | 66 | { |
|
67 | 67 | elf_end(this->e); |
|
68 | 68 | this->e = NULL; |
|
69 | 69 | } |
|
70 | 70 | close(this->elfFile); |
|
71 | 71 | this->elfFile = (int)NULL; |
|
72 | 72 | } |
|
73 | 73 | return 0; |
|
74 | 74 | } |
|
75 | 75 | |
|
76 | 76 | QString elfparser::getClass() |
|
77 | 77 | { |
|
78 | 78 | if(this->e!=NULL) |
|
79 | 79 | { |
|
80 | 80 | int eclass = gelf_getclass(this->e); |
|
81 | 81 | if(eclass==ELFCLASS32)return "ELF32"; |
|
82 | 82 | if(eclass==ELFCLASS64)return "ELF64"; |
|
83 | 83 | } |
|
84 | 84 | return "none"; |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | |
|
88 | 88 | bool elfparser::isopened() |
|
89 | 89 | { |
|
90 | 90 | return this->opened; |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | |
|
94 | 94 | bool elfparser::iself() |
|
95 | 95 | { |
|
96 | 96 | return this->type_elf; |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | |
|
100 | 100 | QString elfparser::getArchitecture() |
|
101 | 101 | { |
|
102 | 102 | if(this->e!=NULL) |
|
103 | 103 | { |
|
104 | 104 | return elfresolveMachine(this->ehdr.e_machine); |
|
105 | 105 | } |
|
106 | 106 | return ""; |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | |
|
110 | 110 | QString elfparser::getType() |
|
111 | 111 | { |
|
112 | 112 | QString kind(""); |
|
113 | 113 | if(this->e!=NULL) |
|
114 | 114 | { |
|
115 | 115 | switch(this->ek) |
|
116 | 116 | { |
|
117 | 117 | case ELF_K_AR: |
|
118 | 118 | kind = "Archive"; |
|
119 | 119 | break; |
|
120 | 120 | case ELF_K_ELF: |
|
121 | 121 | kind = "Elf"; |
|
122 | 122 | break; |
|
123 | 123 | case ELF_K_COFF: |
|
124 | 124 | kind = "COFF"; |
|
125 | 125 | break; |
|
126 | 126 | case ELF_K_NUM: |
|
127 | 127 | kind = "NUM"; |
|
128 | 128 | break; |
|
129 | 129 | case ELF_K_NONE: |
|
130 | 130 | kind = "Data"; |
|
131 | 131 | break; |
|
132 | 132 | default: |
|
133 | 133 | kind = "Unknow"; |
|
134 | 134 | break; |
|
135 | 135 | } |
|
136 | 136 | } |
|
137 | 137 | return kind; |
|
138 | 138 | } |
|
139 | 139 | |
|
140 | 140 | QString elfparser::getEndianness() |
|
141 | 141 | { |
|
142 | 142 | if(this->e!=NULL) |
|
143 | 143 | { |
|
144 | 144 | if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return "2's complement, little endian"; |
|
145 | 145 | if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return "2's complement, big endian"; |
|
146 | 146 | } |
|
147 | 147 | return "none"; |
|
148 | 148 | } |
|
149 | 149 | |
|
150 | 150 | QString elfparser::getABI() |
|
151 | 151 | { |
|
152 | 152 | if(this->e!=NULL) |
|
153 | 153 | { |
|
154 | 154 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NONE)return "UNIX System V ABI"; |
|
155 | 155 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SYSV)return "Alias"; |
|
156 | 156 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_HPUX)return "HP-UX"; |
|
157 | 157 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NETBSD)return "NetBSD"; |
|
158 |
if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ |
|
|
159 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_LINUX)return "Compatibility alias"; | |
|
158 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_LINUX)return "Object uses GNU ELF extensions"; | |
|
160 | 159 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SOLARIS)return "Sun Solaris"; |
|
161 | 160 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_AIX)return "IBM AIX"; |
|
162 | 161 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_IRIX)return "SGI Irix"; |
|
163 | 162 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_FREEBSD)return "FreeBSD"; |
|
164 | 163 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_TRU64)return "Compaq TRU64 UNIX"; |
|
165 | 164 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_MODESTO)return " Novell Modesto"; |
|
166 | 165 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_OPENBSD)return "OpenBSD"; |
|
167 | 166 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM_AEABI)return "ARM EABI"; |
|
168 | 167 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM)return "ARM"; |
|
169 | 168 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_STANDALONE)return "Standalone (embedded) application"; |
|
170 | 169 | } |
|
171 | 170 | return "none"; |
|
172 | 171 | } |
|
173 | 172 | |
|
174 | 173 | |
|
175 | 174 | qint64 elfparser::getVersion() |
|
176 | 175 | { |
|
177 | 176 | if(this->e!=NULL) |
|
178 | 177 | { |
|
179 | 178 | return this->ehdr.e_version; |
|
180 | 179 | } |
|
181 | 180 | return -1; |
|
182 | 181 | } |
|
183 | 182 | |
|
184 | 183 | qint64 elfparser::getEntryPointAddress() |
|
185 | 184 | { |
|
186 | 185 | if(this->e!=NULL) |
|
187 | 186 | { |
|
188 | 187 | return this->ehdr.e_entry; |
|
189 | 188 | } |
|
190 | 189 | return -1; |
|
191 | 190 | } |
|
192 | 191 | |
|
193 | 192 | |
|
194 | 193 | int elfparser::getSectioncount() |
|
195 | 194 | { |
|
196 | 195 | return (int)this->SectionCount; |
|
197 | 196 | } |
|
198 | 197 | |
|
199 | 198 | |
|
200 | 199 | int elfparser::getSegmentcount() |
|
201 | 200 | { |
|
202 | 201 | return (int)this->SegmentCount; |
|
203 | 202 | } |
|
204 | 203 | |
|
205 | 204 | |
|
206 | 205 | QString elfparser::getSegmentType(int index) |
|
207 | 206 | { |
|
208 | 207 | QString type(""); |
|
209 | 208 | if(this->e!=NULL) |
|
210 | 209 | { |
|
211 | 210 | if(index < this->Segments.count()) |
|
212 | 211 | { |
|
213 | 212 | switch(this->Segments.at(index)->p_type) |
|
214 | 213 | { |
|
215 | 214 | case PT_NULL: |
|
216 | 215 | type = "Program header table entry unused"; |
|
217 | 216 | break; |
|
218 | 217 | case PT_LOAD: |
|
219 | 218 | type = "Loadable program segment"; |
|
220 | 219 | break; |
|
221 | 220 | case PT_DYNAMIC : |
|
222 | 221 | type = "Dynamic linking information"; |
|
223 | 222 | break; |
|
224 | 223 | case PT_INTERP: |
|
225 | 224 | type ="Program interpreter"; |
|
226 | 225 | break; |
|
227 | 226 | case PT_NOTE: |
|
228 | 227 | type = "Auxiliary information"; |
|
229 | 228 | break; |
|
230 | 229 | case PT_SHLIB: |
|
231 | 230 | type = "Reserved"; |
|
232 | 231 | break; |
|
233 | 232 | case PT_PHDR: |
|
234 | 233 | type = "Entry for header table itself"; |
|
235 | 234 | break; |
|
236 | 235 | case PT_TLS: |
|
237 | 236 | type = "Thread-local storage segment"; |
|
238 | 237 | break; |
|
239 | 238 | case PT_NUM: |
|
240 | 239 | type = "Number of defined types"; |
|
241 | 240 | break; |
|
242 | 241 | case PT_LOOS: |
|
243 | 242 | type = "Start of OS-specific"; |
|
244 | 243 | break; |
|
245 | 244 | case PT_SUNWSTACK: |
|
246 | 245 | type = "Stack segment"; |
|
247 | 246 | break; |
|
248 | 247 | case PT_LOPROC: |
|
249 | 248 | type = "Start of processor-specific"; |
|
250 | 249 | break; |
|
251 | 250 | case PT_HIPROC: |
|
252 | 251 | type = "End of processor-specific"; |
|
253 | 252 | break; |
|
254 | 253 | default: |
|
255 | 254 | type = "Unknow Section Type"; |
|
256 | 255 | break; |
|
257 | 256 | } |
|
258 | 257 | } |
|
259 | 258 | } |
|
260 | 259 | |
|
261 | 260 | return type; |
|
262 | 261 | } |
|
263 | 262 | |
|
264 | 263 | |
|
265 | 264 | qint64 elfparser::getSegmentOffset(int index) |
|
266 | 265 | { |
|
267 | 266 | qint64 Offset=-1; |
|
268 | 267 | if(this->e!=NULL) |
|
269 | 268 | { |
|
270 | 269 | if(index < this->Segments.count()) |
|
271 | 270 | { |
|
272 | 271 | Offset = (qint64)this->Segments.at(index)->p_offset; |
|
273 | 272 | } |
|
274 | 273 | } |
|
275 | 274 | return Offset; |
|
276 | 275 | } |
|
277 | 276 | |
|
278 | 277 | |
|
279 | 278 | qint64 elfparser::getSegmentVaddr(int index) |
|
280 | 279 | { |
|
281 | 280 | int64_t Vaddr = 0; |
|
282 | 281 | if(this->e!=NULL) |
|
283 | 282 | { |
|
284 | 283 | if(index < this->Segments.count()) |
|
285 | 284 | { |
|
286 | 285 | Vaddr = (int64_t)this->Segments.at(index)->p_vaddr; |
|
287 | 286 | } |
|
288 | 287 | } |
|
289 | 288 | return Vaddr; |
|
290 | 289 | } |
|
291 | 290 | |
|
292 | 291 | |
|
293 | 292 | qint64 elfparser::getSegmentPaddr(int index) |
|
294 | 293 | { |
|
295 | 294 | int64_t Paddr=0; |
|
296 | 295 | if(this->e!=NULL) |
|
297 | 296 | { |
|
298 | 297 | if(index < this->Segments.count()) |
|
299 | 298 | { |
|
300 | 299 | Paddr = (int64_t)this->Segments.at(index)->p_paddr; |
|
301 | 300 | } |
|
302 | 301 | } |
|
303 | 302 | return Paddr; |
|
304 | 303 | } |
|
305 | 304 | |
|
306 | 305 | qint64 elfparser::getSectionPaddr(int index) |
|
307 | 306 | { |
|
308 | 307 | int64_t Paddr=0; |
|
309 | 308 | if(this->e!=NULL) |
|
310 | 309 | { |
|
311 | 310 | if(index < this->sections.count()) |
|
312 | 311 | { |
|
313 | 312 | Paddr = (int64_t)this->sections.at(index)->section_header->sh_addr; |
|
314 | 313 | } |
|
315 | 314 | } |
|
316 | 315 | return Paddr; |
|
317 | 316 | } |
|
318 | 317 | |
|
319 | 318 | |
|
320 | 319 | qint64 elfparser::getSegmentFilesz(int index) |
|
321 | 320 | { |
|
322 | 321 | int64_t FileSz=0; |
|
323 | 322 | if(this->e!=NULL) |
|
324 | 323 | { |
|
325 | 324 | if(index < this->Segments.count()) |
|
326 | 325 | { |
|
327 | 326 | FileSz = (int64_t)this->Segments.at(index)->p_filesz; |
|
328 | 327 | } |
|
329 | 328 | } |
|
330 | 329 | return FileSz; |
|
331 | 330 | } |
|
332 | 331 | |
|
333 | 332 | qint64 elfparser::getSectionDatasz(int index) |
|
334 | 333 | { |
|
335 | 334 | int64_t DataSz=0; |
|
336 | 335 | if(this->e!=NULL) |
|
337 | 336 | { |
|
338 | 337 | if(index < this->sections.count()) |
|
339 | 338 | { |
|
340 | 339 | DataSz = (int64_t)this->sections.at(index)->data->d_size; |
|
341 | 340 | } |
|
342 | 341 | } |
|
343 | 342 | return DataSz; |
|
344 | 343 | } |
|
345 | 344 | |
|
346 | 345 | bool elfparser::getSectionData(int index, char **buffer) |
|
347 | 346 | { |
|
348 | 347 | if(this->e!=NULL) |
|
349 | 348 | { |
|
350 | 349 | if(index < this->sections.count()) |
|
351 | 350 | { |
|
352 | 351 | *buffer = (char *)this->sections.at(index)->data->d_buf; |
|
353 | 352 | return true; |
|
354 | 353 | } |
|
355 | 354 | } |
|
356 | 355 | return false; |
|
357 | 356 | } |
|
358 | 357 | |
|
359 | 358 | |
|
360 | 359 | qint64 elfparser::getSegmentMemsz(int index) |
|
361 | 360 | { |
|
362 | 361 | int64_t MemSz=0; |
|
363 | 362 | if(this->e!=NULL) |
|
364 | 363 | { |
|
365 | 364 | if(index < this->Segments.count()) |
|
366 | 365 | { |
|
367 | 366 | MemSz = (int64_t)this->Segments.at(index)->p_memsz; |
|
368 | 367 | } |
|
369 | 368 | } |
|
370 | 369 | return MemSz; |
|
371 | 370 | } |
|
372 | 371 | |
|
373 | 372 | qint64 elfparser::getSectionMemsz(int index) |
|
374 | 373 | { |
|
375 | 374 | int64_t MemSz=0; |
|
376 | 375 | if(this->e!=NULL) |
|
377 | 376 | { |
|
378 | 377 | if(index < this->sections.count()) |
|
379 | 378 | { |
|
380 | 379 | MemSz = (int64_t)this->sections.at(index)->section_header->sh_size; |
|
381 | 380 | } |
|
382 | 381 | } |
|
383 | 382 | return MemSz; |
|
384 | 383 | } |
|
385 | 384 | |
|
386 | 385 | |
|
387 | 386 | QString elfparser::getSegmentFlags(int index) |
|
388 | 387 | { |
|
389 | 388 | QString flags(""); |
|
390 | 389 | if(this->e!=NULL) |
|
391 | 390 | { |
|
392 | 391 | if(index < this->Segments.count()) |
|
393 | 392 | { |
|
394 | 393 | if((this->Segments.at(index)->p_flags&PF_X) == PF_X)flags+="x"; |
|
395 | 394 | if((this->Segments.at(index)->p_flags&PF_W) == PF_W)flags+="w"; |
|
396 | 395 | if((this->Segments.at(index)->p_flags&PF_R) == PF_R)flags+="r"; |
|
397 | 396 | if((this->Segments.at(index)->p_flags&PF_MASKOS) == PF_MASKOS)flags+=" OS-specific"; |
|
398 | 397 | if((this->Segments.at(index)->p_flags&PF_MASKPROC) == PF_MASKPROC)flags+=" Processor-specific"; |
|
399 | 398 | } |
|
400 | 399 | } |
|
401 | 400 | return flags; |
|
402 | 401 | } |
|
403 | 402 | |
|
404 | 403 | |
|
405 | 404 | QString elfparser::getSectionName(int index) |
|
406 | 405 | { |
|
407 | 406 | char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name); |
|
408 | 407 | return QString(nameChr); |
|
409 | 408 | } |
|
410 | 409 | |
|
411 | 410 | |
|
412 | 411 | void elfparser::updateSections() |
|
413 | 412 | { |
|
414 | 413 | for(int i=0;i<this->sections.count();i++) |
|
415 | 414 | { |
|
416 | 415 | delete this->sections.at(i); |
|
417 | 416 | } |
|
418 | 417 | this->sections.clear(); |
|
419 | 418 | this->scn = elf_nextscn (this->e , NULL ); |
|
420 | 419 | this->SectionCount = 0; |
|
421 | 420 | while( this->scn != NULL ) |
|
422 | 421 | { |
|
423 | 422 | GElf_Shdr* shdr = (GElf_Shdr*)malloc(sizeof(GElf_Shdr)); |
|
424 | 423 | gelf_getshdr ( this->scn , shdr ); |
|
425 | 424 | Elf_Data* data = elf_getdata(this->scn, NULL); |
|
426 | 425 | this->sections.append(new Elf_Section(data,shdr)); |
|
427 | 426 | this->SectionCount+=1; |
|
428 | 427 | this->scn = elf_nextscn(e , scn); |
|
429 | 428 | } |
|
430 | 429 | } |
|
431 | 430 | |
|
432 | 431 | |
|
433 | 432 | void elfparser::updateSegments() |
|
434 | 433 | { |
|
435 | 434 | elf_getphdrnum (this->e , &this->SegmentCount); |
|
436 | 435 | for(int i=0;i<this->Segments.count();i++) |
|
437 | 436 | { |
|
438 | 437 | free(this->Segments.at(i)); |
|
439 | 438 | } |
|
440 | 439 | this->Segments.clear(); |
|
441 | 440 | for(int i=0;i<(int)this->SegmentCount;i++) |
|
442 | 441 | { |
|
443 | 442 | GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr)); |
|
444 | 443 | gelf_getphdr (this->e , i , header ); |
|
445 | 444 | this->Segments.append(header); |
|
446 | 445 | } |
|
447 | 446 | } |
|
448 | 447 | |
|
449 | 448 | |
|
450 | 449 | |
|
451 | 450 | |
|
452 | 451 | |
|
453 | 452 | QString elfparser::getSectionType(int index) |
|
454 | 453 | { |
|
455 | 454 | QString type(""); |
|
456 | 455 | if(this->e!=NULL) |
|
457 | 456 | { |
|
458 | 457 | if(index < this->Segments.count()) |
|
459 | 458 | { |
|
460 | 459 | switch(this->Segments.at(index)->p_type) |
|
461 | 460 | { |
|
462 | 461 | case SHT_NULL : type = "Section header table entry unused"; break; |
|
463 | 462 | case SHT_PROGBITS : type = "Program data"; break; |
|
464 | 463 | case SHT_SYMTAB : type = "Symbol table"; break; |
|
465 | 464 | case SHT_STRTAB : type = "String table"; break; |
|
466 | 465 | case SHT_RELA : type = "Relocation entries with addends"; break; |
|
467 | 466 | case SHT_HASH : type = "Symbol hash table"; break; |
|
468 | 467 | case SHT_DYNAMIC : type = "Dynamic linking information"; break; |
|
469 | 468 | case SHT_NOTE : type = "Notes"; break; |
|
470 | 469 | case SHT_NOBITS :type = "Program space with no data (bss)"; break; |
|
471 | 470 | case SHT_REL :type = "Relocation entries, no addends"; break; |
|
472 | 471 | case SHT_SHLIB : type = "Reserved"; break; |
|
473 | 472 | case SHT_DYNSYM : type = "Dynamic linker symbol table"; break; |
|
474 | 473 | case SHT_INIT_ARRAY : type = "Array of constructors"; break; |
|
475 | 474 | case SHT_FINI_ARRAY : type = "Array of destructors"; break; |
|
476 | 475 | case SHT_PREINIT_ARRAY : type = "Array of pre-constructors"; break; |
|
477 | 476 | case SHT_GROUP : type = "Section group"; break; |
|
478 | 477 | case SHT_SYMTAB_SHNDX : type = "Extended section indeces"; break; |
|
479 | 478 | case SHT_NUM : type = "Number of defined types. "; break; |
|
480 | 479 | case SHT_LOOS : type = "Start OS-specific. "; break; |
|
481 | 480 | case SHT_LOSUNW : type = "Sun-specific low bound. "; break; |
|
482 | 481 | case SHT_SUNW_COMDAT : type = " "; break; |
|
483 | 482 | case SHT_SUNW_syminfo : type = " "; break; |
|
484 | 483 | case SHT_GNU_verdef : type = "Version definition section. "; break; |
|
485 | 484 | case SHT_GNU_verneed : type = "Version needs section. "; break; |
|
486 | 485 | case SHT_GNU_versym : type = "Version symbol table. "; break; |
|
487 | 486 | case SHT_LOPROC : type = "Start of processor-specific"; break; |
|
488 | 487 | case SHT_HIPROC : type = "End of processor-specific"; break; |
|
489 | 488 | case SHT_HIUSER : type = "End of application-specific"; break; |
|
490 | 489 | } |
|
491 | 490 | } |
|
492 | 491 | } |
|
493 | 492 | return type; |
|
494 | 493 | } |
|
495 | 494 | |
|
496 | 495 | bool elfparser::isElf(const QString &File) |
|
497 | 496 | { |
|
498 | 497 | int file =0; |
|
499 | 498 | #ifdef _ELF_WINDOWS_ |
|
500 | 499 | file = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0); |
|
501 | 500 | #else |
|
502 | 501 | file = open(File.toStdString().c_str(),O_RDONLY ,0); |
|
503 | 502 | #endif |
|
504 | 503 | char Magic[4]; |
|
505 | 504 | if(file!=-1) |
|
506 | 505 | { |
|
507 | 506 | size_t res = read(file,Magic,4); |
|
508 | 507 | close(file); |
|
509 | 508 | if((res == 4) && (Magic[0]==0x7f) && (Magic[1]==0x45) && (Magic[2]==0x4c) && (Magic[3]==0x46)) |
|
510 | 509 | { |
|
511 | 510 | return true; |
|
512 | 511 | } |
|
513 | 512 | } |
|
514 | 513 | return false; |
|
515 | 514 | } |
|
516 | 515 | |
|
517 | 516 | |
|
518 | 517 | |
|
519 | 518 | |
|
520 | 519 | |
|
521 | 520 | |
|
522 | 521 | |
|
523 | 522 |
@@ -1,996 +1,1002 | |||
|
1 | 1 | /* |
|
2 | 2 | * elf_repl.h - public header file for systems that lack it. |
|
3 | 3 | * Copyright (C) 1995 - 2006 Michael Riepe |
|
4 | 4 | * |
|
5 | 5 | * This library is free software; you can redistribute it and/or |
|
6 | 6 | * modify it under the terms of the GNU Library General Public |
|
7 | 7 | * License as published by the Free Software Foundation; either |
|
8 | 8 | * version 2 of the License, or (at your option) any later version. |
|
9 | 9 | * |
|
10 | 10 | * This library is distributed in the hope that it will be useful, |
|
11 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 | 13 | * Library General Public License for more details. |
|
14 | 14 | * |
|
15 | 15 | * You should have received a copy of the GNU Library General Public |
|
16 | 16 | * License along with this library; if not, write to the Free Software |
|
17 | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|
18 | 18 | */ |
|
19 | 19 | |
|
20 | 20 | /* @(#) $Id: elf_repl.h,v 1.22 2009/11/01 13:04:19 michael Exp $ */ |
|
21 | 21 | |
|
22 | 22 | /* |
|
23 | 23 | * NEVER INCLUDE THIS FILE DIRECTLY - USE <libelf.h> INSTEAD! |
|
24 | 24 | */ |
|
25 | 25 | |
|
26 | 26 | #ifndef _ELF_REPL_H |
|
27 | 27 | #define _ELF_REPL_H |
|
28 | 28 | |
|
29 | 29 | #ifdef __cplusplus |
|
30 | 30 | extern "C" { |
|
31 | 31 | #endif /* __cplusplus */ |
|
32 | 32 | |
|
33 | 33 | /* |
|
34 | 34 | * Scalar data types |
|
35 | 35 | */ |
|
36 | 36 | typedef __libelf_u32_t Elf32_Addr; |
|
37 | 37 | typedef __libelf_u16_t Elf32_Half; |
|
38 | 38 | typedef __libelf_u32_t Elf32_Off; |
|
39 | 39 | typedef __libelf_i32_t Elf32_Sword; |
|
40 | 40 | typedef __libelf_u32_t Elf32_Word; |
|
41 | 41 | |
|
42 | 42 | #define ELF32_FSZ_ADDR 4 |
|
43 | 43 | #define ELF32_FSZ_HALF 2 |
|
44 | 44 | #define ELF32_FSZ_OFF 4 |
|
45 | 45 | #define ELF32_FSZ_SWORD 4 |
|
46 | 46 | #define ELF32_FSZ_WORD 4 |
|
47 | 47 | |
|
48 | 48 | #if __LIBELF64 |
|
49 | 49 | |
|
50 | 50 | typedef __libelf_u64_t Elf64_Addr; |
|
51 | 51 | typedef __libelf_u16_t Elf64_Half; |
|
52 | 52 | typedef __libelf_u64_t Elf64_Off; |
|
53 | 53 | typedef __libelf_i32_t Elf64_Sword; |
|
54 | 54 | typedef __libelf_u32_t Elf64_Word; |
|
55 | 55 | typedef __libelf_i64_t Elf64_Sxword; |
|
56 | 56 | typedef __libelf_u64_t Elf64_Xword; |
|
57 | 57 | |
|
58 | 58 | #define ELF64_FSZ_ADDR 8 |
|
59 | 59 | #define ELF64_FSZ_HALF 2 |
|
60 | 60 | #define ELF64_FSZ_OFF 8 |
|
61 | 61 | #define ELF64_FSZ_SWORD 4 |
|
62 | 62 | #define ELF64_FSZ_WORD 4 |
|
63 | 63 | #define ELF64_FSZ_SXWORD 8 |
|
64 | 64 | #define ELF64_FSZ_XWORD 8 |
|
65 | 65 | |
|
66 | 66 | /* |
|
67 | 67 | * Blame Sun for this... |
|
68 | 68 | */ |
|
69 | 69 | typedef __libelf_u64_t Elf64_Lword; |
|
70 | 70 | typedef __libelf_u64_t Elf32_Lword; |
|
71 | 71 | |
|
72 | 72 | #endif /* __LIBELF64 */ |
|
73 | 73 | |
|
74 | 74 | /* |
|
75 | 75 | * ELF header |
|
76 | 76 | */ |
|
77 | 77 | #define EI_NIDENT 16 |
|
78 | 78 | |
|
79 | 79 | typedef struct { |
|
80 | 80 | unsigned char e_ident[EI_NIDENT]; |
|
81 | 81 | Elf32_Half e_type; |
|
82 | 82 | Elf32_Half e_machine; |
|
83 | 83 | Elf32_Word e_version; |
|
84 | 84 | Elf32_Addr e_entry; |
|
85 | 85 | Elf32_Off e_phoff; |
|
86 | 86 | Elf32_Off e_shoff; |
|
87 | 87 | Elf32_Word e_flags; |
|
88 | 88 | Elf32_Half e_ehsize; |
|
89 | 89 | Elf32_Half e_phentsize; |
|
90 | 90 | Elf32_Half e_phnum; |
|
91 | 91 | Elf32_Half e_shentsize; |
|
92 | 92 | Elf32_Half e_shnum; |
|
93 | 93 | Elf32_Half e_shstrndx; |
|
94 | 94 | } Elf32_Ehdr; |
|
95 | 95 | |
|
96 | 96 | #if __LIBELF64 |
|
97 | 97 | typedef struct { |
|
98 | 98 | unsigned char e_ident[EI_NIDENT]; |
|
99 | 99 | Elf64_Half e_type; |
|
100 | 100 | Elf64_Half e_machine; |
|
101 | 101 | Elf64_Word e_version; |
|
102 | 102 | Elf64_Addr e_entry; |
|
103 | 103 | Elf64_Off e_phoff; |
|
104 | 104 | Elf64_Off e_shoff; |
|
105 | 105 | Elf64_Word e_flags; |
|
106 | 106 | Elf64_Half e_ehsize; |
|
107 | 107 | Elf64_Half e_phentsize; |
|
108 | 108 | Elf64_Half e_phnum; |
|
109 | 109 | Elf64_Half e_shentsize; |
|
110 | 110 | Elf64_Half e_shnum; |
|
111 | 111 | Elf64_Half e_shstrndx; |
|
112 | 112 | } Elf64_Ehdr; |
|
113 | 113 | #endif /* __LIBELF64 */ |
|
114 | 114 | |
|
115 | 115 | /* |
|
116 | 116 | * e_ident |
|
117 | 117 | */ |
|
118 | 118 | #define EI_MAG0 0 |
|
119 | 119 | #define EI_MAG1 1 |
|
120 | 120 | #define EI_MAG2 2 |
|
121 | 121 | #define EI_MAG3 3 |
|
122 | 122 | #define EI_CLASS 4 |
|
123 | 123 | #define EI_DATA 5 |
|
124 | 124 | #define EI_VERSION 6 |
|
125 | 125 | #define EI_OSABI 7 |
|
126 | 126 | #define EI_ABIVERSION 8 |
|
127 | 127 | #define EI_PAD 9 |
|
128 | 128 | |
|
129 | 129 | #define ELFMAG0 0x7f |
|
130 | 130 | #define ELFMAG1 'E' |
|
131 | 131 | #define ELFMAG2 'L' |
|
132 | 132 | #define ELFMAG3 'F' |
|
133 | 133 | #define ELFMAG "\177ELF" |
|
134 | 134 | #define SELFMAG 4 |
|
135 | 135 | |
|
136 | 136 | /* |
|
137 | 137 | * e_ident[EI_CLASS] |
|
138 | 138 | */ |
|
139 | 139 | #define ELFCLASSNONE 0 |
|
140 | 140 | #define ELFCLASS32 1 |
|
141 | 141 | #define ELFCLASS64 2 |
|
142 | 142 | #define ELFCLASSNUM 3 |
|
143 | 143 | |
|
144 | 144 | /* |
|
145 | 145 | * e_ident[EI_DATA] |
|
146 | 146 | */ |
|
147 | 147 | #define ELFDATANONE 0 |
|
148 | 148 | #define ELFDATA2LSB 1 |
|
149 | 149 | #define ELFDATA2MSB 2 |
|
150 | 150 | #define ELFDATANUM 3 |
|
151 | 151 | |
|
152 | 152 | /* |
|
153 | 153 | * e_ident[EI_OSABI] |
|
154 | 154 | */ |
|
155 | 155 | #define ELFOSABI_NONE 0 /* No extensions or unspecified */ |
|
156 | 156 | #define ELFOSABI_SYSV ELFOSABI_NONE |
|
157 | 157 | #define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */ |
|
158 | 158 | #define ELFOSABI_NETBSD 2 /* NetBSD */ |
|
159 | 159 | #define ELFOSABI_LINUX 3 /* Linux */ |
|
160 | 160 | #define ELFOSABI_SOLARIS 6 /* Sun Solaris */ |
|
161 | 161 | #define ELFOSABI_AIX 7 /* AIX */ |
|
162 | 162 | #define ELFOSABI_IRIX 8 /* IRIX */ |
|
163 | 163 | #define ELFOSABI_FREEBSD 9 /* FreeBSD */ |
|
164 | 164 | #define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */ |
|
165 | 165 | #define ELFOSABI_MODESTO 11 /* Novell Modesto */ |
|
166 | 166 | #define ELFOSABI_OPENBSD 12 /* Open BSD */ |
|
167 | 167 | #define ELFOSABI_OPENVMS 13 /* Open VMS */ |
|
168 | 168 | #define ELFOSABI_NSK 14 /* Hewlett-Packard Non-Stop Kernel */ |
|
169 | 169 | #define ELFOSABI_AROS 15 /* Amiga Research OS */ |
|
170 | 170 | /* these are probably obsolete: */ |
|
171 | #define ELFOSABI_ARM_AEABI 64 /* ARM EABI */ | |
|
171 | 172 | #define ELFOSABI_ARM 97 /* ARM */ |
|
172 | 173 | #define ELFOSABI_STANDALONE 255 /* standalone (embedded) application */ |
|
173 | 174 | |
|
174 | 175 | |
|
175 | 176 | /* |
|
176 | 177 | * e_type |
|
177 | 178 | */ |
|
178 | 179 | #define ET_NONE 0 |
|
179 | 180 | #define ET_REL 1 |
|
180 | 181 | #define ET_EXEC 2 |
|
181 | 182 | #define ET_DYN 3 |
|
182 | 183 | #define ET_CORE 4 |
|
183 | 184 | #define ET_NUM 5 |
|
184 | 185 | #define ET_LOOS 0xfe00 |
|
185 | 186 | #define ET_HIOS 0xfeff |
|
186 | 187 | #define ET_LOPROC 0xff00 |
|
187 | 188 | #define ET_HIPROC 0xffff |
|
188 | 189 | |
|
189 | 190 | /* |
|
190 | 191 | * e_machine |
|
191 | 192 | */ |
|
192 | 193 | #define EM_NONE 0 /* No machine */ |
|
193 | 194 | #define EM_M32 1 /* AT&T WE 32100 */ |
|
194 | 195 | #define EM_SPARC 2 /* SPARC */ |
|
195 | 196 | #define EM_386 3 /* Intel 80386 */ |
|
196 | 197 | #define EM_68K 4 /* Motorola 68000 */ |
|
197 | 198 | #define EM_88K 5 /* Motorola 88000 */ |
|
198 | 199 | #define EM_486 6 /* Intel i486 (DO NOT USE THIS ONE) */ |
|
199 | 200 | #define EM_860 7 /* Intel 80860 */ |
|
200 | 201 | #define EM_MIPS 8 /* MIPS I Architecture */ |
|
201 | 202 | #define EM_S370 9 /* IBM System/370 Processor */ |
|
202 | 203 | #define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */ |
|
203 | 204 | #define EM_SPARC64 11 /* SPARC 64-bit */ |
|
204 | 205 | #define EM_PARISC 15 /* Hewlett-Packard PA-RISC */ |
|
205 | 206 | #define EM_VPP500 17 /* Fujitsu VPP500 */ |
|
206 | 207 | #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ |
|
207 | 208 | #define EM_960 19 /* Intel 80960 */ |
|
208 | 209 | #define EM_PPC 20 /* PowerPC */ |
|
209 | 210 | #define EM_PPC64 21 /* 64-bit PowerPC */ |
|
210 | 211 | #define EM_S390 22 /* IBM System/390 Processor */ |
|
211 | 212 | #define EM_V800 36 /* NEC V800 */ |
|
212 | 213 | #define EM_FR20 37 /* Fujitsu FR20 */ |
|
213 | 214 | #define EM_RH32 38 /* TRW RH-32 */ |
|
214 | 215 | #define EM_RCE 39 /* Motorola RCE */ |
|
215 | 216 | #define EM_ARM 40 /* Advanced RISC Machines ARM */ |
|
216 | #define EM_ALPHA 41 /* Digital Alpha */ | |
|
217 | #define EM_FAKE_ALPHA 41 /* Digital Alpha */ | |
|
217 | 218 | #define EM_SH 42 /* Hitachi SH */ |
|
218 | 219 | #define EM_SPARCV9 43 /* SPARC Version 9 */ |
|
219 | 220 | #define EM_TRICORE 44 /* Siemens TriCore embedded processor */ |
|
220 | 221 | #define EM_ARC 45 /* Argonaut RISC Core, Argonaut Technologies Inc. */ |
|
221 | 222 | #define EM_H8_300 46 /* Hitachi H8/300 */ |
|
222 | 223 | #define EM_H8_300H 47 /* Hitachi H8/300H */ |
|
223 | 224 | #define EM_H8S 48 /* Hitachi H8S */ |
|
224 | 225 | #define EM_H8_500 49 /* Hitachi H8/500 */ |
|
225 | 226 | #define EM_IA_64 50 /* Intel IA-64 processor architecture */ |
|
226 | 227 | #define EM_MIPS_X 51 /* Stanford MIPS-X */ |
|
227 | 228 | #define EM_COLDFIRE 52 /* Motorola ColdFire */ |
|
228 | 229 | #define EM_68HC12 53 /* Motorola M68HC12 */ |
|
229 | 230 | #define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator */ |
|
230 | 231 | #define EM_PCP 55 /* Siemens PCP */ |
|
231 | 232 | #define EM_NCPU 56 /* Sony nCPU embedded RISC processor */ |
|
232 | 233 | #define EM_NDR1 57 /* Denso NDR1 microprocessor */ |
|
233 | 234 | #define EM_STARCORE 58 /* Motorola Star*Core processor */ |
|
234 | 235 | #define EM_ME16 59 /* Toyota ME16 processor */ |
|
235 | 236 | #define EM_ST100 60 /* STMicroelectronics ST100 processor */ |
|
236 | 237 | #define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded processor family */ |
|
237 | 238 | #define EM_X86_64 62 /* AMD x86-64 architecture */ |
|
238 | 239 | #define EM_AMD64 EM_X86_64 |
|
239 | 240 | #define EM_PDSP 63 /* Sony DSP Processor */ |
|
240 | 241 | #define EM_FX66 66 /* Siemens FX66 microcontroller */ |
|
241 | 242 | #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 bit microcontroller */ |
|
242 | 243 | #define EM_ST7 68 /* STMicroelectronics ST7 8-bit microcontroller */ |
|
243 | 244 | #define EM_68HC16 69 /* Motorola MC68HC16 Microcontroller */ |
|
244 | 245 | #define EM_68HC11 70 /* Motorola MC68HC11 Microcontroller */ |
|
245 | 246 | #define EM_68HC08 71 /* Motorola MC68HC08 Microcontroller */ |
|
246 | 247 | #define EM_68HC05 72 /* Motorola MC68HC05 Microcontroller */ |
|
247 | 248 | #define EM_SVX 73 /* Silicon Graphics SVx */ |
|
248 | 249 | #define EM_ST19 74 /* STMicroelectronics ST19 8-bit microcontroller */ |
|
249 | 250 | #define EM_VAX 75 /* Digital VAX */ |
|
250 | 251 | #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ |
|
251 | 252 | #define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */ |
|
252 | 253 | #define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ |
|
253 | 254 | #define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ |
|
254 | 255 | #define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */ |
|
255 | 256 | #define EM_HUANY 81 /* Harvard University machine-independent object files */ |
|
256 | 257 | #define EM_PRISM 82 /* SiTera Prism */ |
|
257 | 258 | #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ |
|
258 | 259 | #define EM_FR30 84 /* Fujitsu FR30 */ |
|
259 | 260 | #define EM_D10V 85 /* Mitsubishi D10V */ |
|
260 | 261 | #define EM_D30V 86 /* Mitsubishi D30V */ |
|
261 | 262 | #define EM_V850 87 /* NEC v850 */ |
|
262 | 263 | #define EM_M32R 88 /* Mitsubishi M32R */ |
|
263 | 264 | #define EM_MN10300 89 /* Matsushita MN10300 */ |
|
264 | 265 | #define EM_MN10200 90 /* Matsushita MN10200 */ |
|
265 | 266 | #define EM_PJ 91 /* picoJava */ |
|
266 | 267 | #define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ |
|
267 | 268 | #define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ |
|
268 | 269 | #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ |
|
269 | 270 | #define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor */ |
|
270 | 271 | #define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose Processor */ |
|
271 | 272 | #define EM_NS32K 97 /* National Semiconductor 32000 series */ |
|
272 | 273 | #define EM_TPC 98 /* Tenor Network TPC processor */ |
|
273 | 274 | #define EM_SNP1K 99 /* Trebia SNP 1000 processor */ |
|
274 | 275 | #define EM_ST200 100 /* STMicroelectronics (www.st.com) ST200 microcontroller */ |
|
275 | 276 | #define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family */ |
|
276 | 277 | #define EM_MAX 102 /* MAX Processor */ |
|
277 | 278 | #define EM_CR 103 /* National Semiconductor CompactRISC microprocessor */ |
|
278 | 279 | #define EM_F2MC16 104 /* Fujitsu F2MC16 */ |
|
279 | 280 | #define EM_MSP430 105 /* Texas Instruments embedded microcontroller msp430 */ |
|
280 | 281 | #define EM_BLACKFIN 106 /* Analog Devices Blackfin (DSP) processor */ |
|
281 | 282 | #define EM_SE_C33 107 /* S1C33 Family of Seiko Epson processors */ |
|
282 | 283 | #define EM_SEP 108 /* Sharp embedded microprocessor */ |
|
283 | 284 | #define EM_ARCA 109 /* Arca RISC Microprocessor */ |
|
284 | 285 | #define EM_UNICORE 110 /* Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University */ |
|
285 | #define EM_NUM 111 | |
|
286 | #define EM_AARCH64 183 /* ARM AARCH64 */ | |
|
287 | #define EM_TILEPRO 188 /* Tilera TILEPro */ | |
|
288 | #define EM_MICROBLAZE 189 /* Xilinx MicroBlaze */ | |
|
289 | #define EM_TILEGX 191 /* Tilera TILE-Gx */ | |
|
290 | #define EM_NUM 192 | |
|
291 | ||
|
286 | 292 | |
|
287 | 293 | /* |
|
288 | 294 | * e_ident[EI_VERSION], e_version |
|
289 | 295 | */ |
|
290 | 296 | #define EV_NONE 0 |
|
291 | 297 | #define EV_CURRENT 1 |
|
292 | 298 | #define EV_NUM 2 |
|
293 | 299 | |
|
294 | 300 | /* |
|
295 | 301 | * Section header |
|
296 | 302 | */ |
|
297 | 303 | typedef struct { |
|
298 | 304 | Elf32_Word sh_name; |
|
299 | 305 | Elf32_Word sh_type; |
|
300 | 306 | Elf32_Word sh_flags; |
|
301 | 307 | Elf32_Addr sh_addr; |
|
302 | 308 | Elf32_Off sh_offset; |
|
303 | 309 | Elf32_Word sh_size; |
|
304 | 310 | Elf32_Word sh_link; |
|
305 | 311 | Elf32_Word sh_info; |
|
306 | 312 | Elf32_Word sh_addralign; |
|
307 | 313 | Elf32_Word sh_entsize; |
|
308 | 314 | } Elf32_Shdr; |
|
309 | 315 | |
|
310 | 316 | #if __LIBELF64 |
|
311 | 317 | typedef struct { |
|
312 | 318 | Elf64_Word sh_name; |
|
313 | 319 | Elf64_Word sh_type; |
|
314 | 320 | Elf64_Xword sh_flags; |
|
315 | 321 | Elf64_Addr sh_addr; |
|
316 | 322 | Elf64_Off sh_offset; |
|
317 | 323 | Elf64_Xword sh_size; |
|
318 | 324 | Elf64_Word sh_link; |
|
319 | 325 | Elf64_Word sh_info; |
|
320 | 326 | Elf64_Xword sh_addralign; |
|
321 | 327 | Elf64_Xword sh_entsize; |
|
322 | 328 | } Elf64_Shdr; |
|
323 | 329 | #endif /* __LIBELF64 */ |
|
324 | 330 | |
|
325 | 331 | /* |
|
326 | 332 | * Special section indices |
|
327 | 333 | */ |
|
328 | 334 | #define SHN_UNDEF 0 |
|
329 | 335 | #define SHN_LORESERVE 0xff00 |
|
330 | 336 | #define SHN_LOPROC 0xff00 |
|
331 | 337 | #define SHN_HIPROC 0xff1f |
|
332 | 338 | #define SHN_LOOS 0xff20 |
|
333 | 339 | #define SHN_HIOS 0xff3f |
|
334 | 340 | #define SHN_ABS 0xfff1 |
|
335 | 341 | #define SHN_COMMON 0xfff2 |
|
336 | 342 | #define SHN_XINDEX 0xffff |
|
337 | 343 | #define SHN_HIRESERVE 0xffff |
|
338 | 344 | |
|
339 | 345 | /* |
|
340 | 346 | * sh_type |
|
341 | 347 | */ |
|
342 | 348 | #define SHT_NULL 0 |
|
343 | 349 | #define SHT_PROGBITS 1 |
|
344 | 350 | #define SHT_SYMTAB 2 |
|
345 | 351 | #define SHT_STRTAB 3 |
|
346 | 352 | #define SHT_RELA 4 |
|
347 | 353 | #define SHT_HASH 5 |
|
348 | 354 | #define SHT_DYNAMIC 6 |
|
349 | 355 | #define SHT_NOTE 7 |
|
350 | 356 | #define SHT_NOBITS 8 |
|
351 | 357 | #define SHT_REL 9 |
|
352 | 358 | #define SHT_SHLIB 10 |
|
353 | 359 | #define SHT_DYNSYM 11 |
|
354 | 360 | #define SHT_INIT_ARRAY 14 |
|
355 | 361 | #define SHT_FINI_ARRAY 15 |
|
356 | 362 | #define SHT_PREINIT_ARRAY 16 |
|
357 | 363 | #define SHT_GROUP 17 |
|
358 | 364 | #define SHT_SYMTAB_SHNDX 18 |
|
359 | 365 | #define SHT_NUM 19 |
|
360 | 366 | #define SHT_LOOS 0x60000000 |
|
361 | 367 | #define SHT_HIOS 0x6fffffff |
|
362 | 368 | #define SHT_LOPROC 0x70000000 |
|
363 | 369 | #define SHT_HIPROC 0x7fffffff |
|
364 | 370 | #define SHT_LOUSER 0x80000000 |
|
365 | 371 | #define SHT_HIUSER 0xffffffff |
|
366 | 372 | |
|
367 | 373 | /* |
|
368 | 374 | * Solaris extensions |
|
369 | 375 | */ |
|
370 | 376 | #define SHT_LOSUNW 0x6ffffff4 |
|
371 | 377 | #define SHT_SUNW_dof 0x6ffffff4 |
|
372 | 378 | #define SHT_SUNW_cap 0x6ffffff5 |
|
373 | 379 | #define SHT_SUNW_SIGNATURE 0x6ffffff6 |
|
374 | 380 | #define SHT_SUNW_ANNOTATE 0x6ffffff7 |
|
375 | 381 | #define SHT_SUNW_DEBUGSTR 0x6ffffff8 |
|
376 | 382 | #define SHT_SUNW_DEBUG 0x6ffffff9 |
|
377 | 383 | #define SHT_SUNW_move 0x6ffffffa |
|
378 | 384 | #define SHT_SUNW_COMDAT 0x6ffffffb |
|
379 | 385 | #define SHT_SUNW_syminfo 0x6ffffffc |
|
380 | 386 | #define SHT_SUNW_verdef 0x6ffffffd |
|
381 | 387 | #define SHT_SUNW_verneed 0x6ffffffe |
|
382 | 388 | #define SHT_SUNW_versym 0x6fffffff |
|
383 | 389 | #define SHT_HISUNW 0x6fffffff |
|
384 | 390 | |
|
385 | 391 | #define SHT_SPARC_GOTDATA 0x70000000 |
|
386 | 392 | #define SHT_AMD64_UNWIND 0x70000001 |
|
387 | 393 | |
|
388 | 394 | /* |
|
389 | 395 | * GNU extensions |
|
390 | 396 | */ |
|
391 | 397 | #define SHT_GNU_verdef 0x6ffffffd |
|
392 | 398 | #define SHT_GNU_verneed 0x6ffffffe |
|
393 | 399 | #define SHT_GNU_versym 0x6fffffff |
|
394 | 400 | |
|
395 | 401 | /* |
|
396 | 402 | * sh_flags |
|
397 | 403 | */ |
|
398 | 404 | #define SHF_WRITE 0x1 |
|
399 | 405 | #define SHF_ALLOC 0x2 |
|
400 | 406 | #define SHF_EXECINSTR 0x4 |
|
401 | 407 | #define SHF_MERGE 0x10 |
|
402 | 408 | #define SHF_STRINGS 0x20 |
|
403 | 409 | #define SHF_INFO_LINK 0x40 |
|
404 | 410 | #define SHF_LINK_ORDER 0x80 |
|
405 | 411 | #define SHF_OS_NONCONFORMING 0x100 |
|
406 | 412 | #define SHF_GROUP 0x200 |
|
407 | 413 | #define SHF_TLS 0x400 |
|
408 | 414 | #define SHF_MASKOS 0x0ff00000 |
|
409 | 415 | #define SHF_MASKPROC 0xf0000000 |
|
410 | 416 | |
|
411 | 417 | /* |
|
412 | 418 | * Solaris extensions |
|
413 | 419 | */ |
|
414 | 420 | #define SHF_AMD64_LARGE 0x10000000 |
|
415 | 421 | #define SHF_ORDERED 0x40000000 |
|
416 | 422 | #define SHF_EXCLUDE 0x80000000 |
|
417 | 423 | |
|
418 | 424 | /* |
|
419 | 425 | * Section group flags |
|
420 | 426 | */ |
|
421 | 427 | #define GRP_COMDAT 0x1 |
|
422 | 428 | #define GRP_MASKOS 0x0ff00000 |
|
423 | 429 | #define GRP_MASKPROC 0xf0000000 |
|
424 | 430 | |
|
425 | 431 | /* |
|
426 | 432 | * Symbol table |
|
427 | 433 | */ |
|
428 | 434 | typedef struct { |
|
429 | 435 | Elf32_Word st_name; |
|
430 | 436 | Elf32_Addr st_value; |
|
431 | 437 | Elf32_Word st_size; |
|
432 | 438 | unsigned char st_info; |
|
433 | 439 | unsigned char st_other; |
|
434 | 440 | Elf32_Half st_shndx; |
|
435 | 441 | } Elf32_Sym; |
|
436 | 442 | |
|
437 | 443 | #if __LIBELF64 |
|
438 | 444 | typedef struct { |
|
439 | 445 | Elf64_Word st_name; |
|
440 | 446 | unsigned char st_info; |
|
441 | 447 | unsigned char st_other; |
|
442 | 448 | Elf64_Half st_shndx; |
|
443 | 449 | Elf64_Addr st_value; |
|
444 | 450 | Elf64_Xword st_size; |
|
445 | 451 | } Elf64_Sym; |
|
446 | 452 | #endif /* __LIBELF64 */ |
|
447 | 453 | |
|
448 | 454 | /* |
|
449 | 455 | * Special symbol indices |
|
450 | 456 | */ |
|
451 | 457 | #define STN_UNDEF 0 |
|
452 | 458 | |
|
453 | 459 | /* |
|
454 | 460 | * Macros for manipulating st_info |
|
455 | 461 | */ |
|
456 | 462 | #define ELF32_ST_BIND(i) ((i)>>4) |
|
457 | 463 | #define ELF32_ST_TYPE(i) ((i)&0xf) |
|
458 | 464 | #define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) |
|
459 | 465 | |
|
460 | 466 | #if __LIBELF64 |
|
461 | 467 | #define ELF64_ST_BIND(i) ((i)>>4) |
|
462 | 468 | #define ELF64_ST_TYPE(i) ((i)&0xf) |
|
463 | 469 | #define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) |
|
464 | 470 | #endif /* __LIBELF64 */ |
|
465 | 471 | |
|
466 | 472 | /* |
|
467 | 473 | * Symbol binding |
|
468 | 474 | */ |
|
469 | 475 | #define STB_LOCAL 0 |
|
470 | 476 | #define STB_GLOBAL 1 |
|
471 | 477 | #define STB_WEAK 2 |
|
472 | 478 | #define STB_NUM 3 |
|
473 | 479 | #define STB_LOOS 10 |
|
474 | 480 | #define STB_HIOS 12 |
|
475 | 481 | #define STB_LOPROC 13 |
|
476 | 482 | #define STB_HIPROC 15 |
|
477 | 483 | |
|
478 | 484 | /* |
|
479 | 485 | * Symbol types |
|
480 | 486 | */ |
|
481 | 487 | #define STT_NOTYPE 0 |
|
482 | 488 | #define STT_OBJECT 1 |
|
483 | 489 | #define STT_FUNC 2 |
|
484 | 490 | #define STT_SECTION 3 |
|
485 | 491 | #define STT_FILE 4 |
|
486 | 492 | #define STT_COMMON 5 |
|
487 | 493 | #define STT_TLS 6 |
|
488 | 494 | #define STT_NUM 7 |
|
489 | 495 | #define STT_LOOS 10 |
|
490 | 496 | #define STT_HIOS 12 |
|
491 | 497 | #define STT_LOPROC 13 |
|
492 | 498 | #define STT_HIPROC 15 |
|
493 | 499 | |
|
494 | 500 | /* |
|
495 | 501 | * Macros for manipulating st_other |
|
496 | 502 | */ |
|
497 | 503 | #define ELF32_ST_VISIBILITY(o) ((o)&0x3) |
|
498 | 504 | #if __LIBELF64 |
|
499 | 505 | #define ELF64_ST_VISIBILITY(o) ((o)&0x3) |
|
500 | 506 | #endif /* __LIBELF64 */ |
|
501 | 507 | |
|
502 | 508 | /* |
|
503 | 509 | * Symbol visibility |
|
504 | 510 | */ |
|
505 | 511 | #define STV_DEFAULT 0 |
|
506 | 512 | #define STV_INTERNAL 1 |
|
507 | 513 | #define STV_HIDDEN 2 |
|
508 | 514 | #define STV_PROTECTED 3 |
|
509 | 515 | |
|
510 | 516 | /* |
|
511 | 517 | * Relocation |
|
512 | 518 | */ |
|
513 | 519 | typedef struct { |
|
514 | 520 | Elf32_Addr r_offset; |
|
515 | 521 | Elf32_Word r_info; |
|
516 | 522 | } Elf32_Rel; |
|
517 | 523 | |
|
518 | 524 | typedef struct { |
|
519 | 525 | Elf32_Addr r_offset; |
|
520 | 526 | Elf32_Word r_info; |
|
521 | 527 | Elf32_Sword r_addend; |
|
522 | 528 | } Elf32_Rela; |
|
523 | 529 | |
|
524 | 530 | #if __LIBELF64 |
|
525 | 531 | typedef struct { |
|
526 | 532 | Elf64_Addr r_offset; |
|
527 | 533 | Elf64_Xword r_info; |
|
528 | 534 | } Elf64_Rel; |
|
529 | 535 | |
|
530 | 536 | typedef struct { |
|
531 | 537 | Elf64_Addr r_offset; |
|
532 | 538 | Elf64_Xword r_info; |
|
533 | 539 | Elf64_Sxword r_addend; |
|
534 | 540 | } Elf64_Rela; |
|
535 | 541 | #endif /* __LIBELF64 */ |
|
536 | 542 | |
|
537 | 543 | /* |
|
538 | 544 | * Macros for manipulating r_info |
|
539 | 545 | */ |
|
540 | 546 | #define ELF32_R_SYM(i) ((i)>>8) |
|
541 | 547 | #define ELF32_R_TYPE(i) ((unsigned char)(i)) |
|
542 | 548 | #define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t)) |
|
543 | 549 | |
|
544 | 550 | #if __LIBELF64 |
|
545 | 551 | #define ELF64_R_SYM(i) ((Elf64_Xword)(i)>>32) |
|
546 | 552 | #define ELF64_R_TYPE(i) ((i)&0xffffffffL) |
|
547 | 553 | #define ELF64_R_INFO(s,t) (((Elf64_Xword)(s)<<32)+((t)&0xffffffffL)) |
|
548 | 554 | #endif /* __LIBELF64 */ |
|
549 | 555 | |
|
550 | 556 | /* |
|
551 | 557 | * Note entry header |
|
552 | 558 | */ |
|
553 | 559 | typedef struct { |
|
554 | 560 | Elf32_Word n_namesz; /* name size */ |
|
555 | 561 | Elf32_Word n_descsz; /* descriptor size */ |
|
556 | 562 | Elf32_Word n_type; /* descriptor type */ |
|
557 | 563 | } Elf32_Nhdr; |
|
558 | 564 | |
|
559 | 565 | #if __LIBELF64 |
|
560 | 566 | /* Solaris and GNU use this layout. Be compatible. */ |
|
561 | 567 | /* XXX: Latest ELF specs say it's 64-bit!!! */ |
|
562 | 568 | typedef struct { |
|
563 | 569 | Elf64_Word n_namesz; /* name size */ |
|
564 | 570 | Elf64_Word n_descsz; /* descriptor size */ |
|
565 | 571 | Elf64_Word n_type; /* descriptor type */ |
|
566 | 572 | } Elf64_Nhdr; |
|
567 | 573 | #endif /* __LIBELF64 */ |
|
568 | 574 | |
|
569 | 575 | /* |
|
570 | 576 | * Well-known descriptor types for ET_CORE files |
|
571 | 577 | */ |
|
572 | 578 | #define NT_PRSTATUS 1 |
|
573 | 579 | #define NT_PRFPREG 2 |
|
574 | 580 | #define NT_PRPSINFO 3 |
|
575 | 581 | |
|
576 | 582 | /* |
|
577 | 583 | * Program header |
|
578 | 584 | */ |
|
579 | 585 | typedef struct { |
|
580 | 586 | Elf32_Word p_type; |
|
581 | 587 | Elf32_Off p_offset; |
|
582 | 588 | Elf32_Addr p_vaddr; |
|
583 | 589 | Elf32_Addr p_paddr; |
|
584 | 590 | Elf32_Word p_filesz; |
|
585 | 591 | Elf32_Word p_memsz; |
|
586 | 592 | Elf32_Word p_flags; |
|
587 | 593 | Elf32_Word p_align; |
|
588 | 594 | } Elf32_Phdr; |
|
589 | 595 | |
|
590 | 596 | #if __LIBELF64 |
|
591 | 597 | typedef struct { |
|
592 | 598 | Elf64_Word p_type; |
|
593 | 599 | Elf64_Word p_flags; |
|
594 | 600 | Elf64_Off p_offset; |
|
595 | 601 | Elf64_Addr p_vaddr; |
|
596 | 602 | Elf64_Addr p_paddr; |
|
597 | 603 | Elf64_Xword p_filesz; |
|
598 | 604 | Elf64_Xword p_memsz; |
|
599 | 605 | Elf64_Xword p_align; |
|
600 | 606 | } Elf64_Phdr; |
|
601 | 607 | #endif /* __LIBELF64 */ |
|
602 | 608 | |
|
603 | 609 | /* |
|
604 | 610 | * Special numbers |
|
605 | 611 | */ |
|
606 | 612 | #define PN_XNUM 0xffff |
|
607 | 613 | |
|
608 | 614 | /* |
|
609 | 615 | * p_type |
|
610 | 616 | */ |
|
611 | 617 | #define PT_NULL 0 |
|
612 | 618 | #define PT_LOAD 1 |
|
613 | 619 | #define PT_DYNAMIC 2 |
|
614 | 620 | #define PT_INTERP 3 |
|
615 | 621 | #define PT_NOTE 4 |
|
616 | 622 | #define PT_SHLIB 5 |
|
617 | 623 | #define PT_PHDR 6 |
|
618 | 624 | #define PT_TLS 7 |
|
619 | 625 | #define PT_NUM 8 |
|
620 | 626 | #define PT_LOOS 0x60000000 |
|
621 | 627 | #define PT_HIOS 0x6fffffff |
|
622 | 628 | #define PT_LOPROC 0x70000000 |
|
623 | 629 | #define PT_HIPROC 0x7fffffff |
|
624 | 630 | |
|
625 | 631 | /* |
|
626 | 632 | * Solaris extensions |
|
627 | 633 | */ |
|
628 | 634 | |
|
629 | 635 | #define PT_SUNW_UNWIND 0x6464e550 |
|
630 | 636 | #define PT_LOSUNW 0x6ffffffa |
|
631 | 637 | #define PT_SUNWBSS 0x6ffffffa |
|
632 | 638 | #define PT_SUNWSTACK 0x6ffffffb |
|
633 | 639 | #define PT_SUNWDTRACE 0x6ffffffc |
|
634 | 640 | #define PT_SUNWCAP 0x6ffffffd |
|
635 | 641 | #define PT_HISUNW 0x6fffffff |
|
636 | 642 | |
|
637 | 643 | /* |
|
638 | 644 | * p_flags |
|
639 | 645 | */ |
|
640 | 646 | #define PF_X 0x1 |
|
641 | 647 | #define PF_W 0x2 |
|
642 | 648 | #define PF_R 0x4 |
|
643 | 649 | #define PF_MASKOS 0x0ff00000 |
|
644 | 650 | #define PF_MASKPROC 0xf0000000 |
|
645 | 651 | |
|
646 | 652 | /* |
|
647 | 653 | * Dynamic structure |
|
648 | 654 | */ |
|
649 | 655 | typedef struct { |
|
650 | 656 | Elf32_Sword d_tag; |
|
651 | 657 | union { |
|
652 | 658 | Elf32_Word d_val; |
|
653 | 659 | Elf32_Addr d_ptr; |
|
654 | 660 | } d_un; |
|
655 | 661 | } Elf32_Dyn; |
|
656 | 662 | |
|
657 | 663 | #if __LIBELF64 |
|
658 | 664 | typedef struct { |
|
659 | 665 | Elf64_Sxword d_tag; |
|
660 | 666 | union { |
|
661 | 667 | Elf64_Xword d_val; |
|
662 | 668 | Elf64_Addr d_ptr; |
|
663 | 669 | } d_un; |
|
664 | 670 | } Elf64_Dyn; |
|
665 | 671 | #endif /* __LIBELF64 */ |
|
666 | 672 | |
|
667 | 673 | /* |
|
668 | 674 | * Dynamic array tags |
|
669 | 675 | */ |
|
670 | 676 | /* d_un exec shared */ |
|
671 | 677 | #define DT_NULL 0 /* ign. mand. mand. */ |
|
672 | 678 | #define DT_NEEDED 1 /* d_val opt. opt. */ |
|
673 | 679 | #define DT_PLTRELSZ 2 /* d_val opt. opt. */ |
|
674 | 680 | #define DT_PLTGOT 3 /* d_ptr opt. opt. */ |
|
675 | 681 | #define DT_HASH 4 /* d_ptr mand. mand. */ |
|
676 | 682 | #define DT_STRTAB 5 /* d_ptr mand. mand. */ |
|
677 | 683 | #define DT_SYMTAB 6 /* d_ptr mand. mand. */ |
|
678 | 684 | #define DT_RELA 7 /* d_ptr mand. opt. */ |
|
679 | 685 | #define DT_RELASZ 8 /* d_val mand. opt. */ |
|
680 | 686 | #define DT_RELAENT 9 /* d_val mand. opt. */ |
|
681 | 687 | #define DT_STRSZ 10 /* d_val mand. mand. */ |
|
682 | 688 | #define DT_SYMENT 11 /* d_val mand. mand. */ |
|
683 | 689 | #define DT_INIT 12 /* d_ptr opt. opt. */ |
|
684 | 690 | #define DT_FINI 13 /* d_ptr opt. opt. */ |
|
685 | 691 | #define DT_SONAME 14 /* d_val ign. opt. */ |
|
686 | 692 | #define DT_RPATH 15 /* d_val opt. ign. */ |
|
687 | 693 | #define DT_SYMBOLIC 16 /* ign. ign. opt. */ |
|
688 | 694 | #define DT_REL 17 /* d_ptr mand. opt. */ |
|
689 | 695 | #define DT_RELSZ 18 /* d_val mand. opt. */ |
|
690 | 696 | #define DT_RELENT 19 /* d_val mand. opt. */ |
|
691 | 697 | #define DT_PLTREL 20 /* d_val opt. opt. */ |
|
692 | 698 | #define DT_DEBUG 21 /* d_ptr opt. ign. */ |
|
693 | 699 | #define DT_TEXTREL 22 /* ign. opt. opt. */ |
|
694 | 700 | #define DT_JMPREL 23 /* d_ptr opt. opt. */ |
|
695 | 701 | #define DT_BIND_NOW 24 /* ign. opt. opt. */ |
|
696 | 702 | #define DT_INIT_ARRAY 25 /* d_ptr opt. opt. */ |
|
697 | 703 | #define DT_FINI_ARRAY 26 /* d_ptr opt. opt. */ |
|
698 | 704 | #define DT_INIT_ARRAYSZ 27 /* d_val opt. opt. */ |
|
699 | 705 | #define DT_FINI_ARRAYSZ 28 /* d_val opt. opt. */ |
|
700 | 706 | #define DT_RUNPATH 29 /* d_val opt. opt. */ |
|
701 | 707 | #define DT_FLAGS 30 /* d_val opt. opt. */ |
|
702 | 708 | #define DT_ENCODING 32 /* odd/even encoding rule starts here */ |
|
703 | 709 | #define DT_PREINIT_ARRAY 32 /* d_ptr opt. ign. */ |
|
704 | 710 | #define DT_PREINIT_ARRAYSZ 33 /* d_val opt. ign. */ |
|
705 | 711 | #define DT_NUM 34 |
|
706 | 712 | #define DT_LOOS 0x6000000D |
|
707 | 713 | #define DT_HIOS 0x6ffff000 |
|
708 | 714 | #define DT_LOPROC 0x70000000 |
|
709 | 715 | #define DT_HIPROC 0x7fffffff |
|
710 | 716 | |
|
711 | 717 | /* |
|
712 | 718 | * DT_FLAGS values |
|
713 | 719 | */ |
|
714 | 720 | #define DF_ORIGIN 0x1 |
|
715 | 721 | #define DF_SYMBOLIC 0x2 |
|
716 | 722 | #define DF_TEXTREL 0x4 |
|
717 | 723 | #define DF_BIND_NOW 0x8 |
|
718 | 724 | #define DF_STATIC_TLS 0x10 |
|
719 | 725 | |
|
720 | 726 | /* |
|
721 | 727 | * Solaris extensions |
|
722 | 728 | */ |
|
723 | 729 | #define DT_VALRNGLO 0x6ffffd00 |
|
724 | 730 | #define DT_CHECKSUM 0x6ffffdf8 |
|
725 | 731 | #define DT_PLTPADSZ 0x6ffffdf9 |
|
726 | 732 | #define DT_MOVEENT 0x6ffffdfa |
|
727 | 733 | #define DT_MOVESZ 0x6ffffdfb |
|
728 | 734 | #define DT_FEATURE_1 0x6ffffdfc |
|
729 | 735 | #define DT_POSFLAG_1 0x6ffffdfd |
|
730 | 736 | #define DT_SYMINSZ 0x6ffffdfe |
|
731 | 737 | #define DT_SYMINENT 0x6ffffdff |
|
732 | 738 | #define DT_VALRNGHI 0x6ffffdff |
|
733 | 739 | |
|
734 | 740 | #define DT_ADDRRNGLO 0x6ffffe00 |
|
735 | 741 | #define DT_CONFIG 0x6ffffefa |
|
736 | 742 | #define DT_DEPAUDIT 0x6ffffefb |
|
737 | 743 | #define DT_AUDIT 0x6ffffefc |
|
738 | 744 | #define DT_PLTPAD 0x6ffffefd |
|
739 | 745 | #define DT_MOVETAB 0x6ffffefe |
|
740 | 746 | #define DT_SYMINFO 0x6ffffeff |
|
741 | 747 | #define DT_ADDRRNGHI 0x6ffffeff |
|
742 | 748 | |
|
743 | 749 | #define DT_RELACOUNT 0x6ffffff9 |
|
744 | 750 | #define DT_RELCOUNT 0x6ffffffa |
|
745 | 751 | #define DT_FLAGS_1 0x6ffffffb |
|
746 | 752 | #define DT_VERDEF 0x6ffffffc |
|
747 | 753 | #define DT_VERDEFNUM 0x6ffffffd |
|
748 | 754 | #define DT_VERNEED 0x6ffffffe |
|
749 | 755 | #define DT_VERNEEDNUM 0x6fffffff |
|
750 | 756 | |
|
751 | 757 | #define DT_AUXILIARY 0x7ffffffd |
|
752 | 758 | #define DT_USED 0x7ffffffe |
|
753 | 759 | #define DT_FILTER 0x7fffffff |
|
754 | 760 | |
|
755 | 761 | /* |
|
756 | 762 | * GNU extensions |
|
757 | 763 | */ |
|
758 | 764 | #define DT_VERSYM 0x6ffffff0 |
|
759 | 765 | |
|
760 | 766 | /* |
|
761 | 767 | * DT_FEATURE_1 values |
|
762 | 768 | */ |
|
763 | 769 | #define DTF_1_PARINIT 0x1 |
|
764 | 770 | #define DTF_1_CONFEXP 0x2 |
|
765 | 771 | |
|
766 | 772 | /* |
|
767 | 773 | * DT_POSFLAG_1 values |
|
768 | 774 | */ |
|
769 | 775 | #define DF_P1_LAZYLOAD 0x1 |
|
770 | 776 | #define DF_P1_GROUPPERM 0x2 |
|
771 | 777 | |
|
772 | 778 | /* |
|
773 | 779 | * DT_FLAGS_1 values |
|
774 | 780 | */ |
|
775 | 781 | #define DF_1_NOW 0x00000001 |
|
776 | 782 | #define DF_1_GLOBAL 0x00000002 |
|
777 | 783 | #define DF_1_GROUP 0x00000004 |
|
778 | 784 | #define DF_1_NODELETE 0x00000008 |
|
779 | 785 | #define DF_1_LOADFLTR 0x00000010 |
|
780 | 786 | #define DF_1_INITFIRST 0x00000020 |
|
781 | 787 | #define DF_1_NOOPEN 0x00000040 |
|
782 | 788 | #define DF_1_ORIGIN 0x00000080 |
|
783 | 789 | #define DF_1_DIRECT 0x00000100 |
|
784 | 790 | #define DF_1_TRANS 0x00000200 |
|
785 | 791 | #define DF_1_INTERPOSE 0x00000400 |
|
786 | 792 | #define DF_1_NODEFLIB 0x00000800 |
|
787 | 793 | #define DF_1_NODUMP 0x00001000 |
|
788 | 794 | #define DF_1_CONFALT 0x00002000 |
|
789 | 795 | #define DF_1_ENDFILTEE 0x00004000 |
|
790 | 796 | #define DF_1_DISPRELDNE 0x00008000 |
|
791 | 797 | #define DF_1_DISPRELPND 0x00010000 |
|
792 | 798 | |
|
793 | 799 | /* |
|
794 | 800 | * Syminfo structure |
|
795 | 801 | */ |
|
796 | 802 | typedef struct { |
|
797 | 803 | Elf32_Half si_boundto; |
|
798 | 804 | Elf32_Half si_flags; |
|
799 | 805 | } Elf32_Syminfo; |
|
800 | 806 | |
|
801 | 807 | #if __LIBELF64 |
|
802 | 808 | typedef struct { |
|
803 | 809 | Elf64_Half si_boundto; |
|
804 | 810 | Elf64_Half si_flags; |
|
805 | 811 | } Elf64_Syminfo; |
|
806 | 812 | #endif /* __LIBELF64 */ |
|
807 | 813 | |
|
808 | 814 | /* |
|
809 | 815 | * Syminfo version (stored in unused first entry) |
|
810 | 816 | */ |
|
811 | 817 | #define SYMINFO_NONE 0 |
|
812 | 818 | #define SYMINFO_CURRENT 1 |
|
813 | 819 | #define SYMINFO_NUM 2 |
|
814 | 820 | |
|
815 | 821 | /* |
|
816 | 822 | * si_boundto special values |
|
817 | 823 | */ |
|
818 | 824 | #define SYMINFO_BT_LOWRESERVE 0xff00 |
|
819 | 825 | #define SYMINFO_BT_PARENT 0xfffe /* bound to parent */ |
|
820 | 826 | #define SYMINFO_BT_SELF 0xffff /* bound to self */ |
|
821 | 827 | |
|
822 | 828 | /* |
|
823 | 829 | * si_flags |
|
824 | 830 | */ |
|
825 | 831 | #define SYMINFO_FLG_DIRECT 0x01 /* bound to an object */ |
|
826 | 832 | #define SYMINFO_FLG_PASSTHRU 0x02 /* pass-thru symbol */ |
|
827 | 833 | #define SYMINFO_FLG_COPY 0x04 /* result of a copy relocation */ |
|
828 | 834 | #define SYMINFO_FLG_LAZYLOAD 0x08 /* bound to lazy-loaded object */ |
|
829 | 835 | |
|
830 | 836 | /* |
|
831 | 837 | * Version definitions |
|
832 | 838 | */ |
|
833 | 839 | typedef struct { |
|
834 | 840 | Elf32_Half vd_version; |
|
835 | 841 | Elf32_Half vd_flags; |
|
836 | 842 | Elf32_Half vd_ndx; |
|
837 | 843 | Elf32_Half vd_cnt; |
|
838 | 844 | Elf32_Word vd_hash; |
|
839 | 845 | Elf32_Word vd_aux; |
|
840 | 846 | Elf32_Word vd_next; |
|
841 | 847 | } Elf32_Verdef; |
|
842 | 848 | |
|
843 | 849 | typedef struct { |
|
844 | 850 | Elf32_Word vda_name; |
|
845 | 851 | Elf32_Word vda_next; |
|
846 | 852 | } Elf32_Verdaux; |
|
847 | 853 | |
|
848 | 854 | typedef struct { |
|
849 | 855 | Elf32_Half vn_version; |
|
850 | 856 | Elf32_Half vn_cnt; |
|
851 | 857 | Elf32_Word vn_file; |
|
852 | 858 | Elf32_Word vn_aux; |
|
853 | 859 | Elf32_Word vn_next; |
|
854 | 860 | } Elf32_Verneed; |
|
855 | 861 | |
|
856 | 862 | typedef struct { |
|
857 | 863 | Elf32_Word vna_hash; |
|
858 | 864 | Elf32_Half vna_flags; |
|
859 | 865 | Elf32_Half vna_other; |
|
860 | 866 | Elf32_Word vna_name; |
|
861 | 867 | Elf32_Word vna_next; |
|
862 | 868 | } Elf32_Vernaux; |
|
863 | 869 | |
|
864 | 870 | typedef Elf32_Half Elf32_Versym; |
|
865 | 871 | |
|
866 | 872 | #if __LIBELF64 |
|
867 | 873 | |
|
868 | 874 | typedef struct { |
|
869 | 875 | Elf64_Half vd_version; |
|
870 | 876 | Elf64_Half vd_flags; |
|
871 | 877 | Elf64_Half vd_ndx; |
|
872 | 878 | Elf64_Half vd_cnt; |
|
873 | 879 | Elf64_Word vd_hash; |
|
874 | 880 | Elf64_Word vd_aux; |
|
875 | 881 | Elf64_Word vd_next; |
|
876 | 882 | } Elf64_Verdef; |
|
877 | 883 | |
|
878 | 884 | typedef struct { |
|
879 | 885 | Elf64_Word vda_name; |
|
880 | 886 | Elf64_Word vda_next; |
|
881 | 887 | } Elf64_Verdaux; |
|
882 | 888 | |
|
883 | 889 | typedef struct { |
|
884 | 890 | Elf64_Half vn_version; |
|
885 | 891 | Elf64_Half vn_cnt; |
|
886 | 892 | Elf64_Word vn_file; |
|
887 | 893 | Elf64_Word vn_aux; |
|
888 | 894 | Elf64_Word vn_next; |
|
889 | 895 | } Elf64_Verneed; |
|
890 | 896 | |
|
891 | 897 | typedef struct { |
|
892 | 898 | Elf64_Word vna_hash; |
|
893 | 899 | Elf64_Half vna_flags; |
|
894 | 900 | Elf64_Half vna_other; |
|
895 | 901 | Elf64_Word vna_name; |
|
896 | 902 | Elf64_Word vna_next; |
|
897 | 903 | } Elf64_Vernaux; |
|
898 | 904 | |
|
899 | 905 | typedef Elf64_Half Elf64_Versym; |
|
900 | 906 | |
|
901 | 907 | #endif /* __LIBELF64 */ |
|
902 | 908 | |
|
903 | 909 | /* |
|
904 | 910 | * vd_version |
|
905 | 911 | */ |
|
906 | 912 | #define VER_DEF_NONE 0 |
|
907 | 913 | #define VER_DEF_CURRENT 1 |
|
908 | 914 | #define VER_DEF_NUM 2 |
|
909 | 915 | |
|
910 | 916 | /* |
|
911 | 917 | * vn_version |
|
912 | 918 | */ |
|
913 | 919 | #define VER_NEED_NONE 0 |
|
914 | 920 | #define VER_NEED_CURRENT 1 |
|
915 | 921 | #define VER_NEED_NUM 2 |
|
916 | 922 | |
|
917 | 923 | /* |
|
918 | 924 | * vd_flags / vna_flags |
|
919 | 925 | */ |
|
920 | 926 | #define VER_FLG_BASE 0x1 /* vd_flags only */ |
|
921 | 927 | #define VER_FLG_WEAK 0x2 |
|
922 | 928 | |
|
923 | 929 | /* |
|
924 | 930 | * Elf*_Versym special values |
|
925 | 931 | */ |
|
926 | 932 | #define VER_NDX_LOCAL 0 |
|
927 | 933 | #define VER_NDX_GLOBAL 1 |
|
928 | 934 | |
|
929 | 935 | /* |
|
930 | 936 | * Solaris extensions |
|
931 | 937 | */ |
|
932 | 938 | |
|
933 | 939 | /* |
|
934 | 940 | * Move section |
|
935 | 941 | */ |
|
936 | 942 | #if __LIBELF64 |
|
937 | 943 | |
|
938 | 944 | typedef struct { |
|
939 | 945 | Elf32_Lword m_value; |
|
940 | 946 | Elf32_Word m_info; |
|
941 | 947 | Elf32_Word m_poffset; |
|
942 | 948 | Elf32_Half m_repeat; |
|
943 | 949 | Elf32_Half m_stride; |
|
944 | 950 | } Elf32_Move; |
|
945 | 951 | |
|
946 | 952 | typedef struct { |
|
947 | 953 | Elf64_Lword m_value; |
|
948 | 954 | Elf64_Xword m_info; |
|
949 | 955 | Elf64_Xword m_poffset; |
|
950 | 956 | Elf64_Half m_repeat; |
|
951 | 957 | Elf64_Half m_stride; |
|
952 | 958 | } Elf64_Move; |
|
953 | 959 | |
|
954 | 960 | #define ELF32_M_SYM(info) ((info)>>8) |
|
955 | 961 | #define ELF32_M_SIZE(info) ((unsigned char)(info)) |
|
956 | 962 | #define ELF32_M_INFO(sym, sz) (((sym)<<8)+(unsigned char)(sz)) |
|
957 | 963 | |
|
958 | 964 | #define ELF64_M_SYM(info) ((Elf64_Xword)(info)>>8) |
|
959 | 965 | #define ELF64_M_SIZE(info) ((unsigned char)(info)) |
|
960 | 966 | #define ELF64_M_INFO(sym, sz) (((Elf64_Xword)(sym)<<8)+(unsigned char)(sz)) |
|
961 | 967 | |
|
962 | 968 | #endif /* __LIBELF64 */ |
|
963 | 969 | |
|
964 | 970 | /* |
|
965 | 971 | * Capabilities |
|
966 | 972 | */ |
|
967 | 973 | |
|
968 | 974 | typedef struct { |
|
969 | 975 | Elf32_Word c_tag; |
|
970 | 976 | union { |
|
971 | 977 | Elf32_Word c_val; |
|
972 | 978 | Elf32_Addr c_ptr; |
|
973 | 979 | } c_un; |
|
974 | 980 | } Elf32_Cap; |
|
975 | 981 | |
|
976 | 982 | #if __LIBELF64 |
|
977 | 983 | |
|
978 | 984 | typedef struct { |
|
979 | 985 | Elf64_Xword c_tag; |
|
980 | 986 | union { |
|
981 | 987 | Elf64_Xword c_val; |
|
982 | 988 | Elf64_Addr c_ptr; |
|
983 | 989 | } c_un; |
|
984 | 990 | } Elf64_Cap; |
|
985 | 991 | |
|
986 | 992 | #endif /* __LIBELF64 */ |
|
987 | 993 | |
|
988 | 994 | #define CA_SUNW_NULL 0 /* c_un ignored */ |
|
989 | 995 | #define CA_SUNW_HW_1 1 /* c_un.c_val */ |
|
990 | 996 | #define CA_SUNW_SF_1 2 /* c_un.c_val */ |
|
991 | 997 | |
|
992 | 998 | #ifdef __cplusplus |
|
993 | 999 | } |
|
994 | 1000 | #endif /* __cplusplus */ |
|
995 | 1001 | |
|
996 | 1002 | #endif /* _ELF_REPL_H */ |
General Comments 0
You need to be logged in to leave comments.
Login now