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