##// END OF EJS Templates
Sync
Jeandet Alexis -
r38:054d8aafe982 default
parent child
Show More
@@ -1,769 +1,769
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "elfparser.h"
22 #include "elfparser.h"
23 #include <sys/types.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
25 #include <fcntl.h>
26 #include <unistd.h>
26 #include <unistd.h>
27
27
28 QString elfresolveMachine(Elf64_Half e_machine)
28 QString elfresolveMachine(Elf64_Half e_machine)
29 {
29 {
30 QString machineName;
30 QString machineName;
31 //Update from with bash script don't write it by yourself!
31 //Update from with bash script don't write it by yourself!
32 switch(e_machine)
32 switch(e_machine)
33 {
33 {
34 case EM_NONE:
34 case EM_NONE:
35 machineName = " No machine ";
35 machineName = " No machine ";
36 break;
36 break;
37 case EM_M32:
37 case EM_M32:
38 machineName = " AT&T WE 32100 ";
38 machineName = " AT&T WE 32100 ";
39 break;
39 break;
40 case EM_SPARC:
40 case EM_SPARC:
41 machineName = " SUN SPARC ";
41 machineName = " SUN SPARC ";
42 break;
42 break;
43 case EM_386:
43 case EM_386:
44 machineName = " Intel 80386 ";
44 machineName = " Intel 80386 ";
45 break;
45 break;
46 case EM_68K:
46 case EM_68K:
47 machineName = " Motorola m68k family ";
47 machineName = " Motorola m68k family ";
48 break;
48 break;
49 case EM_88K:
49 case EM_88K:
50 machineName = " Motorola m88k family ";
50 machineName = " Motorola m88k family ";
51 break;
51 break;
52 case EM_860:
52 case EM_860:
53 machineName = " Intel 80860 ";
53 machineName = " Intel 80860 ";
54 break;
54 break;
55 case EM_MIPS:
55 case EM_MIPS:
56 machineName = " MIPS R3000 big-endian ";
56 machineName = " MIPS R3000 big-endian ";
57 break;
57 break;
58 case EM_S370:
58 case EM_S370:
59 machineName = " IBM System/370 ";
59 machineName = " IBM System/370 ";
60 break;
60 break;
61 case EM_MIPS_RS3_LE:
61 case EM_MIPS_RS3_LE:
62 machineName = " MIPS R3000 little-endian ";
62 machineName = " MIPS R3000 little-endian ";
63 break;
63 break;
64 case EM_PARISC:
64 case EM_PARISC:
65 machineName = " HPPA ";
65 machineName = " HPPA ";
66 break;
66 break;
67 case EM_VPP500:
67 case EM_VPP500:
68 machineName = " Fujitsu VPP500 ";
68 machineName = " Fujitsu VPP500 ";
69 break;
69 break;
70 case EM_SPARC32PLUS:
70 case EM_SPARC32PLUS:
71 machineName = " Sun's \"v8plus\" ";
71 machineName = " Sun's \"v8plus\" ";
72 break;
72 break;
73 case EM_960:
73 case EM_960:
74 machineName = " Intel 80960 ";
74 machineName = " Intel 80960 ";
75 break;
75 break;
76 case EM_PPC:
76 case EM_PPC:
77 machineName = " PowerPC ";
77 machineName = " PowerPC ";
78 break;
78 break;
79 case EM_PPC64:
79 case EM_PPC64:
80 machineName = " PowerPC 64-bit ";
80 machineName = " PowerPC 64-bit ";
81 break;
81 break;
82 case EM_S390:
82 case EM_S390:
83 machineName = " IBM S390 ";
83 machineName = " IBM S390 ";
84 break;
84 break;
85 case EM_V800:
85 case EM_V800:
86 machineName = " NEC V800 series ";
86 machineName = " NEC V800 series ";
87 break;
87 break;
88 case EM_FR20:
88 case EM_FR20:
89 machineName = " Fujitsu FR20 ";
89 machineName = " Fujitsu FR20 ";
90 break;
90 break;
91 case EM_RH32:
91 case EM_RH32:
92 machineName = " TRW RH-32 ";
92 machineName = " TRW RH-32 ";
93 break;
93 break;
94 case EM_RCE:
94 case EM_RCE:
95 machineName = " Motorola RCE ";
95 machineName = " Motorola RCE ";
96 break;
96 break;
97 case EM_ARM:
97 case EM_ARM:
98 machineName = " ARM ";
98 machineName = " ARM ";
99 break;
99 break;
100 case EM_FAKE_ALPHA:
100 case EM_FAKE_ALPHA:
101 machineName = " Digital Alpha ";
101 machineName = " Digital Alpha ";
102 break;
102 break;
103 case EM_SH:
103 case EM_SH:
104 machineName = " Hitachi SH ";
104 machineName = " Hitachi SH ";
105 break;
105 break;
106 case EM_SPARCV9:
106 case EM_SPARCV9:
107 machineName = " SPARC v9 64-bit ";
107 machineName = " SPARC v9 64-bit ";
108 break;
108 break;
109 case EM_TRICORE:
109 case EM_TRICORE:
110 machineName = " Siemens Tricore ";
110 machineName = " Siemens Tricore ";
111 break;
111 break;
112 case EM_ARC:
112 case EM_ARC:
113 machineName = " Argonaut RISC Core ";
113 machineName = " Argonaut RISC Core ";
114 break;
114 break;
115 case EM_H8_300:
115 case EM_H8_300:
116 machineName = " Hitachi H8/300 ";
116 machineName = " Hitachi H8/300 ";
117 break;
117 break;
118 case EM_H8_300H:
118 case EM_H8_300H:
119 machineName = " Hitachi H8/300H ";
119 machineName = " Hitachi H8/300H ";
120 break;
120 break;
121 case EM_H8S:
121 case EM_H8S:
122 machineName = " Hitachi H8S ";
122 machineName = " Hitachi H8S ";
123 break;
123 break;
124 case EM_H8_500:
124 case EM_H8_500:
125 machineName = " Hitachi H8/500 ";
125 machineName = " Hitachi H8/500 ";
126 break;
126 break;
127 case EM_IA_64:
127 case EM_IA_64:
128 machineName = " Intel Merced ";
128 machineName = " Intel Merced ";
129 break;
129 break;
130 case EM_MIPS_X:
130 case EM_MIPS_X:
131 machineName = " Stanford MIPS-X ";
131 machineName = " Stanford MIPS-X ";
132 break;
132 break;
133 case EM_COLDFIRE:
133 case EM_COLDFIRE:
134 machineName = " Motorola Coldfire ";
134 machineName = " Motorola Coldfire ";
135 break;
135 break;
136 case EM_68HC12:
136 case EM_68HC12:
137 machineName = " Motorola M68HC12 ";
137 machineName = " Motorola M68HC12 ";
138 break;
138 break;
139 case EM_MMA:
139 case EM_MMA:
140 machineName = " Fujitsu MMA Multimedia Accelerator";
140 machineName = " Fujitsu MMA Multimedia Accelerator";
141 break;
141 break;
142 case EM_PCP:
142 case EM_PCP:
143 machineName = " Siemens PCP ";
143 machineName = " Siemens PCP ";
144 break;
144 break;
145 case EM_NCPU:
145 case EM_NCPU:
146 machineName = " Sony nCPU embeeded RISC ";
146 machineName = " Sony nCPU embeeded RISC ";
147 break;
147 break;
148 case EM_NDR1:
148 case EM_NDR1:
149 machineName = " Denso NDR1 microprocessor ";
149 machineName = " Denso NDR1 microprocessor ";
150 break;
150 break;
151 case EM_STARCORE:
151 case EM_STARCORE:
152 machineName = " Motorola Start*Core processor ";
152 machineName = " Motorola Start*Core processor ";
153 break;
153 break;
154 case EM_ME16:
154 case EM_ME16:
155 machineName = " Toyota ME16 processor ";
155 machineName = " Toyota ME16 processor ";
156 break;
156 break;
157 case EM_ST100:
157 case EM_ST100:
158 machineName = " STMicroelectronic ST100 processor ";
158 machineName = " STMicroelectronic ST100 processor ";
159 break;
159 break;
160 case EM_TINYJ:
160 case EM_TINYJ:
161 machineName = " Advanced Logic Corp. Tinyj emb.fam";
161 machineName = " Advanced Logic Corp. Tinyj emb.fam";
162 break;
162 break;
163 case EM_X86_64:
163 case EM_X86_64:
164 machineName = " AMD x86-64 architecture ";
164 machineName = " AMD x86-64 architecture ";
165 break;
165 break;
166 case EM_PDSP:
166 case EM_PDSP:
167 machineName = " Sony DSP Processor ";
167 machineName = " Sony DSP Processor ";
168 break;
168 break;
169 case EM_FX66:
169 case EM_FX66:
170 machineName = " Siemens FX66 microcontroller ";
170 machineName = " Siemens FX66 microcontroller ";
171 break;
171 break;
172 case EM_ST9PLUS:
172 case EM_ST9PLUS:
173 machineName = " STMicroelectronics ST9+ 8/16 mc ";
173 machineName = " STMicroelectronics ST9+ 8/16 mc ";
174 break;
174 break;
175 case EM_ST7:
175 case EM_ST7:
176 machineName = " STmicroelectronics ST7 8 bit mc ";
176 machineName = " STmicroelectronics ST7 8 bit mc ";
177 break;
177 break;
178 case EM_68HC16:
178 case EM_68HC16:
179 machineName = " Motorola MC68HC16 microcontroller ";
179 machineName = " Motorola MC68HC16 microcontroller ";
180 break;
180 break;
181 case EM_68HC11:
181 case EM_68HC11:
182 machineName = " Motorola MC68HC11 microcontroller ";
182 machineName = " Motorola MC68HC11 microcontroller ";
183 break;
183 break;
184 case EM_68HC08:
184 case EM_68HC08:
185 machineName = " Motorola MC68HC08 microcontroller ";
185 machineName = " Motorola MC68HC08 microcontroller ";
186 break;
186 break;
187 case EM_68HC05:
187 case EM_68HC05:
188 machineName = " Motorola MC68HC05 microcontroller ";
188 machineName = " Motorola MC68HC05 microcontroller ";
189 break;
189 break;
190 case EM_SVX:
190 case EM_SVX:
191 machineName = " Silicon Graphics SVx ";
191 machineName = " Silicon Graphics SVx ";
192 break;
192 break;
193 case EM_ST19:
193 case EM_ST19:
194 machineName = " STMicroelectronics ST19 8 bit mc ";
194 machineName = " STMicroelectronics ST19 8 bit mc ";
195 break;
195 break;
196 case EM_VAX:
196 case EM_VAX:
197 machineName = " Digital VAX ";
197 machineName = " Digital VAX ";
198 break;
198 break;
199 case EM_CRIS:
199 case EM_CRIS:
200 machineName = " Axis Communications 32-bit embedded processor ";
200 machineName = " Axis Communications 32-bit embedded processor ";
201 break;
201 break;
202 case EM_JAVELIN:
202 case EM_JAVELIN:
203 machineName = " Infineon Technologies 32-bit embedded processor ";
203 machineName = " Infineon Technologies 32-bit embedded processor ";
204 break;
204 break;
205 case EM_FIREPATH:
205 case EM_FIREPATH:
206 machineName = " Element 14 64-bit DSP Processor ";
206 machineName = " Element 14 64-bit DSP Processor ";
207 break;
207 break;
208 case EM_ZSP:
208 case EM_ZSP:
209 machineName = " LSI Logic 16-bit DSP Processor ";
209 machineName = " LSI Logic 16-bit DSP Processor ";
210 break;
210 break;
211 case EM_MMIX:
211 case EM_MMIX:
212 machineName = " Donald Knuth's educational 64-bit processor ";
212 machineName = " Donald Knuth's educational 64-bit processor ";
213 break;
213 break;
214 case EM_HUANY:
214 case EM_HUANY:
215 machineName = " Harvard University machine-independent object files ";
215 machineName = " Harvard University machine-independent object files ";
216 break;
216 break;
217 case EM_PRISM:
217 case EM_PRISM:
218 machineName = " SiTera Prism ";
218 machineName = " SiTera Prism ";
219 break;
219 break;
220 case EM_AVR:
220 case EM_AVR:
221 machineName = " Atmel AVR 8-bit microcontroller ";
221 machineName = " Atmel AVR 8-bit microcontroller ";
222 break;
222 break;
223 case EM_FR30:
223 case EM_FR30:
224 machineName = " Fujitsu FR30 ";
224 machineName = " Fujitsu FR30 ";
225 break;
225 break;
226 case EM_D10V:
226 case EM_D10V:
227 machineName = " Mitsubishi D10V ";
227 machineName = " Mitsubishi D10V ";
228 break;
228 break;
229 case EM_D30V:
229 case EM_D30V:
230 machineName = " Mitsubishi D30V ";
230 machineName = " Mitsubishi D30V ";
231 break;
231 break;
232 case EM_V850:
232 case EM_V850:
233 machineName = " NEC v850 ";
233 machineName = " NEC v850 ";
234 break;
234 break;
235 case EM_M32R:
235 case EM_M32R:
236 machineName = " Mitsubishi M32R ";
236 machineName = " Mitsubishi M32R ";
237 break;
237 break;
238 case EM_MN10300:
238 case EM_MN10300:
239 machineName = " Matsushita MN10300 ";
239 machineName = " Matsushita MN10300 ";
240 break;
240 break;
241 case EM_MN10200:
241 case EM_MN10200:
242 machineName = " Matsushita MN10200 ";
242 machineName = " Matsushita MN10200 ";
243 break;
243 break;
244 case EM_PJ:
244 case EM_PJ:
245 machineName = " picoJava ";
245 machineName = " picoJava ";
246 break;
246 break;
247 case EM_OPENRISC:
247 case EM_OPENRISC:
248 machineName = " OpenRISC 32-bit embedded processor ";
248 machineName = " OpenRISC 32-bit embedded processor ";
249 break;
249 break;
250 case EM_ARC_A5:
250 case EM_ARC_A5:
251 machineName = " ARC Cores Tangent-A5 ";
251 machineName = " ARC Cores Tangent-A5 ";
252 break;
252 break;
253 case EM_XTENSA:
253 case EM_XTENSA:
254 machineName = " Tensilica Xtensa Architecture ";
254 machineName = " Tensilica Xtensa Architecture ";
255 break;
255 break;
256 case EM_AARCH64:
256 case EM_AARCH64:
257 machineName = " ARM AARCH64 ";
257 machineName = " ARM AARCH64 ";
258 break;
258 break;
259 case EM_TILEPRO:
259 case EM_TILEPRO:
260 machineName = " Tilera TILEPro ";
260 machineName = " Tilera TILEPro ";
261 break;
261 break;
262 case EM_MICROBLAZE:
262 case EM_MICROBLAZE:
263 machineName = " Xilinx MicroBlaze ";
263 machineName = " Xilinx MicroBlaze ";
264 break;
264 break;
265 case EM_TILEGX:
265 case EM_TILEGX:
266 machineName = " Tilera TILE-Gx ";
266 machineName = " Tilera TILE-Gx ";
267 break;
267 break;
268 case EM_NUM:
268 case EM_NUM:
269 machineName = "";
269 machineName = "";
270 break;
270 break;
271 default:
271 default:
272 machineName ="Unknow Machine";
272 machineName ="Unknow Machine";
273 break;
273 break;
274 }
274 }
275 return machineName;
275 return machineName;
276 }
276 }
277
277
278
278
279 elfparser::elfparser()
279 elfparser::elfparser()
280 {
280 {
281 this->opened = false;
281 this->opened = false;
282 this->type_elf = false;
282 this->type_elf = false;
283 this->elfFile = NULL;
283 this->elfFile = NULL;
284 this->e = NULL;
284 this->e = NULL;
285 }
285 }
286
286
287
287
288 int elfparser::setFilename(const QString &name)
288 int elfparser::setFilename(const QString &name)
289 {
289 {
290 this->closeFile();
290 this->closeFile();
291 if(elf_version(EV_CURRENT)==EV_NONE)return 0;
291 if(elf_version(EV_CURRENT)==EV_NONE)return 0;
292 #ifdef _ELF_WINDOWS_
292 #ifdef _ELF_WINDOWS_
293 this->elfFile = open(name.toStdString().c_str(),O_RDONLY|O_BINARY ,0);
293 this->elfFile = open(name.toStdString().c_str(),O_RDONLY|O_BINARY ,0);
294 #else
294 #else
295 this->elfFile = open(name.toStdString().c_str(),O_RDONLY ,0);
295 this->elfFile = open(name.toStdString().c_str(),O_RDONLY ,0);
296 #endif
296 #endif
297 if(this->elfFile==NULL)return 0;
297 if(this->elfFile==NULL)return 0;
298 this->e = elf_begin(this->elfFile,ELF_C_READ,NULL);
298 this->e = elf_begin(this->elfFile,ELF_C_READ,NULL);
299 if(this->e==NULL)return 0;
299 if(this->e==NULL)return 0;
300 this->ek = elf_kind(this->e);
300 this->ek = elf_kind(this->e);
301 gelf_getehdr (this->e, &this->ehdr );
301 gelf_getehdr (this->e, &this->ehdr );
302 elf_getshdrstrndx (this->e, &this->shstrndx);
302 elf_getshdrstrndx (this->e, &this->shstrndx);
303 this->updateSegments();
303 this->updateSegments();
304 this->updateSections();
304 this->updateSections();
305 return 1;
305 return 1;
306 }
306 }
307
307
308
308
309 int elfparser::closeFile()
309 int elfparser::closeFile()
310 {
310 {
311 if(this->elfFile!=NULL)
311 if(this->elfFile!=NULL)
312 {
312 {
313 if(this->e!=NULL)
313 if(this->e!=NULL)
314 {
314 {
315 elf_end(this->e);
315 elf_end(this->e);
316 this->e = NULL;
316 this->e = NULL;
317 }
317 }
318 close(this->elfFile);
318 close(this->elfFile);
319 this->elfFile = NULL;
319 this->elfFile = NULL;
320 }
320 }
321 return 0;
321 return 0;
322 }
322 }
323
323
324 QString elfparser::getClass()
324 QString elfparser::getClass()
325 {
325 {
326 if(this->e!=NULL)
326 if(this->e!=NULL)
327 {
327 {
328 int eclass = gelf_getclass(this->e);
328 int eclass = gelf_getclass(this->e);
329 if(eclass==ELFCLASS32)return "ELF32";
329 if(eclass==ELFCLASS32)return "ELF32";
330 if(eclass==ELFCLASS64)return "ELF64";
330 if(eclass==ELFCLASS64)return "ELF64";
331 }
331 }
332 return "none";
332 return "none";
333 }
333 }
334
334
335
335
336 bool elfparser::isopened()
336 bool elfparser::isopened()
337 {
337 {
338 return this->opened;
338 return this->opened;
339 }
339 }
340
340
341
341
342 bool elfparser::iself()
342 bool elfparser::iself()
343 {
343 {
344 return this->type_elf;
344 return this->type_elf;
345 }
345 }
346
346
347
347
348 QString elfparser::getArchitecture()
348 QString elfparser::getArchitecture()
349 {
349 {
350 if(this->e!=NULL)
350 if(this->e!=NULL)
351 {
351 {
352 return elfresolveMachine(this->ehdr.e_machine);
352 return elfresolveMachine(this->ehdr.e_machine);
353 }
353 }
354 return "";
354 return "";
355 }
355 }
356
356
357
357
358 QString elfparser::getType()
358 QString elfparser::getType()
359 {
359 {
360 QString kind("");
360 QString kind("");
361 if(this->e!=NULL)
361 if(this->e!=NULL)
362 {
362 {
363 switch(this->ek)
363 switch(this->ek)
364 {
364 {
365 case ELF_K_AR:
365 case ELF_K_AR:
366 kind = "Archive";
366 kind = "Archive";
367 break;
367 break;
368 case ELF_K_ELF:
368 case ELF_K_ELF:
369 kind = "Elf";
369 kind = "Elf";
370 break;
370 break;
371 case ELF_K_COFF:
371 case ELF_K_COFF:
372 kind = "COFF";
372 kind = "COFF";
373 break;
373 break;
374 case ELF_K_NUM:
374 case ELF_K_NUM:
375 kind = "NUM";
375 kind = "NUM";
376 break;
376 break;
377 case ELF_K_NONE:
377 case ELF_K_NONE:
378 kind = "Data";
378 kind = "Data";
379 break;
379 break;
380 default:
380 default:
381 kind = "Unknow";
381 kind = "Unknow";
382 break;
382 break;
383 }
383 }
384 }
384 }
385 return kind;
385 return kind;
386 }
386 }
387
387
388 QString elfparser::getEndianness()
388 QString elfparser::getEndianness()
389 {
389 {
390 if(this->e!=NULL)
390 if(this->e!=NULL)
391 {
391 {
392 if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return "2's complement, little endian";
392 if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return "2's complement, little endian";
393 if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return "2's complement, big endian";
393 if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return "2's complement, big endian";
394 }
394 }
395 return "none";
395 return "none";
396 }
396 }
397
397
398 QString elfparser::getABI()
398 QString elfparser::getABI()
399 {
399 {
400 if(this->e!=NULL)
400 if(this->e!=NULL)
401 {
401 {
402 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NONE)return "UNIX System V ABI";
402 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NONE)return "UNIX System V ABI";
403 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SYSV)return "Alias";
403 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SYSV)return "Alias";
404 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_HPUX)return "HP-UX";
404 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_HPUX)return "HP-UX";
405 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NETBSD)return "NetBSD";
405 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NETBSD)return "NetBSD";
406 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_GNU)return "Object uses GNU ELF extensions";
406 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_GNU)return "Object uses GNU ELF extensions";
407 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_LINUX)return "Compatibility alias";
407 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_LINUX)return "Compatibility alias";
408 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SOLARIS)return "Sun Solaris";
408 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SOLARIS)return "Sun Solaris";
409 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_AIX)return "IBM AIX";
409 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_AIX)return "IBM AIX";
410 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_IRIX)return "SGI Irix";
410 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_IRIX)return "SGI Irix";
411 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_FREEBSD)return "FreeBSD";
411 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_FREEBSD)return "FreeBSD";
412 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_TRU64)return "Compaq TRU64 UNIX";
412 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_TRU64)return "Compaq TRU64 UNIX";
413 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_MODESTO)return " Novell Modesto";
413 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_MODESTO)return " Novell Modesto";
414 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_OPENBSD)return "OpenBSD";
414 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_OPENBSD)return "OpenBSD";
415 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM_AEABI)return "ARM EABI";
415 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM_AEABI)return "ARM EABI";
416 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM)return "ARM";
416 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM)return "ARM";
417 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_STANDALONE)return "Standalone (embedded) application";
417 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_STANDALONE)return "Standalone (embedded) application";
418 }
418 }
419 return "none";
419 return "none";
420 }
420 }
421
421
422
422
423 int32_t elfparser::getVersion()
423 qint32 elfparser::getVersion()
424 {
424 {
425 if(this->e!=NULL)
425 if(this->e!=NULL)
426 {
426 {
427 return this->ehdr.e_version;
427 return this->ehdr.e_version;
428 }
428 }
429 }
429 }
430
430
431 int64_t elfparser::getEntryPointAddress()
431 qint64 elfparser::getEntryPointAddress()
432 {
432 {
433 if(this->e!=NULL)
433 if(this->e!=NULL)
434 {
434 {
435 return this->ehdr.e_entry;
435 return this->ehdr.e_entry;
436 }
436 }
437 }
437 }
438
438
439
439
440 int elfparser::getSectioncount()
440 int elfparser::getSectioncount()
441 {
441 {
442 return (int)this->SectionCount;
442 return (int)this->SectionCount;
443 }
443 }
444
444
445
445
446 int elfparser::getSegmentcount()
446 int elfparser::getSegmentcount()
447 {
447 {
448 return (int)this->SegmentCount;
448 return (int)this->SegmentCount;
449 }
449 }
450
450
451
451
452 QString elfparser::getSegmentType(int index)
452 QString elfparser::getSegmentType(int index)
453 {
453 {
454 QString type("");
454 QString type("");
455 if(this->e!=NULL)
455 if(this->e!=NULL)
456 {
456 {
457 if(index < this->Segments.count())
457 if(index < this->Segments.count())
458 {
458 {
459 switch(this->Segments.at(index)->p_type)
459 switch(this->Segments.at(index)->p_type)
460 {
460 {
461 case PT_NULL:
461 case PT_NULL:
462 type = "Program header table entry unused";
462 type = "Program header table entry unused";
463 break;
463 break;
464 case PT_LOAD:
464 case PT_LOAD:
465 type = "Loadable program segment";
465 type = "Loadable program segment";
466 break;
466 break;
467 case PT_DYNAMIC :
467 case PT_DYNAMIC :
468 type = "Dynamic linking information";
468 type = "Dynamic linking information";
469 break;
469 break;
470 case PT_INTERP:
470 case PT_INTERP:
471 type ="Program interpreter";
471 type ="Program interpreter";
472 break;
472 break;
473 case PT_NOTE:
473 case PT_NOTE:
474 type = "Auxiliary information";
474 type = "Auxiliary information";
475 break;
475 break;
476 case PT_SHLIB:
476 case PT_SHLIB:
477 type = "Reserved";
477 type = "Reserved";
478 break;
478 break;
479 case PT_PHDR:
479 case PT_PHDR:
480 type = "Entry for header table itself";
480 type = "Entry for header table itself";
481 break;
481 break;
482 case PT_TLS:
482 case PT_TLS:
483 type = "Thread-local storage segment";
483 type = "Thread-local storage segment";
484 break;
484 break;
485 case PT_NUM:
485 case PT_NUM:
486 type = "Number of defined types";
486 type = "Number of defined types";
487 break;
487 break;
488 case PT_LOOS:
488 case PT_LOOS:
489 type = "Start of OS-specific";
489 type = "Start of OS-specific";
490 break;
490 break;
491 case PT_SUNWSTACK:
491 case PT_SUNWSTACK:
492 type = "Stack segment";
492 type = "Stack segment";
493 break;
493 break;
494 case PT_LOPROC:
494 case PT_LOPROC:
495 type = "Start of processor-specific";
495 type = "Start of processor-specific";
496 break;
496 break;
497 case PT_HIPROC:
497 case PT_HIPROC:
498 type = "End of processor-specific";
498 type = "End of processor-specific";
499 break;
499 break;
500 default:
500 default:
501 type = "Unknow Section Type";
501 type = "Unknow Section Type";
502 break;
502 break;
503 }
503 }
504 }
504 }
505 }
505 }
506
506
507 return type;
507 return type;
508 }
508 }
509
509
510
510
511 int64_t elfparser::getSegmentOffset(int index)
511 qint64 elfparser::getSegmentOffset(int index)
512 {
512 {
513 int64_t Offset;
513 int64_t Offset;
514 if(this->e!=NULL)
514 if(this->e!=NULL)
515 {
515 {
516 if(index < this->Segments.count())
516 if(index < this->Segments.count())
517 {
517 {
518 Offset = (int64_t)this->Segments.at(index)->p_offset;
518 Offset = (int64_t)this->Segments.at(index)->p_offset;
519 }
519 }
520 }
520 }
521 return Offset;
521 return Offset;
522 }
522 }
523
523
524
524
525 int64_t elfparser::getSegmentVaddr(int index)
525 qint64 elfparser::getSegmentVaddr(int index)
526 {
526 {
527 int64_t Vaddr = 0;
527 int64_t Vaddr = 0;
528 if(this->e!=NULL)
528 if(this->e!=NULL)
529 {
529 {
530 if(index < this->Segments.count())
530 if(index < this->Segments.count())
531 {
531 {
532 Vaddr = (int64_t)this->Segments.at(index)->p_vaddr;
532 Vaddr = (int64_t)this->Segments.at(index)->p_vaddr;
533 }
533 }
534 }
534 }
535 return Vaddr;
535 return Vaddr;
536 }
536 }
537
537
538
538
539 int64_t elfparser::getSegmentPaddr(int index)
539 qint64 elfparser::getSegmentPaddr(int index)
540 {
540 {
541 int64_t Paddr=0;
541 int64_t Paddr=0;
542 if(this->e!=NULL)
542 if(this->e!=NULL)
543 {
543 {
544 if(index < this->Segments.count())
544 if(index < this->Segments.count())
545 {
545 {
546 Paddr = (int64_t)this->Segments.at(index)->p_paddr;
546 Paddr = (int64_t)this->Segments.at(index)->p_paddr;
547 }
547 }
548 }
548 }
549 return Paddr;
549 return Paddr;
550 }
550 }
551
551
552 int64_t elfparser::getSectionPaddr(int index)
552 qint64 elfparser::getSectionPaddr(int index)
553 {
553 {
554 int64_t Paddr=0;
554 int64_t Paddr=0;
555 if(this->e!=NULL)
555 if(this->e!=NULL)
556 {
556 {
557 if(index < this->sections.count())
557 if(index < this->sections.count())
558 {
558 {
559 Paddr = (int64_t)this->sections.at(index)->section_header->sh_addr;
559 Paddr = (int64_t)this->sections.at(index)->section_header->sh_addr;
560 }
560 }
561 }
561 }
562 return Paddr;
562 return Paddr;
563 }
563 }
564
564
565
565
566 int64_t elfparser::getSegmentFilesz(int index)
566 qint64 elfparser::getSegmentFilesz(int index)
567 {
567 {
568 int64_t FileSz=0;
568 int64_t FileSz=0;
569 if(this->e!=NULL)
569 if(this->e!=NULL)
570 {
570 {
571 if(index < this->Segments.count())
571 if(index < this->Segments.count())
572 {
572 {
573 FileSz = (int64_t)this->Segments.at(index)->p_filesz;
573 FileSz = (int64_t)this->Segments.at(index)->p_filesz;
574 }
574 }
575 }
575 }
576 return FileSz;
576 return FileSz;
577 }
577 }
578
578
579 int64_t elfparser::getSectionDatasz(int index)
579 qint64 elfparser::getSectionDatasz(int index)
580 {
580 {
581 int64_t DataSz=0;
581 int64_t DataSz=0;
582 if(this->e!=NULL)
582 if(this->e!=NULL)
583 {
583 {
584 if(index < this->sections.count())
584 if(index < this->sections.count())
585 {
585 {
586 DataSz = (int64_t)this->sections.at(index)->data->d_size;
586 DataSz = (int64_t)this->sections.at(index)->data->d_size;
587 }
587 }
588 }
588 }
589 return DataSz;
589 return DataSz;
590 }
590 }
591
591
592 bool elfparser::getSectionData(int index, char **buffer)
592 bool elfparser::getSectionData(int index, char **buffer)
593 {
593 {
594 if(this->e!=NULL)
594 if(this->e!=NULL)
595 {
595 {
596 if(index < this->sections.count())
596 if(index < this->sections.count())
597 {
597 {
598 *buffer = (char *)this->sections.at(index)->data->d_buf;
598 *buffer = (char *)this->sections.at(index)->data->d_buf;
599 return true;
599 return true;
600 }
600 }
601 }
601 }
602 return false;
602 return false;
603 }
603 }
604
604
605
605
606 int64_t elfparser::getSegmentMemsz(int index)
606 qint64 elfparser::getSegmentMemsz(int index)
607 {
607 {
608 int64_t MemSz=0;
608 int64_t MemSz=0;
609 if(this->e!=NULL)
609 if(this->e!=NULL)
610 {
610 {
611 if(index < this->Segments.count())
611 if(index < this->Segments.count())
612 {
612 {
613 MemSz = (int64_t)this->Segments.at(index)->p_memsz;
613 MemSz = (int64_t)this->Segments.at(index)->p_memsz;
614 }
614 }
615 }
615 }
616 return MemSz;
616 return MemSz;
617 }
617 }
618
618
619 int64_t elfparser::getSectionMemsz(int index)
619 qint64 elfparser::getSectionMemsz(int index)
620 {
620 {
621 int64_t MemSz=0;
621 int64_t MemSz=0;
622 if(this->e!=NULL)
622 if(this->e!=NULL)
623 {
623 {
624 if(index < this->sections.count())
624 if(index < this->sections.count())
625 {
625 {
626 MemSz = (int64_t)this->sections.at(index)->section_header->sh_size;
626 MemSz = (int64_t)this->sections.at(index)->section_header->sh_size;
627 }
627 }
628 }
628 }
629 return MemSz;
629 return MemSz;
630 }
630 }
631
631
632
632
633 QString elfparser::getSegmentFlags(int index)
633 QString elfparser::getSegmentFlags(int index)
634 {
634 {
635 QString flags("");
635 QString flags("");
636 if(this->e!=NULL)
636 if(this->e!=NULL)
637 {
637 {
638 if(index < this->Segments.count())
638 if(index < this->Segments.count())
639 {
639 {
640 if((this->Segments.at(index)->p_flags&PF_X) == PF_X)flags+="x";
640 if((this->Segments.at(index)->p_flags&PF_X) == PF_X)flags+="x";
641 if((this->Segments.at(index)->p_flags&PF_W) == PF_W)flags+="w";
641 if((this->Segments.at(index)->p_flags&PF_W) == PF_W)flags+="w";
642 if((this->Segments.at(index)->p_flags&PF_R) == PF_R)flags+="r";
642 if((this->Segments.at(index)->p_flags&PF_R) == PF_R)flags+="r";
643 if((this->Segments.at(index)->p_flags&PF_MASKOS) == PF_MASKOS)flags+=" OS-specific";
643 if((this->Segments.at(index)->p_flags&PF_MASKOS) == PF_MASKOS)flags+=" OS-specific";
644 if((this->Segments.at(index)->p_flags&PF_MASKPROC) == PF_MASKPROC)flags+=" Processor-specific";
644 if((this->Segments.at(index)->p_flags&PF_MASKPROC) == PF_MASKPROC)flags+=" Processor-specific";
645 }
645 }
646 }
646 }
647 return flags;
647 return flags;
648 }
648 }
649
649
650
650
651 QString elfparser::getSectionName(int index)
651 QString elfparser::getSectionName(int index)
652 {
652 {
653 char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name);
653 char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name);
654 return QString(nameChr);
654 return QString(nameChr);
655 }
655 }
656
656
657
657
658 void elfparser::updateSections()
658 void elfparser::updateSections()
659 {
659 {
660 for(int i=0;i<this->sections.count();i++)
660 for(int i=0;i<this->sections.count();i++)
661 {
661 {
662 delete this->sections.at(i);
662 delete this->sections.at(i);
663 }
663 }
664 this->sections.clear();
664 this->sections.clear();
665 this->scn = elf_nextscn (this->e , NULL );
665 this->scn = elf_nextscn (this->e , NULL );
666 this->SectionCount = 0;
666 this->SectionCount = 0;
667 while( this->scn != NULL )
667 while( this->scn != NULL )
668 {
668 {
669 GElf_Shdr* shdr = (GElf_Shdr*)malloc(sizeof(GElf_Shdr));
669 GElf_Shdr* shdr = (GElf_Shdr*)malloc(sizeof(GElf_Shdr));
670 gelf_getshdr ( this->scn , shdr );
670 gelf_getshdr ( this->scn , shdr );
671 Elf_Data* data = elf_getdata(this->scn, NULL);
671 Elf_Data* data = elf_getdata(this->scn, NULL);
672 this->sections.append(new Elf_Section(data,shdr));
672 this->sections.append(new Elf_Section(data,shdr));
673 this->SectionCount+=1;
673 this->SectionCount+=1;
674 this->scn = elf_nextscn(e , scn);
674 this->scn = elf_nextscn(e , scn);
675 }
675 }
676 }
676 }
677
677
678
678
679 void elfparser::updateSegments()
679 void elfparser::updateSegments()
680 {
680 {
681 elf_getphdrnum (this->e , &this->SegmentCount);
681 elf_getphdrnum (this->e , &this->SegmentCount);
682 for(int i=0;i<this->Segments.count();i++)
682 for(int i=0;i<this->Segments.count();i++)
683 {
683 {
684 free(this->Segments.at(i));
684 free(this->Segments.at(i));
685 }
685 }
686 this->Segments.clear();
686 this->Segments.clear();
687 for(int i=0;i<this->SegmentCount;i++)
687 for(int i=0;i<this->SegmentCount;i++)
688 {
688 {
689 GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr));
689 GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr));
690 gelf_getphdr (this->e , i , header );
690 gelf_getphdr (this->e , i , header );
691 this->Segments.append(header);
691 this->Segments.append(header);
692 }
692 }
693 }
693 }
694
694
695
695
696
696
697
697
698
698
699 QString elfparser::getSectionType(int index)
699 QString elfparser::getSectionType(int index)
700 {
700 {
701 QString type("");
701 QString type("");
702 if(this->e!=NULL)
702 if(this->e!=NULL)
703 {
703 {
704 if(index < this->Segments.count())
704 if(index < this->Segments.count())
705 {
705 {
706 switch(this->Segments.at(index)->p_type)
706 switch(this->Segments.at(index)->p_type)
707 {
707 {
708 case SHT_NULL : type = "Section header table entry unused"; break;
708 case SHT_NULL : type = "Section header table entry unused"; break;
709 case SHT_PROGBITS : type = "Program data"; break;
709 case SHT_PROGBITS : type = "Program data"; break;
710 case SHT_SYMTAB : type = "Symbol table"; break;
710 case SHT_SYMTAB : type = "Symbol table"; break;
711 case SHT_STRTAB : type = "String table"; break;
711 case SHT_STRTAB : type = "String table"; break;
712 case SHT_RELA : type = "Relocation entries with addends"; break;
712 case SHT_RELA : type = "Relocation entries with addends"; break;
713 case SHT_HASH : type = "Symbol hash table"; break;
713 case SHT_HASH : type = "Symbol hash table"; break;
714 case SHT_DYNAMIC : type = "Dynamic linking information"; break;
714 case SHT_DYNAMIC : type = "Dynamic linking information"; break;
715 case SHT_NOTE : type = "Notes"; break;
715 case SHT_NOTE : type = "Notes"; break;
716 case SHT_NOBITS :type = "Program space with no data (bss)"; break;
716 case SHT_NOBITS :type = "Program space with no data (bss)"; break;
717 case SHT_REL :type = "Relocation entries, no addends"; break;
717 case SHT_REL :type = "Relocation entries, no addends"; break;
718 case SHT_SHLIB : type = "Reserved"; break;
718 case SHT_SHLIB : type = "Reserved"; break;
719 case SHT_DYNSYM : type = "Dynamic linker symbol table"; break;
719 case SHT_DYNSYM : type = "Dynamic linker symbol table"; break;
720 case SHT_INIT_ARRAY : type = "Array of constructors"; break;
720 case SHT_INIT_ARRAY : type = "Array of constructors"; break;
721 case SHT_FINI_ARRAY : type = "Array of destructors"; break;
721 case SHT_FINI_ARRAY : type = "Array of destructors"; break;
722 case SHT_PREINIT_ARRAY : type = "Array of pre-constructors"; break;
722 case SHT_PREINIT_ARRAY : type = "Array of pre-constructors"; break;
723 case SHT_GROUP : type = "Section group"; break;
723 case SHT_GROUP : type = "Section group"; break;
724 case SHT_SYMTAB_SHNDX : type = "Extended section indeces"; break;
724 case SHT_SYMTAB_SHNDX : type = "Extended section indeces"; break;
725 case SHT_NUM : type = "Number of defined types. "; break;
725 case SHT_NUM : type = "Number of defined types. "; break;
726 case SHT_LOOS : type = "Start OS-specific. "; break;
726 case SHT_LOOS : type = "Start OS-specific. "; break;
727 case SHT_LOSUNW : type = "Sun-specific low bound. "; break;
727 case SHT_LOSUNW : type = "Sun-specific low bound. "; break;
728 case SHT_SUNW_COMDAT : type = " "; break;
728 case SHT_SUNW_COMDAT : type = " "; break;
729 case SHT_SUNW_syminfo : type = " "; break;
729 case SHT_SUNW_syminfo : type = " "; break;
730 case SHT_GNU_verdef : type = "Version definition section. "; break;
730 case SHT_GNU_verdef : type = "Version definition section. "; break;
731 case SHT_GNU_verneed : type = "Version needs section. "; break;
731 case SHT_GNU_verneed : type = "Version needs section. "; break;
732 case SHT_GNU_versym : type = "Version symbol table. "; break;
732 case SHT_GNU_versym : type = "Version symbol table. "; break;
733 case SHT_LOPROC : type = "Start of processor-specific"; break;
733 case SHT_LOPROC : type = "Start of processor-specific"; break;
734 case SHT_HIPROC : type = "End of processor-specific"; break;
734 case SHT_HIPROC : type = "End of processor-specific"; break;
735 case SHT_HIUSER : type = "End of application-specific"; break;
735 case SHT_HIUSER : type = "End of application-specific"; break;
736 }
736 }
737 }
737 }
738 }
738 }
739 return type;
739 return type;
740 }
740 }
741
741
742 bool elfparser::isElf(const QString &File)
742 bool elfparser::isElf(const QString &File)
743 {
743 {
744 int file =0;
744 int file =0;
745 #ifdef _ELF_WINDOWS_
745 #ifdef _ELF_WINDOWS_
746 file = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0);
746 file = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0);
747 #else
747 #else
748 file = open(File.toStdString().c_str(),O_RDONLY ,0);
748 file = open(File.toStdString().c_str(),O_RDONLY ,0);
749 #endif
749 #endif
750 char Magic[4];
750 char Magic[4];
751 if(file!=-1)
751 if(file!=-1)
752 {
752 {
753 read(file,Magic,4);
753 read(file,Magic,4);
754 close(file);
754 close(file);
755 if(Magic[0]==0x7f && Magic[1]==0x45 && Magic[2]==0x4c && Magic[3]==0x46)
755 if(Magic[0]==0x7f && Magic[1]==0x45 && Magic[2]==0x4c && Magic[3]==0x46)
756 {
756 {
757 return true;
757 return true;
758 }
758 }
759 }
759 }
760 return false;
760 return false;
761 }
761 }
762
762
763
763
764
764
765
765
766
766
767
767
768
768
769
769
@@ -1,101 +1,101
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #ifndef ELFPARSER_H
22 #ifndef ELFPARSER_H
23 #define ELFPARSER_H
23 #define ELFPARSER_H
24 #include <libelf.h>
24 #include <libelf.h>
25 #include <gelf.h>
25 #include <gelf.h>
26 #include <QString>
26 #include <QString>
27 #include <stdio.h>
27 #include <stdio.h>
28 #include <QList>
28 #include <QList>
29 #include <stdint.h>
29 #include <stdint.h>
30
30
31 class Elf_Section
31 class Elf_Section
32 {
32 {
33 public:
33 public:
34 Elf_Section(){}
34 Elf_Section(){}
35 Elf_Section(Elf_Data* data,GElf_Shdr* section_header)
35 Elf_Section(Elf_Data* data,GElf_Shdr* section_header)
36 {
36 {
37 this->data = data;
37 this->data = data;
38 this->section_header = section_header;
38 this->section_header = section_header;
39 }
39 }
40 Elf_Data* data;
40 Elf_Data* data;
41 GElf_Shdr* section_header;
41 GElf_Shdr* section_header;
42 };
42 };
43
43
44 class elfparser
44 class elfparser
45 {
45 {
46 public:
46 public:
47 elfparser();
47 elfparser();
48 bool iself();
48 bool iself();
49 bool isopened();
49 bool isopened();
50 int setFilename(const QString& name);
50 int setFilename(const QString& name);
51 int closeFile();
51 int closeFile();
52 QString getClass();
52 QString getClass();
53 QString getArchitecture();
53 QString getArchitecture();
54 QString getType();
54 QString getType();
55 QString getEndianness();
55 QString getEndianness();
56 QString getABI();
56 QString getABI();
57 int32_t getVersion();
57 qint32 getVersion();
58 int64_t getEntryPointAddress();
58 qint64 getEntryPointAddress();
59 int getSectioncount();
59 int getSectioncount();
60 int getSegmentcount();
60 int getSegmentcount();
61 QString getSegmentType(int index);
61 QString getSegmentType(int index);
62 int64_t getSegmentOffset(int index);
62 qint64 getSegmentOffset(int index);
63 int64_t getSegmentVaddr(int index);
63 qint64 getSegmentVaddr(int index);
64 int64_t getSegmentPaddr(int index);
64 qint64 getSegmentPaddr(int index);
65 int64_t getSectionPaddr(int index);
65 qint64 getSectionPaddr(int index);
66 int64_t getSegmentFilesz(int index);
66 qint64 getSegmentFilesz(int index);
67 int64_t getSectionDatasz(int index);
67 qint64 getSectionDatasz(int index);
68 bool getSectionData(int index, char **buffer);
68 bool getSectionData(int index, char **buffer);
69 int64_t getSegmentMemsz(int index);
69 qint64 getSegmentMemsz(int index);
70 int64_t getSectionMemsz(int index);
70 qint64 getSectionMemsz(int index);
71 QString getSegmentFlags(int index);
71 QString getSegmentFlags(int index);
72 QString getSectionName(int index);
72 QString getSectionName(int index);
73 QString getSectionType(int index);
73 QString getSectionType(int index);
74 static bool isElf(const QString& File);
74 static bool isElf(const QString& File);
75
75
76 private:
76 private:
77 void updateSections();
77 void updateSections();
78 void updateSegments();
78 void updateSegments();
79 int elfFile;
79 int elfFile;
80 bool opened;
80 bool opened;
81 bool type_elf;
81 bool type_elf;
82 Elf* e;
82 Elf* e;
83 Elf_Kind ek;
83 Elf_Kind ek;
84 GElf_Ehdr ehdr;
84 GElf_Ehdr ehdr;
85 Elf_Scn * scn;
85 Elf_Scn * scn;
86 Elf_Data * data;
86 Elf_Data * data;
87 size_t SectionCount,SegmentCount, shstrndx;
87 size_t SectionCount,SegmentCount, shstrndx;
88 QList<GElf_Phdr*> Segments;
88 QList<GElf_Phdr*> Segments;
89 QList<Elf_Section*> sections;
89 QList<Elf_Section*> sections;
90
90
91 };
91 };
92
92
93 #endif // ELFPARSER_H
93 #endif // ELFPARSER_H
94
94
95
95
96
96
97
97
98
98
99
99
100
100
101
101
General Comments 0
You need to be logged in to leave comments. Login now