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