Some Python wrapping improvment.
Jeandet Alexis -
r39:95ec6cf42fc5 default
Not Reviewed
Show More
Add another comment
TODOs: 0 unresolved 0 Resolved
COMMENTS: 0 General 0 Inline
@@ -1,11 +1,12
1 #include <QObject>
1 #include <QtCore/QObject>
2 #include <QWidget>
2 #include <QtWidgets/QtWidgets>
3 #include "qhexspinbox.h"
3 #include "qhexspinbox.h"
4 #include "memsizewdgt.h"
4 #include "memsizewdgt.h"
5 #include "qhexedit/qhexedit.h"
5 #include "qhexedit/qhexedit.h"
6 #include "SocExplorerPlot.h"
6 #include "SocExplorerPlot.h"
7 #include "tcp_terminal_client.h"
7 #include "tcp_terminal_client.h"
8 #include "elf/elfparser.h"
8 #include "elf/elfparser.h"
9 #include "elf/abstractexecfile.h"
9 #include "abstractexecfile.h"
10 #include "elf/elffile.h"
10 #include "elf/elffile.h"
11 #include "elf/elffilewidget.h"
11 #include "elf/elffilewidget.h"
12 #include "elf/elfinfowdgt.h"
@@ -21,17 +21,10
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "abstractexecfile.h"
22 #include "abstractexecfile.h"
23
23
24 abstractExecFile::abstractExecFile()
25 {
26 }
27
28 abstractExecFile::abstractExecFile(const QString &File)
29 {
30
31 }
32
33
24
34 codeFragment::codeFragment()
25 codeFragment::codeFragment()
35 {
26 {
36
27 data = NULL;
28 size = 0;
29 address = 0;
37 }
30 }
@@ -22,26 +22,27
22 #ifndef ABSTRACTEXECFILE_H
22 #ifndef ABSTRACTEXECFILE_H
23 #define ABSTRACTEXECFILE_H
23 #define ABSTRACTEXECFILE_H
24
24
25 #include <QObject>
25 #include <QtCore/QObject>
26
26
27 class codeFragment
27 class codeFragment
28 {
28 {
29 public:
29 public:
30 codeFragment();
30 codeFragment();
31 codeFragment(char* data, quint32 size, quint32 address):data(data),size(size),address(address){}
31 char* data;
32 char* data;
32 quint32 size;
33 quint32 size;
33 quint32 address;
34 quint32 address;
34 };
35 };
35
36
36 class abstractExecFile
37 class abstractExecFile : public QObject
37 {
38 {
39 Q_OBJECT
38 public:
40 public:
39 abstractExecFile();
41 // virtual abstractExecFile()=0;
40 abstractExecFile(const QString& File);
41 virtual bool openFile(const QString& File)=0;
42 virtual bool openFile(const QString& File)=0;
42 virtual bool isopened()=0;
43 virtual bool isopened()=0;
43 virtual int closeFile()=0;
44 virtual int closeFile()=0;
44 virtual QList<codeFragment> getFragments()=0;
45 virtual QList<codeFragment*> getFragments()=0;
45
46
46 protected:
47 protected:
47 QString p_fileName;
48 QString p_fileName;
@@ -109,6 +109,9 SOURCES += \
109 FORMS += \
109 FORMS += \
110 elf/elffilewidget.ui
110 elf/elffilewidget.ui
111
111
112 OTHER_FILES += \
113 ./pythongenerator.sh \
114 ./pythonQtgeneratorCfg.txt
112
115
113
116
114
117
This diff has been collapsed as it changes many lines, (746 lines changed) Show them Hide them
@@ -23,38 +23,71
23 ----------------------------------------------------------------------------*/
23 ----------------------------------------------------------------------------*/
24 #include "elffile.h"
24 #include "elffile.h"
25
25
26 ElfFile::ElfFile(QObject *parent)
26 ElfFile::ElfFile()
27 :QObject(parent),abstractExecFile(),elfparser()
27 :abstractExecFile()
28 {
28 {
29 this->opened = false;
30 this->type_elf = false;
31 this->elfFile = NULL;
32 this->e = NULL;
29 }
33 }
30
34
31 ElfFile::ElfFile(const QString &File, QObject *parent)
35 ElfFile::ElfFile(const QString &File)
32 :QObject(parent),abstractExecFile(),elfparser()
36 :abstractExecFile()
33 {
37 {
38 this->opened = false;
39 this->type_elf = false;
40 this->elfFile = NULL;
41 this->e = NULL;
34 this->p_fileName = File;
42 this->p_fileName = File;
35 setFilename(File);
43 openFile(File);
36 }
44 }
37
45
38 bool ElfFile::openFile(const QString &File)
46 bool ElfFile::openFile(const QString &File)
39 {
47 {
40 this->p_fileName = File;
48 this->p_fileName = File;
41 return setFilename(File);
49 this->closeFile();
50 if(elf_version(EV_CURRENT)==EV_NONE)return 0;
51 #ifdef _ELF_WINDOWS_
52 this->elfFile = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0);
53 #else
54 this->elfFile = open(File.toStdString().c_str(),O_RDONLY ,0);
55 #endif
56 if(this->elfFile==NULL)return 0;
57 this->e = elf_begin(this->elfFile,ELF_C_READ,NULL);
58 if(this->e==NULL)return 0;
59 this->ek = elf_kind(this->e);
60 gelf_getehdr (this->e, &this->ehdr );
61 elf_getshdrstrndx (this->e, &this->shstrndx);
62 this->updateSegments();
63 this->updateSections();
64 return 1;
42 }
65 }
43
66
44 bool ElfFile::isopened()
67 bool ElfFile::isopened()
45 {
68 {
46 return elfparser::isopened();
69 return this->opened;
47 }
70 }
48
71
49 int ElfFile::closeFile()
72 int ElfFile::closeFile()
50 {
73 {
51 return elfparser::closeFile();
74 if(this->elfFile!=NULL)
75 {
76 if(this->e!=NULL)
77 {
78 elf_end(this->e);
79 this->e = NULL;
80 }
81 close(this->elfFile);
82 this->elfFile = NULL;
83 }
84 return 0;
52 }
85 }
53
86
54
87
55 QList<codeFragment> ElfFile::getFragments(QStringList fragmentList)
88 QList<codeFragment*> ElfFile::getFragments(QStringList fragmentList)
56 {
89 {
57 QList<codeFragment> fragments;
90 QList<codeFragment*> fragments;
58 if (isopened())
91 if (isopened())
59 {
92 {
60 for(int i =0;i<fragmentList.count();i++)
93 for(int i =0;i<fragmentList.count();i++)
@@ -65,22 +98,22 QList<codeFragment> ElfFile::getFragment
65 return fragments;
98 return fragments;
66 }
99 }
67
100
68 QList<codeFragment> ElfFile::getFragments()
101 QList<codeFragment*> ElfFile::getFragments()
69 {
102 {
70 return getFragments(QStringList()<<".data"<<".text");
103 return getFragments(QStringList()<<".data"<<".text");
71 }
104 }
72
105
73 codeFragment ElfFile::getFragment(const QString &name)
106 codeFragment *ElfFile::getFragment(const QString &name)
74 {
107 {
75 codeFragment fragment;
108 codeFragment* fragment= new codeFragment();
76 for(int i=0;i<getSectioncount();i++)
109 for(int i=0;i<getSectioncount();i++)
77 {
110 {
78 if(getSectionName(i) == name)
111 if(getSectionName(i) == name)
79 {
112 {
80 fragment.data =NULL;
113 fragment->data =NULL;
81 fragment.size = getSectionDatasz(i);
114 fragment->size = getSectionDatasz(i);
82 fragment.address = getSectionPaddr(i);
115 fragment->address = getSectionPaddr(i);
83 getSectionData(i,&fragment.data);
116 getSectionData(i,&fragment->data);
84 }
117 }
85 }
118 }
86
119
@@ -92,10 +125,687 codeFragment ElfFile::getFragment(const
92
125
93
126
94
127
128 QString elfresolveMachine(Elf64_Half e_machine)
129 {
130 QString machineName;
131 //Update from with bash script don't write it by yourself!
132 switch(e_machine)
133 {
134 case EM_NONE:
135 machineName = " No machine ";
136 break;
137 case EM_M32:
138 machineName = " AT&T WE 32100 ";
139 break;
140 case EM_SPARC:
141 machineName = " SUN SPARC ";
142 break;
143 case EM_386:
144 machineName = " Intel 80386 ";
145 break;
146 case EM_68K:
147 machineName = " Motorola m68k family ";
148 break;
149 case EM_88K:
150 machineName = " Motorola m88k family ";
151 break;
152 case EM_860:
153 machineName = " Intel 80860 ";
154 break;
155 case EM_MIPS:
156 machineName = " MIPS R3000 big-endian ";
157 break;
158 case EM_S370:
159 machineName = " IBM System/370 ";
160 break;
161 case EM_MIPS_RS3_LE:
162 machineName = " MIPS R3000 little-endian ";
163 break;
164 case EM_PARISC:
165 machineName = " HPPA ";
166 break;
167 case EM_VPP500:
168 machineName = " Fujitsu VPP500 ";
169 break;
170 case EM_SPARC32PLUS:
171 machineName = " Sun's \"v8plus\" ";
172 break;
173 case EM_960:
174 machineName = " Intel 80960 ";
175 break;
176 case EM_PPC:
177 machineName = " PowerPC ";
178 break;
179 case EM_PPC64:
180 machineName = " PowerPC 64-bit ";
181 break;
182 case EM_S390:
183 machineName = " IBM S390 ";
184 break;
185 case EM_V800:
186 machineName = " NEC V800 series ";
187 break;
188 case EM_FR20:
189 machineName = " Fujitsu FR20 ";
190 break;
191 case EM_RH32:
192 machineName = " TRW RH-32 ";
193 break;
194 case EM_RCE:
195 machineName = " Motorola RCE ";
196 break;
197 case EM_ARM:
198 machineName = " ARM ";
199 break;
200 case EM_FAKE_ALPHA:
201 machineName = " Digital Alpha ";
202 break;
203 case EM_SH:
204 machineName = " Hitachi SH ";
205 break;
206 case EM_SPARCV9:
207 machineName = " SPARC v9 64-bit ";
208 break;
209 case EM_TRICORE:
210 machineName = " Siemens Tricore ";
211 break;
212 case EM_ARC:
213 machineName = " Argonaut RISC Core ";
214 break;
215 case EM_H8_300:
216 machineName = " Hitachi H8/300 ";
217 break;
218 case EM_H8_300H:
219 machineName = " Hitachi H8/300H ";
220 break;
221 case EM_H8S:
222 machineName = " Hitachi H8S ";
223 break;
224 case EM_H8_500:
225 machineName = " Hitachi H8/500 ";
226 break;
227 case EM_IA_64:
228 machineName = " Intel Merced ";
229 break;
230 case EM_MIPS_X:
231 machineName = " Stanford MIPS-X ";
232 break;
233 case EM_COLDFIRE:
234 machineName = " Motorola Coldfire ";
235 break;
236 case EM_68HC12:
237 machineName = " Motorola M68HC12 ";
238 break;
239 case EM_MMA:
240 machineName = " Fujitsu MMA Multimedia Accelerator";
241 break;
242 case EM_PCP:
243 machineName = " Siemens PCP ";
244 break;
245 case EM_NCPU:
246 machineName = " Sony nCPU embeeded RISC ";
247 break;
248 case EM_NDR1:
249 machineName = " Denso NDR1 microprocessor ";
250 break;
251 case EM_STARCORE:
252 machineName = " Motorola Start*Core processor ";
253 break;
254 case EM_ME16:
255 machineName = " Toyota ME16 processor ";
256 break;
257 case EM_ST100:
258 machineName = " STMicroelectronic ST100 processor ";
259 break;
260 case EM_TINYJ:
261 machineName = " Advanced Logic Corp. Tinyj emb.fam";
262 break;
263 case EM_X86_64:
264 machineName = " AMD x86-64 architecture ";
265 break;
266 case EM_PDSP:
267 machineName = " Sony DSP Processor ";
268 break;
269 case EM_FX66:
270 machineName = " Siemens FX66 microcontroller ";
271 break;
272 case EM_ST9PLUS:
273 machineName = " STMicroelectronics ST9+ 8/16 mc ";
274 break;
275 case EM_ST7:
276 machineName = " STmicroelectronics ST7 8 bit mc ";
277 break;
278 case EM_68HC16:
279 machineName = " Motorola MC68HC16 microcontroller ";
280 break;
281 case EM_68HC11:
282 machineName = " Motorola MC68HC11 microcontroller ";
283 break;
284 case EM_68HC08:
285 machineName = " Motorola MC68HC08 microcontroller ";
286 break;
287 case EM_68HC05:
288 machineName = " Motorola MC68HC05 microcontroller ";
289 break;
290 case EM_SVX:
291 machineName = " Silicon Graphics SVx ";
292 break;
293 case EM_ST19:
294 machineName = " STMicroelectronics ST19 8 bit mc ";
295 break;
296 case EM_VAX:
297 machineName = " Digital VAX ";
298 break;
299 case EM_CRIS:
300 machineName = " Axis Communications 32-bit embedded processor ";
301 break;
302 case EM_JAVELIN:
303 machineName = " Infineon Technologies 32-bit embedded processor ";
304 break;
305 case EM_FIREPATH:
306 machineName = " Element 14 64-bit DSP Processor ";
307 break;
308 case EM_ZSP:
309 machineName = " LSI Logic 16-bit DSP Processor ";
310 break;
311 case EM_MMIX:
312 machineName = " Donald Knuth's educational 64-bit processor ";
313 break;
314 case EM_HUANY:
315 machineName = " Harvard University machine-independent object files ";
316 break;
317 case EM_PRISM:
318 machineName = " SiTera Prism ";
319 break;
320 case EM_AVR:
321 machineName = " Atmel AVR 8-bit microcontroller ";
322 break;
323 case EM_FR30:
324 machineName = " Fujitsu FR30 ";
325 break;
326 case EM_D10V:
327 machineName = " Mitsubishi D10V ";
328 break;
329 case EM_D30V:
330 machineName = " Mitsubishi D30V ";
331 break;
332 case EM_V850:
333 machineName = " NEC v850 ";
334 break;
335 case EM_M32R:
336 machineName = " Mitsubishi M32R ";
337 break;
338 case EM_MN10300:
339 machineName = " Matsushita MN10300 ";
340 break;
341 case EM_MN10200:
342 machineName = " Matsushita MN10200 ";
343 break;
344 case EM_PJ:
345 machineName = " picoJava ";
346 break;
347 case EM_OPENRISC:
348 machineName = " OpenRISC 32-bit embedded processor ";
349 break;
350 case EM_ARC_A5:
351 machineName = " ARC Cores Tangent-A5 ";
352 break;
353 case EM_XTENSA:
354 machineName = " Tensilica Xtensa Architecture ";
355 break;
356 case EM_AARCH64:
357 machineName = " ARM AARCH64 ";
358 break;
359 case EM_TILEPRO:
360 machineName = " Tilera TILEPro ";
361 break;
362 case EM_MICROBLAZE:
363 machineName = " Xilinx MicroBlaze ";
364 break;
365 case EM_TILEGX:
366 machineName = " Tilera TILE-Gx ";
367 break;
368 case EM_NUM:
369 machineName = "";
370 break;
371 default:
372 machineName ="Unknow Machine";
373 break;
374 }
375 return machineName;
376 }
377
378
379
380
381 QString ElfFile::getClass()
382 {
383 if(this->e!=NULL)
384 {
385 int eclass = gelf_getclass(this->e);
386 if(eclass==ELFCLASS32)return "ELF32";
387 if(eclass==ELFCLASS64)return "ELF64";
388 }
389 return "none";
390 }
391
392
393 bool ElfFile::iself()
394 {
395 return this->type_elf;
396 }
397
398 QString ElfFile::getArchitecture()
399 {
400 if(this->e!=NULL)
401 {
402 return elfresolveMachine(this->ehdr.e_machine);
403 }
404 return "";
405 }
406
407
408 QString ElfFile::getType()
409 {
410 QString kind("");
411 if(this->e!=NULL)
412 {
413 switch(this->ek)
414 {
415 case ELF_K_AR:
416 kind = "Archive";
417 break;
418 case ELF_K_ELF:
419 kind = "Elf";
420 break;
421 case ELF_K_COFF:
422 kind = "COFF";
423 break;
424 case ELF_K_NUM:
425 kind = "NUM";
426 break;
427 case ELF_K_NONE:
428 kind = "Data";
429 break;
430 default:
431 kind = "Unknow";
432 break;
433 }
434 }
435 return kind;
436 }
437
438 QString ElfFile::getEndianness()
439 {
440 if(this->e!=NULL)
441 {
442 if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return "2's complement, little endian";
443 if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return "2's complement, big endian";
444 }
445 return "none";
446 }
447
448 QString ElfFile::getABI()
449 {
450 if(this->e!=NULL)
451 {
452 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NONE)return "UNIX System V ABI";
453 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SYSV)return "Alias";
454 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_HPUX)return "HP-UX";
455 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NETBSD)return "NetBSD";
456 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_GNU)return "Object uses GNU ELF extensions";
457 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_LINUX)return "Compatibility alias";
458 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SOLARIS)return "Sun Solaris";
459 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_AIX)return "IBM AIX";
460 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_IRIX)return "SGI Irix";
461 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_FREEBSD)return "FreeBSD";
462 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_TRU64)return "Compaq TRU64 UNIX";
463 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_MODESTO)return " Novell Modesto";
464 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_OPENBSD)return "OpenBSD";
465 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM_AEABI)return "ARM EABI";
466 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM)return "ARM";
467 if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_STANDALONE)return "Standalone (embedded) application";
468 }
469 return "none";
470 }
471
472
473 qint64 ElfFile::getVersion()
474 {
475 if(this->e!=NULL)
476 {
477 return this->ehdr.e_version;
478 }
479 }
480
481 qint64 ElfFile::getEntryPointAddress()
482 {
483 if(this->e!=NULL)
484 {
485 return this->ehdr.e_entry;
486 }
487 }
488
489
490 int ElfFile::getSectioncount()
491 {
492 return (int)this->SectionCount;
493 }
494
495
496 int ElfFile::getSegmentcount()
497 {
498 return (int)this->SegmentCount;
499 }
500
501
502 QString ElfFile::getSegmentType(int index)
503 {
504 QString type("");
505 if(this->e!=NULL)
506 {
507 if(index < this->Segments.count())
508 {
509 switch(this->Segments.at(index)->p_type)
510 {
511 case PT_NULL:
512 type = "Program header table entry unused";
513 break;
514 case PT_LOAD:
515 type = "Loadable program segment";
516 break;
517 case PT_DYNAMIC :
518 type = "Dynamic linking information";
519 break;
520 case PT_INTERP:
521 type ="Program interpreter";
522 break;
523 case PT_NOTE:
524 type = "Auxiliary information";
525 break;
526 case PT_SHLIB:
527 type = "Reserved";
528 break;
529 case PT_PHDR:
530 type = "Entry for header table itself";
531 break;
532 case PT_TLS:
533 type = "Thread-local storage segment";
534 break;
535 case PT_NUM:
536 type = "Number of defined types";
537 break;
538 case PT_LOOS:
539 type = "Start of OS-specific";
540 break;
541 case PT_SUNWSTACK:
542 type = "Stack segment";
543 break;
544 case PT_LOPROC:
545 type = "Start of processor-specific";
546 break;
547 case PT_HIPROC:
548 type = "End of processor-specific";
549 break;
550 default:
551 type = "Unknow Section Type";
552 break;
553 }
554 }
555 }
556
557 return type;
558 }
559
560
561 qint64 ElfFile::getSegmentOffset(int index)
562 {
563 int64_t Offset;
564 if(this->e!=NULL)
565 {
566 if(index < this->Segments.count())
567 {
568 Offset = (int64_t)this->Segments.at(index)->p_offset;
569 }
570 }
571 return Offset;
572 }
573
574
575 qint64 ElfFile::getSegmentVaddr(int index)
576 {
577 int64_t Vaddr = 0;
578 if(this->e!=NULL)
579 {
580 if(index < this->Segments.count())
581 {
582 Vaddr = (int64_t)this->Segments.at(index)->p_vaddr;
583 }
584 }
585 return Vaddr;
586 }
587
588
589 qint64 ElfFile::getSegmentPaddr(int index)
590 {
591 int64_t Paddr=0;
592 if(this->e!=NULL)
593 {
594 if(index < this->Segments.count())
595 {
596 Paddr = (int64_t)this->Segments.at(index)->p_paddr;
597 }
598 }
599 return Paddr;
600 }
601
602 qint64 ElfFile::getSectionPaddr(int index)
603 {
604 int64_t Paddr=0;
605 if(this->e!=NULL)
606 {
607 if(index < this->sections.count())
608 {
609 Paddr = (int64_t)this->sections.at(index)->section_header->sh_addr;
610 }
611 }
612 return Paddr;
613 }
614
615
616 qint64 ElfFile::getSegmentFilesz(int index)
617 {
618 int64_t FileSz=0;
619 if(this->e!=NULL)
620 {
621 if(index < this->Segments.count())
622 {