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