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