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