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