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