##// END OF EJS Templates
Fusion with 14
jeandet -
r15:cc958c79ba09 merge default
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,7
1 <RCC>
2 <qresource prefix="/img">
3 <file>Gnome-list-add.png</file>
4 <file>Gnome-user-trash.png</file>
5 <file>Gnome-emblem-unreadable.png</file>
6 </qresource>
7 </RCC>
@@ -1,1116 +1,1119
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 "srecfile.h"
26 26 #include "binaryfile.h"
27 27 #include <stdint.h>
28 28
29 29 ElfFile::ElfFile()
30 30 :abstractBinFile()
31 31 {
32 32 this->opened = false;
33 33 this->type_elf = false;
34 34 this->elfFile = (int)NULL;
35 35 this->e = NULL;
36 36 this->data = NULL;
37 this->SymbolCount = 0;
37 38 }
38 39
39 40 ElfFile::ElfFile(const QString &File)
40 41 :abstractBinFile()
41 42 {
42 43 this->opened = false;
43 44 this->type_elf = false;
44 45 this->elfFile = (int)NULL;
45 46 this->e = NULL;
46 47 this->p_fileName = File;
47 48 this->data = NULL;
49 this->SymbolCount = 0;
48 50 openFile(File);
49 51 }
50 52
51 53 ElfFile::~ElfFile()
52 54 {
53 55 closeFile();
54 56 if(scn)free(scn);
55 57 if(data)free(data);
56 58 for(int i=0;i<this->sections.count();i++)
57 59 {
58 60 delete this->sections.at(i);
59 61 }
60 62 this->sections.clear();
61 63 for(int i=0;i<this->Segments.count();i++)
62 64 {
63 65 free(this->Segments.at(i));
64 66 }
65 67 this->Segments.clear();
66 68 for(int i=0;i<symbols.count();i++)
67 69 {
68 70 delete this->symbols.at(i);
69 71 }
70 72 this->symbols.clear();
71 73 }
72 74
73 75 bool ElfFile::openFile(const QString &File)
74 76 {
75 77 this->p_fileName = File;
76 78 this->closeFile();
77 79 if(elf_version(EV_CURRENT)==EV_NONE)return 0;
78 80 #ifdef _ELF_WINDOWS_
79 81 this->elfFile = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0);
80 82 #else
81 83 this->elfFile = open(File.toStdString().c_str(),O_RDONLY ,0);
82 84 #endif
83 85 if(this->elfFile==(int)NULL)return 0;
84 86 this->e = elf_begin(this->elfFile,ELF_C_READ,NULL);
85 87 if(this->e==NULL)return 0;
86 88 this->ek = elf_kind(this->e);
87 89 gelf_getehdr (this->e, &this->ehdr );
88 90 elf_getshdrstrndx (this->e, &this->shstrndx);
89 91 this->updateSegments();
90 92 this->updateSections();
91 93 this->updateSymbols();
92 94 this->opened = true;
93 95 litleendian = isLitleEndian();
94 96 return 1;
95 97 }
96 98
97 99 bool ElfFile::isopened()
98 100 {
99 101 return this->opened;
100 102 }
101 103
102 104 int ElfFile::closeFile()
103 105 {
104 106 if(this->elfFile!=(int)NULL)
105 107 {
106 108 if(this->e!=NULL)
107 109 {
108 110 elf_end(this->e);
109 111 this->e = NULL;
110 112 }
111 113 close(this->elfFile);
112 114 this->elfFile = (int)NULL;
113 115 }
114 116 this->opened = false;
115 117 return 0;
116 118 }
117 119
118 120
119 121 QList<codeFragment*> ElfFile::getFragments(QStringList fragmentList)
120 122 {
121 123 QList<codeFragment*> fragments;
122 124 if (isopened())
123 125 {
124 126 for(int i =0;i<fragmentList.count();i++)
125 127 {
126 128 fragments.append(getFragment(fragmentList.at(i)));
127 129 }
128 130 }
129 131 return fragments;
130 132 }
131 133
132 134 QList<codeFragment*> ElfFile::getFragments()
133 135 {
134 136 return getFragments(QStringList()<<".data"<<".text");
135 137 }
136 138
137 139 codeFragment *ElfFile::getFragment(const QString &name)
138 140 {
139 141 codeFragment* fragment= new codeFragment();
140 142 for(int i=0;i<getSectionCount();i++)
141 143 {
142 144 if(getSectionName(i) == name)
143 145 {
144 146 fragment->data =NULL;
145 147 fragment->size = getSectionDatasz(i);
146 148 fragment->address = getSectionPaddr(i);
147 149 getSectionData(i,&fragment->data);
148 150 }
149 151 }
150 152 return fragment;
151 153 }
152 154
153 155
154 156
155 157
156 158
157 159
158 160
159 161 QString elfresolveMachine(Elf64_Half e_machine)
160 162 {
161 163 QString machineName;
162 164 //Update from with bash script don't write it by yourself!
163 165 switch(e_machine)
164 166 {
165 167 case EM_NONE:
166 168 machineName = " No machine ";
167 169 break;
168 170 case EM_M32:
169 171 machineName = " AT&T WE 32100 ";
170 172 break;
171 173 case EM_SPARC:
172 174 machineName = " SUN SPARC ";
173 175 break;
174 176 case EM_386:
175 177 machineName = " Intel 80386 ";
176 178 break;
177 179 case EM_68K:
178 180 machineName = " Motorola m68k family ";
179 181 break;
180 182 case EM_88K:
181 183 machineName = " Motorola m88k family ";
182 184 break;
183 185 case EM_860:
184 186 machineName = " Intel 80860 ";
185 187 break;
186 188 case EM_MIPS:
187 189 machineName = " MIPS R3000 big-endian ";
188 190 break;
189 191 case EM_S370:
190 192 machineName = " IBM System/370 ";
191 193 break;
192 194 case EM_MIPS_RS3_LE:
193 195 machineName = " MIPS R3000 little-endian ";
194 196 break;
195 197 case EM_PARISC:
196 198 machineName = " HPPA ";
197 199 break;
198 200 case EM_VPP500:
199 201 machineName = " Fujitsu VPP500 ";
200 202 break;
201 203 case EM_SPARC32PLUS:
202 204 machineName = " Sun's \"v8plus\" ";
203 205 break;
204 206 case EM_960:
205 207 machineName = " Intel 80960 ";
206 208 break;
207 209 case EM_PPC:
208 210 machineName = " PowerPC ";
209 211 break;
210 212 case EM_PPC64:
211 213 machineName = " PowerPC 64-bit ";
212 214 break;
213 215 case EM_S390:
214 216 machineName = " IBM S390 ";
215 217 break;
216 218 case EM_V800:
217 219 machineName = " NEC V800 series ";
218 220 break;
219 221 case EM_FR20:
220 222 machineName = " Fujitsu FR20 ";
221 223 break;
222 224 case EM_RH32:
223 225 machineName = " TRW RH-32 ";
224 226 break;
225 227 case EM_RCE:
226 228 machineName = " Motorola RCE ";
227 229 break;
228 230 case EM_ARM:
229 231 machineName = " ARM ";
230 232 break;
231 233 case EM_FAKE_ALPHA:
232 234 machineName = " Digital Alpha ";
233 235 break;
234 236 case EM_SH:
235 237 machineName = " Hitachi SH ";
236 238 break;
237 239 case EM_SPARCV9:
238 240 machineName = " SPARC v9 64-bit ";
239 241 break;
240 242 case EM_TRICORE:
241 243 machineName = " Siemens Tricore ";
242 244 break;
243 245 case EM_ARC:
244 246 machineName = " Argonaut RISC Core ";
245 247 break;
246 248 case EM_H8_300:
247 249 machineName = " Hitachi H8/300 ";
248 250 break;
249 251 case EM_H8_300H:
250 252 machineName = " Hitachi H8/300H ";
251 253 break;
252 254 case EM_H8S:
253 255 machineName = " Hitachi H8S ";
254 256 break;
255 257 case EM_H8_500:
256 258 machineName = " Hitachi H8/500 ";
257 259 break;
258 260 case EM_IA_64:
259 261 machineName = " Intel Merced ";
260 262 break;
261 263 case EM_MIPS_X:
262 264 machineName = " Stanford MIPS-X ";
263 265 break;
264 266 case EM_COLDFIRE:
265 267 machineName = " Motorola Coldfire ";
266 268 break;
267 269 case EM_68HC12:
268 270 machineName = " Motorola M68HC12 ";
269 271 break;
270 272 case EM_MMA:
271 273 machineName = " Fujitsu MMA Multimedia Accelerator";
272 274 break;
273 275 case EM_PCP:
274 276 machineName = " Siemens PCP ";
275 277 break;
276 278 case EM_NCPU:
277 279 machineName = " Sony nCPU embeeded RISC ";
278 280 break;
279 281 case EM_NDR1:
280 282 machineName = " Denso NDR1 microprocessor ";
281 283 break;
282 284 case EM_STARCORE:
283 285 machineName = " Motorola Start*Core processor ";
284 286 break;
285 287 case EM_ME16:
286 288 machineName = " Toyota ME16 processor ";
287 289 break;
288 290 case EM_ST100:
289 291 machineName = " STMicroelectronic ST100 processor ";
290 292 break;
291 293 case EM_TINYJ:
292 294 machineName = " Advanced Logic Corp. Tinyj emb.fam";
293 295 break;
294 296 case EM_X86_64:
295 297 machineName = " AMD x86-64 architecture ";
296 298 break;
297 299 case EM_PDSP:
298 300 machineName = " Sony DSP Processor ";
299 301 break;
300 302 case EM_FX66:
301 303 machineName = " Siemens FX66 microcontroller ";
302 304 break;
303 305 case EM_ST9PLUS:
304 306 machineName = " STMicroelectronics ST9+ 8/16 mc ";
305 307 break;
306 308 case EM_ST7:
307 309 machineName = " STmicroelectronics ST7 8 bit mc ";
308 310 break;
309 311 case EM_68HC16:
310 312 machineName = " Motorola MC68HC16 microcontroller ";
311 313 break;
312 314 case EM_68HC11:
313 315 machineName = " Motorola MC68HC11 microcontroller ";
314 316 break;
315 317 case EM_68HC08:
316 318 machineName = " Motorola MC68HC08 microcontroller ";
317 319 break;
318 320 case EM_68HC05:
319 321 machineName = " Motorola MC68HC05 microcontroller ";
320 322 break;
321 323 case EM_SVX:
322 324 machineName = " Silicon Graphics SVx ";
323 325 break;
324 326 case EM_ST19:
325 327 machineName = " STMicroelectronics ST19 8 bit mc ";
326 328 break;
327 329 case EM_VAX:
328 330 machineName = " Digital VAX ";
329 331 break;
330 332 case EM_CRIS:
331 333 machineName = " Axis Communications 32-bit embedded processor ";
332 334 break;
333 335 case EM_JAVELIN:
334 336 machineName = " Infineon Technologies 32-bit embedded processor ";
335 337 break;
336 338 case EM_FIREPATH:
337 339 machineName = " Element 14 64-bit DSP Processor ";
338 340 break;
339 341 case EM_ZSP:
340 342 machineName = " LSI Logic 16-bit DSP Processor ";
341 343 break;
342 344 case EM_MMIX:
343 345 machineName = " Donald Knuth's educational 64-bit processor ";
344 346 break;
345 347 case EM_HUANY:
346 348 machineName = " Harvard University machine-independent object files ";
347 349 break;
348 350 case EM_PRISM:
349 351 machineName = " SiTera Prism ";
350 352 break;
351 353 case EM_AVR:
352 354 machineName = " Atmel AVR 8-bit microcontroller ";
353 355 break;
354 356 case EM_FR30:
355 357 machineName = " Fujitsu FR30 ";
356 358 break;
357 359 case EM_D10V:
358 360 machineName = " Mitsubishi D10V ";
359 361 break;
360 362 case EM_D30V:
361 363 machineName = " Mitsubishi D30V ";
362 364 break;
363 365 case EM_V850:
364 366 machineName = " NEC v850 ";
365 367 break;
366 368 case EM_M32R:
367 369 machineName = " Mitsubishi M32R ";
368 370 break;
369 371 case EM_MN10300:
370 372 machineName = " Matsushita MN10300 ";
371 373 break;
372 374 case EM_MN10200:
373 375 machineName = " Matsushita MN10200 ";
374 376 break;
375 377 case EM_PJ:
376 378 machineName = " picoJava ";
377 379 break;
378 380 case EM_OPENRISC:
379 381 machineName = " OpenRISC 32-bit embedded processor ";
380 382 break;
381 383 case EM_ARC_A5:
382 384 machineName = " ARC Cores Tangent-A5 ";
383 385 break;
384 386 case EM_XTENSA:
385 387 machineName = " Tensilica Xtensa Architecture ";
386 388 break;
387 389 #ifndef EM_AARCH64
388 390 #define EM_AARCH64 183
389 391 #endif
390 392 case EM_AARCH64:
391 393 machineName = " ARM AARCH64 ";
392 394 break;
393 395 #ifndef EM_TILEPRO
394 396 #define EM_TILEPRO 188
395 397 #endif
396 398 case EM_TILEPRO:
397 399 machineName = " Tilera TILEPro ";
398 400 break;
399 401 #ifndef EM_MICROBLAZE
400 402 #define EM_MICROBLAZE 189
401 403 #endif
402 404 case EM_MICROBLAZE:
403 405 machineName = " Xilinx MicroBlaze ";
404 406 break;
405 407 #ifndef EM_TILEGX
406 408 #define EM_TILEGX 191
407 409 #endif
408 410 case EM_TILEGX:
409 411 machineName = " Tilera TILE-Gx ";
410 412 break;
411 413 case EM_NUM:
412 414 machineName = "";
413 415 break;
414 416 default:
415 417 machineName ="Unknow Machine";
416 418 break;
417 419 }
418 420 return machineName;
419 421 }
420 422
421 423
422 424
423 425
424 426 QString ElfFile::getClass()
425 427 {
426 428 if(this->e!=NULL)
427 429 {
428 430 int eclass = gelf_getclass(this->e);
429 431 if(eclass==ELFCLASS32)return "ELF32";
430 432 if(eclass==ELFCLASS64)return "ELF64";
431 433 }
432 434 return "none";
433 435 }
434 436
435 437
436 438 bool ElfFile::iself()
437 439 {
438 440 return (this->getType()!="Unknow");
439 441 }
440 442
441 443 QString ElfFile::getArchitecture()
442 444 {
443 445 if(this->e!=NULL)
444 446 {
445 447 return elfresolveMachine(this->ehdr.e_machine);
446 448 }
447 449 return "";
448 450 }
449 451
450 452
451 453 QString ElfFile::getType()
452 454 {
453 455 QString kind("");
454 456 if(this->e!=NULL)
455 457 {
456 458 switch(this->ek)
457 459 {
458 460 case ELF_K_AR:
459 461 kind = "Archive";
460 462 break;
461 463 case ELF_K_ELF:
462 464 kind = "Elf";
463 465 break;
464 466 case ELF_K_COFF:
465 467 kind = "COFF";
466 468 break;
467 469 case ELF_K_NUM:
468 470 kind = "NUM";
469 471 break;
470 472 case ELF_K_NONE:
471 473 kind = "Data";
472 474 break;
473 475 default:
474 476 kind = "Unknow";
475 477 break;
476 478 }
477 479 }
478 480 return kind;
479 481 }
480 482
481 483 QString ElfFile::getEndianness()
482 484 {
483 485 if(this->e!=NULL)
484 486 {
485 487 if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return "2's complement, little endian";
486 488 if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return "2's complement, big endian";
487 489 }
488 490 return "none";
489 491 }
490 492
491 493 bool ElfFile::isLitleEndian()
492 494 {
493 495 if(this->e!=NULL)
494 496 {
495 497 if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return true;
496 498 if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return false;
497 499 }
498 500 return false;
499 501 }
500 502
501 503 bool ElfFile::isBigEndian()
502 504 {
503 505 if(this->e!=NULL)
504 506 {
505 507 if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return false;
506 508 if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return true;
507 509 }
508 510 return false;
509 511 }
510 512
511 513 QString ElfFile::getABI()
512 514 {
513 515 if(this->e!=NULL)
514 516 {
515 517 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NONE)return "UNIX System V ABI";
516 518 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SYSV)return "Alias";
517 519 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_HPUX)return "HP-UX";
518 520 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NETBSD)return "NetBSD";
519 521 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_LINUX)return "Object uses GNU ELF extensions";
520 522 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SOLARIS)return "Sun Solaris";
521 523 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_AIX)return "IBM AIX";
522 524 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_IRIX)return "SGI Irix";
523 525 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_FREEBSD)return "FreeBSD";
524 526 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_TRU64)return "Compaq TRU64 UNIX";
525 527 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_MODESTO)return " Novell Modesto";
526 528 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_OPENBSD)return "OpenBSD";
527 529 #ifndef ELFOSABI_ARM_AEABI
528 530 #define ELFOSABI_ARM_AEABI 64
529 531 #endif
530 532 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM_AEABI)return "ARM EABI";
531 533 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM)return "ARM";
532 534 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_STANDALONE)return "Standalone (embedded) application";
533 535 }
534 536 return "none";
535 537 }
536 538
537 539
538 540 qint64 ElfFile::getVersion()
539 541 {
540 542 if(this->e!=NULL)
541 543 {
542 544 return this->ehdr.e_version;
543 545 }
544 546 return -1;
545 547 }
546 548
547 549 qint64 ElfFile::getEntryPointAddress()
548 550 {
549 551 if(this->e!=NULL)
550 552 {
551 553 return this->ehdr.e_entry;
552 554 }
553 555 return -1;
554 556 }
555 557
556 558
557 559 int ElfFile::getSectionCount()
558 560 {
559 561 return (int)this->SectionCount;
560 562 }
561 563
562 564 int ElfFile::getSymbolCount()
563 565 {
564 566 return (int)this->SymbolCount;
565 567 }
566 568
567 569
568 570 int ElfFile::getSegmentCount()
569 571 {
570 572 return (int)this->SegmentCount;
571 573 }
572 574
573 575
574 576 QString ElfFile::getSegmentType(int index)
575 577 {
576 578 QString type("");
577 579 if(this->e!=NULL)
578 580 {
579 581 if(index < this->Segments.count())
580 582 {
581 583 switch(this->Segments.at(index)->p_type)
582 584 {
583 585 case PT_NULL:
584 586 type = "Program header table entry unused";
585 587 break;
586 588 case PT_LOAD:
587 589 type = "Loadable program segment";
588 590 break;
589 591 case PT_DYNAMIC :
590 592 type = "Dynamic linking information";
591 593 break;
592 594 case PT_INTERP:
593 595 type ="Program interpreter";
594 596 break;
595 597 case PT_NOTE:
596 598 type = "Auxiliary information";
597 599 break;
598 600 case PT_SHLIB:
599 601 type = "Reserved";
600 602 break;
601 603 case PT_PHDR:
602 604 type = "Entry for header table itself";
603 605 break;
604 606 case PT_TLS:
605 607 type = "Thread-local storage segment";
606 608 break;
607 609 case PT_NUM:
608 610 type = "Number of defined types";
609 611 break;
610 612 case PT_LOOS:
611 613 type = "Start of OS-specific";
612 614 break;
613 615 case PT_SUNWSTACK:
614 616 type = "Stack segment";
615 617 break;
616 618 case PT_LOPROC:
617 619 type = "Start of processor-specific";
618 620 break;
619 621 case PT_HIPROC:
620 622 type = "End of processor-specific";
621 623 break;
622 624 default:
623 625 type = "Unknow Section Type";
624 626 break;
625 627 }
626 628 }
627 629 }
628 630
629 631 return type;
630 632 }
631 633
632 634
633 635 qint64 ElfFile::getSegmentOffset(int index)
634 636 {
635 637 qint64 Offset = -1;
636 638 if(this->e!=NULL)
637 639 {
638 640 if(index < this->Segments.count())
639 641 {
640 642 Offset = (qint64)this->Segments.at(index)->p_offset;
641 643 }
642 644 }
643 645 return Offset;
644 646 }
645 647
646 648
647 649 qint64 ElfFile::getSegmentVaddr(int index)
648 650 {
649 651 int64_t Vaddr = 0;
650 652 if(this->e!=NULL)
651 653 {
652 654 if(index < this->Segments.count())
653 655 {
654 656 Vaddr = (int64_t)this->Segments.at(index)->p_vaddr;
655 657 }
656 658 }
657 659 return Vaddr;
658 660 }
659 661
660 662
661 663 qint64 ElfFile::getSegmentPaddr(int index)
662 664 {
663 665 int64_t Paddr=0;
664 666 if(this->e!=NULL)
665 667 {
666 668 if(index < this->Segments.count())
667 669 {
668 670 Paddr = (int64_t)this->Segments.at(index)->p_paddr;
669 671 }
670 672 }
671 673 return Paddr;
672 674 }
673 675
674 676 qint64 ElfFile::getSectionPaddr(int index)
675 677 {
676 678 int64_t Paddr=0;
677 679 if(this->e!=NULL)
678 680 {
679 681 if(index < this->sections.count())
680 682 {
681 683 Paddr = (int64_t)this->sections.at(index)->section_header->sh_addr;
682 684 }
683 685 }
684 686 return Paddr;
685 687 }
686 688
687 689
688 690 qint64 ElfFile::getSegmentFilesz(int index)
689 691 {
690 692 int64_t FileSz=0;
691 693 if(this->e!=NULL)
692 694 {
693 695 if(index < this->Segments.count())
694 696 {
695 697 FileSz = (int64_t)this->Segments.at(index)->p_filesz;
696 698 }
697 699 }
698 700 return FileSz;
699 701 }
700 702
701 703 qint64 ElfFile::getSectionDatasz(int index)
702 704 {
703 705 int64_t DataSz=0;
704 706 if(this->e!=NULL)
705 707 {
706 708 if(index < this->sections.count())
707 709 {
708 710 if(this->sections.at(index)->section_header->sh_type==SHT_NOBITS)
709 711 {
710 712 DataSz=0;
711 713 }
712 714 else
713 715 {
714 716 DataSz = (int64_t)this->sections.at(index)->data->d_size;
715 717 }
716 718 }
717 719 }
718 720 return DataSz;
719 721 }
720 722
721 723 bool ElfFile::getSectionData(int index, char **buffer)
722 724 {
723 725 if(this->e!=NULL)
724 726 {
725 727 if(index < this->sections.count())
726 728 {
727 729 *buffer = (char *)malloc(this->sections.at(index)->data->d_size);
728 730 memcpy(*buffer,this->sections.at(index)->data->d_buf,this->sections.at(index)->data->d_size);
729 731 return true;
730 732 }
731 733 }
732 734 return false;
733 735 }
734 736
735 737
736 738 qint64 ElfFile::getSegmentMemsz(int index)
737 739 {
738 740 int64_t MemSz=0;
739 741 if(this->e!=NULL)
740 742 {
741 743 if(index < this->Segments.count())
742 744 {
743 745 MemSz = (int64_t)this->Segments.at(index)->p_memsz;
744 746 }
745 747 }
746 748 return MemSz;
747 749 }
748 750
749 751 qint64 ElfFile::getSectionMemsz(int index)
750 752 {
751 753 int64_t MemSz=0;
752 754 if(this->e!=NULL)
753 755 {
754 756 if(index < this->sections.count())
755 757 {
756 758 MemSz = (int64_t)this->sections.at(index)->section_header->sh_size;
757 759 }
758 760 }
759 761 return MemSz;
760 762 }
761 763
762 764
763 765 QString ElfFile::getSegmentFlags(int index)
764 766 {
765 767 QString flags("");
766 768 if(this->e!=NULL)
767 769 {
768 770 if(index < this->Segments.count())
769 771 {
770 772 if((this->Segments.at(index)->p_flags&PF_X) == PF_X)flags+="x";
771 773 if((this->Segments.at(index)->p_flags&PF_W) == PF_W)flags+="w";
772 774 if((this->Segments.at(index)->p_flags&PF_R) == PF_R)flags+="r";
773 775 if((this->Segments.at(index)->p_flags&PF_MASKOS) == PF_MASKOS)flags+=" OS-specific";
774 776 if((this->Segments.at(index)->p_flags&PF_MASKPROC) == PF_MASKPROC)flags+=" Processor-specific";
775 777 }
776 778 }
777 779 return flags;
778 780 }
779 781
780 782
781 783 QString ElfFile::getSectionName(int index)
782 784 {
783 785 if((index<sections.count()) && (index>=0))
784 786 {
785 787 char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name);
786 788 return QString(nameChr);
787 789 }
788 790 return "";
789 791 }
790 792
791 793
792 794 void ElfFile::updateSections()
793 795 {
794 796 for(int i=0;i<this->sections.count();i++)
795 797 {
796 798 delete this->sections.at(i);
797 799 }
798 800 this->sections.clear();
799 801 this->scn = elf_nextscn (this->e , NULL );
800 802 this->SectionCount = 0;
801 803 while( this->scn != NULL )
802 804 {
803 805 GElf_Shdr* shdr = (GElf_Shdr*)malloc(sizeof(GElf_Shdr));
804 806 gelf_getshdr ( this->scn , shdr );
805 807 Elf_Data* data = elf_getdata(this->scn, NULL);
806 808 this->sections.append(new Elf_Section(data,shdr));
807 809 this->SectionCount+=1;
808 810 this->scn = elf_nextscn(e , scn);
809 811 }
810 812 }
811 813
812 814
813 815 void ElfFile::updateSegments()
814 816 {
815 817 for(int i=0;i<this->Segments.count();i++)
816 818 {
817 819 free(this->Segments.at(i));
818 820 }
819 821 this->Segments.clear();
820 822 this->SegmentCount = 0;
821 823 GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr));
822 824 while ( header == gelf_getphdr(this->e ,this->SegmentCount, header ))
823 825 {
824 826 this->Segments.append(header);
825 827 this->SegmentCount++;
826 828 header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr));
827 829 }
828 830 this->SegmentCount = this->Segments.count();
829 831 free(header);
830 832 }
831 833
832 834 void ElfFile::updateSymbols()
833 835 {
834 836 for(int i=0;i<symbols.count();i++)
835 837 {
836 838 delete this->symbols.at(i);
837 839 }
838 840 this->symbols.clear();
839 841 updateSections(); //Useless in most case but safer to do it
840 842 for(int i=0;i<(int)SectionCount;i++)
841 843 {
842 844 //First find Symbol table
843 if(this->getSectionName(i)==".symtab")
845 QString sectionName = this->getSectionName(i);
846 if(sectionName==".symtab" || sectionName == ".dynsym")
844 847 {
845 848 Elf_Section* sec = sections.at(i);
846 849 this->SymbolCount = sec->section_header->sh_size / sec->section_header->sh_entsize;
847 850 //Then list all symbols
848 851 for(int j=0;j<(int)this->SymbolCount;j++)
849 852 {
850 853 GElf_Sym* esym = (GElf_Sym*)malloc(sizeof(GElf_Sym));
851 854 gelf_getsym(sec->data, j, esym);
852 855 QString name = elf_strptr(this->e,sec->section_header->sh_link,esym->st_name);
853 856 Elf_Symbol* sym = new Elf_Symbol(name,esym);
854 857 symbols.append(sym);
855 858 }
856 859 }
857 860 }
858 861
859 862 }
860 863
861 864
862 865
863 866 QString ElfFile::getSectionType(int index)
864 867 {
865 868 QString type("");
866 869 if(this->e!=NULL)
867 870 {
868 871 if(index < this->sections.count())
869 872 {
870 873 switch(this->sections.at(index)->section_header->sh_type)
871 874 {
872 875 case SHT_NULL : type = "Section header table entry unused"; break;
873 876 case SHT_PROGBITS : type = "Program data"; break;
874 877 case SHT_SYMTAB : type = "Symbol table"; break;
875 878 case SHT_STRTAB : type = "String table"; break;
876 879 case SHT_RELA : type = "Relocation entries with addends"; break;
877 880 case SHT_HASH : type = "Symbol hash table"; break;
878 881 case SHT_DYNAMIC : type = "Dynamic linking information"; break;
879 882 case SHT_NOTE : type = "Notes"; break;
880 883 case SHT_NOBITS :type = "Program space with no data (bss)"; break;
881 884 case SHT_REL :type = "Relocation entries, no addends"; break;
882 885 case SHT_SHLIB : type = "Reserved"; break;
883 886 case SHT_DYNSYM : type = "Dynamic linker symbol table"; break;
884 887 case SHT_INIT_ARRAY : type = "Array of constructors"; break;
885 888 case SHT_FINI_ARRAY : type = "Array of destructors"; break;
886 889 case SHT_PREINIT_ARRAY : type = "Array of pre-constructors"; break;
887 890 case SHT_GROUP : type = "Section group"; break;
888 891 case SHT_SYMTAB_SHNDX : type = "Extended section indeces"; break;
889 892 case SHT_NUM : type = "Number of defined types. "; break;
890 893 case SHT_LOOS : type = "Start OS-specific. "; break;
891 894 case SHT_LOSUNW : type = "Sun-specific low bound. "; break;
892 895 case SHT_SUNW_COMDAT : type = " "; break;
893 896 case SHT_SUNW_syminfo : type = " "; break;
894 897 case SHT_GNU_verdef : type = "Version definition section. "; break;
895 898 case SHT_GNU_verneed : type = "Version needs section. "; break;
896 899 case SHT_GNU_versym : type = "Version symbol table. "; break;
897 900 case SHT_LOPROC : type = "Start of processor-specific"; break;
898 901 case SHT_HIPROC : type = "End of processor-specific"; break;
899 902 case SHT_HIUSER : type = "End of application-specific"; break;
900 903 }
901 904 }
902 905 }
903 906 return type;
904 907 }
905 908
906 909 int ElfFile::getSectionIndex(QString name)
907 910 {
908 911 if(this->e!=NULL)
909 912 {
910 913 for(int i=0;i<sections.count();i++)
911 914 {
912 915 if(getSectionName(i)==name)
913 916 return i;
914 917 }
915 918 }
916 919 return -1;
917 920 }
918 921
919 922 bool ElfFile::sectionIsNobits(int index)
920 923 {
921 924 if(this->e!=NULL)
922 925 {
923 926 if(index < this->sections.count())
924 927 {
925 928 return this->sections.at(index)->section_header->sh_type== SHT_NOBITS;
926 929 }
927 930 }
928 931 return false;
929 932 }
930 933
931 934 QString ElfFile::getSymbolName(int index)
932 935 {
933 936 if(this->e!=NULL)
934 937 {
935 938 if(index < this->symbols.count())
936 939 {
937 940 return symbols.at(index)->name;
938 941 }
939 942 }
940 943 return "";
941 944 }
942 945
943 946 QString ElfFile::getSymbolType(int index)
944 947 {
945 948 if(this->e!=NULL)
946 949 {
947 950 if(index < this->symbols.count())
948 951 {
949 952 int type = GELF_ST_TYPE(symbols.at(index)->sym->st_info);
950 953 switch(type)
951 954 {
952 955 case STT_NOTYPE:
953 956 return "No Type";
954 957 break;
955 958 case STT_OBJECT:
956 959 return "Object";
957 960 break;
958 961 case STT_FUNC:
959 962 return "Function";
960 963 break;
961 964 case STT_SECTION:
962 965 return "Section";
963 966 break;
964 967 case STT_FILE:
965 968 return "File";
966 969 break;
967 970 case STT_COMMON:
968 971 return "Common data object";
969 972 break;
970 973 case STT_TLS:
971 974 return "Thread-local data object";
972 975 break;
973 976 case STT_NUM:
974 977 return "Number of defined types";
975 978 break;
976 979 case STT_LOOS:
977 980 return "Start of OS-specific";
978 981 break;
979 982 case STT_HIOS:
980 983 return "End of OS-specific";
981 984 break;
982 985 case STT_LOPROC:
983 986 return "Start of processor-specific";
984 987 break;
985 988 case STT_HIPROC:
986 989 return "End of processor-specific";
987 990 break;
988 991 default:
989 992 return "none";
990 993 break;
991 994 }
992 995 }
993 996 }
994 997 return "none";
995 998 }
996 999
997 1000 quint64 ElfFile::getSymbolSize(int index)
998 1001 {
999 1002 if(this->e!=NULL)
1000 1003 {
1001 1004 if((index < this->symbols.count()) && (index>=0))
1002 1005 {
1003 1006 return symbols.at(index)->sym->st_size;
1004 1007 }
1005 1008 }
1006 1009 return 0;
1007 1010 }
1008 1011
1009 1012 QString ElfFile::getSymbolSectionName(int index)
1010 1013 {
1011 1014 if(this->e!=NULL)
1012 1015 {
1013 1016 if((index < this->symbols.count()) && (index>=0))
1014 1017 {
1015 1018 return getSectionName(symbols.at(index)->sym->st_shndx-1);
1016 1019 }
1017 1020 }
1018 1021 return "none";
1019 1022 }
1020 1023
1021 1024 int ElfFile::getSymbolSectionIndex(int index)
1022 1025 {
1023 1026 if(this->e!=NULL)
1024 1027 {
1025 1028 if((index < this->symbols.count()) && (index>=0))
1026 1029 {
1027 1030 return symbols.at(index)->sym->st_shndx;
1028 1031 }
1029 1032 }
1030 1033 return 0;
1031 1034 }
1032 1035
1033 1036 quint64 ElfFile::getSymbolAddress(int index)
1034 1037 {
1035 1038 if(this->e!=NULL)
1036 1039 {
1037 1040 if((index < this->symbols.count()) && (index>=0))
1038 1041 {
1039 1042 return symbols.at(index)->sym->st_value;
1040 1043 }
1041 1044 }
1042 1045 return 0;
1043 1046 }
1044 1047
1045 1048 QString ElfFile::getSymbolLinkType(int index)
1046 1049 {
1047 1050 if(this->e!=NULL)
1048 1051 {
1049 1052 if(index < this->symbols.count())
1050 1053 {
1051 1054 int btype = GELF_ST_BIND(symbols.at(index)->sym->st_info);
1052 1055 switch(btype)
1053 1056 {
1054 1057 case STB_LOCAL:
1055 1058 return "Local";
1056 1059 break;
1057 1060 case STB_GLOBAL:
1058 1061 return "Global";
1059 1062 break;
1060 1063 case STB_WEAK:
1061 1064 return "Weak";
1062 1065 break;
1063 1066 case STB_NUM:
1064 1067 return "Number of defined types";
1065 1068 break;
1066 1069 case STB_LOOS:
1067 1070 return "Start of OS-specific";
1068 1071 break;
1069 1072 case STB_HIOS:
1070 1073 return "End of OS-specific";
1071 1074 break;
1072 1075 case STB_LOPROC:
1073 1076 return "Start of processor-specific";
1074 1077 break;
1075 1078 case STB_HIPROC:
1076 1079 return "End of processor-specific";
1077 1080 break;
1078 1081 default:
1079 1082 return "none";
1080 1083 break;
1081 1084 }
1082 1085 }
1083 1086 }
1084 1087 return "none";
1085 1088 }
1086 1089
1087 1090 bool ElfFile::isElf(const QString &File)
1088 1091 {
1089 1092 int file =0;
1090 1093 #ifdef _ELF_WINDOWS_
1091 1094 file = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0);
1092 1095 #else
1093 1096 file = open(File.toStdString().c_str(),O_RDONLY ,0);
1094 1097 #endif
1095 1098 char Magic[4];
1096 1099 if(file!=-1)
1097 1100 {
1098 1101 size_t res = read(file,Magic,4);
1099 1102 close(file);
1100 1103 if((res==4) && (Magic[0]==0x7f) && (Magic[1]==0x45) && (Magic[2]==0x4c) && (Magic[3]==0x46))
1101 1104 {
1102 1105 return true;
1103 1106 }
1104 1107 }
1105 1108 return false;
1106 1109 }
1107 1110
1108 1111 bool ElfFile::toSrec(const QString &File)
1109 1112 {
1110 1113 return srecFile::toSrec(this->getFragments(),File);
1111 1114 }
1112 1115
1113 1116 bool ElfFile::toBinary(const QString &File)
1114 1117 {
1115 1118 return binaryFile::toBinary(getFragments(),File);
1116 1119 }
@@ -1,249 +1,249
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>genericBinaryFileWidget</class>
4 4 <widget class="QWidget" name="genericBinaryFileWidget">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 9 <width>878</width>
10 10 <height>360</height>
11 11 </rect>
12 12 </property>
13 13 <property name="acceptDrops">
14 14 <bool>false</bool>
15 15 </property>
16 16 <property name="windowTitle">
17 17 <string>Form</string>
18 18 </property>
19 19 <layout class="QHBoxLayout" name="horizontalLayout">
20 20 <property name="spacing">
21 21 <number>0</number>
22 22 </property>
23 23 <property name="leftMargin">
24 24 <number>0</number>
25 25 </property>
26 26 <property name="topMargin">
27 27 <number>2</number>
28 28 </property>
29 29 <property name="rightMargin">
30 30 <number>2</number>
31 31 </property>
32 32 <property name="bottomMargin">
33 33 <number>2</number>
34 34 </property>
35 35 <item>
36 36 <widget class="QWidget" name="showFileListWdgt" native="true">
37 37 <layout class="QVBoxLayout" name="verticalLayout">
38 38 <property name="margin">
39 39 <number>0</number>
40 40 </property>
41 41 <item>
42 42 <widget class="QVPushButton" name="showFileListQpb">
43 43 <property name="text">
44 44 <string>File list</string>
45 45 </property>
46 46 </widget>
47 47 </item>
48 48 <item>
49 49 <spacer name="showFileListVSpacer">
50 50 <property name="orientation">
51 51 <enum>Qt::Vertical</enum>
52 52 </property>
53 53 <property name="sizeHint" stdset="0">
54 54 <size>
55 55 <width>20</width>
56 56 <height>40</height>
57 57 </size>
58 58 </property>
59 59 </spacer>
60 60 </item>
61 61 </layout>
62 62 </widget>
63 63 </item>
64 64 <item>
65 65 <widget class="QSplitter" name="splitter">
66 66 <property name="orientation">
67 67 <enum>Qt::Horizontal</enum>
68 68 </property>
69 69 <widget class="QGroupBox" name="fileListGBox">
70 70 <property name="title">
71 71 <string>File list</string>
72 72 </property>
73 73 <layout class="QVBoxLayout" name="verticalLayout_2">
74 74 <property name="spacing">
75 75 <number>2</number>
76 76 </property>
77 77 <property name="margin">
78 78 <number>2</number>
79 79 </property>
80 80 <item>
81 81 <widget class="QWidget" name="fileListWdgt" native="true">
82 82 <layout class="QGridLayout" name="gridLayout">
83 83 <property name="margin">
84 84 <number>2</number>
85 85 </property>
86 86 <property name="spacing">
87 87 <number>2</number>
88 88 </property>
89 89 <item row="1" column="3">
90 90 <widget class="QPushButton" name="hideFileListQpb">
91 91 <property name="minimumSize">
92 92 <size>
93 93 <width>16</width>
94 94 <height>16</height>
95 95 </size>
96 96 </property>
97 97 <property name="maximumSize">
98 98 <size>
99 99 <width>16</width>
100 100 <height>16</height>
101 101 </size>
102 102 </property>
103 103 <property name="text">
104 104 <string/>
105 105 </property>
106 106 <property name="icon">
107 <iconset resource="genericBinaryFiles.qrc">
108 <normaloff>:/img/ressources/Gnome-emblem-unreadable.svg</normaloff>:/img/ressources/Gnome-emblem-unreadable.svg</iconset>
107 <iconset resource="ressources/genericBinaryFiles.qrc">
108 <normaloff>:/img/Gnome-emblem-unreadable.png</normaloff>:/img/Gnome-emblem-unreadable.png</iconset>
109 109 </property>
110 110 </widget>
111 111 </item>
112 112 <item row="2" column="0" colspan="4">
113 113 <widget class="FileList" name="fileList">
114 114 <property name="dragEnabled">
115 115 <bool>false</bool>
116 116 </property>
117 117 <column>
118 118 <property name="text">
119 119 <string>File</string>
120 120 </property>
121 121 </column>
122 122 <column>
123 123 <property name="text">
124 124 <string>Type</string>
125 125 </property>
126 126 </column>
127 127 </widget>
128 128 </item>
129 129 <item row="1" column="0" colspan="3">
130 130 <spacer name="horizontalSpacer_2">
131 131 <property name="orientation">
132 132 <enum>Qt::Horizontal</enum>
133 133 </property>
134 134 <property name="sizeHint" stdset="0">
135 135 <size>
136 136 <width>40</width>
137 137 <height>20</height>
138 138 </size>
139 139 </property>
140 140 </spacer>
141 141 </item>
142 142 <item row="3" column="1">
143 143 <widget class="QPushButton" name="removeFileQpb">
144 144 <property name="minimumSize">
145 145 <size>
146 146 <width>32</width>
147 147 <height>32</height>
148 148 </size>
149 149 </property>
150 150 <property name="maximumSize">
151 151 <size>
152 152 <width>32</width>
153 153 <height>32</height>
154 154 </size>
155 155 </property>
156 156 <property name="text">
157 157 <string/>
158 158 </property>
159 159 <property name="icon">
160 <iconset resource="genericBinaryFiles.qrc">
161 <normaloff>:/img/ressources/Gnome-user-trash.svg</normaloff>:/img/ressources/Gnome-user-trash.svg</iconset>
160 <iconset resource="ressources/genericBinaryFiles.qrc">
161 <normaloff>:/img/Gnome-user-trash.png</normaloff>:/img/Gnome-user-trash.png</iconset>
162 162 </property>
163 163 <property name="iconSize">
164 164 <size>
165 165 <width>24</width>
166 166 <height>24</height>
167 167 </size>
168 168 </property>
169 169 </widget>
170 170 </item>
171 171 <item row="3" column="0">
172 172 <widget class="QPushButton" name="openFileQpb">
173 173 <property name="minimumSize">
174 174 <size>
175 175 <width>32</width>
176 176 <height>32</height>
177 177 </size>
178 178 </property>
179 179 <property name="maximumSize">
180 180 <size>
181 181 <width>32</width>
182 182 <height>32</height>
183 183 </size>
184 184 </property>
185 185 <property name="text">
186 186 <string/>
187 187 </property>
188 188 <property name="icon">
189 <iconset resource="genericBinaryFiles.qrc">
190 <normaloff>:/img/ressources/Gnome-list-add.svg</normaloff>:/img/ressources/Gnome-list-add.svg</iconset>
189 <iconset resource="ressources/genericBinaryFiles.qrc">
190 <normaloff>:/img/Gnome-list-add.png</normaloff>:/img/Gnome-list-add.png</iconset>
191 191 </property>
192 192 <property name="iconSize">
193 193 <size>
194 194 <width>24</width>
195 195 <height>24</height>
196 196 </size>
197 197 </property>
198 198 </widget>
199 199 </item>
200 200 <item row="3" column="2" colspan="2">
201 201 <spacer name="horizontalSpacer">
202 202 <property name="orientation">
203 203 <enum>Qt::Horizontal</enum>
204 204 </property>
205 205 <property name="sizeHint" stdset="0">
206 206 <size>
207 207 <width>40</width>
208 208 <height>20</height>
209 209 </size>
210 210 </property>
211 211 </spacer>
212 212 </item>
213 213 </layout>
214 214 </widget>
215 215 </item>
216 216 </layout>
217 217 </widget>
218 218 <widget class="QTabWidget" name="fileViewerTab">
219 219 <property name="minimumSize">
220 220 <size>
221 221 <width>300</width>
222 222 <height>0</height>
223 223 </size>
224 224 </property>
225 225 <property name="currentIndex">
226 226 <number>-1</number>
227 227 </property>
228 228 </widget>
229 229 </widget>
230 230 </item>
231 231 </layout>
232 232 </widget>
233 233 <customwidgets>
234 234 <customwidget>
235 235 <class>FileList</class>
236 236 <extends>QTableWidget</extends>
237 237 <header>filelist.h</header>
238 238 </customwidget>
239 239 <customwidget>
240 240 <class>QVPushButton</class>
241 241 <extends>QPushButton</extends>
242 242 <header>qvpushbutton.h</header>
243 243 </customwidget>
244 244 </customwidgets>
245 245 <resources>
246 <include location="genericBinaryFiles.qrc"/>
246 <include location="ressources/genericBinaryFiles.qrc"/>
247 247 </resources>
248 248 <connections/>
249 249 </ui>
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now