@@ -0,0 +1,30 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | #include "abstractbinfile.h" | |
|
23 | ||
|
24 | ||
|
25 | codeFragment::codeFragment() | |
|
26 | { | |
|
27 | data = NULL; | |
|
28 | size = 0; | |
|
29 | address = 0; | |
|
30 | } |
@@ -0,0 +1,71 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | #ifndef ABSTRACTBINFILE_H | |
|
23 | #define ABSTRACTBINFILE_H | |
|
24 | ||
|
25 | #include <QtCore/QObject> | |
|
26 | #include <QtWidgets/QWidget> | |
|
27 | ||
|
28 | class codeFragment | |
|
29 | { | |
|
30 | public: | |
|
31 | codeFragment(); | |
|
32 | codeFragment(char* data, quint64 size, quint64 address):data(data),size(size),address(address){} | |
|
33 | ~codeFragment() | |
|
34 | { | |
|
35 | free(data); | |
|
36 | } | |
|
37 | QString header; | |
|
38 | char* data; | |
|
39 | quint64 size; | |
|
40 | quint64 address; | |
|
41 | }; | |
|
42 | ||
|
43 | class abstractBinFile : public QObject | |
|
44 | { | |
|
45 | Q_OBJECT | |
|
46 | public: | |
|
47 | ||
|
48 | virtual bool openFile(const QString& File)=0; | |
|
49 | virtual bool isopened()=0; | |
|
50 | virtual int closeFile()=0; | |
|
51 | virtual QList<codeFragment*> getFragments()=0; | |
|
52 | virtual bool toSrec(const QString& File)=0; | |
|
53 | virtual bool toBinary(const QString& File)=0; | |
|
54 | protected: | |
|
55 | QString p_fileName; | |
|
56 | }; | |
|
57 | ||
|
58 | ||
|
59 | class abstractBinFileWidget : public QWidget | |
|
60 | { | |
|
61 | Q_OBJECT | |
|
62 | ||
|
63 | public: | |
|
64 | abstractBinFileWidget(QWidget* parent = 0):QWidget(parent){} | |
|
65 | ||
|
66 | public slots: | |
|
67 | virtual void setFile(abstractBinFile* file)=0; | |
|
68 | virtual void reloadFile()=0; | |
|
69 | }; | |
|
70 | ||
|
71 | #endif // ABSTRACTBINFILE_H |
This diff has been collapsed as it changes many lines, (1075 lines changed) Show them Hide them | |||
@@ -0,0 +1,1075 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : | |
|
20 | Alexis Jeandet | |
|
21 | -- Mail : | |
|
22 | alexis.jeandet@member.fsf.org | |
|
23 | ----------------------------------------------------------------------------*/ | |
|
24 | #include "elffile.h" | |
|
25 | #include "srecfile.h" | |
|
26 | #include "binaryfile.h" | |
|
27 | #include <stdint.h> | |
|
28 | ||
|
29 | ElfFile::ElfFile() | |
|
30 | :abstractBinFile() | |
|
31 | { | |
|
32 | this->opened = false; | |
|
33 | this->type_elf = false; | |
|
34 | this->elfFile = (int)NULL; | |
|
35 | this->e = NULL; | |
|
36 | } | |
|
37 | ||
|
38 | ElfFile::ElfFile(const QString &File) | |
|
39 | :abstractBinFile() | |
|
40 | { | |
|
41 | this->opened = false; | |
|
42 | this->type_elf = false; | |
|
43 | this->elfFile = (int)NULL; | |
|
44 | this->e = NULL; | |
|
45 | this->p_fileName = File; | |
|
46 | openFile(File); | |
|
47 | } | |
|
48 | ||
|
49 | ElfFile::~ElfFile() | |
|
50 | { | |
|
51 | closeFile(); | |
|
52 | if(scn)free(scn); | |
|
53 | if(data)free(data); | |
|
54 | for(int i=0;i<this->sections.count();i++) | |
|
55 | { | |
|
56 | delete this->sections.at(i); | |
|
57 | } | |
|
58 | this->sections.clear(); | |
|
59 | for(int i=0;i<this->Segments.count();i++) | |
|
60 | { | |
|
61 | free(this->Segments.at(i)); | |
|
62 | } | |
|
63 | this->Segments.clear(); | |
|
64 | for(int i=0;i<symbols.count();i++) | |
|
65 | { | |
|
66 | delete this->symbols.at(i); | |
|
67 | } | |
|
68 | this->symbols.clear(); | |
|
69 | } | |
|
70 | ||
|
71 | bool ElfFile::openFile(const QString &File) | |
|
72 | { | |
|
73 | this->p_fileName = File; | |
|
74 | this->closeFile(); | |
|
75 | if(elf_version(EV_CURRENT)==EV_NONE)return 0; | |
|
76 | #ifdef _ELF_WINDOWS_ | |
|
77 | this->elfFile = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0); | |
|
78 | #else | |
|
79 | this->elfFile = open(File.toStdString().c_str(),O_RDONLY ,0); | |
|
80 | #endif | |
|
81 | if(this->elfFile==(int)NULL)return 0; | |
|
82 | this->e = elf_begin(this->elfFile,ELF_C_READ,NULL); | |
|
83 | if(this->e==NULL)return 0; | |
|
84 | this->ek = elf_kind(this->e); | |
|
85 | gelf_getehdr (this->e, &this->ehdr ); | |
|
86 | elf_getshdrstrndx (this->e, &this->shstrndx); | |
|
87 | this->updateSegments(); | |
|
88 | this->updateSections(); | |
|
89 | this->updateSymbols(); | |
|
90 | this->opened = true; | |
|
91 | return 1; | |
|
92 | } | |
|
93 | ||
|
94 | bool ElfFile::isopened() | |
|
95 | { | |
|
96 | return this->opened; | |
|
97 | } | |
|
98 | ||
|
99 | int ElfFile::closeFile() | |
|
100 | { | |
|
101 | if(this->elfFile!=(int)NULL) | |
|
102 | { | |
|
103 | if(this->e!=NULL) | |
|
104 | { | |
|
105 | elf_end(this->e); | |
|
106 | this->e = NULL; | |
|
107 | } | |
|
108 | close(this->elfFile); | |
|
109 | this->elfFile = (int)NULL; | |
|
110 | } | |
|
111 | this->opened = false; | |
|
112 | return 0; | |
|
113 | } | |
|
114 | ||
|
115 | ||
|
116 | QList<codeFragment*> ElfFile::getFragments(QStringList fragmentList) | |
|
117 | { | |
|
118 | QList<codeFragment*> fragments; | |
|
119 | if (isopened()) | |
|
120 | { | |
|
121 | for(int i =0;i<fragmentList.count();i++) | |
|
122 | { | |
|
123 | fragments.append(getFragment(fragmentList.at(i))); | |
|
124 | } | |
|
125 | } | |
|
126 | return fragments; | |
|
127 | } | |
|
128 | ||
|
129 | QList<codeFragment*> ElfFile::getFragments() | |
|
130 | { | |
|
131 | return getFragments(QStringList()<<".data"<<".text"); | |
|
132 | } | |
|
133 | ||
|
134 | codeFragment *ElfFile::getFragment(const QString &name) | |
|
135 | { | |
|
136 | codeFragment* fragment= new codeFragment(); | |
|
137 | for(int i=0;i<getSectionCount();i++) | |
|
138 | { | |
|
139 | if(getSectionName(i) == name) | |
|
140 | { | |
|
141 | fragment->data =NULL; | |
|
142 | fragment->size = getSectionDatasz(i); | |
|
143 | fragment->address = getSectionPaddr(i); | |
|
144 | getSectionData(i,&fragment->data); | |
|
145 | } | |
|
146 | } | |
|
147 | return fragment; | |
|
148 | } | |
|
149 | ||
|
150 | ||
|
151 | ||
|
152 | ||
|
153 | ||
|
154 | ||
|
155 | ||
|
156 | QString elfresolveMachine(Elf64_Half e_machine) | |
|
157 | { | |
|
158 | QString machineName; | |
|
159 | //Update from with bash script don't write it by yourself! | |
|
160 | switch(e_machine) | |
|
161 | { | |
|
162 | case EM_NONE: | |
|
163 | machineName = " No machine "; | |
|
164 | break; | |
|
165 | case EM_M32: | |
|
166 | machineName = " AT&T WE 32100 "; | |
|
167 | break; | |
|
168 | case EM_SPARC: | |
|
169 | machineName = " SUN SPARC "; | |
|
170 | break; | |
|
171 | case EM_386: | |
|
172 | machineName = " Intel 80386 "; | |
|
173 | break; | |
|
174 | case EM_68K: | |
|
175 | machineName = " Motorola m68k family "; | |
|
176 | break; | |
|
177 | case EM_88K: | |
|
178 | machineName = " Motorola m88k family "; | |
|
179 | break; | |
|
180 | case EM_860: | |
|
181 | machineName = " Intel 80860 "; | |
|
182 | break; | |
|
183 | case EM_MIPS: | |
|
184 | machineName = " MIPS R3000 big-endian "; | |
|
185 | break; | |
|
186 | case EM_S370: | |
|
187 | machineName = " IBM System/370 "; | |
|
188 | break; | |
|
189 | case EM_MIPS_RS3_LE: | |
|
190 | machineName = " MIPS R3000 little-endian "; | |
|
191 | break; | |
|
192 | case EM_PARISC: | |
|
193 | machineName = " HPPA "; | |
|
194 | break; | |
|
195 | case EM_VPP500: | |
|
196 | machineName = " Fujitsu VPP500 "; | |
|
197 | break; | |
|
198 | case EM_SPARC32PLUS: | |
|
199 | machineName = " Sun's \"v8plus\" "; | |
|
200 | break; | |
|
201 | case EM_960: | |
|
202 | machineName = " Intel 80960 "; | |
|
203 | break; | |
|
204 | case EM_PPC: | |
|
205 | machineName = " PowerPC "; | |
|
206 | break; | |
|
207 | case EM_PPC64: | |
|
208 | machineName = " PowerPC 64-bit "; | |
|
209 | break; | |
|
210 | case EM_S390: | |
|
211 | machineName = " IBM S390 "; | |
|
212 | break; | |
|
213 | case EM_V800: | |
|
214 | machineName = " NEC V800 series "; | |
|
215 | break; | |
|
216 | case EM_FR20: | |
|
217 | machineName = " Fujitsu FR20 "; | |
|
218 | break; | |
|
219 | case EM_RH32: | |
|
220 | machineName = " TRW RH-32 "; | |
|
221 | break; | |
|
222 | case EM_RCE: | |
|
223 | machineName = " Motorola RCE "; | |
|
224 | break; | |
|
225 | case EM_ARM: | |
|
226 | machineName = " ARM "; | |
|
227 | break; | |
|
228 | case EM_FAKE_ALPHA: | |
|
229 | machineName = " Digital Alpha "; | |
|
230 | break; | |
|
231 | case EM_SH: | |
|
232 | machineName = " Hitachi SH "; | |
|
233 | break; | |
|
234 | case EM_SPARCV9: | |
|
235 | machineName = " SPARC v9 64-bit "; | |
|
236 | break; | |
|
237 | case EM_TRICORE: | |
|
238 | machineName = " Siemens Tricore "; | |
|
239 | break; | |
|
240 | case EM_ARC: | |
|
241 | machineName = " Argonaut RISC Core "; | |
|
242 | break; | |
|
243 | case EM_H8_300: | |
|
244 | machineName = " Hitachi H8/300 "; | |
|
245 | break; | |
|
246 | case EM_H8_300H: | |
|
247 | machineName = " Hitachi H8/300H "; | |
|
248 | break; | |
|
249 | case EM_H8S: | |
|
250 | machineName = " Hitachi H8S "; | |
|
251 | break; | |
|
252 | case EM_H8_500: | |
|
253 | machineName = " Hitachi H8/500 "; | |
|
254 | break; | |
|
255 | case EM_IA_64: | |
|
256 | machineName = " Intel Merced "; | |
|
257 | break; | |
|
258 | case EM_MIPS_X: | |
|
259 | machineName = " Stanford MIPS-X "; | |
|
260 | break; | |
|
261 | case EM_COLDFIRE: | |
|
262 | machineName = " Motorola Coldfire "; | |
|
263 | break; | |
|
264 | case EM_68HC12: | |
|
265 | machineName = " Motorola M68HC12 "; | |
|
266 | break; | |
|
267 | case EM_MMA: | |
|
268 | machineName = " Fujitsu MMA Multimedia Accelerator"; | |
|
269 | break; | |
|
270 | case EM_PCP: | |
|
271 | machineName = " Siemens PCP "; | |
|
272 | break; | |
|
273 | case EM_NCPU: | |
|
274 | machineName = " Sony nCPU embeeded RISC "; | |
|
275 | break; | |
|
276 | case EM_NDR1: | |
|
277 | machineName = " Denso NDR1 microprocessor "; | |
|
278 | break; | |
|
279 | case EM_STARCORE: | |
|
280 | machineName = " Motorola Start*Core processor "; | |
|
281 | break; | |
|
282 | case EM_ME16: | |
|
283 | machineName = " Toyota ME16 processor "; | |
|
284 | break; | |
|
285 | case EM_ST100: | |
|
286 | machineName = " STMicroelectronic ST100 processor "; | |
|
287 | break; | |
|
288 | case EM_TINYJ: | |
|
289 | machineName = " Advanced Logic Corp. Tinyj emb.fam"; | |
|
290 | break; | |
|
291 | case EM_X86_64: | |
|
292 | machineName = " AMD x86-64 architecture "; | |
|
293 | break; | |
|
294 | case EM_PDSP: | |
|
295 | machineName = " Sony DSP Processor "; | |
|
296 | break; | |
|
297 | case EM_FX66: | |
|
298 | machineName = " Siemens FX66 microcontroller "; | |
|
299 | break; | |
|
300 | case EM_ST9PLUS: | |
|
301 | machineName = " STMicroelectronics ST9+ 8/16 mc "; | |
|
302 | break; | |
|
303 | case EM_ST7: | |
|
304 | machineName = " STmicroelectronics ST7 8 bit mc "; | |
|
305 | break; | |
|
306 | case EM_68HC16: | |
|
307 | machineName = " Motorola MC68HC16 microcontroller "; | |
|
308 | break; | |
|
309 | case EM_68HC11: | |
|
310 | machineName = " Motorola MC68HC11 microcontroller "; | |
|
311 | break; | |
|
312 | case EM_68HC08: | |
|
313 | machineName = " Motorola MC68HC08 microcontroller "; | |
|
314 | break; | |
|
315 | case EM_68HC05: | |
|
316 | machineName = " Motorola MC68HC05 microcontroller "; | |
|
317 | break; | |
|
318 | case EM_SVX: | |
|
319 | machineName = " Silicon Graphics SVx "; | |
|
320 | break; | |
|
321 | case EM_ST19: | |
|
322 | machineName = " STMicroelectronics ST19 8 bit mc "; | |
|
323 | break; | |
|
324 | case EM_VAX: | |
|
325 | machineName = " Digital VAX "; | |
|
326 | break; | |
|
327 | case EM_CRIS: | |
|
328 | machineName = " Axis Communications 32-bit embedded processor "; | |
|
329 | break; | |
|
330 | case EM_JAVELIN: | |
|
331 | machineName = " Infineon Technologies 32-bit embedded processor "; | |
|
332 | break; | |
|
333 | case EM_FIREPATH: | |
|
334 | machineName = " Element 14 64-bit DSP Processor "; | |
|
335 | break; | |
|
336 | case EM_ZSP: | |
|
337 | machineName = " LSI Logic 16-bit DSP Processor "; | |
|
338 | break; | |
|
339 | case EM_MMIX: | |
|
340 | machineName = " Donald Knuth's educational 64-bit processor "; | |
|
341 | break; | |
|
342 | case EM_HUANY: | |
|
343 | machineName = " Harvard University machine-independent object files "; | |
|
344 | break; | |
|
345 | case EM_PRISM: | |
|
346 | machineName = " SiTera Prism "; | |
|
347 | break; | |
|
348 | case EM_AVR: | |
|
349 | machineName = " Atmel AVR 8-bit microcontroller "; | |
|
350 | break; | |
|
351 | case EM_FR30: | |
|
352 | machineName = " Fujitsu FR30 "; | |
|
353 | break; | |
|
354 | case EM_D10V: | |
|
355 | machineName = " Mitsubishi D10V "; | |
|
356 | break; | |
|
357 | case EM_D30V: | |
|
358 | machineName = " Mitsubishi D30V "; | |
|
359 | break; | |
|
360 | case EM_V850: | |
|
361 | machineName = " NEC v850 "; | |
|
362 | break; | |
|
363 | case EM_M32R: | |
|
364 | machineName = " Mitsubishi M32R "; | |
|
365 | break; | |
|
366 | case EM_MN10300: | |
|
367 | machineName = " Matsushita MN10300 "; | |
|
368 | break; | |
|
369 | case EM_MN10200: | |
|
370 | machineName = " Matsushita MN10200 "; | |
|
371 | break; | |
|
372 | case EM_PJ: | |
|
373 | machineName = " picoJava "; | |
|
374 | break; | |
|
375 | case EM_OPENRISC: | |
|
376 | machineName = " OpenRISC 32-bit embedded processor "; | |
|
377 | break; | |
|
378 | case EM_ARC_A5: | |
|
379 | machineName = " ARC Cores Tangent-A5 "; | |
|
380 | break; | |
|
381 | case EM_XTENSA: | |
|
382 | machineName = " Tensilica Xtensa Architecture "; | |
|
383 | break; | |
|
384 | case EM_AARCH64: | |
|
385 | machineName = " ARM AARCH64 "; | |
|
386 | break; | |
|
387 | case EM_TILEPRO: | |
|
388 | machineName = " Tilera TILEPro "; | |
|
389 | break; | |
|
390 | case EM_MICROBLAZE: | |
|
391 | machineName = " Xilinx MicroBlaze "; | |
|
392 | break; | |
|
393 | case EM_TILEGX: | |
|
394 | machineName = " Tilera TILE-Gx "; | |
|
395 | break; | |
|
396 | case EM_NUM: | |
|
397 | machineName = ""; | |
|
398 | break; | |
|
399 | default: | |
|
400 | machineName ="Unknow Machine"; | |
|
401 | break; | |
|
402 | } | |
|
403 | return machineName; | |
|
404 | } | |
|
405 | ||
|
406 | ||
|
407 | ||
|
408 | ||
|
409 | QString ElfFile::getClass() | |
|
410 | { | |
|
411 | if(this->e!=NULL) | |
|
412 | { | |
|
413 | int eclass = gelf_getclass(this->e); | |
|
414 | if(eclass==ELFCLASS32)return "ELF32"; | |
|
415 | if(eclass==ELFCLASS64)return "ELF64"; | |
|
416 | } | |
|
417 | return "none"; | |
|
418 | } | |
|
419 | ||
|
420 | ||
|
421 | bool ElfFile::iself() | |
|
422 | { | |
|
423 | return (this->getType()!="Unknow"); | |
|
424 | } | |
|
425 | ||
|
426 | QString ElfFile::getArchitecture() | |
|
427 | { | |
|
428 | if(this->e!=NULL) | |
|
429 | { | |
|
430 | return elfresolveMachine(this->ehdr.e_machine); | |
|
431 | } | |
|
432 | return ""; | |
|
433 | } | |
|
434 | ||
|
435 | ||
|
436 | QString ElfFile::getType() | |
|
437 | { | |
|
438 | QString kind(""); | |
|
439 | if(this->e!=NULL) | |
|
440 | { | |
|
441 | switch(this->ek) | |
|
442 | { | |
|
443 | case ELF_K_AR: | |
|
444 | kind = "Archive"; | |
|
445 | break; | |
|
446 | case ELF_K_ELF: | |
|
447 | kind = "Elf"; | |
|
448 | break; | |
|
449 | case ELF_K_COFF: | |
|
450 | kind = "COFF"; | |
|
451 | break; | |
|
452 | case ELF_K_NUM: | |
|
453 | kind = "NUM"; | |
|
454 | break; | |
|
455 | case ELF_K_NONE: | |
|
456 | kind = "Data"; | |
|
457 | break; | |
|
458 | default: | |
|
459 | kind = "Unknow"; | |
|
460 | break; | |
|
461 | } | |
|
462 | } | |
|
463 | return kind; | |
|
464 | } | |
|
465 | ||
|
466 | QString ElfFile::getEndianness() | |
|
467 | { | |
|
468 | if(this->e!=NULL) | |
|
469 | { | |
|
470 | if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return "2's complement, little endian"; | |
|
471 | if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return "2's complement, big endian"; | |
|
472 | } | |
|
473 | return "none"; | |
|
474 | } | |
|
475 | ||
|
476 | QString ElfFile::getABI() | |
|
477 | { | |
|
478 | if(this->e!=NULL) | |
|
479 | { | |
|
480 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NONE)return "UNIX System V ABI"; | |
|
481 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SYSV)return "Alias"; | |
|
482 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_HPUX)return "HP-UX"; | |
|
483 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NETBSD)return "NetBSD"; | |
|
484 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_LINUX)return "Object uses GNU ELF extensions"; | |
|
485 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SOLARIS)return "Sun Solaris"; | |
|
486 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_AIX)return "IBM AIX"; | |
|
487 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_IRIX)return "SGI Irix"; | |
|
488 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_FREEBSD)return "FreeBSD"; | |
|
489 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_TRU64)return "Compaq TRU64 UNIX"; | |
|
490 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_MODESTO)return " Novell Modesto"; | |
|
491 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_OPENBSD)return "OpenBSD"; | |
|
492 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM_AEABI)return "ARM EABI"; | |
|
493 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM)return "ARM"; | |
|
494 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_STANDALONE)return "Standalone (embedded) application"; | |
|
495 | } | |
|
496 | return "none"; | |
|
497 | } | |
|
498 | ||
|
499 | ||
|
500 | qint64 ElfFile::getVersion() | |
|
501 | { | |
|
502 | if(this->e!=NULL) | |
|
503 | { | |
|
504 | return this->ehdr.e_version; | |
|
505 | } | |
|
506 | return -1; | |
|
507 | } | |
|
508 | ||
|
509 | qint64 ElfFile::getEntryPointAddress() | |
|
510 | { | |
|
511 | if(this->e!=NULL) | |
|
512 | { | |
|
513 | return this->ehdr.e_entry; | |
|
514 | } | |
|
515 | return -1; | |
|
516 | } | |
|
517 | ||
|
518 | ||
|
519 | int ElfFile::getSectionCount() | |
|
520 | { | |
|
521 | return (int)this->SectionCount; | |
|
522 | } | |
|
523 | ||
|
524 | int ElfFile::getSymbolCount() | |
|
525 | { | |
|
526 | return (int)this->SymbolCount; | |
|
527 | } | |
|
528 | ||
|
529 | ||
|
530 | int ElfFile::getSegmentCount() | |
|
531 | { | |
|
532 | return (int)this->SegmentCount; | |
|
533 | } | |
|
534 | ||
|
535 | ||
|
536 | QString ElfFile::getSegmentType(int index) | |
|
537 | { | |
|
538 | QString type(""); | |
|
539 | if(this->e!=NULL) | |
|
540 | { | |
|
541 | if(index < this->Segments.count()) | |
|
542 | { | |
|
543 | switch(this->Segments.at(index)->p_type) | |
|
544 | { | |
|
545 | case PT_NULL: | |
|
546 | type = "Program header table entry unused"; | |
|
547 | break; | |
|
548 | case PT_LOAD: | |
|
549 | type = "Loadable program segment"; | |
|
550 | break; | |
|
551 | case PT_DYNAMIC : | |
|
552 | type = "Dynamic linking information"; | |
|
553 | break; | |
|
554 | case PT_INTERP: | |
|
555 | type ="Program interpreter"; | |
|
556 | break; | |
|
557 | case PT_NOTE: | |
|
558 | type = "Auxiliary information"; | |
|
559 | break; | |
|
560 | case PT_SHLIB: | |
|
561 | type = "Reserved"; | |
|
562 | break; | |
|
563 | case PT_PHDR: | |
|
564 | type = "Entry for header table itself"; | |
|
565 | break; | |
|
566 | case PT_TLS: | |
|
567 | type = "Thread-local storage segment"; | |
|
568 | break; | |
|
569 | case PT_NUM: | |
|
570 | type = "Number of defined types"; | |
|
571 | break; | |
|
572 | case PT_LOOS: | |
|
573 | type = "Start of OS-specific"; | |
|
574 | break; | |
|
575 | case PT_SUNWSTACK: | |
|
576 | type = "Stack segment"; | |
|
577 | break; | |
|
578 | case PT_LOPROC: | |
|
579 | type = "Start of processor-specific"; | |
|
580 | break; | |
|
581 | case PT_HIPROC: | |
|
582 | type = "End of processor-specific"; | |
|
583 | break; | |
|
584 | default: | |
|
585 | type = "Unknow Section Type"; | |
|
586 | break; | |
|
587 | } | |
|
588 | } | |
|
589 | } | |
|
590 | ||
|
591 | return type; | |
|
592 | } | |
|
593 | ||
|
594 | ||
|
595 | qint64 ElfFile::getSegmentOffset(int index) | |
|
596 | { | |
|
597 | qint64 Offset = -1; | |
|
598 | if(this->e!=NULL) | |
|
599 | { | |
|
600 | if(index < this->Segments.count()) | |
|
601 | { | |
|
602 | Offset = (qint64)this->Segments.at(index)->p_offset; | |
|
603 | } | |
|
604 | } | |
|
605 | return Offset; | |
|
606 | } | |
|
607 | ||
|
608 | ||
|
609 | qint64 ElfFile::getSegmentVaddr(int index) | |
|
610 | { | |
|
611 | int64_t Vaddr = 0; | |
|
612 | if(this->e!=NULL) | |
|
613 | { | |
|
614 | if(index < this->Segments.count()) | |
|
615 | { | |
|
616 | Vaddr = (int64_t)this->Segments.at(index)->p_vaddr; | |
|
617 | } | |
|
618 | } | |
|
619 | return Vaddr; | |
|
620 | } | |
|
621 | ||
|
622 | ||
|
623 | qint64 ElfFile::getSegmentPaddr(int index) | |
|
624 | { | |
|
625 | int64_t Paddr=0; | |
|
626 | if(this->e!=NULL) | |
|
627 | { | |
|
628 | if(index < this->Segments.count()) | |
|
629 | { | |
|
630 | Paddr = (int64_t)this->Segments.at(index)->p_paddr; | |
|
631 | } | |
|
632 | } | |
|
633 | return Paddr; | |
|
634 | } | |
|
635 | ||
|
636 | qint64 ElfFile::getSectionPaddr(int index) | |
|
637 | { | |
|
638 | int64_t Paddr=0; | |
|
639 | if(this->e!=NULL) | |
|
640 | { | |
|
641 | if(index < this->sections.count()) | |
|
642 | { | |
|
643 | Paddr = (int64_t)this->sections.at(index)->section_header->sh_addr; | |
|
644 | } | |
|
645 | } | |
|
646 | return Paddr; | |
|
647 | } | |
|
648 | ||
|
649 | ||
|
650 | qint64 ElfFile::getSegmentFilesz(int index) | |
|
651 | { | |
|
652 | int64_t FileSz=0; | |
|
653 | if(this->e!=NULL) | |
|
654 | { | |
|
655 | if(index < this->Segments.count()) | |
|
656 | { | |
|
657 | FileSz = (int64_t)this->Segments.at(index)->p_filesz; | |
|
658 | } | |
|
659 | } | |
|
660 | return FileSz; | |
|
661 | } | |
|
662 | ||
|
663 | qint64 ElfFile::getSectionDatasz(int index) | |
|
664 | { | |
|
665 | int64_t DataSz=0; | |
|
666 | if(this->e!=NULL) | |
|
667 | { | |
|
668 | if(index < this->sections.count()) | |
|
669 | { | |
|
670 | if(this->sections.at(index)->section_header->sh_type==SHT_NOBITS) | |
|
671 | { | |
|
672 | DataSz=0; | |
|
673 | } | |
|
674 | else | |
|
675 | { | |
|
676 | DataSz = (int64_t)this->sections.at(index)->data->d_size; | |
|
677 | } | |
|
678 | } | |
|
679 | } | |
|
680 | return DataSz; | |
|
681 | } | |
|
682 | ||
|
683 | bool ElfFile::getSectionData(int index, char **buffer) | |
|
684 | { | |
|
685 | if(this->e!=NULL) | |
|
686 | { | |
|
687 | if(index < this->sections.count()) | |
|
688 | { | |
|
689 | *buffer = (char *)malloc(this->sections.at(index)->data->d_size); | |
|
690 | memcpy(*buffer,this->sections.at(index)->data->d_buf,this->sections.at(index)->data->d_size); | |
|
691 | return true; | |
|
692 | } | |
|
693 | } | |
|
694 | return false; | |
|
695 | } | |
|
696 | ||
|
697 | ||
|
698 | qint64 ElfFile::getSegmentMemsz(int index) | |
|
699 | { | |
|
700 | int64_t MemSz=0; | |
|
701 | if(this->e!=NULL) | |
|
702 | { | |
|
703 | if(index < this->Segments.count()) | |
|
704 | { | |
|
705 | MemSz = (int64_t)this->Segments.at(index)->p_memsz; | |
|
706 | } | |
|
707 | } | |
|
708 | return MemSz; | |
|
709 | } | |
|
710 | ||
|
711 | qint64 ElfFile::getSectionMemsz(int index) | |
|
712 | { | |
|
713 | int64_t MemSz=0; | |
|
714 | if(this->e!=NULL) | |
|
715 | { | |
|
716 | if(index < this->sections.count()) | |
|
717 | { | |
|
718 | MemSz = (int64_t)this->sections.at(index)->section_header->sh_size; | |
|
719 | } | |
|
720 | } | |
|
721 | return MemSz; | |
|
722 | } | |
|
723 | ||
|
724 | ||
|
725 | QString ElfFile::getSegmentFlags(int index) | |
|
726 | { | |
|
727 | QString flags(""); | |
|
728 | if(this->e!=NULL) | |
|
729 | { | |
|
730 | if(index < this->Segments.count()) | |
|
731 | { | |
|
732 | if((this->Segments.at(index)->p_flags&PF_X) == PF_X)flags+="x"; | |
|
733 | if((this->Segments.at(index)->p_flags&PF_W) == PF_W)flags+="w"; | |
|
734 | if((this->Segments.at(index)->p_flags&PF_R) == PF_R)flags+="r"; | |
|
735 | if((this->Segments.at(index)->p_flags&PF_MASKOS) == PF_MASKOS)flags+=" OS-specific"; | |
|
736 | if((this->Segments.at(index)->p_flags&PF_MASKPROC) == PF_MASKPROC)flags+=" Processor-specific"; | |
|
737 | } | |
|
738 | } | |
|
739 | return flags; | |
|
740 | } | |
|
741 | ||
|
742 | ||
|
743 | QString ElfFile::getSectionName(int index) | |
|
744 | { | |
|
745 | if((index<sections.count()) && (index>=0)) | |
|
746 | { | |
|
747 | char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name); | |
|
748 | return QString(nameChr); | |
|
749 | } | |
|
750 | return ""; | |
|
751 | } | |
|
752 | ||
|
753 | ||
|
754 | void ElfFile::updateSections() | |
|
755 | { | |
|
756 | for(int i=0;i<this->sections.count();i++) | |
|
757 | { | |
|
758 | delete this->sections.at(i); | |
|
759 | } | |
|
760 | this->sections.clear(); | |
|
761 | this->scn = elf_nextscn (this->e , NULL ); | |
|
762 | this->SectionCount = 0; | |
|
763 | while( this->scn != NULL ) | |
|
764 | { | |
|
765 | GElf_Shdr* shdr = (GElf_Shdr*)malloc(sizeof(GElf_Shdr)); | |
|
766 | gelf_getshdr ( this->scn , shdr ); | |
|
767 | Elf_Data* data = elf_getdata(this->scn, NULL); | |
|
768 | this->sections.append(new Elf_Section(data,shdr)); | |
|
769 | this->SectionCount+=1; | |
|
770 | this->scn = elf_nextscn(e , scn); | |
|
771 | } | |
|
772 | } | |
|
773 | ||
|
774 | ||
|
775 | void ElfFile::updateSegments() | |
|
776 | { | |
|
777 | elf_getphdrnum (this->e , &this->SegmentCount); | |
|
778 | for(int i=0;i<this->Segments.count();i++) | |
|
779 | { | |
|
780 | free(this->Segments.at(i)); | |
|
781 | } | |
|
782 | this->Segments.clear(); | |
|
783 | for(int i=0;i<(int)this->SegmentCount;i++) | |
|
784 | { | |
|
785 | GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr)); | |
|
786 | gelf_getphdr (this->e , i , header ); | |
|
787 | this->Segments.append(header); | |
|
788 | } | |
|
789 | } | |
|
790 | ||
|
791 | void ElfFile::updateSymbols() | |
|
792 | { | |
|
793 | for(int i=0;i<symbols.count();i++) | |
|
794 | { | |
|
795 | delete this->symbols.at(i); | |
|
796 | } | |
|
797 | this->symbols.clear(); | |
|
798 | updateSections(); //Useless in most case but safer to do it | |
|
799 | for(int i=0;i<(int)SectionCount;i++) | |
|
800 | { | |
|
801 | //First find Symbol table | |
|
802 | if(this->getSectionName(i)==".symtab") | |
|
803 | { | |
|
804 | Elf_Section* sec = sections.at(i); | |
|
805 | this->SymbolCount = sec->section_header->sh_size / sec->section_header->sh_entsize; | |
|
806 | //Then list all symbols | |
|
807 | for(int j=0;j<(int)this->SymbolCount;j++) | |
|
808 | { | |
|
809 | GElf_Sym* esym = (GElf_Sym*)malloc(sizeof(GElf_Sym)); | |
|
810 | gelf_getsym(sec->data, j, esym); | |
|
811 | QString name = elf_strptr(this->e,sec->section_header->sh_link,esym->st_name); | |
|
812 | Elf_Symbol* sym = new Elf_Symbol(name,esym); | |
|
813 | symbols.append(sym); | |
|
814 | } | |
|
815 | } | |
|
816 | } | |
|
817 | ||
|
818 | } | |
|
819 | ||
|
820 | ||
|
821 | ||
|
822 | QString ElfFile::getSectionType(int index) | |
|
823 | { | |
|
824 | QString type(""); | |
|
825 | if(this->e!=NULL) | |
|
826 | { | |
|
827 | if(index < this->sections.count()) | |
|
828 | { | |
|
829 | switch(this->sections.at(index)->section_header->sh_type) | |
|
830 | { | |
|
831 | case SHT_NULL : type = "Section header table entry unused"; break; | |
|
832 | case SHT_PROGBITS : type = "Program data"; break; | |
|
833 | case SHT_SYMTAB : type = "Symbol table"; break; | |
|
834 | case SHT_STRTAB : type = "String table"; break; | |
|
835 | case SHT_RELA : type = "Relocation entries with addends"; break; | |
|
836 | case SHT_HASH : type = "Symbol hash table"; break; | |
|
837 | case SHT_DYNAMIC : type = "Dynamic linking information"; break; | |
|
838 | case SHT_NOTE : type = "Notes"; break; | |
|
839 | case SHT_NOBITS :type = "Program space with no data (bss)"; break; | |
|
840 | case SHT_REL :type = "Relocation entries, no addends"; break; | |
|
841 | case SHT_SHLIB : type = "Reserved"; break; | |
|
842 | case SHT_DYNSYM : type = "Dynamic linker symbol table"; break; | |
|
843 | case SHT_INIT_ARRAY : type = "Array of constructors"; break; | |
|
844 | case SHT_FINI_ARRAY : type = "Array of destructors"; break; | |
|
845 | case SHT_PREINIT_ARRAY : type = "Array of pre-constructors"; break; | |
|
846 | case SHT_GROUP : type = "Section group"; break; | |
|
847 | case SHT_SYMTAB_SHNDX : type = "Extended section indeces"; break; | |
|
848 | case SHT_NUM : type = "Number of defined types. "; break; | |
|
849 | case SHT_LOOS : type = "Start OS-specific. "; break; | |
|
850 | case SHT_LOSUNW : type = "Sun-specific low bound. "; break; | |
|
851 | case SHT_SUNW_COMDAT : type = " "; break; | |
|
852 | case SHT_SUNW_syminfo : type = " "; break; | |
|
853 | case SHT_GNU_verdef : type = "Version definition section. "; break; | |
|
854 | case SHT_GNU_verneed : type = "Version needs section. "; break; | |
|
855 | case SHT_GNU_versym : type = "Version symbol table. "; break; | |
|
856 | case SHT_LOPROC : type = "Start of processor-specific"; break; | |
|
857 | case SHT_HIPROC : type = "End of processor-specific"; break; | |
|
858 | case SHT_HIUSER : type = "End of application-specific"; break; | |
|
859 | } | |
|
860 | } | |
|
861 | } | |
|
862 | return type; | |
|
863 | } | |
|
864 | ||
|
865 | int ElfFile::getSectionIndex(QString name) | |
|
866 | { | |
|
867 | if(this->e!=NULL) | |
|
868 | { | |
|
869 | for(int i=0;i<sections.count();i++) | |
|
870 | { | |
|
871 | if(getSectionName(i)==name) | |
|
872 | return i; | |
|
873 | } | |
|
874 | } | |
|
875 | return -1; | |
|
876 | } | |
|
877 | ||
|
878 | bool ElfFile::sectionIsNobits(int index) | |
|
879 | { | |
|
880 | if(this->e!=NULL) | |
|
881 | { | |
|
882 | if(index < this->sections.count()) | |
|
883 | { | |
|
884 | return this->sections.at(index)->section_header->sh_type== SHT_NOBITS; | |
|
885 | } | |
|
886 | } | |
|
887 | return false; | |
|
888 | } | |
|
889 | ||
|
890 | QString ElfFile::getSymbolName(int index) | |
|
891 | { | |
|
892 | if(this->e!=NULL) | |
|
893 | { | |
|
894 | if(index < this->symbols.count()) | |
|
895 | { | |
|
896 | return symbols.at(index)->name; | |
|
897 | } | |
|
898 | } | |
|
899 | return ""; | |
|
900 | } | |
|
901 | ||
|
902 | QString ElfFile::getSymbolType(int index) | |
|
903 | { | |
|
904 | if(this->e!=NULL) | |
|
905 | { | |
|
906 | if(index < this->symbols.count()) | |
|
907 | { | |
|
908 | int type = GELF_ST_TYPE(symbols.at(index)->sym->st_info); | |
|
909 | switch(type) | |
|
910 | { | |
|
911 | case STT_NOTYPE: | |
|
912 | return "No Type"; | |
|
913 | break; | |
|
914 | case STT_OBJECT: | |
|
915 | return "Object"; | |
|
916 | break; | |
|
917 | case STT_FUNC: | |
|
918 | return "Function"; | |
|
919 | break; | |
|
920 | case STT_SECTION: | |
|
921 | return "Section"; | |
|
922 | break; | |
|
923 | case STT_FILE: | |
|
924 | return "File"; | |
|
925 | break; | |
|
926 | case STT_COMMON: | |
|
927 | return "Common data object"; | |
|
928 | break; | |
|
929 | case STT_TLS: | |
|
930 | return "Thread-local data object"; | |
|
931 | break; | |
|
932 | case STT_NUM: | |
|
933 | return "Number of defined types"; | |
|
934 | break; | |
|
935 | case STT_LOOS: | |
|
936 | return "Start of OS-specific"; | |
|
937 | break; | |
|
938 | case STT_HIOS: | |
|
939 | return "End of OS-specific"; | |
|
940 | break; | |
|
941 | case STT_LOPROC: | |
|
942 | return "Start of processor-specific"; | |
|
943 | break; | |
|
944 | case STT_HIPROC: | |
|
945 | return "End of processor-specific"; | |
|
946 | break; | |
|
947 | default: | |
|
948 | return "none"; | |
|
949 | break; | |
|
950 | } | |
|
951 | } | |
|
952 | } | |
|
953 | return "none"; | |
|
954 | } | |
|
955 | ||
|
956 | quint64 ElfFile::getSymbolSize(int index) | |
|
957 | { | |
|
958 | if(this->e!=NULL) | |
|
959 | { | |
|
960 | if((index < this->symbols.count()) && (index>=0)) | |
|
961 | { | |
|
962 | return symbols.at(index)->sym->st_size; | |
|
963 | } | |
|
964 | } | |
|
965 | return 0; | |
|
966 | } | |
|
967 | ||
|
968 | QString ElfFile::getSymbolSectionName(int index) | |
|
969 | { | |
|
970 | if(this->e!=NULL) | |
|
971 | { | |
|
972 | if((index < this->symbols.count()) && (index>=0)) | |
|
973 | { | |
|
974 | return getSectionName(symbols.at(index)->sym->st_shndx-1); | |
|
975 | } | |
|
976 | } | |
|
977 | return "none"; | |
|
978 | } | |
|
979 | ||
|
980 | int ElfFile::getSymbolSectionIndex(int index) | |
|
981 | { | |
|
982 | if(this->e!=NULL) | |
|
983 | { | |
|
984 | if((index < this->symbols.count()) && (index>=0)) | |
|
985 | { | |
|
986 | return symbols.at(index)->sym->st_shndx; | |
|
987 | } | |
|
988 | } | |
|
989 | return 0; | |
|
990 | } | |
|
991 | ||
|
992 | quint64 ElfFile::getSymbolAddress(int index) | |
|
993 | { | |
|
994 | if(this->e!=NULL) | |
|
995 | { | |
|
996 | if((index < this->symbols.count()) && (index>=0)) | |
|
997 | { | |
|
998 | return symbols.at(index)->sym->st_value; | |
|
999 | } | |
|
1000 | } | |
|
1001 | return 0; | |
|
1002 | } | |
|
1003 | ||
|
1004 | QString ElfFile::getSymbolLinkType(int index) | |
|
1005 | { | |
|
1006 | if(this->e!=NULL) | |
|
1007 | { | |
|
1008 | if(index < this->symbols.count()) | |
|
1009 | { | |
|
1010 | int btype = GELF_ST_BIND(symbols.at(index)->sym->st_info); | |
|
1011 | switch(btype) | |
|
1012 | { | |
|
1013 | case STB_LOCAL: | |
|
1014 | return "Local"; | |
|
1015 | break; | |
|
1016 | case STB_GLOBAL: | |
|
1017 | return "Global"; | |
|
1018 | break; | |
|
1019 | case STB_WEAK: | |
|
1020 | return "Weak"; | |
|
1021 | break; | |
|
1022 | case STB_NUM: | |
|
1023 | return "Number of defined types"; | |
|
1024 | break; | |
|
1025 | case STB_LOOS: | |
|
1026 | return "Start of OS-specific"; | |
|
1027 | break; | |
|
1028 | case STB_HIOS: | |
|
1029 | return "End of OS-specific"; | |
|
1030 | break; | |
|
1031 | case STB_LOPROC: | |
|
1032 | return "Start of processor-specific"; | |
|
1033 | break; | |
|
1034 | case STB_HIPROC: | |
|
1035 | return "End of processor-specific"; | |
|
1036 | break; | |
|
1037 | default: | |
|
1038 | return "none"; | |
|
1039 | break; | |
|
1040 | } | |
|
1041 | } | |
|
1042 | } | |
|
1043 | return "none"; | |
|
1044 | } | |
|
1045 | ||
|
1046 | bool ElfFile::isElf(const QString &File) | |
|
1047 | { | |
|
1048 | int file =0; | |
|
1049 | #ifdef _ELF_WINDOWS_ | |
|
1050 | file = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0); | |
|
1051 | #else | |
|
1052 | file = open(File.toStdString().c_str(),O_RDONLY ,0); | |
|
1053 | #endif | |
|
1054 | char Magic[4]; | |
|
1055 | if(file!=-1) | |
|
1056 | { | |
|
1057 | size_t res = read(file,Magic,4); | |
|
1058 | close(file); | |
|
1059 | if((res==4) && (Magic[0]==0x7f) && (Magic[1]==0x45) && (Magic[2]==0x4c) && (Magic[3]==0x46)) | |
|
1060 | { | |
|
1061 | return true; | |
|
1062 | } | |
|
1063 | } | |
|
1064 | return false; | |
|
1065 | } | |
|
1066 | ||
|
1067 | bool ElfFile::toSrec(const QString &File) | |
|
1068 | { | |
|
1069 | return srecFile::toSrec(this->getFragments(),File); | |
|
1070 | } | |
|
1071 | ||
|
1072 | bool ElfFile::toBinary(const QString &File) | |
|
1073 | { | |
|
1074 | return binaryFile::toBinary(getFragments(),File); | |
|
1075 | } |
@@ -0,0 +1,136 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | #include <abstractbinfile.h> | |
|
23 | #include <QtCore/QObject> | |
|
24 | #include <QtCore/QStringList> | |
|
25 | #include <libelf.h> | |
|
26 | #include <gelf.h> | |
|
27 | #include <sys/types.h> | |
|
28 | #include <sys/stat.h> | |
|
29 | #include <fcntl.h> | |
|
30 | #include <unistd.h> | |
|
31 | #ifndef ELFFILE_H | |
|
32 | #define ELFFILE_H | |
|
33 | ||
|
34 | class Elf_Section | |
|
35 | { | |
|
36 | public: | |
|
37 | Elf_Section(){} | |
|
38 | Elf_Section(Elf_Data* data,GElf_Shdr* section_header) | |
|
39 | { | |
|
40 | this->data = data; | |
|
41 | this->section_header = section_header; | |
|
42 | } | |
|
43 | ~Elf_Section() | |
|
44 | { | |
|
45 | free(section_header); | |
|
46 | } | |
|
47 | Elf_Data* data; | |
|
48 | GElf_Shdr* section_header; | |
|
49 | }; | |
|
50 | ||
|
51 | class Elf_Symbol | |
|
52 | { | |
|
53 | public: | |
|
54 | Elf_Symbol(){} | |
|
55 | Elf_Symbol(const QString& name,GElf_Sym* sym):name(name),sym(sym){} | |
|
56 | ~Elf_Symbol(){free(sym);} | |
|
57 | QString name; | |
|
58 | GElf_Sym* sym; | |
|
59 | }; | |
|
60 | ||
|
61 | class ElfFile : public abstractBinFile | |
|
62 | { | |
|
63 | Q_OBJECT | |
|
64 | public: | |
|
65 | ElfFile(); | |
|
66 | ElfFile(const QString& File); | |
|
67 | ~ElfFile(); | |
|
68 | bool openFile(const QString& File); | |
|
69 | bool isopened(); | |
|
70 | int closeFile(); | |
|
71 | QList<codeFragment*> getFragments(); | |
|
72 | QList<codeFragment*> getFragments(QStringList fragmentList); | |
|
73 | ||
|
74 | QString getClass(); | |
|
75 | QString getArchitecture(); | |
|
76 | QString getType(); | |
|
77 | QString getEndianness(); | |
|
78 | QString getABI(); | |
|
79 | qint64 getVersion(); | |
|
80 | qint64 getEntryPointAddress(); | |
|
81 | ||
|
82 | int getSectionCount(); | |
|
83 | int getSymbolCount(); | |
|
84 | int getSegmentCount(); | |
|
85 | ||
|
86 | QString getSegmentType(int index); | |
|
87 | qint64 getSegmentOffset(int index); | |
|
88 | qint64 getSegmentVaddr(int index); | |
|
89 | qint64 getSegmentPaddr(int index); | |
|
90 | qint64 getSegmentFilesz(int index); | |
|
91 | qint64 getSegmentMemsz(int index); | |
|
92 | QString getSegmentFlags(int index); | |
|
93 | ||
|
94 | bool getSectionData(int index, char **buffer); | |
|
95 | qint64 getSectionPaddr(int index); | |
|
96 | qint64 getSectionMemsz(int index); | |
|
97 | qint64 getSectionDatasz(int index); | |
|
98 | QString getSectionName(int index); | |
|
99 | QString getSectionType(int index); | |
|
100 | int getSectionIndex(QString name); | |
|
101 | bool sectionIsNobits(int index); | |
|
102 | ||
|
103 | QString getSymbolName(int index); | |
|
104 | QString getSymbolType(int index); | |
|
105 | quint64 getSymbolSize(int index); | |
|
106 | QString getSymbolSectionName(int index); | |
|
107 | int getSymbolSectionIndex(int index); | |
|
108 | quint64 getSymbolAddress(int index); | |
|
109 | QString getSymbolLinkType(int index); | |
|
110 | bool iself(); | |
|
111 | static bool isElf(const QString& File); | |
|
112 | ||
|
113 | bool toSrec(const QString& File); | |
|
114 | bool toBinary(const QString& File); | |
|
115 | ||
|
116 | private: | |
|
117 | codeFragment* getFragment(const QString& name); | |
|
118 | void updateSections(); | |
|
119 | void updateSegments(); | |
|
120 | void updateSymbols(); | |
|
121 | int elfFile; | |
|
122 | bool opened; | |
|
123 | bool type_elf; | |
|
124 | Elf* e; | |
|
125 | Elf_Kind ek; | |
|
126 | GElf_Ehdr ehdr; | |
|
127 | Elf_Scn * scn; | |
|
128 | Elf_Data * data; | |
|
129 | size_t SymbolCount,SectionCount,SegmentCount, shstrndx; | |
|
130 | QList<GElf_Phdr*> Segments; | |
|
131 | QList<Elf_Section*> sections; | |
|
132 | QList<Elf_Symbol*> symbols; | |
|
133 | ||
|
134 | }; | |
|
135 | ||
|
136 | #endif // ELFFILE_H |
@@ -0,0 +1,346 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | #include "elffilewidget.h" | |
|
23 | #include "ui_elffilewidget.h" | |
|
24 | #include <QtWidgets/QTableWidgetItem> | |
|
25 | #include <QtWidgets/QFileDialog> | |
|
26 | #include "qhexedit.h" | |
|
27 | #include "qtablewidgetintitem.h" | |
|
28 | #include "../srec/srecfile.h" | |
|
29 | #include "../BinFile/binaryfile.h" | |
|
30 | ||
|
31 | elfFileWidget::elfFileWidget(QWidget *parent) : | |
|
32 | abstractBinFileWidget(parent), | |
|
33 | ui(new Ui::elfFileWidget) | |
|
34 | { | |
|
35 | ui->setupUi(this); | |
|
36 | exportToSREC_action = new QAction(tr("Export to SREC"),this); | |
|
37 | exportToBIN_action = new QAction(tr("Export to Binary"),this); | |
|
38 | viewSymbolInHexViewer_action = new QAction(tr("View in Hexviewer"),this); | |
|
39 | connect(this->ui->sectionsList,SIGNAL(cellActivated(int,int)),this,SLOT(sectionCellActivated(int,int))); | |
|
40 | this->ui->sectionsList->addAction(exportToSREC_action); | |
|
41 | this->ui->sectionsList->addAction(exportToBIN_action); | |
|
42 | this->ui->symbolsList->addAction(viewSymbolInHexViewer_action); | |
|
43 | this->ui->symbolsList->addAction(exportToSREC_action); | |
|
44 | this->ui->symbolsList->addAction(exportToBIN_action); | |
|
45 | connect(this->exportToBIN_action,SIGNAL(triggered()),this,SLOT(exportToBIN())); | |
|
46 | connect(this->exportToSREC_action,SIGNAL(triggered()),this,SLOT(exportToSREC())); | |
|
47 | connect(this->ui->symbolsFilter,SIGNAL(textChanged(QString)),this,SLOT(filterSymbols(QString))); | |
|
48 | connect(this->ui->caseSensitive,SIGNAL(toggled(bool)),this,SLOT(filterSymbolsCaseUpdate(bool))); | |
|
49 | connect(this->viewSymbolInHexViewer_action,SIGNAL(triggered()),this,SLOT(viewSymbolInHexViewer())); | |
|
50 | this->p_hexviewer = new QHexEdit(); | |
|
51 | this->p_hexviewer->setWindowTitle("SocExplorer Hexadecimal viewer"); | |
|
52 | this->setWindowTitle("SocExplorer Elf viewer"); | |
|
53 | } | |
|
54 | ||
|
55 | ||
|
56 | ||
|
57 | elfFileWidget::~elfFileWidget() | |
|
58 | { | |
|
59 | delete ui; | |
|
60 | delete p_hexviewer; | |
|
61 | } | |
|
62 | ||
|
63 | ||
|
64 | ||
|
65 | void elfFileWidget::setFile(ElfFile *file) | |
|
66 | { | |
|
67 | this->p_elf = file; | |
|
68 | if(p_elf->isopened() && p_elf->iself()) | |
|
69 | { | |
|
70 | this->ui->classLabel->setText(p_elf->getClass()); | |
|
71 | this->ui->VersionLabel->setText(QString::number(p_elf->getVersion())); | |
|
72 | this->ui->machineLabel->setText(p_elf->getArchitecture()); | |
|
73 | this->ui->endiannesLabel->setText(p_elf->getEndianness()); | |
|
74 | this->ui->abiLabel->setText(p_elf->getABI()); | |
|
75 | this->ui->entryPointLabel->setText(QString("0x%1").arg((uint)p_elf->getEntryPointAddress(),8,16)); | |
|
76 | this->ui->typeLabel->setText(p_elf->getType()); | |
|
77 | this->ui->sectionCountLabel->setText(QString::number(p_elf->getSectionCount())); | |
|
78 | this->ui->symbolCountLabel->setText(QString::number(p_elf->getSymbolCount())); | |
|
79 | } | |
|
80 | reloadFile(); | |
|
81 | } | |
|
82 | ||
|
83 | void elfFileWidget::reloadFile() | |
|
84 | { | |
|
85 | updateSymbols(); | |
|
86 | updateSections(); | |
|
87 | } | |
|
88 | ||
|
89 | ||
|
90 | ||
|
91 | void elfFileWidget::updateSymbols() | |
|
92 | { | |
|
93 | this->ui->symbolsList->clear(); | |
|
94 | this->ui->symbolsList->setRowCount(p_elf->getSymbolCount()); | |
|
95 | this->ui->symbolsList->setHorizontalHeaderLabels(QStringList()<<"Index"<<"Value"<<"Size"<<"Type"<<"Link"<<"Section"<<"Name"); | |
|
96 | for(int i=0;i<p_elf->getSymbolCount();i++) | |
|
97 | { | |
|
98 | QTableWidgetItem *newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(i),DecimalItem); | |
|
99 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
100 | this->ui->symbolsList->setItem(i, 0, newItem); | |
|
101 | ||
|
102 | newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("0x%1").arg(p_elf->getSymbolAddress(i),8,16).replace(" ","0"),HexaDecimalItem); | |
|
103 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
104 | this->ui->symbolsList->setItem(i, 1, newItem); | |
|
105 | ||
|
106 | newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(p_elf->getSymbolSize(i)),DecimalItem); | |
|
107 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
108 | this->ui->symbolsList->setItem(i, 2, newItem); | |
|
109 | ||
|
110 | newItem = new QTableWidgetItem(p_elf->getSymbolType(i)); | |
|
111 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
112 | this->ui->symbolsList->setItem(i, 3, newItem); | |
|
113 | ||
|
114 | newItem = new QTableWidgetItem(p_elf->getSymbolLinkType(i)); | |
|
115 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
116 | this->ui->symbolsList->setItem(i, 4, newItem); | |
|
117 | ||
|
118 | newItem = new QTableWidgetItem(p_elf->getSymbolSectionName(i)); | |
|
119 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
120 | this->ui->symbolsList->setItem(i, 5, newItem); | |
|
121 | ||
|
122 | newItem = new QTableWidgetItem(p_elf->getSymbolName(i)); | |
|
123 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
124 | this->ui->symbolsList->setItem(i, 6, newItem); | |
|
125 | } | |
|
126 | this->ui->symbolsList->resizeColumnsToContents(); | |
|
127 | } | |
|
128 | ||
|
129 | ||
|
130 | ||
|
131 | void elfFileWidget::updateSections() | |
|
132 | { | |
|
133 | this->ui->sectionsList->clear(); | |
|
134 | this->ui->sectionsList->setRowCount(p_elf->getSectionCount()); | |
|
135 | this->ui->sectionsList->setHorizontalHeaderLabels(QStringList()<<"Index"<<"Name"<<"Address"<<"Size"<<"File Size"<<"Type"); | |
|
136 | for(int i=0;i<p_elf->getSectionCount();i++) | |
|
137 | { | |
|
138 | QTableWidgetItem *newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("%1").arg(i),DecimalItem); | |
|
139 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
140 | this->ui->sectionsList->setItem(i,0, newItem); | |
|
141 | ||
|
142 | newItem = new QTableWidgetItem(p_elf->getSectionName(i)); | |
|
143 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
144 | this->ui->sectionsList->setItem(i, 1, newItem); | |
|
145 | ||
|
146 | newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("0x%1").arg(p_elf->getSectionPaddr(i),8,16).replace(" ","0"),HexaDecimalItem); | |
|
147 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
148 | this->ui->sectionsList->setItem(i, 2, newItem); | |
|
149 | ||
|
150 | newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("%1").arg(p_elf->getSectionMemsz(i)),DecimalItem); | |
|
151 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
152 | this->ui->sectionsList->setItem(i, 3, newItem); | |
|
153 | ||
|
154 | newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("%1").arg(p_elf->getSectionDatasz(i)),DecimalItem); | |
|
155 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
156 | this->ui->sectionsList->setItem(i, 4, newItem); | |
|
157 | ||
|
158 | newItem = new QTableWidgetItem(p_elf->getSectionType(i)); | |
|
159 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
160 | this->ui->sectionsList->setItem(i, 5, newItem); | |
|
161 | } | |
|
162 | this->ui->sectionsList->resizeColumnsToContents(); | |
|
163 | } | |
|
164 | ||
|
165 | void elfFileWidget::sectionCellActivated(int row, int column) | |
|
166 | { | |
|
167 | Q_UNUSED(column) | |
|
168 | char* buff=NULL; | |
|
169 | int sectionIndex = p_elf->getSectionIndex(this->ui->sectionsList->item(row,1)->text()); | |
|
170 | if(sectionIndex!=-1) | |
|
171 | { | |
|
172 | QString type = p_elf->getSectionType(sectionIndex); | |
|
173 | if(!p_elf->sectionIsNobits(sectionIndex)) | |
|
174 | { | |
|
175 | this->p_elf->getSectionData(sectionIndex,&buff); | |
|
176 | this->ui->sectionsHexView->setData(QByteArray(buff,this->p_elf->getSectionDatasz(sectionIndex))); | |
|
177 | this->ui->sectionsHexView->setAddressOffset(this->p_elf->getSectionPaddr(sectionIndex)); | |
|
178 | } | |
|
179 | } | |
|
180 | } | |
|
181 | ||
|
182 | void elfFileWidget::exportToSREC() | |
|
183 | { | |
|
184 | QList<codeFragment *> fragments; | |
|
185 | if(this->ui->tabWidget->currentWidget()==this->ui->symbolsTab) | |
|
186 | { | |
|
187 | fragments = getSelectedSymbolsFragments(); | |
|
188 | } | |
|
189 | if(this->ui->tabWidget->currentWidget()==this->ui->sectionsTab) | |
|
190 | { | |
|
191 | QStringList sectionList=getSelectedSectionsNames(); | |
|
192 | if(sectionList.count()>0) | |
|
193 | fragments = p_elf->getFragments(sectionList); | |
|
194 | } | |
|
195 | if(fragments.count()>0) | |
|
196 | { | |
|
197 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), | |
|
198 | NULL, | |
|
199 | tr("SREC Files (*.srec)")); | |
|
200 | if(!fileName.isEmpty()) | |
|
201 | { | |
|
202 | srecFile::toSrec(fragments,fileName); | |
|
203 | } | |
|
204 | } | |
|
205 | ||
|
206 | } | |
|
207 | ||
|
208 | void elfFileWidget::exportToBIN() | |
|
209 | { | |
|
210 | QList<codeFragment *> fragments; | |
|
211 | if(this->ui->tabWidget->currentWidget()==this->ui->symbolsTab) | |
|
212 | { | |
|
213 | fragments = getSelectedSymbolsFragments(); | |
|
214 | } | |
|
215 | if(this->ui->tabWidget->currentWidget()==this->ui->sectionsTab) | |
|
216 | { | |
|
217 | QStringList sectionList=getSelectedSectionsNames(); | |
|
218 | if(sectionList.count()>0) | |
|
219 | fragments = p_elf->getFragments(sectionList); | |
|
220 | } | |
|
221 | if(fragments.count()>0) | |
|
222 | { | |
|
223 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), | |
|
224 | NULL, | |
|
225 | tr("Binary Files (*.bin)")); | |
|
226 | if(!fileName.isEmpty()) | |
|
227 | { | |
|
228 | binaryFile::toBinary(fragments,fileName); | |
|
229 | } | |
|
230 | } | |
|
231 | ||
|
232 | } | |
|
233 | ||
|
234 | void elfFileWidget::viewSymbolInHexViewer() | |
|
235 | { | |
|
236 | int row=this->ui->symbolsList->item(this->ui->symbolsList->currentRow(),0)->text().toInt(); | |
|
237 | int section = p_elf->getSectionIndex(p_elf->getSymbolSectionName(row)); | |
|
238 | qint64 address = p_elf->getSymbolAddress(row); | |
|
239 | qint64 secAddress = p_elf->getSectionPaddr(section); | |
|
240 | qint64 size = p_elf->getSymbolSize(row); | |
|
241 | char* buff=NULL; | |
|
242 | char* symBuff=NULL; | |
|
243 | if(size && !p_elf->sectionIsNobits(section)) | |
|
244 | { | |
|
245 | if(section!=-1) | |
|
246 | { | |
|
247 | symBuff = (char*)malloc(size); | |
|
248 | this->p_elf->getSectionData(section,&buff); | |
|
249 | memcpy(symBuff,buff+(address-secAddress),size); | |
|
250 | this->p_hexviewer->setData(QByteArray(symBuff,size)); | |
|
251 | this->p_hexviewer->setAddressOffset(address); | |
|
252 | this->p_hexviewer->show(); | |
|
253 | } | |
|
254 | } | |
|
255 | } | |
|
256 | ||
|
257 | void elfFileWidget::filterSymbols(const QString &pattern) | |
|
258 | { | |
|
259 | Qt::MatchFlags flag = Qt::MatchContains | Qt::MatchStartsWith | Qt::MatchEndsWith | Qt::MatchRegExp | Qt::MatchWildcard | Qt::MatchWrap |Qt::MatchRecursive; | |
|
260 | if(this->ui->caseSensitive->isChecked()) | |
|
261 | flag |= Qt::MatchCaseSensitive; | |
|
262 | if(pattern.isEmpty()) | |
|
263 | { | |
|
264 | for(int i=0;i<this->ui->symbolsList->rowCount();i++) | |
|
265 | this->ui->symbolsList->setRowHidden(i,false); | |
|
266 | } | |
|
267 | else | |
|
268 | { | |
|
269 | for(int i=0;i<this->ui->symbolsList->rowCount();i++) | |
|
270 | this->ui->symbolsList->setRowHidden(i,true); | |
|
271 | QList<QTableWidgetItem*> items = this->ui->symbolsList->findItems(pattern,flag); | |
|
272 | for(int i=0;i<items.count();i++) | |
|
273 | this->ui->symbolsList->setRowHidden(items.at(i)->row(),false); | |
|
274 | } | |
|
275 | } | |
|
276 | ||
|
277 | void elfFileWidget::filterSymbolsCaseUpdate(bool toggled) | |
|
278 | { | |
|
279 | Q_UNUSED(toggled) | |
|
280 | this->filterSymbols(this->ui->symbolsFilter->text()); | |
|
281 | } | |
|
282 | ||
|
283 | QList<codeFragment *> elfFileWidget::getSelectedSymbolsFragments() | |
|
284 | { | |
|
285 | QList<codeFragment *> fragments; | |
|
286 | codeFragment * fragment; | |
|
287 | if(p_elf->isopened()) | |
|
288 | { | |
|
289 | QList<QTableWidgetItem*> items = this->ui->symbolsList->selectedItems(); | |
|
290 | for(int i=0;i<items.count();i++) | |
|
291 | { | |
|
292 | int row=this->ui->symbolsList->item(items.at(i)->row(),0)->text().toInt(); | |
|
293 | int section = p_elf->getSectionIndex(p_elf->getSymbolSectionName(row)); | |
|
294 | qint64 address = p_elf->getSymbolAddress(row); | |
|
295 | qint64 secAddress = p_elf->getSectionPaddr(section); | |
|
296 | qint64 size = p_elf->getSymbolSize(row); | |
|
297 | char* buff=NULL; | |
|
298 | if(size && !p_elf->sectionIsNobits(section)) | |
|
299 | { | |
|
300 | if(section!=-1) | |
|
301 | { | |
|
302 | fragment= new codeFragment(); | |
|
303 | fragment->data = (char*)malloc(size); | |
|
304 | fragment->address = address; | |
|
305 | fragment->size = size; | |
|
306 | this->p_elf->getSectionData(section,&buff); | |
|
307 | memcpy(fragment->data,buff+(address-secAddress),size); | |
|
308 | fragments.append(fragment); | |
|
309 | } | |
|
310 | } | |
|
311 | } | |
|
312 | } | |
|
313 | return fragments; | |
|
314 | ||
|
315 | } | |
|
316 | ||
|
317 | ||
|
318 | ||
|
319 | QStringList elfFileWidget::getSelectedSectionsNames() | |
|
320 | { | |
|
321 | QStringList sectionList; | |
|
322 | QList<QTableWidgetItem*> items = this->ui->sectionsList->selectedItems(); | |
|
323 | for(int i=0;i<items.count();i++) | |
|
324 | { | |
|
325 | QString section = p_elf->getSectionName(items.at(i)->row()); | |
|
326 | if(!sectionList.contains(section)) | |
|
327 | { | |
|
328 | sectionList.append(section); | |
|
329 | } | |
|
330 | } | |
|
331 | return sectionList; | |
|
332 | } | |
|
333 | ||
|
334 | ||
|
335 | ||
|
336 | ||
|
337 | ||
|
338 | ||
|
339 | ||
|
340 | ||
|
341 | ||
|
342 | ||
|
343 | ||
|
344 | ||
|
345 | ||
|
346 |
@@ -0,0 +1,66 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | #ifndef ELFFILEWIDGET_H | |
|
23 | #define ELFFILEWIDGET_H | |
|
24 | ||
|
25 | #include <QtWidgets/QWidget> | |
|
26 | #include "elffile.h" | |
|
27 | #include <QtWidgets/QAction> | |
|
28 | #include <qhexedit.h> | |
|
29 | ||
|
30 | namespace Ui { | |
|
31 | class elfFileWidget; | |
|
32 | } | |
|
33 | ||
|
34 | class elfFileWidget : public abstractBinFileWidget | |
|
35 | { | |
|
36 | Q_OBJECT | |
|
37 | ||
|
38 | public: | |
|
39 | elfFileWidget(QWidget *parent = 0); | |
|
40 | ~elfFileWidget(); | |
|
41 | ||
|
42 | public slots: | |
|
43 | void setFile(ElfFile* file); | |
|
44 | void reloadFile(); | |
|
45 | void updateSymbols(); | |
|
46 | void updateSections(); | |
|
47 | ||
|
48 | private slots: | |
|
49 | void sectionCellActivated(int row, int column); | |
|
50 | void exportToSREC(); | |
|
51 | void exportToBIN(); | |
|
52 | void viewSymbolInHexViewer(); | |
|
53 | void filterSymbols(const QString& pattern); | |
|
54 | void filterSymbolsCaseUpdate(bool toggled); | |
|
55 | private: | |
|
56 | QList<codeFragment*> getSelectedSymbolsFragments(); | |
|
57 | Ui::elfFileWidget *ui; | |
|
58 | QStringList getSelectedSectionsNames(); | |
|
59 | ElfFile* p_elf; | |
|
60 | QAction* exportToSREC_action; | |
|
61 | QAction* exportToBIN_action; | |
|
62 | QAction* viewSymbolInHexViewer_action; | |
|
63 | QHexEdit* p_hexviewer; | |
|
64 | }; | |
|
65 | ||
|
66 | #endif // ELFFILEWIDGET_H |
@@ -0,0 +1,337 | |||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
|
2 | <ui version="4.0"> | |
|
3 | <class>elfFileWidget</class> | |
|
4 | <widget class="QWidget" name="elfFileWidget"> | |
|
5 | <property name="geometry"> | |
|
6 | <rect> | |
|
7 | <x>0</x> | |
|
8 | <y>0</y> | |
|
9 | <width>786</width> | |
|
10 | <height>387</height> | |
|
11 | </rect> | |
|
12 | </property> | |
|
13 | <property name="minimumSize"> | |
|
14 | <size> | |
|
15 | <width>0</width> | |
|
16 | <height>0</height> | |
|
17 | </size> | |
|
18 | </property> | |
|
19 | <property name="focusPolicy"> | |
|
20 | <enum>Qt::NoFocus</enum> | |
|
21 | </property> | |
|
22 | <property name="windowTitle"> | |
|
23 | <string>Form</string> | |
|
24 | </property> | |
|
25 | <layout class="QGridLayout" name="gridLayout"> | |
|
26 | <item row="0" column="0"> | |
|
27 | <widget class="QTabWidget" name="tabWidget"> | |
|
28 | <property name="currentIndex"> | |
|
29 | <number>0</number> | |
|
30 | </property> | |
|
31 | <widget class="QWidget" name="generalInfoTab"> | |
|
32 | <attribute name="title"> | |
|
33 | <string>File Informations</string> | |
|
34 | </attribute> | |
|
35 | <layout class="QGridLayout" name="gridLayout_4"> | |
|
36 | <item row="0" column="0"> | |
|
37 | <widget class="QGroupBox" name="groupBox"> | |
|
38 | <property name="title"> | |
|
39 | <string>Elf header</string> | |
|
40 | </property> | |
|
41 | <layout class="QFormLayout" name="formLayout"> | |
|
42 | <item row="0" column="0"> | |
|
43 | <widget class="QLabel" name="label"> | |
|
44 | <property name="text"> | |
|
45 | <string>Class:</string> | |
|
46 | </property> | |
|
47 | </widget> | |
|
48 | </item> | |
|
49 | <item row="0" column="1"> | |
|
50 | <widget class="QLabel" name="classLabel"> | |
|
51 | <property name="text"> | |
|
52 | <string>none</string> | |
|
53 | </property> | |
|
54 | </widget> | |
|
55 | </item> | |
|
56 | <item row="1" column="0"> | |
|
57 | <widget class="QLabel" name="label_3"> | |
|
58 | <property name="text"> | |
|
59 | <string>Endianness:</string> | |
|
60 | </property> | |
|
61 | </widget> | |
|
62 | </item> | |
|
63 | <item row="1" column="1"> | |
|
64 | <widget class="QLabel" name="endiannesLabel"> | |
|
65 | <property name="text"> | |
|
66 | <string>none</string> | |
|
67 | </property> | |
|
68 | </widget> | |
|
69 | </item> | |
|
70 | <item row="2" column="0"> | |
|
71 | <widget class="QLabel" name="label_5"> | |
|
72 | <property name="text"> | |
|
73 | <string>Version:</string> | |
|
74 | </property> | |
|
75 | </widget> | |
|
76 | </item> | |
|
77 | <item row="3" column="0"> | |
|
78 | <widget class="QLabel" name="label_6"> | |
|
79 | <property name="text"> | |
|
80 | <string>Type:</string> | |
|
81 | </property> | |
|
82 | </widget> | |
|
83 | </item> | |
|
84 | <item row="4" column="0"> | |
|
85 | <widget class="QLabel" name="label_7"> | |
|
86 | <property name="text"> | |
|
87 | <string>Machine:</string> | |
|
88 | </property> | |
|
89 | </widget> | |
|
90 | </item> | |
|
91 | <item row="6" column="0"> | |
|
92 | <widget class="QLabel" name="label_8"> | |
|
93 | <property name="text"> | |
|
94 | <string>Entry point address:</string> | |
|
95 | </property> | |
|
96 | </widget> | |
|
97 | </item> | |
|
98 | <item row="2" column="1"> | |
|
99 | <widget class="QLabel" name="VersionLabel"> | |
|
100 | <property name="text"> | |
|
101 | <string>none</string> | |
|
102 | </property> | |
|
103 | </widget> | |
|
104 | </item> | |
|
105 | <item row="3" column="1"> | |
|
106 | <widget class="QLabel" name="typeLabel"> | |
|
107 | <property name="text"> | |
|
108 | <string>none</string> | |
|
109 | </property> | |
|
110 | </widget> | |
|
111 | </item> | |
|
112 | <item row="4" column="1"> | |
|
113 | <widget class="QLabel" name="machineLabel"> | |
|
114 | <property name="text"> | |
|
115 | <string>none</string> | |
|
116 | </property> | |
|
117 | </widget> | |
|
118 | </item> | |
|
119 | <item row="6" column="1"> | |
|
120 | <widget class="QLabel" name="entryPointLabel"> | |
|
121 | <property name="text"> | |
|
122 | <string>none</string> | |
|
123 | </property> | |
|
124 | </widget> | |
|
125 | </item> | |
|
126 | <item row="5" column="0"> | |
|
127 | <widget class="QLabel" name="label_17"> | |
|
128 | <property name="text"> | |
|
129 | <string>OS/ABI:</string> | |
|
130 | </property> | |
|
131 | </widget> | |
|
132 | </item> | |
|
133 | <item row="5" column="1"> | |
|
134 | <widget class="QLabel" name="abiLabel"> | |
|
135 | <property name="text"> | |
|
136 | <string>none</string> | |
|
137 | </property> | |
|
138 | </widget> | |
|
139 | </item> | |
|
140 | </layout> | |
|
141 | </widget> | |
|
142 | </item> | |
|
143 | <item row="1" column="0"> | |
|
144 | <widget class="QGroupBox" name="groupBox_2"> | |
|
145 | <property name="title"> | |
|
146 | <string>Sections & Symbols</string> | |
|
147 | </property> | |
|
148 | <layout class="QFormLayout" name="formLayout_2"> | |
|
149 | <item row="0" column="0"> | |
|
150 | <widget class="QLabel" name="label_9"> | |
|
151 | <property name="text"> | |
|
152 | <string>Section count:</string> | |
|
153 | </property> | |
|
154 | </widget> | |
|
155 | </item> | |
|
156 | <item row="1" column="0"> | |
|
157 | <widget class="QLabel" name="label_10"> | |
|
158 | <property name="text"> | |
|
159 | <string>Symbols count:</string> | |
|
160 | </property> | |
|
161 | </widget> | |
|
162 | </item> | |
|
163 | <item row="0" column="1"> | |
|
164 | <widget class="QLabel" name="sectionCountLabel"> | |
|
165 | <property name="text"> | |
|
166 | <string>none</string> | |
|
167 | </property> | |
|
168 | </widget> | |
|
169 | </item> | |
|
170 | <item row="1" column="1"> | |
|
171 | <widget class="QLabel" name="symbolCountLabel"> | |
|
172 | <property name="text"> | |
|
173 | <string>none</string> | |
|
174 | </property> | |
|
175 | </widget> | |
|
176 | </item> | |
|
177 | </layout> | |
|
178 | </widget> | |
|
179 | </item> | |
|
180 | </layout> | |
|
181 | </widget> | |
|
182 | <widget class="QWidget" name="symbolsTab"> | |
|
183 | <attribute name="title"> | |
|
184 | <string>Symbols</string> | |
|
185 | </attribute> | |
|
186 | <layout class="QGridLayout" name="gridLayout_2"> | |
|
187 | <item row="0" column="1"> | |
|
188 | <widget class="QLineEdit" name="symbolsFilter"/> | |
|
189 | </item> | |
|
190 | <item row="0" column="0"> | |
|
191 | <widget class="QLabel" name="label_2"> | |
|
192 | <property name="text"> | |
|
193 | <string>Filter:</string> | |
|
194 | </property> | |
|
195 | </widget> | |
|
196 | </item> | |
|
197 | <item row="0" column="2"> | |
|
198 | <widget class="QCheckBox" name="caseSensitive"> | |
|
199 | <property name="text"> | |
|
200 | <string>Case Sensitive</string> | |
|
201 | </property> | |
|
202 | </widget> | |
|
203 | </item> | |
|
204 | <item row="2" column="0" colspan="3"> | |
|
205 | <widget class="QTableWidget" name="symbolsList"> | |
|
206 | <property name="contextMenuPolicy"> | |
|
207 | <enum>Qt::ActionsContextMenu</enum> | |
|
208 | </property> | |
|
209 | <property name="sortingEnabled"> | |
|
210 | <bool>true</bool> | |
|
211 | </property> | |
|
212 | <attribute name="verticalHeaderVisible"> | |
|
213 | <bool>false</bool> | |
|
214 | </attribute> | |
|
215 | <attribute name="verticalHeaderShowSortIndicator" stdset="0"> | |
|
216 | <bool>false</bool> | |
|
217 | </attribute> | |
|
218 | <column> | |
|
219 | <property name="text"> | |
|
220 | <string>Index</string> | |
|
221 | </property> | |
|
222 | </column> | |
|
223 | <column> | |
|
224 | <property name="text"> | |
|
225 | <string>Value</string> | |
|
226 | </property> | |
|
227 | </column> | |
|
228 | <column> | |
|
229 | <property name="text"> | |
|
230 | <string>Size</string> | |
|
231 | </property> | |
|
232 | </column> | |
|
233 | <column> | |
|
234 | <property name="text"> | |
|
235 | <string>Type</string> | |
|
236 | </property> | |
|
237 | </column> | |
|
238 | <column> | |
|
239 | <property name="text"> | |
|
240 | <string>Link</string> | |
|
241 | </property> | |
|
242 | </column> | |
|
243 | <column> | |
|
244 | <property name="text"> | |
|
245 | <string>Section</string> | |
|
246 | </property> | |
|
247 | </column> | |
|
248 | <column> | |
|
249 | <property name="text"> | |
|
250 | <string>Name</string> | |
|
251 | </property> | |
|
252 | </column> | |
|
253 | </widget> | |
|
254 | </item> | |
|
255 | </layout> | |
|
256 | </widget> | |
|
257 | <widget class="QWidget" name="sectionsTab"> | |
|
258 | <attribute name="title"> | |
|
259 | <string>Sections</string> | |
|
260 | </attribute> | |
|
261 | <layout class="QGridLayout" name="gridLayout_3"> | |
|
262 | <item row="0" column="0"> | |
|
263 | <widget class="QSplitter" name="splitter"> | |
|
264 | <property name="orientation"> | |
|
265 | <enum>Qt::Horizontal</enum> | |
|
266 | </property> | |
|
267 | <widget class="QHexEdit" name="sectionsHexView" native="true"> | |
|
268 | <property name="minimumSize"> | |
|
269 | <size> | |
|
270 | <width>100</width> | |
|
271 | <height>0</height> | |
|
272 | </size> | |
|
273 | </property> | |
|
274 | </widget> | |
|
275 | <widget class="QTableWidget" name="sectionsList"> | |
|
276 | <property name="contextMenuPolicy"> | |
|
277 | <enum>Qt::ActionsContextMenu</enum> | |
|
278 | </property> | |
|
279 | <property name="sortingEnabled"> | |
|
280 | <bool>true</bool> | |
|
281 | </property> | |
|
282 | <attribute name="verticalHeaderVisible"> | |
|
283 | <bool>false</bool> | |
|
284 | </attribute> | |
|
285 | <attribute name="verticalHeaderShowSortIndicator" stdset="0"> | |
|
286 | <bool>false</bool> | |
|
287 | </attribute> | |
|
288 | <column> | |
|
289 | <property name="text"> | |
|
290 | <string>Index</string> | |
|
291 | </property> | |
|
292 | </column> | |
|
293 | <column> | |
|
294 | <property name="text"> | |
|
295 | <string>Name</string> | |
|
296 | </property> | |
|
297 | </column> | |
|
298 | <column> | |
|
299 | <property name="text"> | |
|
300 | <string>Address</string> | |
|
301 | </property> | |
|
302 | </column> | |
|
303 | <column> | |
|
304 | <property name="text"> | |
|
305 | <string>Size</string> | |
|
306 | </property> | |
|
307 | </column> | |
|
308 | <column> | |
|
309 | <property name="text"> | |
|
310 | <string>File Size</string> | |
|
311 | </property> | |
|
312 | </column> | |
|
313 | <column> | |
|
314 | <property name="text"> | |
|
315 | <string>Type</string> | |
|
316 | </property> | |
|
317 | </column> | |
|
318 | </widget> | |
|
319 | </widget> | |
|
320 | </item> | |
|
321 | </layout> | |
|
322 | </widget> | |
|
323 | </widget> | |
|
324 | </item> | |
|
325 | </layout> | |
|
326 | </widget> | |
|
327 | <customwidgets> | |
|
328 | <customwidget> | |
|
329 | <class>QHexEdit</class> | |
|
330 | <extends>QWidget</extends> | |
|
331 | <header location="global">qhexedit.h</header> | |
|
332 | <container>1</container> | |
|
333 | </customwidget> | |
|
334 | </customwidgets> | |
|
335 | <resources/> | |
|
336 | <connections/> | |
|
337 | </ui> |
@@ -0,0 +1,164 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | ||
|
23 | #include "elfinfowdgt.h" | |
|
24 | ||
|
25 | elfInfoWdgt::elfInfoWdgt(QWidget *parent) : | |
|
26 | QWidget(parent) | |
|
27 | { | |
|
28 | this->mainLayout = new QVBoxLayout; | |
|
29 | this->ElfArchitecture= new QLabel; | |
|
30 | this->ElfType = new QLabel; | |
|
31 | this->ElfVersion = new QLabel; | |
|
32 | this->splitter = new QSplitter; | |
|
33 | this->hexViewer = new QHexEdit; | |
|
34 | this->elfInfoWdgtLay = new QWidget; | |
|
35 | this->elfInfoWdgtLayout = new QVBoxLayout; | |
|
36 | this->segmentsListTableWdgt = new QTableWidget; | |
|
37 | this->segmentsListTableWdgt->setColumnCount(7); | |
|
38 | this->segmentsListTableWdgt->setHorizontalHeaderLabels(QStringList()<<"Type"<<"Offset"<<"Vaddr"<<"Paddr"<<"File Size"<<"Mem Size"<<"Flags"); | |
|
39 | this->sectionsListTableWdgt = new QTableWidget; | |
|
40 | this->sectionsListTableWdgt->setColumnCount(2); | |
|
41 | this->sectionsListTableWdgt->setHorizontalHeaderLabels(QStringList()<<"Name"<<"Type"); | |
|
42 | this->ElfArchitecture->setText(QString("Architecture: ")); | |
|
43 | this->ElfType->setText(QString("Type: ")); | |
|
44 | this->ElfVersion->setText(QString("Version: ")); | |
|
45 | this->elfInfoWdgtLayout->addWidget(this->ElfArchitecture); | |
|
46 | this->elfInfoWdgtLayout->addWidget(this->ElfType); | |
|
47 | this->elfInfoWdgtLayout->addWidget(this->ElfVersion); | |
|
48 | this->elfInfoWdgtLayout->addWidget(this->segmentsListTableWdgt); | |
|
49 | this->elfInfoWdgtLayout->addWidget(this->sectionsListTableWdgt); | |
|
50 | this->splitter->addWidget(this->hexViewer); | |
|
51 | this->splitter->addWidget(this->elfInfoWdgtLay); | |
|
52 | this->elfInfoWdgtLay->setLayout(this->elfInfoWdgtLayout); | |
|
53 | this->mainLayout->addWidget(this->splitter); | |
|
54 | this->setLayout(this->mainLayout); | |
|
55 | connect(this->segmentsListTableWdgt,SIGNAL(cellActivated(int,int)),this,SLOT(cellActivated(int,int))); | |
|
56 | connect(this->sectionsListTableWdgt,SIGNAL(cellActivated(int,int)),this,SLOT(cellActivated(int,int))); | |
|
57 | } | |
|
58 | ||
|
59 | ||
|
60 | void elfInfoWdgt::updateInfo(elfparser *parser) | |
|
61 | { | |
|
62 | if(parser!=NULL) | |
|
63 | { | |
|
64 | this->ElfArchitecture->setText(QString("Architecture: ")+parser->getArchitecture()); | |
|
65 | this->ElfType->setText(QString("Type: ")+parser->getType()); | |
|
66 | this->ElfVersion->setText(QString("Version: 0x")+QString::number(parser->getVersion(),16)); | |
|
67 | this->updateSectionsTable(parser); | |
|
68 | this->updateSegmentsTable(parser); | |
|
69 | } | |
|
70 | ||
|
71 | } | |
|
72 | ||
|
73 | void elfInfoWdgt::cellActivated(int row, int column) | |
|
74 | { | |
|
75 | char* buff=NULL; | |
|
76 | this->parser->getSectionData(row,&buff); | |
|
77 | this->hexViewer->setData(QByteArray(buff,this->parser->getSectionDatasz(row))); | |
|
78 | } | |
|
79 | ||
|
80 | ||
|
81 | void elfInfoWdgt::updateSectionsTable(elfparser* parser) | |
|
82 | { | |
|
83 | if(parser!=NULL) | |
|
84 | { | |
|
85 | this->parser = parser; | |
|
86 | QTableWidgetItem *item; | |
|
87 | for(int i=0 ;i<this->sectionsListTableWdgt->rowCount();i++) | |
|
88 | { | |
|
89 | for(int l=0;l<this->sectionsListTableWdgt->columnCount();l++) | |
|
90 | { | |
|
91 | item = this->sectionsListTableWdgt->item(i,l); | |
|
92 | delete item; | |
|
93 | } | |
|
94 | } | |
|
95 | this->sectionsListTableWdgt->setRowCount(parser->getSectioncount()); | |
|
96 | for(int i=0;i<parser->getSectioncount();i++) | |
|
97 | { | |
|
98 | item = new QTableWidgetItem(parser->getSectionName(i)); | |
|
99 | item->setFlags(item->flags() &~ Qt::ItemIsEditable); | |
|
100 | this->sectionsListTableWdgt->setItem(i,0,item); | |
|
101 | item = new QTableWidgetItem(parser->getSectionType(i)); | |
|
102 | item->setFlags(item->flags() &~ Qt::ItemIsEditable); | |
|
103 | this->sectionsListTableWdgt->setItem(i,1,item); | |
|
104 | } | |
|
105 | this->sectionsListTableWdgt->resizeColumnsToContents(); | |
|
106 | this->sectionsListTableWdgt->resizeRowsToContents(); | |
|
107 | } | |
|
108 | } | |
|
109 | ||
|
110 | ||
|
111 | void elfInfoWdgt::updateSegmentsTable(elfparser* parser) | |
|
112 | { | |
|
113 | if(parser!=NULL) | |
|
114 | { | |
|
115 | this->parser = parser; | |
|
116 | QTableWidgetItem *item; | |
|
117 | for(int i=0 ;i<this->segmentsListTableWdgt->rowCount();i++) | |
|
118 | { | |
|
119 | for(int l=0;l<this->segmentsListTableWdgt->columnCount();l++) | |
|
120 | { | |
|
121 | item = this->segmentsListTableWdgt->item(i,l); | |
|
122 | delete item; | |
|
123 | } | |
|
124 | } | |
|
125 | this->segmentsListTableWdgt->setRowCount(parser->getSegmentcount()); | |
|
126 | for(int i=0;i<parser->getSegmentcount();i++) | |
|
127 | { | |
|
128 | item = new QTableWidgetItem(parser->getSegmentType(i)); | |
|
129 | item->setFlags(item->flags() &~ Qt::ItemIsEditable); | |
|
130 | this->segmentsListTableWdgt->setItem(i,0,item); | |
|
131 | item = new QTableWidgetItem("0x"+QString::number(parser->getSegmentOffset(i),16)); | |
|
132 | item->setFlags(item->flags() &~ Qt::ItemIsEditable); | |
|
133 | this->segmentsListTableWdgt->setItem(i,1,item); | |
|
134 | item = new QTableWidgetItem("0x"+QString::number(parser->getSegmentVaddr(i),16)); | |
|
135 | item->setFlags(item->flags() &~ Qt::ItemIsEditable); | |
|
136 | this->segmentsListTableWdgt->setItem(i,2,item); | |
|
137 | item = new QTableWidgetItem("0x"+QString::number(parser->getSegmentPaddr(i),16)); | |
|
138 | item->setFlags(item->flags() &~ Qt::ItemIsEditable); | |
|
139 | this->segmentsListTableWdgt->setItem(i,3,item); | |
|
140 | item = new QTableWidgetItem("0x"+QString::number(parser->getSegmentFilesz(i),16)); | |
|
141 | item->setFlags(item->flags() &~ Qt::ItemIsEditable); | |
|
142 | this->segmentsListTableWdgt->setItem(i,4,item); | |
|
143 | item = new QTableWidgetItem("0x"+QString::number(parser->getSegmentMemsz(i),16)); | |
|
144 | item->setFlags(item->flags() &~ Qt::ItemIsEditable); | |
|
145 | this->segmentsListTableWdgt->setItem(i,5,item); | |
|
146 | item = new QTableWidgetItem(parser->getSegmentFlags(i)); | |
|
147 | item->setFlags(item->flags() &~ Qt::ItemIsEditable); | |
|
148 | this->segmentsListTableWdgt->setItem(i,6,item); | |
|
149 | } | |
|
150 | this->segmentsListTableWdgt->resizeColumnsToContents(); | |
|
151 | this->segmentsListTableWdgt->resizeRowsToContents(); | |
|
152 | } | |
|
153 | } | |
|
154 | ||
|
155 | ||
|
156 | ||
|
157 | ||
|
158 | ||
|
159 | ||
|
160 | ||
|
161 | ||
|
162 | ||
|
163 | ||
|
164 |
@@ -0,0 +1,64 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | #ifndef ELFINFOWDGT_H | |
|
23 | #define ELFINFOWDGT_H | |
|
24 | ||
|
25 | #include <QtWidgets/QWidget> | |
|
26 | #include "elfparser.h" | |
|
27 | #include <QtWidgets/QVBoxLayout> | |
|
28 | #include <QtWidgets/QHBoxLayout> | |
|
29 | #include <QtWidgets/QLabel> | |
|
30 | #include <QtWidgets/QTextEdit> | |
|
31 | #include <QtWidgets/QTableWidget> | |
|
32 | #include <qhexedit.h> | |
|
33 | #include <QtWidgets/QSplitter> | |
|
34 | ||
|
35 | class elfInfoWdgt : public QWidget | |
|
36 | { | |
|
37 | Q_OBJECT | |
|
38 | public: | |
|
39 | explicit elfInfoWdgt(QWidget *parent = 0); | |
|
40 | ||
|
41 | signals: | |
|
42 | ||
|
43 | ||
|
44 | public slots: | |
|
45 | void updateInfo(elfparser* parser); | |
|
46 | void cellActivated ( int row, int column ); | |
|
47 | ||
|
48 | private: | |
|
49 | void updateSectionsTable(elfparser* parser); | |
|
50 | void updateSegmentsTable(elfparser* parser); | |
|
51 | QVBoxLayout* mainLayout; | |
|
52 | QLabel* ElfArchitecture; | |
|
53 | QLabel* ElfType; | |
|
54 | QLabel* ElfVersion; | |
|
55 | QTableWidget* segmentsListTableWdgt,*sectionsListTableWdgt; | |
|
56 | QHexEdit* hexViewer; | |
|
57 | QSplitter* splitter; | |
|
58 | QWidget* elfInfoWdgtLay; | |
|
59 | QVBoxLayout* elfInfoWdgtLayout; | |
|
60 | elfparser* parser; | |
|
61 | ||
|
62 | }; | |
|
63 | ||
|
64 | #endif // ELFINFOWDGT_H |
This diff has been collapsed as it changes many lines, (522 lines changed) Show them Hide them | |||
@@ -0,0 +1,522 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | #include "elfparser.h" | |
|
23 | #include <sys/types.h> | |
|
24 | #include <sys/stat.h> | |
|
25 | #include <fcntl.h> | |
|
26 | #include <unistd.h> | |
|
27 | ||
|
28 | extern QString elfresolveMachine(Elf64_Half e_machine); | |
|
29 | ||
|
30 | ||
|
31 | elfparser::elfparser() | |
|
32 | { | |
|
33 | this->opened = false; | |
|
34 | this->type_elf = false; | |
|
35 | this->elfFile = (int)NULL; | |
|
36 | this->e = NULL; | |
|
37 | } | |
|
38 | ||
|
39 | ||
|
40 | int elfparser::setFilename(const QString &name) | |
|
41 | { | |
|
42 | this->closeFile(); | |
|
43 | if(elf_version(EV_CURRENT)==EV_NONE)return 0; | |
|
44 | #ifdef _ELF_WINDOWS_ | |
|
45 | this->elfFile = open(name.toStdString().c_str(),O_RDONLY|O_BINARY ,0); | |
|
46 | #else | |
|
47 | this->elfFile = open(name.toStdString().c_str(),O_RDONLY ,0); | |
|
48 | #endif | |
|
49 | if(this->elfFile==(int)NULL)return 0; | |
|
50 | this->e = elf_begin(this->elfFile,ELF_C_READ,NULL); | |
|
51 | if(this->e==NULL)return 0; | |
|
52 | this->ek = elf_kind(this->e); | |
|
53 | gelf_getehdr (this->e, &this->ehdr ); | |
|
54 | elf_getshdrstrndx (this->e, &this->shstrndx); | |
|
55 | this->updateSegments(); | |
|
56 | this->updateSections(); | |
|
57 | return 1; | |
|
58 | } | |
|
59 | ||
|
60 | ||
|
61 | int elfparser::closeFile() | |
|
62 | { | |
|
63 | if(this->elfFile!=(int)NULL) | |
|
64 | { | |
|
65 | if(this->e!=NULL) | |
|
66 | { | |
|
67 | elf_end(this->e); | |
|
68 | this->e = NULL; | |
|
69 | } | |
|
70 | close(this->elfFile); | |
|
71 | this->elfFile = (int)NULL; | |
|
72 | } | |
|
73 | return 0; | |
|
74 | } | |
|
75 | ||
|
76 | QString elfparser::getClass() | |
|
77 | { | |
|
78 | if(this->e!=NULL) | |
|
79 | { | |
|
80 | int eclass = gelf_getclass(this->e); | |
|
81 | if(eclass==ELFCLASS32)return "ELF32"; | |
|
82 | if(eclass==ELFCLASS64)return "ELF64"; | |
|
83 | } | |
|
84 | return "none"; | |
|
85 | } | |
|
86 | ||
|
87 | ||
|
88 | bool elfparser::isopened() | |
|
89 | { | |
|
90 | return this->opened; | |
|
91 | } | |
|
92 | ||
|
93 | ||
|
94 | bool elfparser::iself() | |
|
95 | { | |
|
96 | return this->type_elf; | |
|
97 | } | |
|
98 | ||
|
99 | ||
|
100 | QString elfparser::getArchitecture() | |
|
101 | { | |
|
102 | if(this->e!=NULL) | |
|
103 | { | |
|
104 | return elfresolveMachine(this->ehdr.e_machine); | |
|
105 | } | |
|
106 | return ""; | |
|
107 | } | |
|
108 | ||
|
109 | ||
|
110 | QString elfparser::getType() | |
|
111 | { | |
|
112 | QString kind(""); | |
|
113 | if(this->e!=NULL) | |
|
114 | { | |
|
115 | switch(this->ek) | |
|
116 | { | |
|
117 | case ELF_K_AR: | |
|
118 | kind = "Archive"; | |
|
119 | break; | |
|
120 | case ELF_K_ELF: | |
|
121 | kind = "Elf"; | |
|
122 | break; | |
|
123 | case ELF_K_COFF: | |
|
124 | kind = "COFF"; | |
|
125 | break; | |
|
126 | case ELF_K_NUM: | |
|
127 | kind = "NUM"; | |
|
128 | break; | |
|
129 | case ELF_K_NONE: | |
|
130 | kind = "Data"; | |
|
131 | break; | |
|
132 | default: | |
|
133 | kind = "Unknow"; | |
|
134 | break; | |
|
135 | } | |
|
136 | } | |
|
137 | return kind; | |
|
138 | } | |
|
139 | ||
|
140 | QString elfparser::getEndianness() | |
|
141 | { | |
|
142 | if(this->e!=NULL) | |
|
143 | { | |
|
144 | if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return "2's complement, little endian"; | |
|
145 | if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return "2's complement, big endian"; | |
|
146 | } | |
|
147 | return "none"; | |
|
148 | } | |
|
149 | ||
|
150 | QString elfparser::getABI() | |
|
151 | { | |
|
152 | if(this->e!=NULL) | |
|
153 | { | |
|
154 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NONE)return "UNIX System V ABI"; | |
|
155 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SYSV)return "Alias"; | |
|
156 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_HPUX)return "HP-UX"; | |
|
157 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_NETBSD)return "NetBSD"; | |
|
158 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_LINUX)return "Object uses GNU ELF extensions"; | |
|
159 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_SOLARIS)return "Sun Solaris"; | |
|
160 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_AIX)return "IBM AIX"; | |
|
161 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_IRIX)return "SGI Irix"; | |
|
162 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_FREEBSD)return "FreeBSD"; | |
|
163 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_TRU64)return "Compaq TRU64 UNIX"; | |
|
164 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_MODESTO)return " Novell Modesto"; | |
|
165 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_OPENBSD)return "OpenBSD"; | |
|
166 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM_AEABI)return "ARM EABI"; | |
|
167 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_ARM)return "ARM"; | |
|
168 | if(this->ehdr.e_ident[EI_OSABI]==ELFOSABI_STANDALONE)return "Standalone (embedded) application"; | |
|
169 | } | |
|
170 | return "none"; | |
|
171 | } | |
|
172 | ||
|
173 | ||
|
174 | qint64 elfparser::getVersion() | |
|
175 | { | |
|
176 | if(this->e!=NULL) | |
|
177 | { | |
|
178 | return this->ehdr.e_version; | |
|
179 | } | |
|
180 | return -1; | |
|
181 | } | |
|
182 | ||
|
183 | qint64 elfparser::getEntryPointAddress() | |
|
184 | { | |
|
185 | if(this->e!=NULL) | |
|
186 | { | |
|
187 | return this->ehdr.e_entry; | |
|
188 | } | |
|
189 | return -1; | |
|
190 | } | |
|
191 | ||
|
192 | ||
|
193 | int elfparser::getSectioncount() | |
|
194 | { | |
|
195 | return (int)this->SectionCount; | |
|
196 | } | |
|
197 | ||
|
198 | ||
|
199 | int elfparser::getSegmentcount() | |
|
200 | { | |
|
201 | return (int)this->SegmentCount; | |
|
202 | } | |
|
203 | ||
|
204 | ||
|
205 | QString elfparser::getSegmentType(int index) | |
|
206 | { | |
|
207 | QString type(""); | |
|
208 | if(this->e!=NULL) | |
|
209 | { | |
|
210 | if(index < this->Segments.count()) | |
|
211 | { | |
|
212 | switch(this->Segments.at(index)->p_type) | |
|
213 | { | |
|
214 | case PT_NULL: | |
|
215 | type = "Program header table entry unused"; | |
|
216 | break; | |
|
217 | case PT_LOAD: | |
|
218 | type = "Loadable program segment"; | |
|
219 | break; | |
|
220 | case PT_DYNAMIC : | |
|
221 | type = "Dynamic linking information"; | |
|
222 | break; | |
|
223 | case PT_INTERP: | |
|
224 | type ="Program interpreter"; | |
|
225 | break; | |
|
226 | case PT_NOTE: | |
|
227 | type = "Auxiliary information"; | |
|
228 | break; | |
|
229 | case PT_SHLIB: | |
|
230 | type = "Reserved"; | |
|
231 | break; | |
|
232 | case PT_PHDR: | |
|
233 | type = "Entry for header table itself"; | |
|
234 | break; | |
|
235 | case PT_TLS: | |
|
236 | type = "Thread-local storage segment"; | |
|
237 | break; | |
|
238 | case PT_NUM: | |
|
239 | type = "Number of defined types"; | |
|
240 | break; | |
|
241 | case PT_LOOS: | |
|
242 | type = "Start of OS-specific"; | |
|
243 | break; | |
|
244 | case PT_SUNWSTACK: | |
|
245 | type = "Stack segment"; | |
|
246 | break; | |
|
247 | case PT_LOPROC: | |
|
248 | type = "Start of processor-specific"; | |
|
249 | break; | |
|
250 | case PT_HIPROC: | |
|
251 | type = "End of processor-specific"; | |
|
252 | break; | |
|
253 | default: | |
|
254 | type = "Unknow Section Type"; | |
|
255 | break; | |
|
256 | } | |
|
257 | } | |
|
258 | } | |
|
259 | ||
|
260 | return type; | |
|
261 | } | |
|
262 | ||
|
263 | ||
|
264 | qint64 elfparser::getSegmentOffset(int index) | |
|
265 | { | |
|
266 | qint64 Offset=-1; | |
|
267 | if(this->e!=NULL) | |
|
268 | { | |
|
269 | if(index < this->Segments.count()) | |
|
270 | { | |
|
271 | Offset = (qint64)this->Segments.at(index)->p_offset; | |
|
272 | } | |
|
273 | } | |
|
274 | return Offset; | |
|
275 | } | |
|
276 | ||
|
277 | ||
|
278 | qint64 elfparser::getSegmentVaddr(int index) | |
|
279 | { | |
|
280 | int64_t Vaddr = 0; | |
|
281 | if(this->e!=NULL) | |
|
282 | { | |
|
283 | if(index < this->Segments.count()) | |
|
284 | { | |
|
285 | Vaddr = (int64_t)this->Segments.at(index)->p_vaddr; | |
|
286 | } | |
|
287 | } | |
|
288 | return Vaddr; | |
|
289 | } | |
|
290 | ||
|
291 | ||
|
292 | qint64 elfparser::getSegmentPaddr(int index) | |
|
293 | { | |
|
294 | int64_t Paddr=0; | |
|
295 | if(this->e!=NULL) | |
|
296 | { | |
|
297 | if(index < this->Segments.count()) | |
|
298 | { | |
|
299 | Paddr = (int64_t)this->Segments.at(index)->p_paddr; | |
|
300 | } | |
|
301 | } | |
|
302 | return Paddr; | |
|
303 | } | |
|
304 | ||
|
305 | qint64 elfparser::getSectionPaddr(int index) | |
|
306 | { | |
|
307 | int64_t Paddr=0; | |
|
308 | if(this->e!=NULL) | |
|
309 | { | |
|
310 | if(index < this->sections.count()) | |
|
311 | { | |
|
312 | Paddr = (int64_t)this->sections.at(index)->section_header->sh_addr; | |
|
313 | } | |
|
314 | } | |
|
315 | return Paddr; | |
|
316 | } | |
|
317 | ||
|
318 | ||
|
319 | qint64 elfparser::getSegmentFilesz(int index) | |
|
320 | { | |
|
321 | int64_t FileSz=0; | |
|
322 | if(this->e!=NULL) | |
|
323 | { | |
|
324 | if(index < this->Segments.count()) | |
|
325 | { | |
|
326 | FileSz = (int64_t)this->Segments.at(index)->p_filesz; | |
|
327 | } | |
|
328 | } | |
|
329 | return FileSz; | |
|
330 | } | |
|
331 | ||
|
332 | qint64 elfparser::getSectionDatasz(int index) | |
|
333 | { | |
|
334 | int64_t DataSz=0; | |
|
335 | if(this->e!=NULL) | |
|
336 | { | |
|
337 | if(index < this->sections.count()) | |
|
338 | { | |
|
339 | DataSz = (int64_t)this->sections.at(index)->data->d_size; | |
|
340 | } | |
|
341 | } | |
|
342 | return DataSz; | |
|
343 | } | |
|
344 | ||
|
345 | bool elfparser::getSectionData(int index, char **buffer) | |
|
346 | { | |
|
347 | if(this->e!=NULL) | |
|
348 | { | |
|
349 | if(index < this->sections.count()) | |
|
350 | { | |
|
351 | *buffer = (char *)this->sections.at(index)->data->d_buf; | |
|
352 | return true; | |
|
353 | } | |
|
354 | } | |
|
355 | return false; | |
|
356 | } | |
|
357 | ||
|
358 | ||
|
359 | qint64 elfparser::getSegmentMemsz(int index) | |
|
360 | { | |
|
361 | int64_t MemSz=0; | |
|
362 | if(this->e!=NULL) | |
|
363 | { | |
|
364 | if(index < this->Segments.count()) | |
|
365 | { | |
|
366 | MemSz = (int64_t)this->Segments.at(index)->p_memsz; | |
|
367 | } | |
|
368 | } | |
|
369 | return MemSz; | |
|
370 | } | |
|
371 | ||
|
372 | qint64 elfparser::getSectionMemsz(int index) | |
|
373 | { | |
|
374 | int64_t MemSz=0; | |
|
375 | if(this->e!=NULL) | |
|
376 | { | |
|
377 | if(index < this->sections.count()) | |
|
378 | { | |
|
379 | MemSz = (int64_t)this->sections.at(index)->section_header->sh_size; | |
|
380 | } | |
|
381 | } | |
|
382 | return MemSz; | |
|
383 | } | |
|
384 | ||
|
385 | ||
|
386 | QString elfparser::getSegmentFlags(int index) | |
|
387 | { | |
|
388 | QString flags(""); | |
|
389 | if(this->e!=NULL) | |
|
390 | { | |
|
391 | if(index < this->Segments.count()) | |
|
392 | { | |
|
393 | if((this->Segments.at(index)->p_flags&PF_X) == PF_X)flags+="x"; | |
|
394 | if((this->Segments.at(index)->p_flags&PF_W) == PF_W)flags+="w"; | |
|
395 | if((this->Segments.at(index)->p_flags&PF_R) == PF_R)flags+="r"; | |
|
396 | if((this->Segments.at(index)->p_flags&PF_MASKOS) == PF_MASKOS)flags+=" OS-specific"; | |
|
397 | if((this->Segments.at(index)->p_flags&PF_MASKPROC) == PF_MASKPROC)flags+=" Processor-specific"; | |
|
398 | } | |
|
399 | } | |
|
400 | return flags; | |
|
401 | } | |
|
402 | ||
|
403 | ||
|
404 | QString elfparser::getSectionName(int index) | |
|
405 | { | |
|
406 | char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name); | |
|
407 | return QString(nameChr); | |
|
408 | } | |
|
409 | ||
|
410 | ||
|
411 | void elfparser::updateSections() | |
|
412 | { | |
|
413 | for(int i=0;i<this->sections.count();i++) | |
|
414 | { | |
|
415 | delete this->sections.at(i); | |
|
416 | } | |
|
417 | this->sections.clear(); | |
|
418 | this->scn = elf_nextscn (this->e , NULL ); | |
|
419 | this->SectionCount = 0; | |
|
420 | while( this->scn != NULL ) | |
|
421 | { | |
|
422 | GElf_Shdr* shdr = (GElf_Shdr*)malloc(sizeof(GElf_Shdr)); | |
|
423 | gelf_getshdr ( this->scn , shdr ); | |
|
424 | Elf_Data* data = elf_getdata(this->scn, NULL); | |
|
425 | this->sections.append(new Elf_Section(data,shdr)); | |
|
426 | this->SectionCount+=1; | |
|
427 | this->scn = elf_nextscn(e , scn); | |
|
428 | } | |
|
429 | } | |
|
430 | ||
|
431 | ||
|
432 | void elfparser::updateSegments() | |
|
433 | { | |
|
434 | elf_getphdrnum (this->e , &this->SegmentCount); | |
|
435 | for(int i=0;i<this->Segments.count();i++) | |
|
436 | { | |
|
437 | free(this->Segments.at(i)); | |
|
438 | } | |
|
439 | this->Segments.clear(); | |
|
440 | for(int i=0;i<(int)this->SegmentCount;i++) | |
|
441 | { | |
|
442 | GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr)); | |
|
443 | gelf_getphdr (this->e , i , header ); | |
|
444 | this->Segments.append(header); | |
|
445 | } | |
|
446 | } | |
|
447 | ||
|
448 | ||
|
449 | ||
|
450 | ||
|
451 | ||
|
452 | QString elfparser::getSectionType(int index) | |
|
453 | { | |
|
454 | QString type(""); | |
|
455 | if(this->e!=NULL) | |
|
456 | { | |
|
457 | if(index < this->Segments.count()) | |
|
458 | { | |
|
459 | switch(this->Segments.at(index)->p_type) | |
|
460 | { | |
|
461 | case SHT_NULL : type = "Section header table entry unused"; break; | |
|
462 | case SHT_PROGBITS : type = "Program data"; break; | |
|
463 | case SHT_SYMTAB : type = "Symbol table"; break; | |
|
464 | case SHT_STRTAB : type = "String table"; break; | |
|
465 | case SHT_RELA : type = "Relocation entries with addends"; break; | |
|
466 | case SHT_HASH : type = "Symbol hash table"; break; | |
|
467 | case SHT_DYNAMIC : type = "Dynamic linking information"; break; | |
|
468 | case SHT_NOTE : type = "Notes"; break; | |
|
469 | case SHT_NOBITS :type = "Program space with no data (bss)"; break; | |
|
470 | case SHT_REL :type = "Relocation entries, no addends"; break; | |
|
471 | case SHT_SHLIB : type = "Reserved"; break; | |
|
472 | case SHT_DYNSYM : type = "Dynamic linker symbol table"; break; | |
|
473 | case SHT_INIT_ARRAY : type = "Array of constructors"; break; | |
|
474 | case SHT_FINI_ARRAY : type = "Array of destructors"; break; | |
|
475 | case SHT_PREINIT_ARRAY : type = "Array of pre-constructors"; break; | |
|
476 | case SHT_GROUP : type = "Section group"; break; | |
|
477 | case SHT_SYMTAB_SHNDX : type = "Extended section indeces"; break; | |
|
478 | case SHT_NUM : type = "Number of defined types. "; break; | |
|
479 | case SHT_LOOS : type = "Start OS-specific. "; break; | |
|
480 | case SHT_LOSUNW : type = "Sun-specific low bound. "; break; | |
|
481 | case SHT_SUNW_COMDAT : type = " "; break; | |
|
482 | case SHT_SUNW_syminfo : type = " "; break; | |
|
483 | case SHT_GNU_verdef : type = "Version definition section. "; break; | |
|
484 | case SHT_GNU_verneed : type = "Version needs section. "; break; | |
|
485 | case SHT_GNU_versym : type = "Version symbol table. "; break; | |
|
486 | case SHT_LOPROC : type = "Start of processor-specific"; break; | |
|
487 | case SHT_HIPROC : type = "End of processor-specific"; break; | |
|
488 | case SHT_HIUSER : type = "End of application-specific"; break; | |
|
489 | } | |
|
490 | } | |
|
491 | } | |
|
492 | return type; | |
|
493 | } | |
|
494 | ||
|
495 | bool elfparser::isElf(const QString &File) | |
|
496 | { | |
|
497 | int file =0; | |
|
498 | #ifdef _ELF_WINDOWS_ | |
|
499 | file = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0); | |
|
500 | #else | |
|
501 | file = open(File.toStdString().c_str(),O_RDONLY ,0); | |
|
502 | #endif | |
|
503 | char Magic[4]; | |
|
504 | if(file!=-1) | |
|
505 | { | |
|
506 | size_t res = read(file,Magic,4); | |
|
507 | close(file); | |
|
508 | if((res == 4) && (Magic[0]==0x7f) && (Magic[1]==0x45) && (Magic[2]==0x4c) && (Magic[3]==0x46)) | |
|
509 | { | |
|
510 | return true; | |
|
511 | } | |
|
512 | } | |
|
513 | return false; | |
|
514 | } | |
|
515 | ||
|
516 | ||
|
517 | ||
|
518 | ||
|
519 | ||
|
520 | ||
|
521 | ||
|
522 |
@@ -0,0 +1,89 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | #ifndef ELFPARSER_H | |
|
23 | #define ELFPARSER_H | |
|
24 | #include <libelf.h> | |
|
25 | #include <gelf.h> | |
|
26 | #include <QString> | |
|
27 | #include <stdio.h> | |
|
28 | #include <QList> | |
|
29 | #include <stdint.h> | |
|
30 | #include "elffile.h" | |
|
31 | ||
|
32 | class elfparser | |
|
33 | { | |
|
34 | public: | |
|
35 | elfparser(); | |
|
36 | bool iself(); | |
|
37 | bool isopened(); | |
|
38 | int setFilename(const QString& name); | |
|
39 | int closeFile(); | |
|
40 | QString getClass(); | |
|
41 | QString getArchitecture(); | |
|
42 | QString getType(); | |
|
43 | QString getEndianness(); | |
|
44 | QString getABI(); | |
|
45 | qint64 getVersion(); | |
|
46 | qint64 getEntryPointAddress(); | |
|
47 | int getSectioncount(); | |
|
48 | int getSegmentcount(); | |
|
49 | QString getSegmentType(int index); | |
|
50 | qint64 getSegmentOffset(int index); | |
|
51 | qint64 getSegmentVaddr(int index); | |
|
52 | qint64 getSegmentPaddr(int index); | |
|
53 | qint64 getSectionPaddr(int index); | |
|
54 | qint64 getSegmentFilesz(int index); | |
|
55 | qint64 getSectionDatasz(int index); | |
|
56 | bool getSectionData(int index, char **buffer); | |
|
57 | qint64 getSegmentMemsz(int index); | |
|
58 | qint64 getSectionMemsz(int index); | |
|
59 | QString getSegmentFlags(int index); | |
|
60 | QString getSectionName(int index); | |
|
61 | QString getSectionType(int index); | |
|
62 | static bool isElf(const QString& File); | |
|
63 | ||
|
64 | private: | |
|
65 | void updateSections(); | |
|
66 | void updateSegments(); | |
|
67 | int elfFile; | |
|
68 | bool opened; | |
|
69 | bool type_elf; | |
|
70 | Elf* e; | |
|
71 | Elf_Kind ek; | |
|
72 | GElf_Ehdr ehdr; | |
|
73 | Elf_Scn * scn; | |
|
74 | Elf_Data * data; | |
|
75 | size_t SectionCount,SegmentCount, shstrndx; | |
|
76 | QList<GElf_Phdr*> Segments; | |
|
77 | QList<Elf_Section*> sections; | |
|
78 | ||
|
79 | }; | |
|
80 | ||
|
81 | #endif // ELFPARSER_H | |
|
82 | ||
|
83 | ||
|
84 | ||
|
85 | ||
|
86 | ||
|
87 | ||
|
88 | ||
|
89 |
@@ -0,0 +1,481 | |||
|
1 | GNU LIBRARY GENERAL PUBLIC LICENSE | |
|
2 | Version 2, June 1991 | |
|
3 | ||
|
4 | Copyright (C) 1991 Free Software Foundation, Inc. | |
|
5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
6 | Everyone is permitted to copy and distribute verbatim copies | |
|
7 | of this license document, but changing it is not allowed. | |
|
8 | ||
|
9 | [This is the first released version of the library GPL. It is | |
|
10 | numbered 2 because it goes with version 2 of the ordinary GPL.] | |
|
11 | ||
|
12 | Preamble | |
|
13 | ||
|
14 | The licenses for most software are designed to take away your | |
|
15 | freedom to share and change it. By contrast, the GNU General Public | |
|
16 | Licenses are intended to guarantee your freedom to share and change | |
|
17 | free software--to make sure the software is free for all its users. | |
|
18 | ||
|
19 | This license, the Library General Public License, applies to some | |
|
20 | specially designated Free Software Foundation software, and to any | |
|
21 | other libraries whose authors decide to use it. You can use it for | |
|
22 | your libraries, too. | |
|
23 | ||
|
24 | When we speak of free software, we are referring to freedom, not | |
|
25 | price. Our General Public Licenses are designed to make sure that you | |
|
26 | have the freedom to distribute copies of free software (and charge for | |
|
27 | this service if you wish), that you receive source code or can get it | |
|
28 | if you want it, that you can change the software or use pieces of it | |
|
29 | in new free programs; and that you know you can do these things. | |
|
30 | ||
|
31 | To protect your rights, we need to make restrictions that forbid | |
|
32 | anyone to deny you these rights or to ask you to surrender the rights. | |
|
33 | These restrictions translate to certain responsibilities for you if | |
|
34 | you distribute copies of the library, or if you modify it. | |
|
35 | ||
|
36 | For example, if you distribute copies of the library, whether gratis | |
|
37 | or for a fee, you must give the recipients all the rights that we gave | |
|
38 | you. You must make sure that they, too, receive or can get the source | |
|
39 | code. If you link a program with the library, you must provide | |
|
40 | complete object files to the recipients so that they can relink them | |
|
41 | with the library, after making changes to the library and recompiling | |
|
42 | it. And you must show them these terms so they know their rights. | |
|
43 | ||
|
44 | Our method of protecting your rights has two steps: (1) copyright | |
|
45 | the library, and (2) offer you this license which gives you legal | |
|
46 | permission to copy, distribute and/or modify the library. | |
|
47 | ||
|
48 | Also, for each distributor's protection, we want to make certain | |
|
49 | that everyone understands that there is no warranty for this free | |
|
50 | library. If the library is modified by someone else and passed on, we | |
|
51 | want its recipients to know that what they have is not the original | |
|
52 | version, so that any problems introduced by others will not reflect on | |
|
53 | the original authors' reputations. | |
|
54 | ||
|
55 | Finally, any free program is threatened constantly by software | |
|
56 | patents. We wish to avoid the danger that companies distributing free | |
|
57 | software will individually obtain patent licenses, thus in effect | |
|
58 | transforming the program into proprietary software. To prevent this, | |
|
59 | we have made it clear that any patent must be licensed for everyone's | |
|
60 | free use or not licensed at all. | |
|
61 | ||
|
62 | Most GNU software, including some libraries, is covered by the ordinary | |
|
63 | GNU General Public License, which was designed for utility programs. This | |
|
64 | license, the GNU Library General Public License, applies to certain | |
|
65 | designated libraries. This license is quite different from the ordinary | |
|
66 | one; be sure to read it in full, and don't assume that anything in it is | |
|
67 | the same as in the ordinary license. | |
|
68 | ||
|
69 | The reason we have a separate public license for some libraries is that | |
|
70 | they blur the distinction we usually make between modifying or adding to a | |
|
71 | program and simply using it. Linking a program with a library, without | |
|
72 | changing the library, is in some sense simply using the library, and is | |
|
73 | analogous to running a utility program or application program. However, in | |
|
74 | a textual and legal sense, the linked executable is a combined work, a | |
|
75 | derivative of the original library, and the ordinary General Public License | |
|
76 | treats it as such. | |
|
77 | ||
|
78 | Because of this blurred distinction, using the ordinary General | |
|
79 | Public License for libraries did not effectively promote software | |
|
80 | sharing, because most developers did not use the libraries. We | |
|
81 | concluded that weaker conditions might promote sharing better. | |
|
82 | ||
|
83 | However, unrestricted linking of non-free programs would deprive the | |
|
84 | users of those programs of all benefit from the free status of the | |
|
85 | libraries themselves. This Library General Public License is intended to | |
|
86 | permit developers of non-free programs to use free libraries, while | |
|
87 | preserving your freedom as a user of such programs to change the free | |
|
88 | libraries that are incorporated in them. (We have not seen how to achieve | |
|
89 | this as regards changes in header files, but we have achieved it as regards | |
|
90 | changes in the actual functions of the Library.) The hope is that this | |
|
91 | will lead to faster development of free libraries. | |
|
92 | ||
|
93 | The precise terms and conditions for copying, distribution and | |
|
94 | modification follow. Pay close attention to the difference between a | |
|
95 | "work based on the library" and a "work that uses the library". The | |
|
96 | former contains code derived from the library, while the latter only | |
|
97 | works together with the library. | |
|
98 | ||
|
99 | Note that it is possible for a library to be covered by the ordinary | |
|
100 | General Public License rather than by this special one. | |
|
101 | ||
|
102 | GNU LIBRARY GENERAL PUBLIC LICENSE | |
|
103 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
|
104 | ||
|
105 | 0. This License Agreement applies to any software library which | |
|
106 | contains a notice placed by the copyright holder or other authorized | |
|
107 | party saying it may be distributed under the terms of this Library | |
|
108 | General Public License (also called "this License"). Each licensee is | |
|
109 | addressed as "you". | |
|
110 | ||
|
111 | A "library" means a collection of software functions and/or data | |
|
112 | prepared so as to be conveniently linked with application programs | |
|
113 | (which use some of those functions and data) to form executables. | |
|
114 | ||
|
115 | The "Library", below, refers to any such software library or work | |
|
116 | which has been distributed under these terms. A "work based on the | |
|
117 | Library" means either the Library or any derivative work under | |
|
118 | copyright law: that is to say, a work containing the Library or a | |
|
119 | portion of it, either verbatim or with modifications and/or translated | |
|
120 | straightforwardly into another language. (Hereinafter, translation is | |
|
121 | included without limitation in the term "modification".) | |
|
122 | ||
|
123 | "Source code" for a work means the preferred form of the work for | |
|
124 | making modifications to it. For a library, complete source code means | |
|
125 | all the source code for all modules it contains, plus any associated | |
|
126 | interface definition files, plus the scripts used to control compilation | |
|
127 | and installation of the library. | |
|
128 | ||
|
129 | Activities other than copying, distribution and modification are not | |
|
130 | covered by this License; they are outside its scope. The act of | |
|
131 | running a program using the Library is not restricted, and output from | |
|
132 | such a program is covered only if its contents constitute a work based | |
|
133 | on the Library (independent of the use of the Library in a tool for | |
|
134 | writing it). Whether that is true depends on what the Library does | |
|
135 | and what the program that uses the Library does. | |
|
136 | ||
|
137 | 1. You may copy and distribute verbatim copies of the Library's | |
|
138 | complete source code as you receive it, in any medium, provided that | |
|
139 | you conspicuously and appropriately publish on each copy an | |
|
140 | appropriate copyright notice and disclaimer of warranty; keep intact | |
|
141 | all the notices that refer to this License and to the absence of any | |
|
142 | warranty; and distribute a copy of this License along with the | |
|
143 | Library. | |
|
144 | ||
|
145 | You may charge a fee for the physical act of transferring a copy, | |
|
146 | and you may at your option offer warranty protection in exchange for a | |
|
147 | fee. | |
|
148 | ||
|
149 | 2. You may modify your copy or copies of the Library or any portion | |
|
150 | of it, thus forming a work based on the Library, and copy and | |
|
151 | distribute such modifications or work under the terms of Section 1 | |
|
152 | above, provided that you also meet all of these conditions: | |
|
153 | ||
|
154 | a) The modified work must itself be a software library. | |
|
155 | ||
|
156 | b) You must cause the files modified to carry prominent notices | |
|
157 | stating that you changed the files and the date of any change. | |
|
158 | ||
|
159 | c) You must cause the whole of the work to be licensed at no | |
|
160 | charge to all third parties under the terms of this License. | |
|
161 | ||
|
162 | d) If a facility in the modified Library refers to a function or a | |
|
163 | table of data to be supplied by an application program that uses | |
|
164 | the facility, other than as an argument passed when the facility | |
|
165 | is invoked, then you must make a good faith effort to ensure that, | |
|
166 | in the event an application does not supply such function or | |
|
167 | table, the facility still operates, and performs whatever part of | |
|
168 | its purpose remains meaningful. | |
|
169 | ||
|
170 | (For example, a function in a library to compute square roots has | |
|
171 | a purpose that is entirely well-defined independent of the | |
|
172 | application. Therefore, Subsection 2d requires that any | |
|
173 | application-supplied function or table used by this function must | |
|
174 | be optional: if the application does not supply it, the square | |
|
175 | root function must still compute square roots.) | |
|
176 | ||
|
177 | These requirements apply to the modified work as a whole. If | |
|
178 | identifiable sections of that work are not derived from the Library, | |
|
179 | and can be reasonably considered independent and separate works in | |
|
180 | themselves, then this License, and its terms, do not apply to those | |
|
181 | sections when you distribute them as separate works. But when you | |
|
182 | distribute the same sections as part of a whole which is a work based | |
|
183 | on the Library, the distribution of the whole must be on the terms of | |
|
184 | this License, whose permissions for other licensees extend to the | |
|
185 | entire whole, and thus to each and every part regardless of who wrote | |
|
186 | it. | |
|
187 | ||
|
188 | Thus, it is not the intent of this section to claim rights or contest | |
|
189 | your rights to work written entirely by you; rather, the intent is to | |
|
190 | exercise the right to control the distribution of derivative or | |
|
191 | collective works based on the Library. | |
|
192 | ||
|
193 | In addition, mere aggregation of another work not based on the Library | |
|
194 | with the Library (or with a work based on the Library) on a volume of | |
|
195 | a storage or distribution medium does not bring the other work under | |
|
196 | the scope of this License. | |
|
197 | ||
|
198 | 3. You may opt to apply the terms of the ordinary GNU General Public | |
|
199 | License instead of this License to a given copy of the Library. To do | |
|
200 | this, you must alter all the notices that refer to this License, so | |
|
201 | that they refer to the ordinary GNU General Public License, version 2, | |
|
202 | instead of to this License. (If a newer version than version 2 of the | |
|
203 | ordinary GNU General Public License has appeared, then you can specify | |
|
204 | that version instead if you wish.) Do not make any other change in | |
|
205 | these notices. | |
|
206 | ||
|
207 | Once this change is made in a given copy, it is irreversible for | |
|
208 | that copy, so the ordinary GNU General Public License applies to all | |
|
209 | subsequent copies and derivative works made from that copy. | |
|
210 | ||
|
211 | This option is useful when you wish to copy part of the code of | |
|
212 | the Library into a program that is not a library. | |
|
213 | ||
|
214 | 4. You may copy and distribute the Library (or a portion or | |
|
215 | derivative of it, under Section 2) in object code or executable form | |
|
216 | under the terms of Sections 1 and 2 above provided that you accompany | |
|
217 | it with the complete corresponding machine-readable source code, which | |
|
218 | must be distributed under the terms of Sections 1 and 2 above on a | |
|
219 | medium customarily used for software interchange. | |
|
220 | ||
|
221 | If distribution of object code is made by offering access to copy | |
|
222 | from a designated place, then offering equivalent access to copy the | |
|
223 | source code from the same place satisfies the requirement to | |
|
224 | distribute the source code, even though third parties are not | |
|
225 | compelled to copy the source along with the object code. | |
|
226 | ||
|
227 | 5. A program that contains no derivative of any portion of the | |
|
228 | Library, but is designed to work with the Library by being compiled or | |
|
229 | linked with it, is called a "work that uses the Library". Such a | |
|
230 | work, in isolation, is not a derivative work of the Library, and | |
|
231 | therefore falls outside the scope of this License. | |
|
232 | ||
|
233 | However, linking a "work that uses the Library" with the Library | |
|
234 | creates an executable that is a derivative of the Library (because it | |
|
235 | contains portions of the Library), rather than a "work that uses the | |
|
236 | library". The executable is therefore covered by this License. | |
|
237 | Section 6 states terms for distribution of such executables. | |
|
238 | ||
|
239 | When a "work that uses the Library" uses material from a header file | |
|
240 | that is part of the Library, the object code for the work may be a | |
|
241 | derivative work of the Library even though the source code is not. | |
|
242 | Whether this is true is especially significant if the work can be | |
|
243 | linked without the Library, or if the work is itself a library. The | |
|
244 | threshold for this to be true is not precisely defined by law. | |
|
245 | ||
|
246 | If such an object file uses only numerical parameters, data | |
|
247 | structure layouts and accessors, and small macros and small inline | |
|
248 | functions (ten lines or less in length), then the use of the object | |
|
249 | file is unrestricted, regardless of whether it is legally a derivative | |
|
250 | work. (Executables containing this object code plus portions of the | |
|
251 | Library will still fall under Section 6.) | |
|
252 | ||
|
253 | Otherwise, if the work is a derivative of the Library, you may | |
|
254 | distribute the object code for the work under the terms of Section 6. | |
|
255 | Any executables containing that work also fall under Section 6, | |
|
256 | whether or not they are linked directly with the Library itself. | |
|
257 | ||
|
258 | 6. As an exception to the Sections above, you may also compile or | |
|
259 | link a "work that uses the Library" with the Library to produce a | |
|
260 | work containing portions of the Library, and distribute that work | |
|
261 | under terms of your choice, provided that the terms permit | |
|
262 | modification of the work for the customer's own use and reverse | |
|
263 | engineering for debugging such modifications. | |
|
264 | ||
|
265 | You must give prominent notice with each copy of the work that the | |
|
266 | Library is used in it and that the Library and its use are covered by | |
|
267 | this License. You must supply a copy of this License. If the work | |
|
268 | during execution displays copyright notices, you must include the | |
|
269 | copyright notice for the Library among them, as well as a reference | |
|
270 | directing the user to the copy of this License. Also, you must do one | |
|
271 | of these things: | |
|
272 | ||
|
273 | a) Accompany the work with the complete corresponding | |
|
274 | machine-readable source code for the Library including whatever | |
|
275 | changes were used in the work (which must be distributed under | |
|
276 | Sections 1 and 2 above); and, if the work is an executable linked | |
|
277 | with the Library, with the complete machine-readable "work that | |
|
278 | uses the Library", as object code and/or source code, so that the | |
|
279 | user can modify the Library and then relink to produce a modified | |
|
280 | executable containing the modified Library. (It is understood | |
|
281 | that the user who changes the contents of definitions files in the | |
|
282 | Library will not necessarily be able to recompile the application | |
|
283 | to use the modified definitions.) | |
|
284 | ||
|
285 | b) Accompany the work with a written offer, valid for at | |
|
286 | least three years, to give the same user the materials | |
|
287 | specified in Subsection 6a, above, for a charge no more | |
|
288 | than the cost of performing this distribution. | |
|
289 | ||
|
290 | c) If distribution of the work is made by offering access to copy | |
|
291 | from a designated place, offer equivalent access to copy the above | |
|
292 | specified materials from the same place. | |
|
293 | ||
|
294 | d) Verify that the user has already received a copy of these | |
|
295 | materials or that you have already sent this user a copy. | |
|
296 | ||
|
297 | For an executable, the required form of the "work that uses the | |
|
298 | Library" must include any data and utility programs needed for | |
|
299 | reproducing the executable from it. However, as a special exception, | |
|
300 | the source code distributed need not include anything that is normally | |
|
301 | distributed (in either source or binary form) with the major | |
|
302 | components (compiler, kernel, and so on) of the operating system on | |
|
303 | which the executable runs, unless that component itself accompanies | |
|
304 | the executable. | |
|
305 | ||
|
306 | It may happen that this requirement contradicts the license | |
|
307 | restrictions of other proprietary libraries that do not normally | |
|
308 | accompany the operating system. Such a contradiction means you cannot | |
|
309 | use both them and the Library together in an executable that you | |
|
310 | distribute. | |
|
311 | ||
|
312 | 7. You may place library facilities that are a work based on the | |
|
313 | Library side-by-side in a single library together with other library | |
|
314 | facilities not covered by this License, and distribute such a combined | |
|
315 | library, provided that the separate distribution of the work based on | |
|
316 | the Library and of the other library facilities is otherwise | |
|
317 | permitted, and provided that you do these two things: | |
|
318 | ||
|
319 | a) Accompany the combined library with a copy of the same work | |
|
320 | based on the Library, uncombined with any other library | |
|
321 | facilities. This must be distributed under the terms of the | |
|
322 | Sections above. | |
|
323 | ||
|
324 | b) Give prominent notice with the combined library of the fact | |
|
325 | that part of it is a work based on the Library, and explaining | |
|
326 | where to find the accompanying uncombined form of the same work. | |
|
327 | ||
|
328 | 8. You may not copy, modify, sublicense, link with, or distribute | |
|
329 | the Library except as expressly provided under this License. Any | |
|
330 | attempt otherwise to copy, modify, sublicense, link with, or | |
|
331 | distribute the Library is void, and will automatically terminate your | |
|
332 | rights under this License. However, parties who have received copies, | |
|
333 | or rights, from you under this License will not have their licenses | |
|
334 | terminated so long as such parties remain in full compliance. | |
|
335 | ||
|
336 | 9. You are not required to accept this License, since you have not | |
|
337 | signed it. However, nothing else grants you permission to modify or | |
|
338 | distribute the Library or its derivative works. These actions are | |
|
339 | prohibited by law if you do not accept this License. Therefore, by | |
|
340 | modifying or distributing the Library (or any work based on the | |
|
341 | Library), you indicate your acceptance of this License to do so, and | |
|
342 | all its terms and conditions for copying, distributing or modifying | |
|
343 | the Library or works based on it. | |
|
344 | ||
|
345 | 10. Each time you redistribute the Library (or any work based on the | |
|
346 | Library), the recipient automatically receives a license from the | |
|
347 | original licensor to copy, distribute, link with or modify the Library | |
|
348 | subject to these terms and conditions. You may not impose any further | |
|
349 | restrictions on the recipients' exercise of the rights granted herein. | |
|
350 | You are not responsible for enforcing compliance by third parties to | |
|
351 | this License. | |
|
352 | ||
|
353 | 11. If, as a consequence of a court judgment or allegation of patent | |
|
354 | infringement or for any other reason (not limited to patent issues), | |
|
355 | conditions are imposed on you (whether by court order, agreement or | |
|
356 | otherwise) that contradict the conditions of this License, they do not | |
|
357 | excuse you from the conditions of this License. If you cannot | |
|
358 | distribute so as to satisfy simultaneously your obligations under this | |
|
359 | License and any other pertinent obligations, then as a consequence you | |
|
360 | may not distribute the Library at all. For example, if a patent | |
|
361 | license would not permit royalty-free redistribution of the Library by | |
|
362 | all those who receive copies directly or indirectly through you, then | |
|
363 | the only way you could satisfy both it and this License would be to | |
|
364 | refrain entirely from distribution of the Library. | |
|
365 | ||
|
366 | If any portion of this section is held invalid or unenforceable under any | |
|
367 | particular circumstance, the balance of the section is intended to apply, | |
|
368 | and the section as a whole is intended to apply in other circumstances. | |
|
369 | ||
|
370 | It is not the purpose of this section to induce you to infringe any | |
|
371 | patents or other property right claims or to contest validity of any | |
|
372 | such claims; this section has the sole purpose of protecting the | |
|
373 | integrity of the free software distribution system which is | |
|
374 | implemented by public license practices. Many people have made | |
|
375 | generous contributions to the wide range of software distributed | |
|
376 | through that system in reliance on consistent application of that | |
|
377 | system; it is up to the author/donor to decide if he or she is willing | |
|
378 | to distribute software through any other system and a licensee cannot | |
|
379 | impose that choice. | |
|
380 | ||
|
381 | This section is intended to make thoroughly clear what is believed to | |
|
382 | be a consequence of the rest of this License. | |
|
383 | ||
|
384 | 12. If the distribution and/or use of the Library is restricted in | |
|
385 | certain countries either by patents or by copyrighted interfaces, the | |
|
386 | original copyright holder who places the Library under this License may add | |
|
387 | an explicit geographical distribution limitation excluding those countries, | |
|
388 | so that distribution is permitted only in or among countries not thus | |
|
389 | excluded. In such case, this License incorporates the limitation as if | |
|
390 | written in the body of this License. | |
|
391 | ||
|
392 | 13. The Free Software Foundation may publish revised and/or new | |
|
393 | versions of the Library General Public License from time to time. | |
|
394 | Such new versions will be similar in spirit to the present version, | |
|
395 | but may differ in detail to address new problems or concerns. | |
|
396 | ||
|
397 | Each version is given a distinguishing version number. If the Library | |
|
398 | specifies a version number of this License which applies to it and | |
|
399 | "any later version", you have the option of following the terms and | |
|
400 | conditions either of that version or of any later version published by | |
|
401 | the Free Software Foundation. If the Library does not specify a | |
|
402 | license version number, you may choose any version ever published by | |
|
403 | the Free Software Foundation. | |
|
404 | ||
|
405 | 14. If you wish to incorporate parts of the Library into other free | |
|
406 | programs whose distribution conditions are incompatible with these, | |
|
407 | write to the author to ask for permission. For software which is | |
|
408 | copyrighted by the Free Software Foundation, write to the Free | |
|
409 | Software Foundation; we sometimes make exceptions for this. Our | |
|
410 | decision will be guided by the two goals of preserving the free status | |
|
411 | of all derivatives of our free software and of promoting the sharing | |
|
412 | and reuse of software generally. | |
|
413 | ||
|
414 | NO WARRANTY | |
|
415 | ||
|
416 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO | |
|
417 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. | |
|
418 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR | |
|
419 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY | |
|
420 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE | |
|
421 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
|
422 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE | |
|
423 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME | |
|
424 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. | |
|
425 | ||
|
426 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN | |
|
427 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY | |
|
428 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU | |
|
429 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR | |
|
430 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE | |
|
431 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING | |
|
432 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A | |
|
433 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF | |
|
434 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH | |
|
435 | DAMAGES. | |
|
436 | ||
|
437 | END OF TERMS AND CONDITIONS | |
|
438 | ||
|
439 | How to Apply These Terms to Your New Libraries | |
|
440 | ||
|
441 | If you develop a new library, and you want it to be of the greatest | |
|
442 | possible use to the public, we recommend making it free software that | |
|
443 | everyone can redistribute and change. You can do so by permitting | |
|
444 | redistribution under these terms (or, alternatively, under the terms of the | |
|
445 | ordinary General Public License). | |
|
446 | ||
|
447 | To apply these terms, attach the following notices to the library. It is | |
|
448 | safest to attach them to the start of each source file to most effectively | |
|
449 | convey the exclusion of warranty; and each file should have at least the | |
|
450 | "copyright" line and a pointer to where the full notice is found. | |
|
451 | ||
|
452 | <one line to give the library's name and a brief idea of what it does.> | |
|
453 | Copyright (C) <year> <name of author> | |
|
454 | ||
|
455 | This library is free software; you can redistribute it and/or | |
|
456 | modify it under the terms of the GNU Library General Public | |
|
457 | License as published by the Free Software Foundation; either | |
|
458 | version 2 of the License, or (at your option) any later version. | |
|
459 | ||
|
460 | This library is distributed in the hope that it will be useful, | |
|
461 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
462 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
463 | Library General Public License for more details. | |
|
464 | ||
|
465 | You should have received a copy of the GNU Library General Public | |
|
466 | License along with this library; if not, write to the Free | |
|
467 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
468 | ||
|
469 | Also add information on how to contact you by electronic and paper mail. | |
|
470 | ||
|
471 | You should also get your employer (if you work as a programmer) or your | |
|
472 | school, if any, to sign a "copyright disclaimer" for the library, if | |
|
473 | necessary. Here is a sample; alter the names: | |
|
474 | ||
|
475 | Yoyodyne, Inc., hereby disclaims all copyright interest in the | |
|
476 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. | |
|
477 | ||
|
478 | <signature of Ty Coon>, 1 April 1990 | |
|
479 | Ty Coon, President of Vice | |
|
480 | ||
|
481 | That's all there is to it! |
@@ -0,0 +1,176 | |||
|
1 | Basic Installation | |
|
2 | ================== | |
|
3 | ||
|
4 | These are generic installation instructions. | |
|
5 | ||
|
6 | The `configure' shell script attempts to guess correct values for | |
|
7 | various system-dependent variables used during compilation. It uses | |
|
8 | those values to create a `Makefile' in each directory of the package. | |
|
9 | It may also create one or more `.h' files containing system-dependent | |
|
10 | definitions. Finally, it creates a shell script `config.status' that | |
|
11 | you can run in the future to recreate the current configuration, a file | |
|
12 | `config.cache' that saves the results of its tests to speed up | |
|
13 | reconfiguring, and a file `config.log' containing compiler output | |
|
14 | (useful mainly for debugging `configure'). | |
|
15 | ||
|
16 | If you need to do unusual things to compile the package, please try | |
|
17 | to figure out how `configure' could check whether to do them, and mail | |
|
18 | diffs or instructions to the address given in the `README' so they can | |
|
19 | be considered for the next release. If at some point `config.cache' | |
|
20 | contains results you don't want to keep, you may remove or edit it. | |
|
21 | ||
|
22 | The file `configure.in' is used to create `configure' by a program | |
|
23 | called `autoconf'. You only need `configure.in' if you want to change | |
|
24 | it or regenerate `configure' using a newer version of `autoconf'. | |
|
25 | ||
|
26 | The simplest way to compile this package is: | |
|
27 | ||
|
28 | 1. `cd' to the directory containing the package's source code and type | |
|
29 | `./configure' to configure the package for your system. If you're | |
|
30 | using `csh' on an old version of System V, you might need to type | |
|
31 | `sh ./configure' instead to prevent `csh' from trying to execute | |
|
32 | `configure' itself. | |
|
33 | ||
|
34 | Running `configure' takes awhile. While running, it prints some | |
|
35 | messages telling which features it is checking for. | |
|
36 | ||
|
37 | 2. Type `make' to compile the package. | |
|
38 | ||
|
39 | 3. Optionally, type `make check' to run any self-tests that come with | |
|
40 | the package. | |
|
41 | ||
|
42 | 4. Type `make install' to install the programs and any data files and | |
|
43 | documentation. | |
|
44 | ||
|
45 | 5. You can remove the program binaries and object files from the | |
|
46 | source code directory by typing `make clean'. To also remove the | |
|
47 | files that `configure' created (so you can compile the package for | |
|
48 | a different kind of computer), type `make distclean'. There is | |
|
49 | also a `make maintainer-clean' target, but that is intended mainly | |
|
50 | for the package's developers. If you use it, you may have to get | |
|
51 | all sorts of other programs in order to regenerate files that came | |
|
52 | with the distribution. | |
|
53 | ||
|
54 | Compilers and Options | |
|
55 | ===================== | |
|
56 | ||
|
57 | Some systems require unusual options for compilation or linking that | |
|
58 | the `configure' script does not know about. You can give `configure' | |
|
59 | initial values for variables by setting them in the environment. Using | |
|
60 | a Bourne-compatible shell, you can do that on the command line like | |
|
61 | this: | |
|
62 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure | |
|
63 | ||
|
64 | Or on systems that have the `env' program, you can do it like this: | |
|
65 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure | |
|
66 | ||
|
67 | Compiling For Multiple Architectures | |
|
68 | ==================================== | |
|
69 | ||
|
70 | You can compile the package for more than one kind of computer at the | |
|
71 | same time, by placing the object files for each architecture in their | |
|
72 | own directory. To do this, you must use a version of `make' that | |
|
73 | supports the `VPATH' variable, such as GNU `make'. `cd' to the | |
|
74 | directory where you want the object files and executables to go and run | |
|
75 | the `configure' script. `configure' automatically checks for the | |
|
76 | source code in the directory that `configure' is in and in `..'. | |
|
77 | ||
|
78 | If you have to use a `make' that does not supports the `VPATH' | |
|
79 | variable, you have to compile the package for one architecture at a time | |
|
80 | in the source code directory. After you have installed the package for | |
|
81 | one architecture, use `make distclean' before reconfiguring for another | |
|
82 | architecture. | |
|
83 | ||
|
84 | Installation Names | |
|
85 | ================== | |
|
86 | ||
|
87 | By default, `make install' will install the package's files in | |
|
88 | `/usr/local/bin', `/usr/local/man', etc. You can specify an | |
|
89 | installation prefix other than `/usr/local' by giving `configure' the | |
|
90 | option `--prefix=PATH'. | |
|
91 | ||
|
92 | You can specify separate installation prefixes for | |
|
93 | architecture-specific files and architecture-independent files. If you | |
|
94 | give `configure' the option `--exec-prefix=PATH', the package will use | |
|
95 | PATH as the prefix for installing programs and libraries. | |
|
96 | Documentation and other data files will still use the regular prefix. | |
|
97 | ||
|
98 | If the package supports it, you can cause programs to be installed | |
|
99 | with an extra prefix or suffix on their names by giving `configure' the | |
|
100 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. | |
|
101 | ||
|
102 | Optional Features | |
|
103 | ================= | |
|
104 | ||
|
105 | Some packages pay attention to `--enable-FEATURE' options to | |
|
106 | `configure', where FEATURE indicates an optional part of the package. | |
|
107 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE | |
|
108 | is something like `gnu-as' or `x' (for the X Window System). The | |
|
109 | `README' should mention any `--enable-' and `--with-' options that the | |
|
110 | package recognizes. | |
|
111 | ||
|
112 | For packages that use the X Window System, `configure' can usually | |
|
113 | find the X include and library files automatically, but if it doesn't, | |
|
114 | you can use the `configure' options `--x-includes=DIR' and | |
|
115 | `--x-libraries=DIR' to specify their locations. | |
|
116 | ||
|
117 | Specifying the System Type | |
|
118 | ========================== | |
|
119 | ||
|
120 | There may be some features `configure' can not figure out | |
|
121 | automatically, but needs to determine by the type of host the package | |
|
122 | will run on. Usually `configure' can figure that out, but if it prints | |
|
123 | a message saying it can not guess the host type, give it the | |
|
124 | `--host=TYPE' option. TYPE can either be a short name for the system | |
|
125 | type, such as `sun4', or a canonical name with three fields: | |
|
126 | CPU-COMPANY-SYSTEM | |
|
127 | ||
|
128 | See the file `config.sub' for the possible values of each field. If | |
|
129 | `config.sub' isn't included in this package, then this package doesn't | |
|
130 | need to know the host type. | |
|
131 | ||
|
132 | If you are building compiler tools for cross-compiling, you can also | |
|
133 | use the `--target=TYPE' option to select the type of system they will | |
|
134 | produce code for and the `--build=TYPE' option to select the type of | |
|
135 | system on which you are compiling the package. | |
|
136 | ||
|
137 | Sharing Defaults | |
|
138 | ================ | |
|
139 | ||
|
140 | If you want to set default values for `configure' scripts to share, | |
|
141 | you can create a site shell script called `config.site' that gives | |
|
142 | default values for variables like `CC', `cache_file', and `prefix'. | |
|
143 | `configure' looks for `PREFIX/share/config.site' if it exists, then | |
|
144 | `PREFIX/etc/config.site' if it exists. Or, you can set the | |
|
145 | `CONFIG_SITE' environment variable to the location of the site script. | |
|
146 | A warning: not all `configure' scripts look for a site script. | |
|
147 | ||
|
148 | Operation Controls | |
|
149 | ================== | |
|
150 | ||
|
151 | `configure' recognizes the following options to control how it | |
|
152 | operates. | |
|
153 | ||
|
154 | `--cache-file=FILE' | |
|
155 | Use and save the results of the tests in FILE instead of | |
|
156 | `./config.cache'. Set FILE to `/dev/null' to disable caching, for | |
|
157 | debugging `configure'. | |
|
158 | ||
|
159 | `--help' | |
|
160 | Print a summary of the options to `configure', and exit. | |
|
161 | ||
|
162 | `--quiet' | |
|
163 | `--silent' | |
|
164 | `-q' | |
|
165 | Do not print messages saying which checks are being made. | |
|
166 | ||
|
167 | `--srcdir=DIR' | |
|
168 | Look for the package's source code in directory DIR. Usually | |
|
169 | `configure' can determine that directory automatically. | |
|
170 | ||
|
171 | `--version' | |
|
172 | Print the version of Autoconf used to generate the `configure' | |
|
173 | script, and exit. | |
|
174 | ||
|
175 | `configure' also accepts some other, not widely useful, options. | |
|
176 |
@@ -0,0 +1,96 | |||
|
1 | 25275 COPYING.LIB | |
|
2 | 35406 ChangeLog | |
|
3 | 7462 INSTALL | |
|
4 | 5908 Makefile.in | |
|
5 | 13232 README | |
|
6 | 7 VERSION | |
|
7 | 2955 acconfig.h | |
|
8 | 9381 aclocal.m4 | |
|
9 | 43611 config.guess | |
|
10 | 3987 config.h.in | |
|
11 | 31160 config.sub | |
|
12 | 110753 configure | |
|
13 | 11736 configure.in | |
|
14 | 2186 install-sh | |
|
15 | 4798 lib/32.fsize.c | |
|
16 | 1556 lib/32.getehdr.c | |
|
17 | 1557 lib/32.getphdr.c | |
|
18 | 1665 lib/32.getshdr.c | |
|
19 | 2181 lib/32.newehdr.c | |
|
20 | 3055 lib/32.newphdr.c | |
|
21 | 12322 lib/32.xlatetof.c | |
|
22 | 14221 lib/64.xlatetof.c | |
|
23 | 8012 lib/Makefile.in | |
|
24 | 4010 lib/Makefile.w32 | |
|
25 | 1119 lib/assert.c | |
|
26 | 10463 lib/begin.c | |
|
27 | 1685 lib/build.bat | |
|
28 | 3566 lib/byteswap.h | |
|
29 | 3937 lib/checksum.c | |
|
30 | 1901 lib/cntl.c | |
|
31 | 4851 lib/config.h.w32 | |
|
32 | 12554 lib/cook.c | |
|
33 | 1183 lib/data.c | |
|
34 | 24585 lib/elf_repl.h | |
|
35 | 2899 lib/end.c | |
|
36 | 2137 lib/errmsg.c | |
|
37 | 1037 lib/errno.c | |
|
38 | 6222 lib/errors.h | |
|
39 | 8107 lib/ext_types.h | |
|
40 | 997 lib/fill.c | |
|
41 | 2400 lib/flag.c | |
|
42 | 5103 lib/gelf.h | |
|
43 | 4151 lib/gelfehdr.c | |
|
44 | 3965 lib/gelfphdr.c | |
|
45 | 3758 lib/gelfshdr.c | |
|
46 | 9456 lib/gelftrans.c | |
|
47 | 1175 lib/getarhdr.c | |
|
48 | 1380 lib/getaroff.c | |
|
49 | 2421 lib/getarsym.c | |
|
50 | 1096 lib/getbase.c | |
|
51 | 3841 lib/getdata.c | |
|
52 | 1353 lib/getident.c | |
|
53 | 1449 lib/getscn.c | |
|
54 | 1212 lib/hash.c | |
|
55 | 2562 lib/input.c | |
|
56 | 1088 lib/kind.c | |
|
57 | 1214 lib/libelf.def | |
|
58 | 9050 lib/libelf.h | |
|
59 | 1505 lib/memset.c | |
|
60 | 1098 lib/ndxscn.c | |
|
61 | 1558 lib/newdata.c | |
|
62 | 3488 lib/newscn.c | |
|
63 | 1356 lib/next.c | |
|
64 | 1607 lib/nextscn.c | |
|
65 | 5898 lib/nlist.c | |
|
66 | 1452 lib/nlist.h | |
|
67 | 5071 lib/opt.delscn.c | |
|
68 | 13133 lib/private.h | |
|
69 | 1286 lib/rand.c | |
|
70 | 2543 lib/rawdata.c | |
|
71 | 1541 lib/rawfile.c | |
|
72 | 3393 lib/strptr.c | |
|
73 | 2285 lib/swap64.c | |
|
74 | 3812 lib/sys_elf.h.in | |
|
75 | 4066 lib/sys_elf.h.w32 | |
|
76 | 26008 lib/update.c | |
|
77 | 6884 lib/verdef.h | |
|
78 | 1586 lib/verdef_32_tof.c | |
|
79 | 1586 lib/verdef_32_tom.c | |
|
80 | 1614 lib/verdef_64_tof.c | |
|
81 | 1614 lib/verdef_64_tom.c | |
|
82 | 7135 lib/verneed.h | |
|
83 | 1435 lib/version.c | |
|
84 | 4425 lib/x.elfext.c | |
|
85 | 2721 lib/x.movscn.c | |
|
86 | 2870 lib/x.remscn.c | |
|
87 | 254 libelf.pc.in | |
|
88 | 619 mkinstalldirs | |
|
89 | 4593 po/Makefile.in | |
|
90 | 8748 po/de.gmo | |
|
91 | 52 po/de.msg | |
|
92 | 11332 po/de.po | |
|
93 | 3011 po/gmo2msg.c | |
|
94 | 6483 po/libelf.pot | |
|
95 | 10 po/stamp-po | |
|
96 | 10 stamp-h.in |
@@ -0,0 +1,332 | |||
|
1 | This is the public release of libelf-0.8.13, a free ELF object | |
|
2 | file access library. If you have problems with applications | |
|
3 | that use libelf and work with the commercial (SVR4, Solaris) | |
|
4 | version but not with this one, please contact me. | |
|
5 | ||
|
6 | IMPORTANT NOTE: If you have libelf-0.5.2 installed, you probably | |
|
7 | have a file .../include/elf.h that contains the single line | |
|
8 | ``#include <libelf/elf.h>''. REMOVE THIS FILE BEFORE YOU RUN | |
|
9 | configure. | |
|
10 | ||
|
11 | Installation is straightforward - the package is autoconf'ed. Just do | |
|
12 | ``cd libelf-0.8.13; ./configure; make; make install''. Header files | |
|
13 | will be installed in .../include/libelf/. If your system does not | |
|
14 | provide its own versions of libelf.h, nlist.h or gelf.h, ``make | |
|
15 | install'' will add the missing headers. If you prefer not to have | |
|
16 | these files installed in /usr/include, use ``--disable-compat'' and | |
|
17 | add ``-I /usr/include/libelf'' to your CFLAGS when compiling | |
|
18 | libelf-based programs. | |
|
19 | ||
|
20 | Note to distribution makers: You can install libelf in a separate root | |
|
21 | hierarchy by using the command ``make instroot=/my/root install''. | |
|
22 | You should also use the ``--enable-compat'' configure option in that | |
|
23 | case, or run ``make instroot=/my/root install-compat'' manually, to | |
|
24 | install all the required header files. | |
|
25 | ||
|
26 | If you are running Linux with libc 5.* as the default C library, | |
|
27 | and you plan to use the 64-bit functions, you must either use | |
|
28 | ``-I.../include/libelf'', or remove /usr/include/libelf.h and use | |
|
29 | ``--enable-compat'' when running configure. Libc 6.* (aka glibc2) | |
|
30 | doesn't have its own <libelf.h>, <nlist.h> or <gelf.h>. | |
|
31 | ||
|
32 | You need an ANSI/ISO C compiler to build libelf. Gcc is optimal. | |
|
33 | ||
|
34 | On some systems (in particular, Solaris and all variants of Linux), | |
|
35 | ``make'' will try to build a shared library. If you run into problems | |
|
36 | on your system, please pass ``--disable-shared'' to configure. | |
|
37 | If you build a shared library and want it to be installed as | |
|
38 | ``libelf-0.8.13.so'' rather than ``libelf.so.0.8.13'', please use | |
|
39 | ``./configure --enable-gnu-names''. Other files, e.g. ``libelf.so'' and | |
|
40 | ``libelf.so.0'' are NOT affected. | |
|
41 | ||
|
42 | Another configure option, ``--enable-debug'', adds debugging code to | |
|
43 | libelf; if you don't run into problems, you will probably not need it. | |
|
44 | ||
|
45 | When creating an ELF shared library, it is possible to add references | |
|
46 | to other shared libraries in the DYNAMIC section of the resulting | |
|
47 | file. The make variable DEPSHLIBS contains a list of libraries to add. | |
|
48 | It is set to ``-lc'' on Linux systems, and empty otherwise. To | |
|
49 | override this setting, use something like ``make DEPSHLIBS="-la -lb"''. | |
|
50 | For Linux, `-lc' is included automagically. | |
|
51 | ||
|
52 | NLS is available and enabled by default. To turn it off, pass the | |
|
53 | ``--disable-nls'' option to configure. | |
|
54 | ||
|
55 | Libelf can use gettext or catgets for accessing message | |
|
56 | catalogs. If gettext is available AND is part of libc (i.e. not | |
|
57 | in a separate library), it will be used. Otherwise, configure | |
|
58 | will look for catgets. If you have gettext in a separate | |
|
59 | library and want to use it, you should pass the library's name | |
|
60 | to configure, e.g. ``LIBS=-lintl ./configure''. Note that you | |
|
61 | MUST link your libelf-based applications with -lintl then, | |
|
62 | which is probably not what you want, or change the DEPSHLIBS variable | |
|
63 | described above (in case you're building a shared library). | |
|
64 | ||
|
65 | If you have GNU gettext 0.10 installed on your system, and if GNU gettext | |
|
66 | runs on top of the catgets interface (rather old Linux systems, using | |
|
67 | libc5), configure will refuse to use it and use catgets instead. If you | |
|
68 | absolutely want to use GNU gettext, go ahead and rebuild it (which is | |
|
69 | IMHO a good idea in general in this case): | |
|
70 | ||
|
71 | cd .../gettext-0.10 | |
|
72 | ac_cv_func_catgets=no ac_cv_func_gettext=no ./configure | |
|
73 | make | |
|
74 | make install | |
|
75 | ||
|
76 | After that, return to the libelf build directory, remove | |
|
77 | config.cache, and start over. | |
|
78 | ||
|
79 | *** Large File Support (LFS) applications *** | |
|
80 | ||
|
81 | Some 32-bit systems support files that are larger than the address space | |
|
82 | of the architecture. On these, the `off_t' data type may have 32 or | |
|
83 | 64 bits, depending on the API you choose. Since off_t is also part of | |
|
84 | the libelf API, in particular the Elf_Data and Elf_Arhdr structures, | |
|
85 | an application compiled with large file support will need a version of | |
|
86 | libelf that has also been compiled with LFS; otherwise, it won't work | |
|
87 | correctly. Similarly, a program compiled without LFS needs a library | |
|
88 | compiled without LFS. | |
|
89 | ||
|
90 | Note that libelf is currently unable to process large files on 32-bit | |
|
91 | architectures, whether you compile it for LFS or not, for the simple | |
|
92 | reason that the files won't fit into the processes' address space. | |
|
93 | Therefore, libelf is compiled without LFS by default. It can of course | |
|
94 | read and write ELF files for 64-bit architectures, but they will be | |
|
95 | limited in length on a 32-bit system. | |
|
96 | ||
|
97 | You may compile libelf with large file support by setting CPPFLAGS at | |
|
98 | configuration time: | |
|
99 | ||
|
100 | CPPFLAGS=`getconf LFS_CFLAGS` ./configure | |
|
101 | ||
|
102 | But I really, really recommend you don't, because it breaks binary | |
|
103 | compatibility with existing libelf based applications. | |
|
104 | ||
|
105 | *** 64-bit support *** | |
|
106 | ||
|
107 | Starting with libelf-0.7.0, libelf also supports 64-bit ELF files. | |
|
108 | This is enabled by default unless your system (or your compiler) does | |
|
109 | not support 64-bit integers, or lacks 64-bit declarations in <elf.h>. | |
|
110 | If you have problems building with 64-bit support, please do | |
|
111 | ||
|
112 | ./configure --disable-elf64 | |
|
113 | ||
|
114 | for the moment, and contact me. Please note that I haven't tested 64-bit | |
|
115 | support much. There are still some unresolved problems, e.g. IRIX | |
|
116 | uses different Elf64_Rel and Elf64_Rela structures (they replaced the | |
|
117 | r_info member), and the enumeration values for Elf_Type differ from | |
|
118 | the commercial (SVR4) implementation of libelf - they broke binary | |
|
119 | compatibility for no good reason, and I'm not willing to follow their | |
|
120 | footsteps. The result is that libelf-0.7.* ist upward compatible with | |
|
121 | libelf-0.6.4 (as it should be) but INCOMPATIBLE WITH SVR4 LIBELF. If you | |
|
122 | have both versions installed, you'd better make sure that you link with | |
|
123 | the library that matches the <libelf.h> you're #include'ing. | |
|
124 | ||
|
125 | *** Symbol Versioning *** | |
|
126 | ||
|
127 | Libelf >= 0.8.0 supports the data structures and definitions used for | |
|
128 | symbol versioning on Solaris and Linux, in particular, the Elfxx_Verdef, | |
|
129 | Elfxx_Verdaux, Elfxx_Verneed, Elfxx_Vernaux and Elfxx_Versym structures | |
|
130 | and the SHT_XXX_verdef, SHT_XXX_verneed and SHT_XXX_versym section types | |
|
131 | (where `xx' is either `32' or `64', and `XXX' is either `SUNW' or `GNU'). | |
|
132 | Libelf now translates versioning sections to/from their external | |
|
133 | representation properly (earlier versions left them in `raw' format, | |
|
134 | with the data type set to ELF_T_BYTE). This may cause problems on | |
|
135 | systems which use the same (OS-specific) section types for different | |
|
136 | purposes. The configure program tries to figure out if your OS uses | |
|
137 | versioning; if that check fails, you can use | |
|
138 | ||
|
139 | ./configure --disable-versioning | |
|
140 | ||
|
141 | to turn off versioning translation support. | |
|
142 | ||
|
143 | *** W32 Support *** | |
|
144 | ||
|
145 | There is now some support for building on W32 systems (requires Microsoft | |
|
146 | VC++). In order to build a W32 DLL, cd into the `lib' subdirectory, edit | |
|
147 | build.bat if necessary (it needs the path to your compiler binaries) and | |
|
148 | run it. If you're lucky, libelf.dll and the import/export libraries will | |
|
149 | be built. If not, please drop me a line. | |
|
150 | ||
|
151 | I tested it on XP Pro (SP2), using VC++ 2005 Express Edition. | |
|
152 | Apparently, Visual Studio .NET 2003 works fine as well. | |
|
153 | ||
|
154 | Various notes regarding the W32 port: | |
|
155 | ||
|
156 | - When you open() an ELF file, remember to use the O_BINARY flag. | |
|
157 | - You may have to add /MD to the linker command line. | |
|
158 | ||
|
159 | *** Missing things *** | |
|
160 | ||
|
161 | * There is no documentation. You can use the Solaris | |
|
162 | manpages instead (available at http://docs.sun.com/). | |
|
163 | The ELF file format is described in several places; | |
|
164 | among them Suns "Linker and Libraries Guide" and the | |
|
165 | "System V Application Binary Interface" documents; | |
|
166 | http://www.caldera.com/developer/devspecs/gabi41.pdf and | |
|
167 | http://www.caldera.com/developer/gabi/ are probably good | |
|
168 | starting points. Processor-specific documentation is spread | |
|
169 | across a number of `Processor Supplement' documents, one | |
|
170 | for each architecture; you'll have to use a search engine to | |
|
171 | find them. | |
|
172 | ||
|
173 | * The COFF file format is not understood. This is so obsolete | |
|
174 | that it will probably never be implemented. | |
|
175 | ||
|
176 | * nlist(3) is incomplete; the n_type and n_sclass | |
|
177 | members of struct nl are set to zero even if type | |
|
178 | (that is, debug) information is available. | |
|
179 | ||
|
180 | * Libelf does not translate Solaris' `Move' and `Syminfo' | |
|
181 | sections. You can read them using elf_getdata(), but you'll | |
|
182 | only get raw (untranslated) bytes. | |
|
183 | ||
|
184 | Changes since 0.8.12: | |
|
185 | ||
|
186 | * New function elf_getaroff(). | |
|
187 | ||
|
188 | * Build fixes. | |
|
189 | ||
|
190 | Changes since 0.8.11: | |
|
191 | ||
|
192 | * Due to some unfortunate confusion, the elf_getphnum(), | |
|
193 | elf_getshnum() and elf_getshstrndx() are not compatible | |
|
194 | between libelf implementations. Therefore, the developers | |
|
195 | decided to replace them with new functions: elf_getphdrnum(), | |
|
196 | elf_getshdrnum() and elf_getshdrstrndx(), which will always | |
|
197 | return -1 on failure and 0 on success. Code using the old | |
|
198 | interface should be upgraded to increase portability. | |
|
199 | ||
|
200 | Changes since 0.8.10: | |
|
201 | ||
|
202 | * Fixed a bug in elf_rawfile(). | |
|
203 | * If you use ELF_F_LAYOUT together with ELF_F_LAYOUT_OVERLAP, | |
|
204 | elf_update() will now tolerate overlapping sections. | |
|
205 | ||
|
206 | Changes since 0.8.9: | |
|
207 | ||
|
208 | * Ported to QNX Neutrino. | |
|
209 | * Fixed Windows build errors. | |
|
210 | * Parallel (make -j) installation should work now. | |
|
211 | ||
|
212 | * It's now possible to enable and disable select sanity checks | |
|
213 | libelf performs. Currently, this affects the "NUL terminated | |
|
214 | string table entry" check performed in elf_strptr(). By | |
|
215 | default, the function will return an error if the string | |
|
216 | requested is not properly terminated - because some | |
|
217 | applications might dump core otherwise. If you configure | |
|
218 | libelf with `--disable-sanity-checks', however, the check | |
|
219 | (and, in the future, probably others as well) is disabled | |
|
220 | by default. You can still turn it on and off at runtime by | |
|
221 | setting the LIBELF_SANITY_CHECKS environment variable to | |
|
222 | an integer value: | |
|
223 | ||
|
224 | # disable all sanity checks | |
|
225 | export LIBELF_SANITY_CHECKS=0 | |
|
226 | ||
|
227 | # enable all sanity checks | |
|
228 | export LIBELF_SANITY_CHECKS=-1 | |
|
229 | ||
|
230 | Each bit of the value corresponds to a particular check, | |
|
231 | so you could use LIBELF_SANITY_CHECKS=1 to enable only | |
|
232 | the elf_strptr() check. You may also use a value in hex | |
|
233 | (0x...) or octal (0...) format. | |
|
234 | ||
|
235 | Changes since 0.8.8: | |
|
236 | ||
|
237 | * Improved translator for symbol versioning sections. | |
|
238 | * The W32 library is now built in the `lib' subdirectory. | |
|
239 | * Windows DLLs should work now. | |
|
240 | ||
|
241 | Changes since 0.8.6: | |
|
242 | ||
|
243 | * added elf_getphnum(). | |
|
244 | * added elf_getshnum(). | |
|
245 | * added elf_getshstrndx(). | |
|
246 | * added elfx_update_shstrndx(). | |
|
247 | * handle interrupted reads/writes more gracefully. | |
|
248 | * added (partial) support for unusual e_[ps]hentsize values. | |
|
249 | * fixed the bugs introduced in 0.8.7. | |
|
250 | ||
|
251 | Changes since 0.8.5: | |
|
252 | ||
|
253 | * added W32 support. | |
|
254 | * added workaround for alignment errors in archive members. | |
|
255 | * my email address has changed again ;) | |
|
256 | ||
|
257 | Changes since 0.8.4: | |
|
258 | ||
|
259 | * elf_strptr() should now work more safely with fragmented | |
|
260 | or badly formatted string tables. | |
|
261 | ||
|
262 | Changes since 0.8.3: | |
|
263 | ||
|
264 | * Fixed a bug in elf_update() that was introduced in 0.8.3. | |
|
265 | ||
|
266 | Changes since 0.8.2: | |
|
267 | ||
|
268 | * Should compile on MacOSX now. | |
|
269 | ||
|
270 | * Can read and write files with more than 65280 sections | |
|
271 | ||
|
272 | * Tries to handle 64-bit ELF files that use 8-byte hash table | |
|
273 | entries. In particular, libelf tries to guess the data type in | |
|
274 | elf_getdata(), and doesn't override sh_entsize in elf_update() | |
|
275 | any longer. If you want the library to pick the entry size, | |
|
276 | you must set its value to 0 before you call elf_update(). | |
|
277 | ||
|
278 | * No longer dumps core in elf_update() when a versioning section | |
|
279 | has no data. Instead, it returns an error message. Note that | |
|
280 | you're supposed to provide a valid d_buf for any section, unless | |
|
281 | it's empty or has SHT_NOBITS type. | |
|
282 | ||
|
283 | * Building a shared library is now the default (if supported). | |
|
284 | ||
|
285 | Changes since 0.8.0: | |
|
286 | ||
|
287 | * Corrected typo in lib/{32,64}.xlatetof.c that sometimes | |
|
288 | caused a compilation failure. | |
|
289 | ||
|
290 | * Use open(name, O_RDONLY|O_BINARY) in lib/nlist.c. | |
|
291 | ||
|
292 | Changes since 0.7.0: | |
|
293 | ||
|
294 | * I implemented the gelf_* interface, as found on Solaris. | |
|
295 | I don't know whether it's compatible -- the Solaris manpage | |
|
296 | isn't very specific, so I had to guess return values etc. in | |
|
297 | some cases. | |
|
298 | ||
|
299 | * Added elf{32,64}_checksum (supposed to be compatible with | |
|
300 | Solaris). | |
|
301 | ||
|
302 | * Added symbol versioning support. | |
|
303 | ||
|
304 | Changes since 0.6.4: | |
|
305 | ||
|
306 | * Fixed configure for IRIX systems | |
|
307 | * Added check for truncated archive members | |
|
308 | * Added check for misaligned SHDR/PHDR tables | |
|
309 | * Support for building libelf together with GNU libc | |
|
310 | * Added elf_memory(3) | |
|
311 | * Added 64-bit support | |
|
312 | ||
|
313 | Changes since 0.5.2: | |
|
314 | ||
|
315 | * some bug fixes | |
|
316 | * mmap support | |
|
317 | * new directory layout | |
|
318 | * There is a new function, elf_delscn(), that deletes | |
|
319 | a section from an ELF file. It also adjusts the | |
|
320 | sh_link and sh_info members in the section header | |
|
321 | table, if (and ONLY if) the ELF standard indicates | |
|
322 | that these values are section indices. References | |
|
323 | to the deleted section will be cleared, so be careful. | |
|
324 | * my email address has changed ;) | |
|
325 | ||
|
326 | Where to get libelf: | |
|
327 | ||
|
328 | ftp://ftp.ibiblio.org/pub/Linux/libs/ | |
|
329 | http://www.mr511.de/software/ | |
|
330 | ||
|
331 | Michael "Tired" Riepe | |
|
332 | <libelf@mr511.de> |
@@ -0,0 +1,1 | |||
|
1 | 0.8.13 |
@@ -0,0 +1,95 | |||
|
1 | /* | |
|
2 | byteswap.h - functions and macros for byte swapping. | |
|
3 | Copyright (C) 1995 - 2001 Michael Riepe | |
|
4 | ||
|
5 | This library is free software; you can redistribute it and/or | |
|
6 | modify it under the terms of the GNU Library General Public | |
|
7 | License as published by the Free Software Foundation; either | |
|
8 | version 2 of the License, or (at your option) any later version. | |
|
9 | ||
|
10 | This library is distributed in the hope that it will be useful, | |
|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
13 | Library General Public License for more details. | |
|
14 | ||
|
15 | You should have received a copy of the GNU Library General Public | |
|
16 | License along with this library; if not, write to the Free Software | |
|
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | |
|
18 | */ | |
|
19 | ||
|
20 | /* @(#) $Id: byteswap.h,v 1.7 2008/05/23 08:15:34 michael Exp $ */ | |
|
21 | ||
|
22 | #ifndef _BYTESWAP_H | |
|
23 | #define _BYTESWAP_H | |
|
24 | ||
|
25 | #define lu(from,i,s) (((__libelf_u32_t)((unsigned char*)(from))[i])<<(s)) | |
|
26 | #define li(from,i,s) (((__libelf_i32_t)(( signed char*)(from))[i])<<(s)) | |
|
27 | ||
|
28 | #define __load_u16L(from) ((__libelf_u32_t) \ | |
|
29 | (lu(from,1,8) | lu(from,0,0))) | |
|
30 | #define __load_u16M(from) ((__libelf_u32_t) \ | |
|
31 | (lu(from,0,8) | lu(from,1,0))) | |
|
32 | #define __load_i16L(from) ((__libelf_i32_t) \ | |
|
33 | (li(from,1,8) | lu(from,0,0))) | |
|
34 | #define __load_i16M(from) ((__libelf_i32_t) \ | |
|
35 | (li(from,0,8) | lu(from,1,0))) | |
|
36 | ||
|
37 | #define __load_u32L(from) ((__libelf_u32_t) \ | |
|
38 | (lu(from,3,24) | lu(from,2,16) | lu(from,1,8) | lu(from,0,0))) | |
|
39 | #define __load_u32M(from) ((__libelf_u32_t) \ | |
|
40 | (lu(from,0,24) | lu(from,1,16) | lu(from,2,8) | lu(from,3,0))) | |
|
41 | #define __load_i32L(from) ((__libelf_i32_t) \ | |
|
42 | (li(from,3,24) | lu(from,2,16) | lu(from,1,8) | lu(from,0,0))) | |
|
43 | #define __load_i32M(from) ((__libelf_i32_t) \ | |
|
44 | (li(from,0,24) | lu(from,1,16) | lu(from,2,8) | lu(from,3,0))) | |
|
45 | ||
|
46 | #define su(to,i,v,s) (((char*)(to))[i]=((__libelf_u32_t)(v)>>(s))) | |
|
47 | #define si(to,i,v,s) (((char*)(to))[i]=((__libelf_i32_t)(v)>>(s))) | |
|
48 | ||
|
49 | #define __store_u16L(to,v) \ | |
|
50 | (su(to,1,v,8), su(to,0,v,0)) | |
|
51 | #define __store_u16M(to,v) \ | |
|
52 | (su(to,0,v,8), su(to,1,v,0)) | |
|
53 | #define __store_i16L(to,v) \ | |
|
54 | (si(to,1,v,8), si(to,0,v,0)) | |
|
55 | #define __store_i16M(to,v) \ | |
|
56 | (si(to,0,v,8), si(to,1,v,0)) | |
|
57 | ||
|
58 | #define __store_u32L(to,v) \ | |
|
59 | (su(to,3,v,24), su(to,2,v,16), su(to,1,v,8), su(to,0,v,0)) | |
|
60 | #define __store_u32M(to,v) \ | |
|
61 | (su(to,0,v,24), su(to,1,v,16), su(to,2,v,8), su(to,3,v,0)) | |
|
62 | #define __store_i32L(to,v) \ | |
|
63 | (si(to,3,v,24), si(to,2,v,16), si(to,1,v,8), si(to,0,v,0)) | |
|
64 | #define __store_i32M(to,v) \ | |
|
65 | (si(to,0,v,24), si(to,1,v,16), si(to,2,v,8), si(to,3,v,0)) | |
|
66 | ||
|
67 | #if __LIBELF64 | |
|
68 | ||
|
69 | /* | |
|
70 | * conversion functions from swap64.c | |
|
71 | */ | |
|
72 | extern __libelf_u64_t _elf_load_u64L(const unsigned char *from); | |
|
73 | extern __libelf_u64_t _elf_load_u64M(const unsigned char *from); | |
|
74 | extern __libelf_i64_t _elf_load_i64L(const unsigned char *from); | |
|
75 | extern __libelf_i64_t _elf_load_i64M(const unsigned char *from); | |
|
76 | extern void _elf_store_u64L(unsigned char *to, __libelf_u64_t v); | |
|
77 | extern void _elf_store_u64M(unsigned char *to, __libelf_u64_t v); | |
|
78 | extern void _elf_store_i64L(unsigned char *to, __libelf_u64_t v); | |
|
79 | extern void _elf_store_i64M(unsigned char *to, __libelf_u64_t v); | |
|
80 | ||
|
81 | /* | |
|
82 | * aliases for existing conversion code | |
|
83 | */ | |
|
84 | #define __load_u64L _elf_load_u64L | |
|
85 | #define __load_u64M _elf_load_u64M | |
|
86 | #define __load_i64L _elf_load_i64L | |
|
87 | #define __load_i64M _elf_load_i64M | |
|
88 | #define __store_u64L _elf_store_u64L | |
|
89 | #define __store_u64M _elf_store_u64M | |
|
90 | #define __store_i64L _elf_store_i64L | |
|
91 | #define __store_i64M _elf_store_i64M | |
|
92 | ||
|
93 | #endif /* __LIBELF64 */ | |
|
94 | ||
|
95 | #endif /* _BYTESWAP_H */ |
This diff has been collapsed as it changes many lines, (1002 lines changed) Show them Hide them | |||
@@ -0,0 +1,1002 | |||
|
1 | /* | |
|
2 | * elf_repl.h - public header file for systems that lack it. | |
|
3 | * Copyright (C) 1995 - 2006 Michael Riepe | |
|
4 | * | |
|
5 | * This library is free software; you can redistribute it and/or | |
|
6 | * modify it under the terms of the GNU Library General Public | |
|
7 | * License as published by the Free Software Foundation; either | |
|
8 | * version 2 of the License, or (at your option) any later version. | |
|
9 | * | |
|
10 | * This library is distributed in the hope that it will be useful, | |
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
13 | * Library General Public License for more details. | |
|
14 | * | |
|
15 | * You should have received a copy of the GNU Library General Public | |
|
16 | * License along with this library; if not, write to the Free Software | |
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | |
|
18 | */ | |
|
19 | ||
|
20 | /* @(#) $Id: elf_repl.h,v 1.22 2009/11/01 13:04:19 michael Exp $ */ | |
|
21 | ||
|
22 | /* | |
|
23 | * NEVER INCLUDE THIS FILE DIRECTLY - USE <libelf.h> INSTEAD! | |
|
24 | */ | |
|
25 | ||
|
26 | #ifndef _ELF_REPL_H | |
|
27 | #define _ELF_REPL_H | |
|
28 | ||
|
29 | #ifdef __cplusplus | |
|
30 | extern "C" { | |
|
31 | #endif /* __cplusplus */ | |
|
32 | ||
|
33 | /* | |
|
34 | * Scalar data types | |
|
35 | */ | |
|
36 | typedef __libelf_u32_t Elf32_Addr; | |
|
37 | typedef __libelf_u16_t Elf32_Half; | |
|
38 | typedef __libelf_u32_t Elf32_Off; | |
|
39 | typedef __libelf_i32_t Elf32_Sword; | |
|
40 | typedef __libelf_u32_t Elf32_Word; | |
|
41 | ||
|
42 | #define ELF32_FSZ_ADDR 4 | |
|
43 | #define ELF32_FSZ_HALF 2 | |
|
44 | #define ELF32_FSZ_OFF 4 | |
|
45 | #define ELF32_FSZ_SWORD 4 | |
|
46 | #define ELF32_FSZ_WORD 4 | |
|
47 | ||
|
48 | #if __LIBELF64 | |
|
49 | ||
|
50 | typedef __libelf_u64_t Elf64_Addr; | |
|
51 | typedef __libelf_u16_t Elf64_Half; | |
|
52 | typedef __libelf_u64_t Elf64_Off; | |
|
53 | typedef __libelf_i32_t Elf64_Sword; | |
|
54 | typedef __libelf_u32_t Elf64_Word; | |
|
55 | typedef __libelf_i64_t Elf64_Sxword; | |
|
56 | typedef __libelf_u64_t Elf64_Xword; | |
|
57 | ||
|
58 | #define ELF64_FSZ_ADDR 8 | |
|
59 | #define ELF64_FSZ_HALF 2 | |
|
60 | #define ELF64_FSZ_OFF 8 | |
|
61 | #define ELF64_FSZ_SWORD 4 | |
|
62 | #define ELF64_FSZ_WORD 4 | |
|
63 | #define ELF64_FSZ_SXWORD 8 | |
|
64 | #define ELF64_FSZ_XWORD 8 | |
|
65 | ||
|
66 | /* | |
|
67 | * Blame Sun for this... | |
|
68 | */ | |
|
69 | typedef __libelf_u64_t Elf64_Lword; | |
|
70 | typedef __libelf_u64_t Elf32_Lword; | |
|
71 | ||
|
72 | #endif /* __LIBELF64 */ | |
|
73 | ||
|
74 | /* | |
|
75 | * ELF header | |
|
76 | */ | |
|
77 | #define EI_NIDENT 16 | |
|
78 | ||
|
79 | typedef struct { | |
|
80 | unsigned char e_ident[EI_NIDENT]; | |
|
81 | Elf32_Half e_type; | |
|
82 | Elf32_Half e_machine; | |
|
83 | Elf32_Word e_version; | |
|
84 | Elf32_Addr e_entry; | |
|
85 | Elf32_Off e_phoff; | |
|
86 | Elf32_Off e_shoff; | |
|
87 | Elf32_Word e_flags; | |
|
88 | Elf32_Half e_ehsize; | |
|
89 | Elf32_Half e_phentsize; | |
|
90 | Elf32_Half e_phnum; | |
|
91 | Elf32_Half e_shentsize; | |
|
92 | Elf32_Half e_shnum; | |
|
93 | Elf32_Half e_shstrndx; | |
|
94 | } Elf32_Ehdr; | |
|
95 | ||
|
96 | #if __LIBELF64 | |
|
97 | typedef struct { | |
|
98 | unsigned char e_ident[EI_NIDENT]; | |
|
99 | Elf64_Half e_type; | |
|
100 | Elf64_Half e_machine; | |
|
101 | Elf64_Word e_version; | |
|
102 | Elf64_Addr e_entry; | |
|
103 | Elf64_Off e_phoff; | |
|
104 | Elf64_Off e_shoff; | |
|
105 | Elf64_Word e_flags; | |
|
106 | Elf64_Half e_ehsize; | |
|
107 | Elf64_Half e_phentsize; | |
|
108 | Elf64_Half e_phnum; | |
|
109 | Elf64_Half e_shentsize; | |
|
110 | Elf64_Half e_shnum; | |
|
111 | Elf64_Half e_shstrndx; | |
|
112 | } Elf64_Ehdr; | |
|
113 | #endif /* __LIBELF64 */ | |
|
114 | ||
|
115 | /* | |
|
116 | * e_ident | |
|
117 | */ | |
|
118 | #define EI_MAG0 0 | |
|
119 | #define EI_MAG1 1 | |
|
120 | #define EI_MAG2 2 | |
|
121 | #define EI_MAG3 3 | |
|
122 | #define EI_CLASS 4 | |
|
123 | #define EI_DATA 5 | |
|
124 | #define EI_VERSION 6 | |
|
125 | #define EI_OSABI 7 | |
|
126 | #define EI_ABIVERSION 8 | |
|
127 | #define EI_PAD 9 | |
|
128 | ||
|
129 | #define ELFMAG0 0x7f | |
|
130 | #define ELFMAG1 'E' | |
|
131 | #define ELFMAG2 'L' | |
|
132 | #define ELFMAG3 'F' | |
|
133 | #define ELFMAG "\177ELF" | |
|
134 | #define SELFMAG 4 | |
|
135 | ||
|
136 | /* | |
|
137 | * e_ident[EI_CLASS] | |
|
138 | */ | |
|
139 | #define ELFCLASSNONE 0 | |
|
140 | #define ELFCLASS32 1 | |
|
141 | #define ELFCLASS64 2 | |
|
142 | #define ELFCLASSNUM 3 | |
|
143 | ||
|
144 | /* | |
|
145 | * e_ident[EI_DATA] | |
|
146 | */ | |
|
147 | #define ELFDATANONE 0 | |
|
148 | #define ELFDATA2LSB 1 | |
|
149 | #define ELFDATA2MSB 2 | |
|
150 | #define ELFDATANUM 3 | |
|
151 | ||
|
152 | /* | |
|
153 | * e_ident[EI_OSABI] | |
|
154 | */ | |
|
155 | #define ELFOSABI_NONE 0 /* No extensions or unspecified */ | |
|
156 | #define ELFOSABI_SYSV ELFOSABI_NONE | |
|
157 | #define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */ | |
|
158 | #define ELFOSABI_NETBSD 2 /* NetBSD */ | |
|
159 | #define ELFOSABI_LINUX 3 /* Linux */ | |
|
160 | #define ELFOSABI_SOLARIS 6 /* Sun Solaris */ | |
|
161 | #define ELFOSABI_AIX 7 /* AIX */ | |
|
162 | #define ELFOSABI_IRIX 8 /* IRIX */ | |
|
163 | #define ELFOSABI_FREEBSD 9 /* FreeBSD */ | |
|
164 | #define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */ | |
|
165 | #define ELFOSABI_MODESTO 11 /* Novell Modesto */ | |
|
166 | #define ELFOSABI_OPENBSD 12 /* Open BSD */ | |
|
167 | #define ELFOSABI_OPENVMS 13 /* Open VMS */ | |
|
168 | #define ELFOSABI_NSK 14 /* Hewlett-Packard Non-Stop Kernel */ | |
|
169 | #define ELFOSABI_AROS 15 /* Amiga Research OS */ | |
|
170 | /* these are probably obsolete: */ | |
|
171 | #define ELFOSABI_ARM_AEABI 64 /* ARM EABI */ | |
|
172 | #define ELFOSABI_ARM 97 /* ARM */ | |
|
173 | #define ELFOSABI_STANDALONE 255 /* standalone (embedded) application */ | |
|
174 | ||
|
175 | ||
|
176 | /* | |
|
177 | * e_type | |
|
178 | */ | |
|
179 | #define ET_NONE 0 | |
|
180 | #define ET_REL 1 | |
|
181 | #define ET_EXEC 2 | |
|
182 | #define ET_DYN 3 | |
|
183 | #define ET_CORE 4 | |
|
184 | #define ET_NUM 5 | |
|
185 | #define ET_LOOS 0xfe00 | |
|
186 | #define ET_HIOS 0xfeff | |
|
187 | #define ET_LOPROC 0xff00 | |
|
188 | #define ET_HIPROC 0xffff | |
|
189 | ||
|
190 | /* | |
|
191 | * e_machine | |
|
192 | */ | |
|
193 | #define EM_NONE 0 /* No machine */ | |
|
194 | #define EM_M32 1 /* AT&T WE 32100 */ | |
|
195 | #define EM_SPARC 2 /* SPARC */ | |
|
196 | #define EM_386 3 /* Intel 80386 */ | |
|
197 | #define EM_68K 4 /* Motorola 68000 */ | |
|
198 | #define EM_88K 5 /* Motorola 88000 */ | |
|
199 | #define EM_486 6 /* Intel i486 (DO NOT USE THIS ONE) */ | |
|
200 | #define EM_860 7 /* Intel 80860 */ | |
|
201 | #define EM_MIPS 8 /* MIPS I Architecture */ | |
|
202 | #define EM_S370 9 /* IBM System/370 Processor */ | |
|
203 | #define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */ | |
|
204 | #define EM_SPARC64 11 /* SPARC 64-bit */ | |
|
205 | #define EM_PARISC 15 /* Hewlett-Packard PA-RISC */ | |
|
206 | #define EM_VPP500 17 /* Fujitsu VPP500 */ | |
|
207 | #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ | |
|
208 | #define EM_960 19 /* Intel 80960 */ | |
|
209 | #define EM_PPC 20 /* PowerPC */ | |
|
210 | #define EM_PPC64 21 /* 64-bit PowerPC */ | |
|
211 | #define EM_S390 22 /* IBM System/390 Processor */ | |
|
212 | #define EM_V800 36 /* NEC V800 */ | |
|
213 | #define EM_FR20 37 /* Fujitsu FR20 */ | |
|
214 | #define EM_RH32 38 /* TRW RH-32 */ | |
|
215 | #define EM_RCE 39 /* Motorola RCE */ | |
|
216 | #define EM_ARM 40 /* Advanced RISC Machines ARM */ | |
|
217 | #define EM_FAKE_ALPHA 41 /* Digital Alpha */ | |
|
218 | #define EM_SH 42 /* Hitachi SH */ | |
|
219 | #define EM_SPARCV9 43 /* SPARC Version 9 */ | |
|
220 | #define EM_TRICORE 44 /* Siemens TriCore embedded processor */ | |
|
221 | #define EM_ARC 45 /* Argonaut RISC Core, Argonaut Technologies Inc. */ | |
|
222 | #define EM_H8_300 46 /* Hitachi H8/300 */ | |
|
223 | #define EM_H8_300H 47 /* Hitachi H8/300H */ | |
|
224 | #define EM_H8S 48 /* Hitachi H8S */ | |
|
225 | #define EM_H8_500 49 /* Hitachi H8/500 */ | |
|
226 | #define EM_IA_64 50 /* Intel IA-64 processor architecture */ | |
|
227 | #define EM_MIPS_X 51 /* Stanford MIPS-X */ | |
|
228 | #define EM_COLDFIRE 52 /* Motorola ColdFire */ | |
|
229 | #define EM_68HC12 53 /* Motorola M68HC12 */ | |
|
230 | #define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator */ | |
|
231 | #define EM_PCP 55 /* Siemens PCP */ | |
|
232 | #define EM_NCPU 56 /* Sony nCPU embedded RISC processor */ | |
|
233 | #define EM_NDR1 57 /* Denso NDR1 microprocessor */ | |
|
234 | #define EM_STARCORE 58 /* Motorola Star*Core processor */ | |
|
235 | #define EM_ME16 59 /* Toyota ME16 processor */ | |
|
236 | #define EM_ST100 60 /* STMicroelectronics ST100 processor */ | |
|
237 | #define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded processor family */ | |
|
238 | #define EM_X86_64 62 /* AMD x86-64 architecture */ | |
|
239 | #define EM_AMD64 EM_X86_64 | |
|
240 | #define EM_PDSP 63 /* Sony DSP Processor */ | |
|
241 | #define EM_FX66 66 /* Siemens FX66 microcontroller */ | |
|
242 | #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 bit microcontroller */ | |
|
243 | #define EM_ST7 68 /* STMicroelectronics ST7 8-bit microcontroller */ | |
|
244 | #define EM_68HC16 69 /* Motorola MC68HC16 Microcontroller */ | |
|
245 | #define EM_68HC11 70 /* Motorola MC68HC11 Microcontroller */ | |
|
246 | #define EM_68HC08 71 /* Motorola MC68HC08 Microcontroller */ | |
|
247 | #define EM_68HC05 72 /* Motorola MC68HC05 Microcontroller */ | |
|
248 | #define EM_SVX 73 /* Silicon Graphics SVx */ | |
|
249 | #define EM_ST19 74 /* STMicroelectronics ST19 8-bit microcontroller */ | |
|
250 | #define EM_VAX 75 /* Digital VAX */ | |
|
251 | #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ | |
|
252 | #define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */ | |
|
253 | #define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ | |
|
254 | #define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ | |
|
255 | #define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */ | |
|
256 | #define EM_HUANY 81 /* Harvard University machine-independent object files */ | |
|
257 | #define EM_PRISM 82 /* SiTera Prism */ | |
|
258 | #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ | |
|
259 | #define EM_FR30 84 /* Fujitsu FR30 */ | |
|
260 | #define EM_D10V 85 /* Mitsubishi D10V */ | |
|
261 | #define EM_D30V 86 /* Mitsubishi D30V */ | |
|
262 | #define EM_V850 87 /* NEC v850 */ | |
|
263 | #define EM_M32R 88 /* Mitsubishi M32R */ | |
|
264 | #define EM_MN10300 89 /* Matsushita MN10300 */ | |
|
265 | #define EM_MN10200 90 /* Matsushita MN10200 */ | |
|
266 | #define EM_PJ 91 /* picoJava */ | |
|
267 | #define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ | |
|
268 | #define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ | |
|
269 | #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ | |
|
270 | #define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor */ | |
|
271 | #define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose Processor */ | |
|
272 | #define EM_NS32K 97 /* National Semiconductor 32000 series */ | |
|
273 | #define EM_TPC 98 /* Tenor Network TPC processor */ | |
|
274 | #define EM_SNP1K 99 /* Trebia SNP 1000 processor */ | |
|
275 | #define EM_ST200 100 /* STMicroelectronics (www.st.com) ST200 microcontroller */ | |
|
276 | #define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family */ | |
|
277 | #define EM_MAX 102 /* MAX Processor */ | |
|
278 | #define EM_CR 103 /* National Semiconductor CompactRISC microprocessor */ | |
|
279 | #define EM_F2MC16 104 /* Fujitsu F2MC16 */ | |
|
280 | #define EM_MSP430 105 /* Texas Instruments embedded microcontroller msp430 */ | |
|
281 | #define EM_BLACKFIN 106 /* Analog Devices Blackfin (DSP) processor */ | |
|
282 | #define EM_SE_C33 107 /* S1C33 Family of Seiko Epson processors */ | |
|
283 | #define EM_SEP 108 /* Sharp embedded microprocessor */ | |
|
284 | #define EM_ARCA 109 /* Arca RISC Microprocessor */ | |
|
285 | #define EM_UNICORE 110 /* Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University */ | |
|
286 | #define EM_AARCH64 183 /* ARM AARCH64 */ | |
|
287 | #define EM_TILEPRO 188 /* Tilera TILEPro */ | |
|
288 | #define EM_MICROBLAZE 189 /* Xilinx MicroBlaze */ | |
|
289 | #define EM_TILEGX 191 /* Tilera TILE-Gx */ | |
|
290 | #define EM_NUM 192 | |
|
291 | ||
|
292 | ||
|
293 | /* | |
|
294 | * e_ident[EI_VERSION], e_version | |
|
295 | */ | |
|
296 | #define EV_NONE 0 | |
|
297 | #define EV_CURRENT 1 | |
|
298 | #define EV_NUM 2 | |
|
299 | ||
|
300 | /* | |
|
301 | * Section header | |
|
302 | */ | |
|
303 | typedef struct { | |
|
304 | Elf32_Word sh_name; | |
|
305 | Elf32_Word sh_type; | |
|
306 | Elf32_Word sh_flags; | |
|
307 | Elf32_Addr sh_addr; | |
|
308 | Elf32_Off sh_offset; | |
|
309 | Elf32_Word sh_size; | |
|
310 | Elf32_Word sh_link; | |
|
311 | Elf32_Word sh_info; | |
|
312 | Elf32_Word sh_addralign; | |
|
313 | Elf32_Word sh_entsize; | |
|
314 | } Elf32_Shdr; | |
|
315 | ||
|
316 | #if __LIBELF64 | |
|
317 | typedef struct { | |
|
318 | Elf64_Word sh_name; | |
|
319 | Elf64_Word sh_type; | |
|
320 | Elf64_Xword sh_flags; | |
|
321 | Elf64_Addr sh_addr; | |
|
322 | Elf64_Off sh_offset; | |
|
323 | Elf64_Xword sh_size; | |
|
324 | Elf64_Word sh_link; | |
|
325 | Elf64_Word sh_info; | |
|
326 | Elf64_Xword sh_addralign; | |
|
327 | Elf64_Xword sh_entsize; | |
|
328 | } Elf64_Shdr; | |
|
329 | #endif /* __LIBELF64 */ | |
|
330 | ||
|
331 | /* | |
|
332 | * Special section indices | |
|
333 | */ | |
|
334 | #define SHN_UNDEF 0 | |
|
335 | #define SHN_LORESERVE 0xff00 | |
|
336 | #define SHN_LOPROC 0xff00 | |
|
337 | #define SHN_HIPROC 0xff1f | |
|
338 | #define SHN_LOOS 0xff20 | |
|
339 | #define SHN_HIOS 0xff3f | |
|
340 | #define SHN_ABS 0xfff1 | |
|
341 | #define SHN_COMMON 0xfff2 | |
|
342 | #define SHN_XINDEX 0xffff | |
|
343 | #define SHN_HIRESERVE 0xffff | |
|
344 | ||
|
345 | /* | |
|
346 | * sh_type | |
|
347 | */ | |
|
348 | #define SHT_NULL 0 | |
|
349 | #define SHT_PROGBITS 1 | |
|
350 | #define SHT_SYMTAB 2 | |
|
351 | #define SHT_STRTAB 3 | |
|
352 | #define SHT_RELA 4 | |
|
353 | #define SHT_HASH 5 | |
|
354 | #define SHT_DYNAMIC 6 | |
|
355 | #define SHT_NOTE 7 | |
|
356 | #define SHT_NOBITS 8 | |
|
357 | #define SHT_REL 9 | |
|
358 | #define SHT_SHLIB 10 | |
|
359 | #define SHT_DYNSYM 11 | |
|
360 | #define SHT_INIT_ARRAY 14 | |
|
361 | #define SHT_FINI_ARRAY 15 | |
|
362 | #define SHT_PREINIT_ARRAY 16 | |
|
363 | #define SHT_GROUP 17 | |
|
364 | #define SHT_SYMTAB_SHNDX 18 | |
|
365 | #define SHT_NUM 19 | |
|
366 | #define SHT_LOOS 0x60000000 | |
|
367 | #define SHT_HIOS 0x6fffffff | |
|
368 | #define SHT_LOPROC 0x70000000 | |
|
369 | #define SHT_HIPROC 0x7fffffff | |
|
370 | #define SHT_LOUSER 0x80000000 | |
|
371 | #define SHT_HIUSER 0xffffffff | |
|
372 | ||
|
373 | /* | |
|
374 | * Solaris extensions | |
|
375 | */ | |
|
376 | #define SHT_LOSUNW 0x6ffffff4 | |
|
377 | #define SHT_SUNW_dof 0x6ffffff4 | |
|
378 | #define SHT_SUNW_cap 0x6ffffff5 | |
|
379 | #define SHT_SUNW_SIGNATURE 0x6ffffff6 | |
|
380 | #define SHT_SUNW_ANNOTATE 0x6ffffff7 | |
|
381 | #define SHT_SUNW_DEBUGSTR 0x6ffffff8 | |
|
382 | #define SHT_SUNW_DEBUG 0x6ffffff9 | |
|
383 | #define SHT_SUNW_move 0x6ffffffa | |
|
384 | #define SHT_SUNW_COMDAT 0x6ffffffb | |
|
385 | #define SHT_SUNW_syminfo 0x6ffffffc | |
|
386 | #define SHT_SUNW_verdef 0x6ffffffd | |
|
387 | #define SHT_SUNW_verneed 0x6ffffffe | |
|
388 | #define SHT_SUNW_versym 0x6fffffff | |
|
389 | #define SHT_HISUNW 0x6fffffff | |
|
390 | ||
|
391 | #define SHT_SPARC_GOTDATA 0x70000000 | |
|
392 | #define SHT_AMD64_UNWIND 0x70000001 | |
|
393 | ||
|
394 | /* | |
|
395 | * GNU extensions | |
|
396 | */ | |
|
397 | #define SHT_GNU_verdef 0x6ffffffd | |
|
398 | #define SHT_GNU_verneed 0x6ffffffe | |
|
399 | #define SHT_GNU_versym 0x6fffffff | |
|
400 | ||
|
401 | /* | |
|
402 | * sh_flags | |
|
403 | */ | |
|
404 | #define SHF_WRITE 0x1 | |
|
405 | #define SHF_ALLOC 0x2 | |
|
406 | #define SHF_EXECINSTR 0x4 | |
|
407 | #define SHF_MERGE 0x10 | |
|
408 | #define SHF_STRINGS 0x20 | |
|
409 | #define SHF_INFO_LINK 0x40 | |
|
410 | #define SHF_LINK_ORDER 0x80 | |
|
411 | #define SHF_OS_NONCONFORMING 0x100 | |
|
412 | #define SHF_GROUP 0x200 | |
|
413 | #define SHF_TLS 0x400 | |
|
414 | #define SHF_MASKOS 0x0ff00000 | |
|
415 | #define SHF_MASKPROC 0xf0000000 | |
|
416 | ||
|
417 | /* | |
|
418 | * Solaris extensions | |
|
419 | */ | |
|
420 | #define SHF_AMD64_LARGE 0x10000000 | |
|
421 | #define SHF_ORDERED 0x40000000 | |
|
422 | #define SHF_EXCLUDE 0x80000000 | |
|
423 | ||
|
424 | /* | |
|
425 | * Section group flags | |
|
426 | */ | |
|
427 | #define GRP_COMDAT 0x1 | |
|
428 | #define GRP_MASKOS 0x0ff00000 | |
|
429 | #define GRP_MASKPROC 0xf0000000 | |
|
430 | ||
|
431 | /* | |
|
432 | * Symbol table | |
|
433 | */ | |
|
434 | typedef struct { | |
|
435 | Elf32_Word st_name; | |
|
436 | Elf32_Addr st_value; | |
|
437 | Elf32_Word st_size; | |
|
438 | unsigned char st_info; | |
|
439 | unsigned char st_other; | |
|
440 | Elf32_Half st_shndx; | |
|
441 | } Elf32_Sym; | |
|
442 | ||
|
443 | #if __LIBELF64 | |
|
444 | typedef struct { | |
|
445 | Elf64_Word st_name; | |
|
446 | unsigned char st_info; | |
|
447 | unsigned char st_other; | |
|
448 | Elf64_Half st_shndx; | |
|
449 | Elf64_Addr st_value; | |
|
450 | Elf64_Xword st_size; | |
|
451 | } Elf64_Sym; | |
|
452 | #endif /* __LIBELF64 */ | |
|
453 | ||
|
454 | /* | |
|
455 | * Special symbol indices | |
|
456 | */ | |
|
457 | #define STN_UNDEF 0 | |
|
458 | ||
|
459 | /* | |
|
460 | * Macros for manipulating st_info | |
|
461 | */ | |
|
462 | #define ELF32_ST_BIND(i) ((i)>>4) | |
|
463 | #define ELF32_ST_TYPE(i) ((i)&0xf) | |
|
464 | #define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) | |
|
465 | ||
|
466 | #if __LIBELF64 | |
|
467 | #define ELF64_ST_BIND(i) ((i)>>4) | |
|
468 | #define ELF64_ST_TYPE(i) ((i)&0xf) | |
|
469 | #define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) | |
|
470 | #endif /* __LIBELF64 */ | |
|
471 | ||
|
472 | /* | |
|
473 | * Symbol binding | |
|
474 | */ | |
|
475 | #define STB_LOCAL 0 | |
|
476 | #define STB_GLOBAL 1 | |
|
477 | #define STB_WEAK 2 | |
|
478 | #define STB_NUM 3 | |
|
479 | #define STB_LOOS 10 | |
|
480 | #define STB_HIOS 12 | |
|
481 | #define STB_LOPROC 13 | |
|
482 | #define STB_HIPROC 15 | |
|
483 | ||
|
484 | /* | |
|
485 | * Symbol types | |
|
486 | */ | |
|
487 | #define STT_NOTYPE 0 | |
|
488 | #define STT_OBJECT 1 | |
|
489 | #define STT_FUNC 2 | |
|
490 | #define STT_SECTION 3 | |
|
491 | #define STT_FILE 4 | |
|
492 | #define STT_COMMON 5 | |
|
493 | #define STT_TLS 6 | |
|
494 | #define STT_NUM 7 | |
|
495 | #define STT_LOOS 10 | |
|
496 | #define STT_HIOS 12 | |
|
497 | #define STT_LOPROC 13 | |
|
498 | #define STT_HIPROC 15 | |
|
499 | ||
|
500 | /* | |
|
501 | * Macros for manipulating st_other | |
|
502 | */ | |
|
503 | #define ELF32_ST_VISIBILITY(o) ((o)&0x3) | |
|
504 | #if __LIBELF64 | |
|
505 | #define ELF64_ST_VISIBILITY(o) ((o)&0x3) | |
|
506 | #endif /* __LIBELF64 */ | |
|
507 | ||
|
508 | /* | |
|
509 | * Symbol visibility | |
|
510 | */ | |
|
511 | #define STV_DEFAULT 0 | |
|
512 | #define STV_INTERNAL 1 | |
|
513 | #define STV_HIDDEN 2 | |
|
514 | #define STV_PROTECTED 3 | |
|
515 | ||
|
516 | /* | |
|
517 | * Relocation | |
|
518 | */ | |
|
519 | typedef struct { | |
|
520 | Elf32_Addr r_offset; | |
|
521 | Elf32_Word r_info; | |
|
522 | } Elf32_Rel; | |
|
523 | ||
|
524 | typedef struct { | |
|
525 | Elf32_Addr r_offset; | |
|
526 | Elf32_Word r_info; | |
|
527 | Elf32_Sword r_addend; | |
|
528 | } Elf32_Rela; | |
|
529 | ||
|
530 | #if __LIBELF64 | |
|
531 | typedef struct { | |
|
532 | Elf64_Addr r_offset; | |
|
533 | Elf64_Xword r_info; | |
|
534 | } Elf64_Rel; | |
|
535 | ||
|
536 | typedef struct { | |
|
537 | Elf64_Addr r_offset; | |
|
538 | Elf64_Xword r_info; | |
|
539 | Elf64_Sxword r_addend; | |
|
540 | } Elf64_Rela; | |
|
541 | #endif /* __LIBELF64 */ | |
|
542 | ||
|
543 | /* | |
|
544 | * Macros for manipulating r_info | |
|
545 | */ | |
|
546 | #define ELF32_R_SYM(i) ((i)>>8) | |
|
547 | #define ELF32_R_TYPE(i) ((unsigned char)(i)) | |
|
548 | #define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t)) | |
|
549 | ||
|
550 | #if __LIBELF64 | |
|
551 | #define ELF64_R_SYM(i) ((Elf64_Xword)(i)>>32) | |
|
552 | #define ELF64_R_TYPE(i) ((i)&0xffffffffL) | |
|
553 | #define ELF64_R_INFO(s,t) (((Elf64_Xword)(s)<<32)+((t)&0xffffffffL)) | |
|
554 | #endif /* __LIBELF64 */ | |
|
555 | ||
|
556 | /* | |
|
557 | * Note entry header | |
|
558 | */ | |
|
559 | typedef struct { | |
|
560 | Elf32_Word n_namesz; /* name size */ | |
|
561 | Elf32_Word n_descsz; /* descriptor size */ | |
|
562 | Elf32_Word n_type; /* descriptor type */ | |
|
563 | } Elf32_Nhdr; | |
|
564 | ||
|
565 | #if __LIBELF64 | |
|
566 | /* Solaris and GNU use this layout. Be compatible. */ | |
|
567 | /* XXX: Latest ELF specs say it's 64-bit!!! */ | |
|
568 | typedef struct { | |
|
569 | Elf64_Word n_namesz; /* name size */ | |
|
570 | Elf64_Word n_descsz; /* descriptor size */ | |
|
571 | Elf64_Word n_type; /* descriptor type */ | |
|
572 | } Elf64_Nhdr; | |
|
573 | #endif /* __LIBELF64 */ | |
|
574 | ||
|
575 | /* | |
|
576 | * Well-known descriptor types for ET_CORE files | |
|
577 | */ | |
|
578 | #define NT_PRSTATUS 1 | |
|
579 | #define NT_PRFPREG 2 | |
|
580 | #define NT_PRPSINFO 3 | |
|
581 | ||
|
582 | /* | |
|
583 | * Program header | |
|
584 | */ | |
|
585 | typedef struct { | |
|
586 | Elf32_Word p_type; | |
|
587 | Elf32_Off p_offset; | |
|
588 | Elf32_Addr p_vaddr; | |
|
589 | Elf32_Addr p_paddr; | |
|
590 | Elf32_Word p_filesz; | |
|
591 | Elf32_Word p_memsz; | |
|
592 | Elf32_Word p_flags; | |
|
593 | Elf32_Word p_align; | |
|
594 | } Elf32_Phdr; | |
|
595 | ||
|
596 | #if __LIBELF64 | |
|
597 | typedef struct { | |
|
598 | Elf64_Word p_type; | |
|
599 | Elf64_Word p_flags; | |
|
600 | Elf64_Off p_offset; | |
|
601 | Elf64_Addr p_vaddr; | |
|
602 | Elf64_Addr p_paddr; | |
|
603 | Elf64_Xword p_filesz; | |
|
604 | Elf64_Xword p_memsz; | |
|
605 | Elf64_Xword p_align; | |
|
606 | } Elf64_Phdr; | |
|
607 | #endif /* __LIBELF64 */ | |
|
608 | ||
|
609 | /* | |
|
610 | * Special numbers | |
|
611 | */ | |
|
612 | #define PN_XNUM 0xffff | |
|
613 | ||
|
614 | /* | |
|
615 | * p_type | |
|
616 | */ | |
|
617 | #define PT_NULL 0 | |
|
618 | #define PT_LOAD 1 | |
|
619 | #define PT_DYNAMIC 2 | |
|
620 | #define PT_INTERP 3 | |
|
621 | #define PT_NOTE 4 | |
|
622 | #define PT_SHLIB 5 | |
|
623 | #define PT_PHDR 6 | |
|
624 | #define PT_TLS 7 | |
|
625 | #define PT_NUM 8 | |
|
626 | #define PT_LOOS 0x60000000 | |
|
627 | #define PT_HIOS 0x6fffffff | |
|
628 | #define PT_LOPROC 0x70000000 | |
|
629 | #define PT_HIPROC 0x7fffffff | |
|
630 | ||
|
631 | /* | |
|
632 | * Solaris extensions | |
|
633 | */ | |
|
634 | ||
|
635 | #define PT_SUNW_UNWIND 0x6464e550 | |
|
636 | #define PT_LOSUNW 0x6ffffffa | |
|
637 | #define PT_SUNWBSS 0x6ffffffa | |
|
638 | #define PT_SUNWSTACK 0x6ffffffb | |
|
639 | #define PT_SUNWDTRACE 0x6ffffffc | |
|
640 | #define PT_SUNWCAP 0x6ffffffd | |
|
641 | #define PT_HISUNW 0x6fffffff | |
|
642 | ||
|
643 | /* | |
|
644 | * p_flags | |
|
645 | */ | |
|
646 | #define PF_X 0x1 | |
|
647 | #define PF_W 0x2 | |
|
648 | #define PF_R 0x4 | |
|
649 | #define PF_MASKOS 0x0ff00000 | |
|
650 | #define PF_MASKPROC 0xf0000000 | |
|
651 | ||
|
652 | /* | |
|
653 | * Dynamic structure | |
|
654 | */ | |
|
655 | typedef struct { | |
|
656 | Elf32_Sword d_tag; | |
|
657 | union { | |
|
658 | Elf32_Word d_val; | |
|
659 | Elf32_Addr d_ptr; | |
|
660 | } d_un; | |
|
661 | } Elf32_Dyn; | |
|
662 | ||
|
663 | #if __LIBELF64 | |
|
664 | typedef struct { | |
|
665 | Elf64_Sxword d_tag; | |
|
666 | union { | |
|
667 | Elf64_Xword d_val; | |
|
668 | Elf64_Addr d_ptr; | |
|
669 | } d_un; | |
|
670 | } Elf64_Dyn; | |
|
671 | #endif /* __LIBELF64 */ | |
|
672 | ||
|
673 | /* | |
|
674 | * Dynamic array tags | |
|
675 | */ | |
|
676 | /* d_un exec shared */ | |
|
677 | #define DT_NULL 0 /* ign. mand. mand. */ | |
|
678 | #define DT_NEEDED 1 /* d_val opt. opt. */ | |
|
679 | #define DT_PLTRELSZ 2 /* d_val opt. opt. */ | |
|
680 | #define DT_PLTGOT 3 /* d_ptr opt. opt. */ | |
|
681 | #define DT_HASH 4 /* d_ptr mand. mand. */ | |
|
682 | #define DT_STRTAB 5 /* d_ptr mand. mand. */ | |
|
683 | #define DT_SYMTAB 6 /* d_ptr mand. mand. */ | |
|
684 | #define DT_RELA 7 /* d_ptr mand. opt. */ | |
|
685 | #define DT_RELASZ 8 /* d_val mand. opt. */ | |
|
686 | #define DT_RELAENT 9 /* d_val mand. opt. */ | |
|
687 | #define DT_STRSZ 10 /* d_val mand. mand. */ | |
|
688 | #define DT_SYMENT 11 /* d_val mand. mand. */ | |
|
689 | #define DT_INIT 12 /* d_ptr opt. opt. */ | |
|
690 | #define DT_FINI 13 /* d_ptr opt. opt. */ | |
|
691 | #define DT_SONAME 14 /* d_val ign. opt. */ | |
|
692 | #define DT_RPATH 15 /* d_val opt. ign. */ | |
|
693 | #define DT_SYMBOLIC 16 /* ign. ign. opt. */ | |
|
694 | #define DT_REL 17 /* d_ptr mand. opt. */ | |
|
695 | #define DT_RELSZ 18 /* d_val mand. opt. */ | |
|
696 | #define DT_RELENT 19 /* d_val mand. opt. */ | |
|
697 | #define DT_PLTREL 20 /* d_val opt. opt. */ | |
|
698 | #define DT_DEBUG 21 /* d_ptr opt. ign. */ | |
|
699 | #define DT_TEXTREL 22 /* ign. opt. opt. */ | |
|
700 | #define DT_JMPREL 23 /* d_ptr opt. opt. */ | |
|
701 | #define DT_BIND_NOW 24 /* ign. opt. opt. */ | |
|
702 | #define DT_INIT_ARRAY 25 /* d_ptr opt. opt. */ | |
|
703 | #define DT_FINI_ARRAY 26 /* d_ptr opt. opt. */ | |
|
704 | #define DT_INIT_ARRAYSZ 27 /* d_val opt. opt. */ | |
|
705 | #define DT_FINI_ARRAYSZ 28 /* d_val opt. opt. */ | |
|
706 | #define DT_RUNPATH 29 /* d_val opt. opt. */ | |
|
707 | #define DT_FLAGS 30 /* d_val opt. opt. */ | |
|
708 | #define DT_ENCODING 32 /* odd/even encoding rule starts here */ | |
|
709 | #define DT_PREINIT_ARRAY 32 /* d_ptr opt. ign. */ | |
|
710 | #define DT_PREINIT_ARRAYSZ 33 /* d_val opt. ign. */ | |
|
711 | #define DT_NUM 34 | |
|
712 | #define DT_LOOS 0x6000000D | |
|
713 | #define DT_HIOS 0x6ffff000 | |
|
714 | #define DT_LOPROC 0x70000000 | |
|
715 | #define DT_HIPROC 0x7fffffff | |
|
716 | ||
|
717 | /* | |
|
718 | * DT_FLAGS values | |
|
719 | */ | |
|
720 | #define DF_ORIGIN 0x1 | |
|
721 | #define DF_SYMBOLIC 0x2 | |
|
722 | #define DF_TEXTREL 0x4 | |
|
723 | #define DF_BIND_NOW 0x8 | |
|
724 | #define DF_STATIC_TLS 0x10 | |
|
725 | ||
|
726 | /* | |
|
727 | * Solaris extensions | |
|
728 | */ | |
|
729 | #define DT_VALRNGLO 0x6ffffd00 | |
|
730 | #define DT_CHECKSUM 0x6ffffdf8 | |
|
731 | #define DT_PLTPADSZ 0x6ffffdf9 | |
|
732 | #define DT_MOVEENT 0x6ffffdfa | |
|
733 | #define DT_MOVESZ 0x6ffffdfb | |
|
734 | #define DT_FEATURE_1 0x6ffffdfc | |
|
735 | #define DT_POSFLAG_1 0x6ffffdfd | |
|
736 | #define DT_SYMINSZ 0x6ffffdfe | |
|
737 | #define DT_SYMINENT 0x6ffffdff | |
|
738 | #define DT_VALRNGHI 0x6ffffdff | |
|
739 | ||
|
740 | #define DT_ADDRRNGLO 0x6ffffe00 | |
|
741 | #define DT_CONFIG 0x6ffffefa | |
|
742 | #define DT_DEPAUDIT 0x6ffffefb | |
|
743 | #define DT_AUDIT 0x6ffffefc | |
|
744 | #define DT_PLTPAD 0x6ffffefd | |
|
745 | #define DT_MOVETAB 0x6ffffefe | |
|
746 | #define DT_SYMINFO 0x6ffffeff | |
|
747 | #define DT_ADDRRNGHI 0x6ffffeff | |
|
748 | ||
|
749 | #define DT_RELACOUNT 0x6ffffff9 | |
|
750 | #define DT_RELCOUNT 0x6ffffffa | |
|
751 | #define DT_FLAGS_1 0x6ffffffb | |
|
752 | #define DT_VERDEF 0x6ffffffc | |
|
753 | #define DT_VERDEFNUM 0x6ffffffd | |
|
754 | #define DT_VERNEED 0x6ffffffe | |
|
755 | #define DT_VERNEEDNUM 0x6fffffff | |
|
756 | ||
|
757 | #define DT_AUXILIARY 0x7ffffffd | |
|
758 | #define DT_USED 0x7ffffffe | |
|
759 | #define DT_FILTER 0x7fffffff | |
|
760 | ||
|
761 | /* | |
|
762 | * GNU extensions | |
|
763 | */ | |
|
764 | #define DT_VERSYM 0x6ffffff0 | |
|
765 | ||
|
766 | /* | |
|
767 | * DT_FEATURE_1 values | |
|
768 | */ | |
|
769 | #define DTF_1_PARINIT 0x1 | |
|
770 | #define DTF_1_CONFEXP 0x2 | |
|
771 | ||
|
772 | /* | |
|
773 | * DT_POSFLAG_1 values | |
|
774 | */ | |
|
775 | #define DF_P1_LAZYLOAD 0x1 | |
|
776 | #define DF_P1_GROUPPERM 0x2 | |
|
777 | ||
|
778 | /* | |
|
779 | * DT_FLAGS_1 values | |
|
780 | */ | |
|
781 | #define DF_1_NOW 0x00000001 | |
|
782 | #define DF_1_GLOBAL 0x00000002 | |
|
783 | #define DF_1_GROUP 0x00000004 | |
|
784 | #define DF_1_NODELETE 0x00000008 | |
|
785 | #define DF_1_LOADFLTR 0x00000010 | |
|
786 | #define DF_1_INITFIRST 0x00000020 | |
|
787 | #define DF_1_NOOPEN 0x00000040 | |
|
788 | #define DF_1_ORIGIN 0x00000080 | |
|
789 | #define DF_1_DIRECT 0x00000100 | |
|
790 | #define DF_1_TRANS 0x00000200 | |
|
791 | #define DF_1_INTERPOSE 0x00000400 | |
|
792 | #define DF_1_NODEFLIB 0x00000800 | |
|
793 | #define DF_1_NODUMP 0x00001000 | |
|
794 | #define DF_1_CONFALT 0x00002000 | |
|
795 | #define DF_1_ENDFILTEE 0x00004000 | |
|
796 | #define DF_1_DISPRELDNE 0x00008000 | |
|
797 | #define DF_1_DISPRELPND 0x00010000 | |
|
798 | ||
|
799 | /* | |
|
800 | * Syminfo structure | |
|
801 | */ | |
|
802 | typedef struct { | |
|
803 | Elf32_Half si_boundto; | |
|
804 | Elf32_Half si_flags; | |
|
805 | } Elf32_Syminfo; | |
|
806 | ||
|
807 | #if __LIBELF64 | |
|
808 | typedef struct { | |
|
809 | Elf64_Half si_boundto; | |
|
810 | Elf64_Half si_flags; | |
|
811 | } Elf64_Syminfo; | |
|
812 | #endif /* __LIBELF64 */ | |
|
813 | ||
|
814 | /* | |
|
815 | * Syminfo version (stored in unused first entry) | |
|
816 | */ | |
|
817 | #define SYMINFO_NONE 0 | |
|
818 | #define SYMINFO_CURRENT 1 | |
|
819 | #define SYMINFO_NUM 2 | |
|
820 | ||
|
821 | /* | |
|
822 | * si_boundto special values | |
|
823 | */ | |
|
824 | #define SYMINFO_BT_LOWRESERVE 0xff00 | |
|
825 | #define SYMINFO_BT_PARENT 0xfffe /* bound to parent */ | |
|
826 | #define SYMINFO_BT_SELF 0xffff /* bound to self */ | |
|
827 | ||
|
828 | /* | |
|
829 | * si_flags | |
|
830 | */ | |
|
831 | #define SYMINFO_FLG_DIRECT 0x01 /* bound to an object */ | |
|
832 | #define SYMINFO_FLG_PASSTHRU 0x02 /* pass-thru symbol */ | |
|
833 | #define SYMINFO_FLG_COPY 0x04 /* result of a copy relocation */ | |
|
834 | #define SYMINFO_FLG_LAZYLOAD 0x08 /* bound to lazy-loaded object */ | |
|
835 | ||
|
836 | /* | |
|
837 | * Version definitions | |
|
838 | */ | |
|
839 | typedef struct { | |
|
840 | Elf32_Half vd_version; | |
|
841 | Elf32_Half vd_flags; | |
|
842 | Elf32_Half vd_ndx; | |
|
843 | Elf32_Half vd_cnt; | |
|
844 | Elf32_Word vd_hash; | |
|
845 | Elf32_Word vd_aux; | |
|
846 | Elf32_Word vd_next; | |
|
847 | } Elf32_Verdef; | |
|
848 | ||
|
849 | typedef struct { | |
|
850 | Elf32_Word vda_name; | |
|
851 | Elf32_Word vda_next; | |
|
852 | } Elf32_Verdaux; | |
|
853 | ||
|
854 | typedef struct { | |
|
855 | Elf32_Half vn_version; | |
|
856 | Elf32_Half vn_cnt; | |
|
857 | Elf32_Word vn_file; | |
|
858 | Elf32_Word vn_aux; | |
|
859 | Elf32_Word vn_next; | |
|
860 | } Elf32_Verneed; | |
|
861 | ||
|
862 | typedef struct { | |
|
863 | Elf32_Word vna_hash; | |
|
864 | Elf32_Half vna_flags; | |
|
865 | Elf32_Half vna_other; | |
|
866 | Elf32_Word vna_name; | |
|
867 | Elf32_Word vna_next; | |
|
868 | } Elf32_Vernaux; | |
|
869 | ||
|
870 | typedef Elf32_Half Elf32_Versym; | |
|
871 | ||
|
872 | #if __LIBELF64 | |
|
873 | ||
|
874 | typedef struct { | |
|
875 | Elf64_Half vd_version; | |
|
876 | Elf64_Half vd_flags; | |
|
877 | Elf64_Half vd_ndx; | |
|
878 | Elf64_Half vd_cnt; | |
|
879 | Elf64_Word vd_hash; | |
|
880 | Elf64_Word vd_aux; | |
|
881 | Elf64_Word vd_next; | |
|
882 | } Elf64_Verdef; | |
|
883 | ||
|
884 | typedef struct { | |
|
885 | Elf64_Word vda_name; | |
|
886 | Elf64_Word vda_next; | |
|
887 | } Elf64_Verdaux; | |
|
888 | ||
|
889 | typedef struct { | |
|
890 | Elf64_Half vn_version; | |
|
891 | Elf64_Half vn_cnt; | |
|
892 | Elf64_Word vn_file; | |
|
893 | Elf64_Word vn_aux; | |
|
894 | Elf64_Word vn_next; | |
|
895 | } Elf64_Verneed; | |
|
896 | ||
|
897 | typedef struct { | |
|
898 | Elf64_Word vna_hash; | |
|
899 | Elf64_Half vna_flags; | |
|
900 | Elf64_Half vna_other; | |
|
901 | Elf64_Word vna_name; | |
|
902 | Elf64_Word vna_next; | |
|
903 | } Elf64_Vernaux; | |
|
904 | ||
|
905 | typedef Elf64_Half Elf64_Versym; | |
|
906 | ||
|
907 | #endif /* __LIBELF64 */ | |
|
908 | ||
|
909 | /* | |
|
910 | * vd_version | |
|
911 | */ | |
|
912 | #define VER_DEF_NONE 0 | |
|
913 | #define VER_DEF_CURRENT 1 | |
|
914 | #define VER_DEF_NUM 2 | |
|
915 | ||
|
916 | /* | |
|
917 | * vn_version | |
|
918 | */ | |
|
919 | #define VER_NEED_NONE 0 | |
|
920 | #define VER_NEED_CURRENT 1 | |
|
921 | #define VER_NEED_NUM 2 | |
|
922 | ||
|
923 | /* | |
|
924 | * vd_flags / vna_flags | |
|
925 | */ | |
|
926 | #define VER_FLG_BASE 0x1 /* vd_flags only */ | |
|
927 | #define VER_FLG_WEAK 0x2 | |
|
928 | ||
|
929 | /* | |
|
930 | * Elf*_Versym special values | |
|
931 | */ | |
|
932 | #define VER_NDX_LOCAL 0 | |
|
933 | #define VER_NDX_GLOBAL 1 | |
|
934 | ||
|
935 | /* | |
|
936 | * Solaris extensions | |
|
937 | */ | |
|
938 | ||
|
939 | /* | |
|
940 | * Move section | |
|
941 | */ | |
|
942 | #if __LIBELF64 | |
|
943 | ||
|
944 | typedef struct { | |
|
945 | Elf32_Lword m_value; | |
|
946 | Elf32_Word m_info; | |
|
947 | Elf32_Word m_poffset; | |
|
948 | Elf32_Half m_repeat; | |
|
949 | Elf32_Half m_stride; | |
|
950 | } Elf32_Move; | |
|
951 | ||
|
952 | typedef struct { | |
|
953 | Elf64_Lword m_value; | |
|
954 | Elf64_Xword m_info; | |
|
955 | Elf64_Xword m_poffset; | |
|
956 | Elf64_Half m_repeat; | |
|
957 | Elf64_Half m_stride; | |
|
958 | } Elf64_Move; | |
|
959 | ||
|
960 | #define ELF32_M_SYM(info) ((info)>>8) | |
|
961 | #define ELF32_M_SIZE(info) ((unsigned char)(info)) | |
|
962 | #define ELF32_M_INFO(sym, sz) (((sym)<<8)+(unsigned char)(sz)) | |
|
963 | ||
|
964 | #define ELF64_M_SYM(info) ((Elf64_Xword)(info)>>8) | |
|
965 | #define ELF64_M_SIZE(info) ((unsigned char)(info)) | |
|
966 | #define ELF64_M_INFO(sym, sz) (((Elf64_Xword)(sym)<<8)+(unsigned char)(sz)) | |
|
967 | ||
|
968 | #endif /* __LIBELF64 */ | |
|
969 | ||
|
970 | /* | |
|
971 | * Capabilities | |
|
972 | */ | |
|
973 | ||
|
974 | typedef struct { | |
|
975 | Elf32_Word c_tag; | |
|
976 | union { | |
|
977 | Elf32_Word c_val; | |
|
978 | Elf32_Addr c_ptr; | |
|
979 | } c_un; | |
|
980 | } Elf32_Cap; | |
|
981 | ||
|
982 | #if __LIBELF64 | |
|
983 | ||
|
984 | typedef struct { | |
|
985 | Elf64_Xword c_tag; | |
|
986 | union { | |
|
987 | Elf64_Xword c_val; | |
|
988 | Elf64_Addr c_ptr; | |
|
989 | } c_un; | |
|
990 | } Elf64_Cap; | |
|
991 | ||
|
992 | #endif /* __LIBELF64 */ | |
|
993 | ||
|
994 | #define CA_SUNW_NULL 0 /* c_un ignored */ | |
|
995 | #define CA_SUNW_HW_1 1 /* c_un.c_val */ | |
|
996 | #define CA_SUNW_SF_1 2 /* c_un.c_val */ | |
|
997 | ||
|
998 | #ifdef __cplusplus | |
|
999 | } | |
|
1000 | #endif /* __cplusplus */ | |
|
1001 | ||
|
1002 | #endif /* _ELF_REPL_H */ |
@@ -0,0 +1,100 | |||
|
1 | /* | |
|
2 | * errors.h - exhaustive list of all error codes and messages for libelf. | |
|
3 | * Copyright (C) 1995 - 2003, 2006 Michael Riepe | |
|
4 | * | |
|
5 | * This library is free software; you can redistribute it and/or | |
|
6 | * modify it under the terms of the GNU Library General Public | |
|
7 | * License as published by the Free Software Foundation; either | |
|
8 | * version 2 of the License, or (at your option) any later version. | |
|
9 | * | |
|
10 | * This library is distributed in the hope that it will be useful, | |
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
13 | * Library General Public License for more details. | |
|
14 | * | |
|
15 | * You should have received a copy of the GNU Library General Public | |
|
16 | * License along with this library; if not, write to the Free Software | |
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | |
|
18 | */ | |
|
19 | ||
|
20 | /* @(#) $Id: errors.h,v 1.18 2008/05/23 08:15:34 michael Exp $ */ | |
|
21 | ||
|
22 | /* dummy for xgettext */ | |
|
23 | #define _(str) str | |
|
24 | ||
|
25 | __err__(ERROR_OK, _("no error")) | |
|
26 | __err__(ERROR_UNKNOWN, _("unknown error")) | |
|
27 | __err__(ERROR_INTERNAL, _("Internal error: unknown reason")) | |
|
28 | __err__(ERROR_UNIMPLEMENTED, _("Internal error: not implemented")) | |
|
29 | __err__(ERROR_WRONLY, _("Request error: cntl(ELF_C_FDREAD) on write-only file")) | |
|
30 | __err__(ERROR_INVALID_CMD, _("Request error: invalid ELF_C_* argument")) | |
|
31 | __err__(ERROR_FDDISABLED, _("Request error: file descriptor disabled")) | |
|
32 | __err__(ERROR_NOTARCHIVE, _("Request error: not an archive")) | |
|
33 | __err__(ERROR_BADOFF, _("Request error: offset out of range")) | |
|
34 | __err__(ERROR_UNKNOWN_VERSION, _("Request error: unknown ELF version")) | |
|
35 | __err__(ERROR_CMDMISMATCH, _("Request error: ELF_C_* argument does not match")) | |
|
36 | __err__(ERROR_MEMBERWRITE, _("Request error: archive member begin() for writing")) | |
|
37 | __err__(ERROR_FDMISMATCH, _("Request error: archive/member file descriptor mismatch")) | |
|
38 | __err__(ERROR_NOTELF, _("Request error: not an ELF file")) | |
|
39 | __err__(ERROR_CLASSMISMATCH, _("Request error: class file/memory mismatch")) | |
|
40 | __err__(ERROR_UNKNOWN_TYPE, _("Request error: invalid ELF_T_* argument")) | |
|
41 | __err__(ERROR_UNKNOWN_ENCODING, _("Request error: unknown data encoding")) | |
|
42 | __err__(ERROR_DST2SMALL, _("Request error: destination buffer too small")) | |
|
43 | __err__(ERROR_NULLBUF, _("Request error: d_buf is NULL")) | |
|
44 | __err__(ERROR_UNKNOWN_CLASS, _("Request error: unknown ELF class")) | |
|
45 | __err__(ERROR_ELFSCNMISMATCH, _("Request error: section does not belong to file")) | |
|
46 | __err__(ERROR_NOSUCHSCN, _("Request error: no section at index")) | |
|
47 | __err__(ERROR_NULLSCN, _("Request error: can't manipulate null section")) | |
|
48 | __err__(ERROR_SCNDATAMISMATCH, _("Request error: data does not belong to section")) | |
|
49 | __err__(ERROR_NOSTRTAB, _("Request error: no string table")) | |
|
50 | __err__(ERROR_BADSTROFF, _("Request error: string table offset out of range")) | |
|
51 | __err__(ERROR_RDONLY, _("Request error: update(ELF_C_WRITE) on read-only file")) | |
|
52 | __err__(ERROR_IO_SEEK, _("I/O error: seek")) | |
|
53 | __err__(ERROR_IO_2BIG, _("I/O error: file too big for memory")) | |
|
54 | __err__(ERROR_IO_READ, _("I/O error: raw read")) | |
|
55 | __err__(ERROR_IO_GETSIZE, _("I/O error: get file size")) | |
|
56 | __err__(ERROR_IO_WRITE, _("I/O error: output write")) | |
|
57 | __err__(ERROR_IO_TRUNC, _("I/O error: can't truncate output file")) | |
|
58 | __err__(ERROR_VERSION_UNSET, _("Sequence error: must set ELF version first")) | |
|
59 | __err__(ERROR_NOEHDR, _("Sequence error: must create ELF header first")) | |
|
60 | __err__(ERROR_OUTSIDE, _("Format error: reference outside file")) | |
|
61 | __err__(ERROR_TRUNC_ARHDR, _("Format error: archive header truncated")) | |
|
62 | __err__(ERROR_ARFMAG, _("Format error: archive fmag")) | |
|
63 | __err__(ERROR_ARHDR, _("Format error: archive header")) | |
|
64 | __err__(ERROR_TRUNC_MEMBER, _("Format error: archive member truncated")) | |
|
65 | __err__(ERROR_SIZE_ARSYMTAB, _("Format error: archive symbol table size")) | |
|
66 | __err__(ERROR_ARSTRTAB, _("Format error: archive string table")) | |
|
67 | __err__(ERROR_ARSPECIAL, _("Format error: archive special name unknown")) | |
|
68 | __err__(ERROR_TRUNC_EHDR, _("Format error: ELF header truncated")) | |
|
69 | __err__(ERROR_TRUNC_PHDR, _("Format error: program header table truncated")) | |
|
70 | __err__(ERROR_TRUNC_SHDR, _("Format error: section header table truncated")) | |
|
71 | __err__(ERROR_TRUNC_SCN, _("Format error: data region truncated")) | |
|
72 | __err__(ERROR_ALIGN_PHDR, _("Format error: program header table alignment")) | |
|
73 | __err__(ERROR_ALIGN_SHDR, _("Format error: section header table alignment")) | |
|
74 | __err__(ERROR_VERDEF_FORMAT, _("Format error: bad parameter in Verdef record")) | |
|
75 | __err__(ERROR_VERDEF_VERSION, _("Format error: unknown Verdef version")) | |
|
76 | __err__(ERROR_VERNEED_FORMAT, _("Format error: bad parameter in Verneed record")) | |
|
77 | __err__(ERROR_VERNEED_VERSION, _("Format error: unknown Verneed version")) | |
|
78 | __err__(ERROR_EHDR_SHNUM, _("Format error: bad e_shnum value")) | |
|
79 | __err__(ERROR_EHDR_SHENTSIZE, _("Format error: bad e_shentsize value")) | |
|
80 | __err__(ERROR_EHDR_PHENTSIZE, _("Format error: bad e_phentsize value")) | |
|
81 | __err__(ERROR_UNTERM, _("Format error: unterminated string in string table")) | |
|
82 | __err__(ERROR_SCN2SMALL, _("Layout error: section size too small for data")) | |
|
83 | __err__(ERROR_SCN_OVERLAP, _("Layout error: overlapping sections")) | |
|
84 | __err__(ERROR_MEM_ELF, _("Memory error: elf descriptor")) | |
|
85 | __err__(ERROR_MEM_ARSYMTAB, _("Memory error: archive symbol table")) | |
|
86 | __err__(ERROR_MEM_ARHDR, _("Memory error: archive member header")) | |
|
87 | __err__(ERROR_MEM_EHDR, _("Memory error: ELF header")) | |
|
88 | __err__(ERROR_MEM_PHDR, _("Memory error: program header table")) | |
|
89 | __err__(ERROR_MEM_SHDR, _("Memory error: section header table")) | |
|
90 | __err__(ERROR_MEM_SCN, _("Memory error: section descriptor")) | |
|
91 | __err__(ERROR_MEM_SCNDATA, _("Memory error: section data")) | |
|
92 | __err__(ERROR_MEM_OUTBUF, _("Memory error: output file space")) | |
|
93 | __err__(ERROR_MEM_TEMPORARY, _("Memory error: temporary buffer")) | |
|
94 | __err__(ERROR_BADVALUE, _("GElf error: value out of range")) | |
|
95 | __err__(ERROR_BADINDEX, _("GElf error: index out of range")) | |
|
96 | __err__(ERROR_BADTYPE, _("GElf error: type mismatch")) | |
|
97 | __err__(ERROR_MEM_SYM, _("GElf error: not enough memory for GElf_Sym")) | |
|
98 | __err__(ERROR_MEM_DYN, _("GElf error: not enough memory for GElf_Dyn")) | |
|
99 | __err__(ERROR_MEM_RELA, _("GElf error: not enough memory for GElf_Rela")) | |
|
100 | __err__(ERROR_MEM_REL, _("GElf error: not enough memory for GElf_Rel")) |
@@ -0,0 +1,334 | |||
|
1 | /* | |
|
2 | ext_types.h - external representation of ELF data types. | |
|
3 | Copyright (C) 1995 - 1998 Michael Riepe | |
|
4 | ||
|
5 | This library is free software; you can redistribute it and/or | |
|
6 | modify it under the terms of the GNU Library General Public | |
|
7 | License as published by the Free Software Foundation; either | |
|
8 | version 2 of the License, or (at your option) any later version. | |
|
9 | ||
|
10 | This library is distributed in the hope that it will be useful, | |
|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
13 | Library General Public License for more details. | |
|
14 | ||
|
15 | You should have received a copy of the GNU Library General Public | |
|
16 | License along with this library; if not, write to the Free Software | |
|
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | |
|
18 | */ | |
|
19 | ||
|
20 | /* @(#) $Id: ext_types.h,v 1.9 2008/05/23 08:15:34 michael Exp $ */ | |
|
21 | ||
|
22 | #ifndef _EXT_TYPES_H | |
|
23 | #define _EXT_TYPES_H | |
|
24 | ||
|
25 | #ifdef __cplusplus | |
|
26 | extern "C" { | |
|
27 | #endif /* __cplusplus */ | |
|
28 | ||
|
29 | /* | |
|
30 | * Scalar data types | |
|
31 | */ | |
|
32 | typedef unsigned char __ext_Elf32_Addr [ELF32_FSZ_ADDR]; | |
|
33 | typedef unsigned char __ext_Elf32_Half [ELF32_FSZ_HALF]; | |
|
34 | typedef unsigned char __ext_Elf32_Off [ELF32_FSZ_OFF]; | |
|
35 | typedef unsigned char __ext_Elf32_Sword [ELF32_FSZ_SWORD]; | |
|
36 | typedef unsigned char __ext_Elf32_Word [ELF32_FSZ_WORD]; | |
|
37 | ||
|
38 | #if __LIBELF64 | |
|
39 | ||
|
40 | typedef unsigned char __ext_Elf32_Lword [8]; | |
|
41 | ||
|
42 | typedef unsigned char __ext_Elf64_Addr [ELF64_FSZ_ADDR]; | |
|
43 | typedef unsigned char __ext_Elf64_Half [ELF64_FSZ_HALF]; | |
|
44 | typedef unsigned char __ext_Elf64_Off [ELF64_FSZ_OFF]; | |
|
45 | typedef unsigned char __ext_Elf64_Sword [ELF64_FSZ_SWORD]; | |
|
46 | typedef unsigned char __ext_Elf64_Word [ELF64_FSZ_WORD]; | |
|
47 | typedef unsigned char __ext_Elf64_Sxword[ELF64_FSZ_SXWORD]; | |
|
48 | typedef unsigned char __ext_Elf64_Xword [ELF64_FSZ_XWORD]; | |
|
49 | ||
|
50 | typedef unsigned char __ext_Elf64_Lword [8]; | |
|
51 | ||
|
52 | #endif /* __LIBELF64 */ | |
|
53 | ||
|
54 | /* | |
|
55 | * ELF header | |
|
56 | */ | |
|
57 | typedef struct { | |
|
58 | unsigned char e_ident[EI_NIDENT]; | |
|
59 | __ext_Elf32_Half e_type; | |
|
60 | __ext_Elf32_Half e_machine; | |
|
61 | __ext_Elf32_Word e_version; | |
|
62 | __ext_Elf32_Addr e_entry; | |
|
63 | __ext_Elf32_Off e_phoff; | |
|
64 | __ext_Elf32_Off e_shoff; | |
|
65 | __ext_Elf32_Word e_flags; | |
|
66 | __ext_Elf32_Half e_ehsize; | |
|
67 | __ext_Elf32_Half e_phentsize; | |
|
68 | __ext_Elf32_Half e_phnum; | |
|
69 | __ext_Elf32_Half e_shentsize; | |
|
70 | __ext_Elf32_Half e_shnum; | |
|
71 | __ext_Elf32_Half e_shstrndx; | |
|
72 | } __ext_Elf32_Ehdr; | |
|
73 | ||
|
74 | #if __LIBELF64 | |
|
75 | typedef struct { | |
|
76 | unsigned char e_ident[EI_NIDENT]; | |
|
77 | __ext_Elf64_Half e_type; | |
|
78 | __ext_Elf64_Half e_machine; | |
|
79 | __ext_Elf64_Word e_version; | |
|
80 | __ext_Elf64_Addr e_entry; | |
|
81 | __ext_Elf64_Off e_phoff; | |
|
82 | __ext_Elf64_Off e_shoff; | |
|
83 | __ext_Elf64_Word e_flags; | |
|
84 | __ext_Elf64_Half e_ehsize; | |
|
85 | __ext_Elf64_Half e_phentsize; | |
|
86 | __ext_Elf64_Half e_phnum; | |
|
87 | __ext_Elf64_Half e_shentsize; | |
|
88 | __ext_Elf64_Half e_shnum; | |
|
89 | __ext_Elf64_Half e_shstrndx; | |
|
90 | } __ext_Elf64_Ehdr; | |
|
91 | #endif /* __LIBELF64 */ | |
|
92 | ||
|
93 | /* | |
|
94 | * Section header | |
|
95 | */ | |
|
96 | typedef struct { | |
|
97 | __ext_Elf32_Word sh_name; | |
|
98 | __ext_Elf32_Word sh_type; | |
|
99 | __ext_Elf32_Word sh_flags; | |
|
100 | __ext_Elf32_Addr sh_addr; | |
|
101 | __ext_Elf32_Off sh_offset; | |
|
102 | __ext_Elf32_Word sh_size; | |
|
103 | __ext_Elf32_Word sh_link; | |
|
104 | __ext_Elf32_Word sh_info; | |
|
105 | __ext_Elf32_Word sh_addralign; | |
|
106 | __ext_Elf32_Word sh_entsize; | |
|
107 | } __ext_Elf32_Shdr; | |
|
108 | ||
|
109 | #if __LIBELF64 | |
|
110 | typedef struct { | |
|
111 | __ext_Elf64_Word sh_name; | |
|
112 | __ext_Elf64_Word sh_type; | |
|
113 | __ext_Elf64_Xword sh_flags; | |
|
114 | __ext_Elf64_Addr sh_addr; | |
|
115 | __ext_Elf64_Off sh_offset; | |
|
116 | __ext_Elf64_Xword sh_size; | |
|
117 | __ext_Elf64_Word sh_link; | |
|
118 | __ext_Elf64_Word sh_info; | |
|
119 | __ext_Elf64_Xword sh_addralign; | |
|
120 | __ext_Elf64_Xword sh_entsize; | |
|
121 | } __ext_Elf64_Shdr; | |
|
122 | #endif /* __LIBELF64 */ | |
|
123 | ||
|
124 | /* | |
|
125 | * Symbol table | |
|
126 | */ | |
|
127 | typedef struct { | |
|
128 | __ext_Elf32_Word st_name; | |
|
129 | __ext_Elf32_Addr st_value; | |
|
130 | __ext_Elf32_Word st_size; | |
|
131 | unsigned char st_info; | |
|
132 | unsigned char st_other; | |
|
133 | __ext_Elf32_Half st_shndx; | |
|
134 | } __ext_Elf32_Sym; | |
|
135 | ||
|
136 | #if __LIBELF64 | |
|
137 | typedef struct { | |
|
138 | __ext_Elf64_Word st_name; | |
|
139 | unsigned char st_info; | |
|
140 | unsigned char st_other; | |
|
141 | __ext_Elf64_Half st_shndx; | |
|
142 | __ext_Elf64_Addr st_value; | |
|
143 | __ext_Elf64_Xword st_size; | |
|
144 | } __ext_Elf64_Sym; | |
|
145 | #endif /* __LIBELF64 */ | |
|
146 | ||
|
147 | /* | |
|
148 | * Relocation | |
|
149 | */ | |
|
150 | typedef struct { | |
|
151 | __ext_Elf32_Addr r_offset; | |
|
152 | __ext_Elf32_Word r_info; | |
|
153 | } __ext_Elf32_Rel; | |
|
154 | ||
|
155 | typedef struct { | |
|
156 | __ext_Elf32_Addr r_offset; | |
|
157 | __ext_Elf32_Word r_info; | |
|
158 | __ext_Elf32_Sword r_addend; | |
|
159 | } __ext_Elf32_Rela; | |
|
160 | ||
|
161 | #if __LIBELF64 | |
|
162 | typedef struct { | |
|
163 | __ext_Elf64_Addr r_offset; | |
|
164 | #if __LIBELF64_IRIX | |
|
165 | __ext_Elf64_Word r_sym; | |
|
166 | unsigned char r_ssym; | |
|
167 | unsigned char r_type3; | |
|
168 | unsigned char r_type2; | |
|
169 | unsigned char r_type; | |
|
170 | #else /* __LIBELF64_IRIX */ | |
|
171 | __ext_Elf64_Xword r_info; | |
|
172 | #endif /* __LIBELF64_IRIX */ | |
|
173 | } __ext_Elf64_Rel; | |
|
174 | ||
|
175 | typedef struct { | |
|
176 | __ext_Elf64_Addr r_offset; | |
|
177 | #if __LIBELF64_IRIX | |
|
178 | __ext_Elf64_Word r_sym; | |
|
179 | unsigned char r_ssym; | |
|
180 | unsigned char r_type3; | |
|
181 | unsigned char r_type2; | |
|
182 | unsigned char r_type; | |
|
183 | #else /* __LIBELF64_IRIX */ | |
|
184 | __ext_Elf64_Xword r_info; | |
|
185 | #endif /* __LIBELF64_IRIX */ | |
|
186 | __ext_Elf64_Sxword r_addend; | |
|
187 | } __ext_Elf64_Rela; | |
|
188 | #endif /* __LIBELF64 */ | |
|
189 | ||
|
190 | /* | |
|
191 | * Program header | |
|
192 | */ | |
|
193 | typedef struct { | |
|
194 | __ext_Elf32_Word p_type; | |
|
195 | __ext_Elf32_Off p_offset; | |
|
196 | __ext_Elf32_Addr p_vaddr; | |
|
197 | __ext_Elf32_Addr p_paddr; | |
|
198 | __ext_Elf32_Word p_filesz; | |
|
199 | __ext_Elf32_Word p_memsz; | |
|
200 | __ext_Elf32_Word p_flags; | |
|
201 | __ext_Elf32_Word p_align; | |
|
202 | } __ext_Elf32_Phdr; | |
|
203 | ||
|
204 | #if __LIBELF64 | |
|
205 | typedef struct { | |
|
206 | __ext_Elf64_Word p_type; | |
|
207 | __ext_Elf64_Word p_flags; | |
|
208 | __ext_Elf64_Off p_offset; | |
|
209 | __ext_Elf64_Addr p_vaddr; | |
|
210 | __ext_Elf64_Addr p_paddr; | |
|
211 | __ext_Elf64_Xword p_filesz; | |
|
212 | __ext_Elf64_Xword p_memsz; | |
|
213 | __ext_Elf64_Xword p_align; | |
|
214 | } __ext_Elf64_Phdr; | |
|
215 | #endif /* __LIBELF64 */ | |
|
216 | ||
|
217 | /* | |
|
218 | * Dynamic structure | |
|
219 | */ | |
|
220 | typedef struct { | |
|
221 | __ext_Elf32_Sword d_tag; | |
|
222 | union { | |
|
223 | __ext_Elf32_Word d_val; | |
|
224 | __ext_Elf32_Addr d_ptr; | |
|
225 | } d_un; | |
|
226 | } __ext_Elf32_Dyn; | |
|
227 | ||
|
228 | #if __LIBELF64 | |
|
229 | typedef struct { | |
|
230 | __ext_Elf64_Sxword d_tag; | |
|
231 | union { | |
|
232 | __ext_Elf64_Xword d_val; | |
|
233 | __ext_Elf64_Addr d_ptr; | |
|
234 | } d_un; | |
|
235 | } __ext_Elf64_Dyn; | |
|
236 | #endif /* __LIBELF64 */ | |
|
237 | ||
|
238 | /* | |
|
239 | * Version definitions | |
|
240 | */ | |
|
241 | typedef struct { | |
|
242 | __ext_Elf32_Half vd_version; | |
|
243 | __ext_Elf32_Half vd_flags; | |
|
244 | __ext_Elf32_Half vd_ndx; | |
|
245 | __ext_Elf32_Half vd_cnt; | |
|
246 | __ext_Elf32_Word vd_hash; | |
|
247 | __ext_Elf32_Word vd_aux; | |
|
248 | __ext_Elf32_Word vd_next; | |
|
249 | } __ext_Elf32_Verdef; | |
|
250 | ||
|
251 | typedef struct { | |
|
252 | __ext_Elf32_Word vda_name; | |
|
253 | __ext_Elf32_Word vda_next; | |
|
254 | } __ext_Elf32_Verdaux; | |
|
255 | ||
|
256 | typedef struct { | |
|
257 | __ext_Elf32_Half vn_version; | |
|
258 | __ext_Elf32_Half vn_cnt; | |
|
259 | __ext_Elf32_Word vn_file; | |
|
260 | __ext_Elf32_Word vn_aux; | |
|
261 | __ext_Elf32_Word vn_next; | |
|
262 | } __ext_Elf32_Verneed; | |
|
263 | ||
|
264 | typedef struct { | |
|
265 | __ext_Elf32_Word vna_hash; | |
|
266 | __ext_Elf32_Half vna_flags; | |
|
267 | __ext_Elf32_Half vna_other; | |
|
268 | __ext_Elf32_Word vna_name; | |
|
269 | __ext_Elf32_Word vna_next; | |
|
270 | } __ext_Elf32_Vernaux; | |
|
271 | ||
|
272 | #if __LIBELF64 | |
|
273 | ||
|
274 | typedef struct { | |
|
275 | __ext_Elf64_Half vd_version; | |
|
276 | __ext_Elf64_Half vd_flags; | |
|
277 | __ext_Elf64_Half vd_ndx; | |
|
278 | __ext_Elf64_Half vd_cnt; | |
|
279 | __ext_Elf64_Word vd_hash; | |
|
280 | __ext_Elf64_Word vd_aux; | |
|
281 | __ext_Elf64_Word vd_next; | |
|
282 | } __ext_Elf64_Verdef; | |
|
283 | ||
|
284 | typedef struct { | |
|
285 | __ext_Elf64_Word vda_name; | |
|
286 | __ext_Elf64_Word vda_next; | |
|
287 | } __ext_Elf64_Verdaux; | |
|
288 | ||
|
289 | typedef struct { | |
|
290 | __ext_Elf64_Half vn_version; | |
|
291 | __ext_Elf64_Half vn_cnt; | |
|
292 | __ext_Elf64_Word vn_file; | |
|
293 | __ext_Elf64_Word vn_aux; | |
|
294 | __ext_Elf64_Word vn_next; | |
|
295 | } __ext_Elf64_Verneed; | |
|
296 | ||
|
297 | typedef struct { | |
|
298 | __ext_Elf64_Word vna_hash; | |
|
299 | __ext_Elf64_Half vna_flags; | |
|
300 | __ext_Elf64_Half vna_other; | |
|
301 | __ext_Elf64_Word vna_name; | |
|
302 | __ext_Elf64_Word vna_next; | |
|
303 | } __ext_Elf64_Vernaux; | |
|
304 | ||
|
305 | #endif /* __LIBELF64 */ | |
|
306 | ||
|
307 | /* | |
|
308 | * Move section | |
|
309 | */ | |
|
310 | #if __LIBELF64 | |
|
311 | ||
|
312 | typedef struct { | |
|
313 | __ext_Elf32_Lword m_value; | |
|
314 | __ext_Elf32_Word m_info; | |
|
315 | __ext_Elf32_Word m_poffset; | |
|
316 | __ext_Elf32_Half m_repeat; | |
|
317 | __ext_Elf32_Half m_stride; | |
|
318 | } __ext_Elf32_Move; | |
|
319 | ||
|
320 | typedef struct { | |
|
321 | __ext_Elf64_Lword m_value; | |
|
322 | __ext_Elf64_Xword m_info; | |
|
323 | __ext_Elf64_Xword m_poffset; | |
|
324 | __ext_Elf64_Half m_repeat; | |
|
325 | __ext_Elf64_Half m_stride; | |
|
326 | } __ext_Elf64_Move; | |
|
327 | ||
|
328 | #endif /* __LIBELF64 */ | |
|
329 | ||
|
330 | #ifdef __cplusplus | |
|
331 | } | |
|
332 | #endif /* __cplusplus */ | |
|
333 | ||
|
334 | #endif /* _EXT_TYPES_H */ |
@@ -0,0 +1,155 | |||
|
1 | /* | |
|
2 | * gelf.h - public header file for libelf. | |
|
3 | * Copyright (C) 2000 - 2006 Michael Riepe | |
|
4 | * | |
|
5 | * This library is free software; you can redistribute it and/or | |
|
6 | * modify it under the terms of the GNU Library General Public | |
|
7 | * License as published by the Free Software Foundation; either | |
|
8 | * version 2 of the License, or (at your option) any later version. | |
|
9 | * | |
|
10 | * This library is distributed in the hope that it will be useful, | |
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
13 | * Library General Public License for more details. | |
|
14 | * | |
|
15 | * You should have received a copy of the GNU Library General Public | |
|
16 | * License along with this library; if not, write to the Free Software | |
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | |
|
18 | */ | |
|
19 | ||
|
20 | /* @(#) $Id: gelf.h,v 1.16 2008/05/23 08:15:34 michael Exp $ */ | |
|
21 | ||
|
22 | #ifndef _GELF_H | |
|
23 | #define _GELF_H | |
|
24 | ||
|
25 | #if __LIBELF_INTERNAL__ | |
|
26 | #include <libelf.h> | |
|
27 | #else /* __LIBELF_INTERNAL__ */ | |
|
28 | #include <libelf/libelf.h> | |
|
29 | #endif /* __LIBELF_INTERNAL__ */ | |
|
30 | ||
|
31 | #if __LIBELF_NEED_LINK_H | |
|
32 | #include <link.h> | |
|
33 | #elif __LIBELF_NEED_SYS_LINK_H | |
|
34 | #include <sys/link.h> | |
|
35 | #endif /* __LIBELF_NEED_LINK_H */ | |
|
36 | ||
|
37 | #ifdef __cplusplus | |
|
38 | extern "C" { | |
|
39 | #endif /* __cplusplus */ | |
|
40 | ||
|
41 | #ifndef __P | |
|
42 | # if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32) | |
|
43 | # define __P(args) args | |
|
44 | # else /* __STDC__ || defined(__cplusplus) */ | |
|
45 | # define __P(args) () | |
|
46 | # endif /* __STDC__ || defined(__cplusplus) */ | |
|
47 | #endif /* __P */ | |
|
48 | ||
|
49 | #if !__LIBELF64 | |
|
50 | ||
|
51 | #error "GElf is not supported on this system." | |
|
52 | ||
|
53 | #else /* __LIBELF64 */ | |
|
54 | ||
|
55 | typedef Elf64_Addr GElf_Addr; | |
|
56 | typedef Elf64_Half GElf_Half; | |
|
57 | typedef Elf64_Off GElf_Off; | |
|
58 | typedef Elf64_Sword GElf_Sword; | |
|
59 | typedef Elf64_Word GElf_Word; | |
|
60 | typedef Elf64_Sxword GElf_Sxword; | |
|
61 | typedef Elf64_Xword GElf_Xword; | |
|
62 | ||
|
63 | typedef Elf64_Ehdr GElf_Ehdr; | |
|
64 | typedef Elf64_Phdr GElf_Phdr; | |
|
65 | typedef Elf64_Shdr GElf_Shdr; | |
|
66 | typedef Elf64_Dyn GElf_Dyn; | |
|
67 | typedef Elf64_Rel GElf_Rel; | |
|
68 | typedef Elf64_Rela GElf_Rela; | |
|
69 | typedef Elf64_Sym GElf_Sym; | |
|
70 | ||
|
71 | /* | |
|
72 | * Symbol versioning | |
|
73 | */ | |
|
74 | #if __LIBELF_SYMBOL_VERSIONS | |
|
75 | typedef Elf64_Verdef GElf_Verdef; | |
|
76 | typedef Elf64_Verneed GElf_Verneed; | |
|
77 | typedef Elf64_Verdaux GElf_Verdaux; | |
|
78 | typedef Elf64_Vernaux GElf_Vernaux; | |
|
79 | #endif /* __LIBELF_SYMBOL_VERSIONS */ | |
|
80 | ||
|
81 | /* | |
|
82 | * These types aren't implemented (yet) | |
|
83 | * | |
|
84 | typedef Elf64_Move GElf_Move; | |
|
85 | typedef Elf64_Syminfo GElf_Syminfo; | |
|
86 | */ | |
|
87 | ||
|
88 | /* | |
|
89 | * Generic macros | |
|
90 | */ | |
|
91 | #define GELF_ST_BIND ELF64_ST_BIND | |
|
92 | #define GELF_ST_TYPE ELF64_ST_TYPE | |
|
93 | #define GELF_ST_INFO ELF64_ST_INFO | |
|
94 | ||
|
95 | #define GELF_R_TYPE ELF64_R_TYPE | |
|
96 | #define GELF_R_SYM ELF64_R_SYM | |
|
97 | #define GELF_R_INFO ELF64_R_INFO | |
|
98 | ||
|
99 | /* | |
|
100 | * Function declarations | |
|
101 | */ | |
|
102 | extern int gelf_getclass __P((Elf *__elf)); | |
|
103 | ||
|
104 | extern size_t gelf_fsize __P((Elf *__elf, Elf_Type __type, size_t __count, unsigned __ver)); | |
|
105 | ||
|
106 | extern Elf_Data *gelf_xlatetof __P((Elf *__elf, Elf_Data *__dst, const Elf_Data *__src, unsigned __encode)); | |
|
107 | extern Elf_Data *gelf_xlatetom __P((Elf *__elf, Elf_Data *__dst, const Elf_Data *__src, unsigned __encode)); | |
|
108 | ||
|
109 | extern GElf_Ehdr *gelf_getehdr __P((Elf *__elf, GElf_Ehdr *__dst)); | |
|
110 | extern int gelf_update_ehdr __P((Elf *__elf, GElf_Ehdr *__src)); | |
|
111 | extern unsigned long gelf_newehdr __P((Elf *__elf, int __elfclass)); | |
|
112 | ||
|
113 | extern GElf_Phdr *gelf_getphdr __P((Elf *__elf, int ndx, GElf_Phdr *__dst)); | |
|
114 | extern int gelf_update_phdr __P((Elf *__elf, int ndx, GElf_Phdr *__src)); | |
|
115 | extern unsigned long gelf_newphdr __P((Elf *__elf, size_t __phnum)); | |
|
116 | ||
|
117 | extern GElf_Shdr *gelf_getshdr __P((Elf_Scn *__scn, GElf_Shdr *__dst)); | |
|
118 | extern int gelf_update_shdr __P((Elf_Scn *__scn, GElf_Shdr *__src)); | |
|
119 | ||
|
120 | extern GElf_Dyn *gelf_getdyn __P((Elf_Data *__src, int __ndx, GElf_Dyn *__dst)); | |
|
121 | extern int gelf_update_dyn __P((Elf_Data *__dst, int __ndx, GElf_Dyn *__src)); | |
|
122 | ||
|
123 | extern GElf_Rel *gelf_getrel __P((Elf_Data *__src, int __ndx, GElf_Rel *__dst)); | |
|
124 | extern int gelf_update_rel __P((Elf_Data *__dst, int __ndx, GElf_Rel *__src)); | |
|
125 | ||
|
126 | extern GElf_Rela *gelf_getrela __P((Elf_Data *__src, int __ndx, GElf_Rela *__dst)); | |
|
127 | extern int gelf_update_rela __P((Elf_Data *__dst, int __ndx, GElf_Rela *__src)); | |
|
128 | ||
|
129 | extern GElf_Sym *gelf_getsym __P((Elf_Data *__src, int __ndx, GElf_Sym *__dst)); | |
|
130 | extern int gelf_update_sym __P((Elf_Data *__dst, int __ndx, GElf_Sym *__src)); | |
|
131 | ||
|
132 | extern long gelf_checksum __P((Elf *__elf)); | |
|
133 | ||
|
134 | /* | |
|
135 | * These functions aren't implemented (yet) | |
|
136 | * | |
|
137 | extern GElf_Move *gelf_getmove __P((Elf_Data *__src, int __ndx, GElf_Move *__src)); | |
|
138 | extern int gelf_update_move __P((Elf_Data *__dst, int __ndx, GElf_Move *__src)); | |
|
139 | * | |
|
140 | extern GElf_Syminfo* gelf_getsyminfo __P((Elf_Data *__src, int __ndx, GElf_Syminfo *__dst)); | |
|
141 | extern int gelf_update_syminfo __P((Elf_Data *__dst, int __ndx, GElf_Syminfo *__src)); | |
|
142 | */ | |
|
143 | ||
|
144 | /* | |
|
145 | * Extensions (not available in other versions of libelf) | |
|
146 | */ | |
|
147 | extern size_t gelf_msize __P((Elf *__elf, Elf_Type __type, size_t __count, unsigned __ver)); | |
|
148 | ||
|
149 | #endif /* __LIBELF64 */ | |
|
150 | ||
|
151 | #ifdef __cplusplus | |
|
152 | } | |
|
153 | #endif /* __cplusplus */ | |
|
154 | ||
|
155 | #endif /* _GELF_H */ |
@@ -0,0 +1,305 | |||
|
1 | /* | |
|
2 | * libelf.h - public header file for libelf. | |
|
3 | * Copyright (C) 1995 - 2008 Michael Riepe | |
|
4 | * | |
|
5 | * This library is free software; you can redistribute it and/or | |
|
6 | * modify it under the terms of the GNU Library General Public | |
|
7 | * License as published by the Free Software Foundation; either | |
|
8 | * version 2 of the License, or (at your option) any later version. | |
|
9 | * | |
|
10 | * This library is distributed in the hope that it will be useful, | |
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
13 | * Library General Public License for more details. | |
|
14 | * | |
|
15 | * You should have received a copy of the GNU Library General Public | |
|
16 | * License along with this library; if not, write to the Free Software | |
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | |
|
18 | */ | |
|
19 | ||
|
20 | /* @(#) $Id: libelf.h,v 1.29 2009/07/07 17:57:43 michael Exp $ */ | |
|
21 | ||
|
22 | #ifndef _LIBELF_H | |
|
23 | #define _LIBELF_H | |
|
24 | ||
|
25 | #include <stddef.h> /* for size_t */ | |
|
26 | #include <sys/types.h> | |
|
27 | ||
|
28 | #if __LIBELF_INTERNAL__ | |
|
29 | #include <sys_elf.h> | |
|
30 | #else /* __LIBELF_INTERNAL__ */ | |
|
31 | #include <libelf/sys_elf.h> | |
|
32 | #endif /* __LIBELF_INTERNAL__ */ | |
|
33 | ||
|
34 | #if defined __GNUC__ && !defined __cplusplus | |
|
35 | #define DEPRECATED __attribute__((deprecated)) | |
|
36 | #else | |
|
37 | #define DEPRECATED /* nothing */ | |
|
38 | #endif | |
|
39 | ||
|
40 | #ifdef __cplusplus | |
|
41 | extern "C" { | |
|
42 | #endif /* __cplusplus */ | |
|
43 | ||
|
44 | #ifndef __P | |
|
45 | # if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32) | |
|
46 | # define __P(args) args | |
|
47 | # else /* __STDC__ || defined(__cplusplus) */ | |
|
48 | # define __P(args) () | |
|
49 | # endif /* __STDC__ || defined(__cplusplus) */ | |
|
50 | #endif /* __P */ | |
|
51 | ||
|
52 | /* | |
|
53 | * Commands | |
|
54 | */ | |
|
55 | typedef enum { | |
|
56 | ELF_C_NULL = 0, /* must be first, 0 */ | |
|
57 | ELF_C_READ, | |
|
58 | ELF_C_WRITE, | |
|
59 | ELF_C_CLR, | |
|
60 | ELF_C_SET, | |
|
61 | ELF_C_FDDONE, | |
|
62 | ELF_C_FDREAD, | |
|
63 | ELF_C_RDWR, | |
|
64 | ELF_C_NUM /* must be last */ | |
|
65 | } Elf_Cmd; | |
|
66 | ||
|
67 | /* | |
|
68 | * Flags | |
|
69 | */ | |
|
70 | #define ELF_F_DIRTY 0x1 | |
|
71 | #define ELF_F_LAYOUT 0x4 | |
|
72 | /* | |
|
73 | * Allow sections to overlap when ELF_F_LAYOUT is in effect. | |
|
74 | * Note that this flag ist NOT portable, and that it may render | |
|
75 | * the output file unusable. Use with extreme caution! | |
|
76 | */ | |
|
77 | #define ELF_F_LAYOUT_OVERLAP 0x10000000 | |
|
78 | ||
|
79 | /* | |
|
80 | * File types | |
|
81 | */ | |
|
82 | typedef enum { | |
|
83 | ELF_K_NONE = 0, /* must be first, 0 */ | |
|
84 | ELF_K_AR, | |
|
85 | ELF_K_COFF, | |
|
86 | ELF_K_ELF, | |
|
87 | ELF_K_NUM /* must be last */ | |
|
88 | } Elf_Kind; | |
|
89 | ||
|
90 | /* | |
|
91 | * Data types | |
|
92 | */ | |
|
93 | typedef enum { | |
|
94 | ELF_T_BYTE = 0, /* must be first, 0 */ | |
|
95 | ELF_T_ADDR, | |
|
96 | ELF_T_DYN, | |
|
97 | ELF_T_EHDR, | |
|
98 | ELF_T_HALF, | |
|
99 | ELF_T_OFF, | |
|
100 | ELF_T_PHDR, | |
|
101 | ELF_T_RELA, | |
|
102 | ELF_T_REL, | |
|
103 | ELF_T_SHDR, | |
|
104 | ELF_T_SWORD, | |
|
105 | ELF_T_SYM, | |
|
106 | ELF_T_WORD, | |
|
107 | /* | |
|
108 | * New stuff for 64-bit. | |
|
109 | * | |
|
110 | * Most implementations add ELF_T_SXWORD after ELF_T_SWORD | |
|
111 | * which breaks binary compatibility with earlier versions. | |
|
112 | * If this causes problems for you, contact me. | |
|
113 | */ | |
|
114 | ELF_T_SXWORD, | |
|
115 | ELF_T_XWORD, | |
|
116 | /* | |
|
117 | * Symbol versioning. Sun broke binary compatibility (again!), | |
|
118 | * but I won't. | |
|
119 | */ | |
|
120 | ELF_T_VDEF, | |
|
121 | ELF_T_VNEED, | |
|
122 | ELF_T_NUM /* must be last */ | |
|
123 | } Elf_Type; | |
|
124 | ||
|
125 | /* | |
|
126 | * Elf descriptor | |
|
127 | */ | |
|
128 | typedef struct Elf Elf; | |
|
129 | ||
|
130 | /* | |
|
131 | * Section descriptor | |
|
132 | */ | |
|
133 | typedef struct Elf_Scn Elf_Scn; | |
|
134 | ||
|
135 | /* | |
|
136 | * Archive member header | |
|
137 | */ | |
|
138 | typedef struct { | |
|
139 | char* ar_name; | |
|
140 | time_t ar_date; | |
|
141 | long ar_uid; | |
|
142 | long ar_gid; | |
|
143 | unsigned long ar_mode; | |
|
144 | off_t ar_size; | |
|
145 | char* ar_rawname; | |
|
146 | } Elf_Arhdr; | |
|
147 | ||
|
148 | /* | |
|
149 | * Archive symbol table | |
|
150 | */ | |
|
151 | typedef struct { | |
|
152 | char* as_name; | |
|
153 | size_t as_off; | |
|
154 | unsigned long as_hash; | |
|
155 | } Elf_Arsym; | |
|
156 | ||
|
157 | /* | |
|
158 | * Data descriptor | |
|
159 | */ | |
|
160 | typedef struct { | |
|
161 | void* d_buf; | |
|
162 | Elf_Type d_type; | |
|
163 | size_t d_size; | |
|
164 | off_t d_off; | |
|
165 | size_t d_align; | |
|
166 | unsigned d_version; | |
|
167 | } Elf_Data; | |
|
168 | ||
|
169 | /* | |
|
170 | * Function declarations | |
|
171 | */ | |
|
172 | extern Elf *elf_begin __P((int __fd, Elf_Cmd __cmd, Elf *__ref)); | |
|
173 | extern Elf *elf_memory __P((char *__image, size_t __size)); | |
|
174 | extern int elf_cntl __P((Elf *__elf, Elf_Cmd __cmd)); | |
|
175 | extern int elf_end __P((Elf *__elf)); | |
|
176 | extern const char *elf_errmsg __P((int __err)); | |
|
177 | extern int elf_errno __P((void)); | |
|
178 | extern void elf_fill __P((int __fill)); | |
|
179 | extern unsigned elf_flagdata __P((Elf_Data *__data, Elf_Cmd __cmd, | |
|
180 | unsigned __flags)); | |
|
181 | extern unsigned elf_flagehdr __P((Elf *__elf, Elf_Cmd __cmd, | |
|
182 | unsigned __flags)); | |
|
183 | extern unsigned elf_flagelf __P((Elf *__elf, Elf_Cmd __cmd, | |
|
184 | unsigned __flags)); | |
|
185 | extern unsigned elf_flagphdr __P((Elf *__elf, Elf_Cmd __cmd, | |
|
186 | unsigned __flags)); | |
|
187 | extern unsigned elf_flagscn __P((Elf_Scn *__scn, Elf_Cmd __cmd, | |
|
188 | unsigned __flags)); | |
|
189 | extern unsigned elf_flagshdr __P((Elf_Scn *__scn, Elf_Cmd __cmd, | |
|
190 | unsigned __flags)); | |
|
191 | extern size_t elf32_fsize __P((Elf_Type __type, size_t __count, | |
|
192 | unsigned __ver)); | |
|
193 | extern Elf_Arhdr *elf_getarhdr __P((Elf *__elf)); | |
|
194 | extern Elf_Arsym *elf_getarsym __P((Elf *__elf, size_t *__ptr)); | |
|
195 | extern off_t elf_getbase __P((Elf *__elf)); | |
|
196 | extern Elf_Data *elf_getdata __P((Elf_Scn *__scn, Elf_Data *__data)); | |
|
197 | extern Elf32_Ehdr *elf32_getehdr __P((Elf *__elf)); | |
|
198 | extern char *elf_getident __P((Elf *__elf, size_t *__ptr)); | |
|
199 | extern Elf32_Phdr *elf32_getphdr __P((Elf *__elf)); | |
|
200 | extern Elf_Scn *elf_getscn __P((Elf *__elf, size_t __index)); | |
|
201 | extern Elf32_Shdr *elf32_getshdr __P((Elf_Scn *__scn)); | |
|
202 | extern unsigned long elf_hash __P((const unsigned char *__name)); | |
|
203 | extern Elf_Kind elf_kind __P((Elf *__elf)); | |
|
204 | extern size_t elf_ndxscn __P((Elf_Scn *__scn)); | |
|
205 | extern Elf_Data *elf_newdata __P((Elf_Scn *__scn)); | |
|
206 | extern Elf32_Ehdr *elf32_newehdr __P((Elf *__elf)); | |
|
207 | extern Elf32_Phdr *elf32_newphdr __P((Elf *__elf, size_t __count)); | |
|
208 | extern Elf_Scn *elf_newscn __P((Elf *__elf)); | |
|
209 | extern Elf_Cmd elf_next __P((Elf *__elf)); | |
|
210 | extern Elf_Scn *elf_nextscn __P((Elf *__elf, Elf_Scn *__scn)); | |
|
211 | extern size_t elf_rand __P((Elf *__elf, size_t __offset)); | |
|
212 | extern Elf_Data *elf_rawdata __P((Elf_Scn *__scn, Elf_Data *__data)); | |
|
213 | extern char *elf_rawfile __P((Elf *__elf, size_t *__ptr)); | |
|
214 | extern char *elf_strptr __P((Elf *__elf, size_t __section, size_t __offset)); | |
|
215 | extern off_t elf_update __P((Elf *__elf, Elf_Cmd __cmd)); | |
|
216 | extern unsigned elf_version __P((unsigned __ver)); | |
|
217 | extern Elf_Data *elf32_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src, | |
|
218 | unsigned __encode)); | |
|
219 | extern Elf_Data *elf32_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src, | |
|
220 | unsigned __encode)); | |
|
221 | ||
|
222 | /* | |
|
223 | * Additional functions found on Solaris | |
|
224 | */ | |
|
225 | extern long elf32_checksum __P((Elf *__elf)); | |
|
226 | ||
|
227 | #if __LIBELF64 | |
|
228 | /* | |
|
229 | * 64-bit ELF functions | |
|
230 | * Not available on all platforms | |
|
231 | */ | |
|
232 | extern Elf64_Ehdr *elf64_getehdr __P((Elf *__elf)); | |
|
233 | extern Elf64_Ehdr *elf64_newehdr __P((Elf *__elf)); | |
|
234 | extern Elf64_Phdr *elf64_getphdr __P((Elf *__elf)); | |
|
235 | extern Elf64_Phdr *elf64_newphdr __P((Elf *__elf, size_t __count)); | |
|
236 | extern Elf64_Shdr *elf64_getshdr __P((Elf_Scn *__scn)); | |
|
237 | extern size_t elf64_fsize __P((Elf_Type __type, size_t __count, | |
|
238 | unsigned __ver)); | |
|
239 | extern Elf_Data *elf64_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src, | |
|
240 | unsigned __encode)); | |
|
241 | extern Elf_Data *elf64_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src, | |
|
242 | unsigned __encode)); | |
|
243 | ||
|
244 | /* | |
|
245 | * Additional functions found on Solaris | |
|
246 | */ | |
|
247 | extern long elf64_checksum __P((Elf *__elf)); | |
|
248 | ||
|
249 | #endif /* __LIBELF64 */ | |
|
250 | ||
|
251 | /* | |
|
252 | * ELF format extensions | |
|
253 | * | |
|
254 | * These functions return 0 on failure, 1 on success. Since other | |
|
255 | * implementations of libelf may behave differently (there was quite | |
|
256 | * some confusion about the correct values), they are now officially | |
|
257 | * deprecated and should be replaced with the three new functions below. | |
|
258 | */ | |
|
259 | DEPRECATED extern int elf_getphnum __P((Elf *__elf, size_t *__resultp)); | |
|
260 | DEPRECATED extern int elf_getshnum __P((Elf *__elf, size_t *__resultp)); | |
|
261 | DEPRECATED extern int elf_getshstrndx __P((Elf *__elf, size_t *__resultp)); | |
|
262 | /* | |
|
263 | * Replacement functions (return -1 on failure, 0 on success). | |
|
264 | */ | |
|
265 | extern int elf_getphdrnum __P((Elf *__elf, size_t *__resultp)); | |
|
266 | extern int elf_getshdrnum __P((Elf *__elf, size_t *__resultp)); | |
|
267 | extern int elf_getshdrstrndx __P((Elf *__elf, size_t *__resultp)); | |
|
268 | ||
|
269 | /* | |
|
270 | * Convenience functions | |
|
271 | * | |
|
272 | * elfx_update_shstrndx is elf_getshstrndx's counterpart. | |
|
273 | * It should be used to set the e_shstrndx member. | |
|
274 | * There is no update function for e_shnum or e_phnum | |
|
275 | * because libelf handles them internally. | |
|
276 | */ | |
|
277 | extern int elfx_update_shstrndx __P((Elf *__elf, size_t __index)); | |
|
278 | ||
|
279 | /* | |
|
280 | * Experimental extensions: | |
|
281 | * | |
|
282 | * elfx_movscn() moves section `__scn' directly after section `__after'. | |
|
283 | * elfx_remscn() removes section `__scn'. Both functions update | |
|
284 | * the section indices; elfx_remscn() also adjusts the ELF header's | |
|
285 | * e_shnum member. The application is responsible for updating other | |
|
286 | * data (in particular, e_shstrndx and the section headers' sh_link and | |
|
287 | * sh_info members). | |
|
288 | * | |
|
289 | * elfx_movscn() returns the new index of the moved section. | |
|
290 | * elfx_remscn() returns the original index of the removed section. | |
|
291 | * A return value of zero indicates an error. | |
|
292 | */ | |
|
293 | extern size_t elfx_movscn __P((Elf *__elf, Elf_Scn *__scn, Elf_Scn *__after)); | |
|
294 | extern size_t elfx_remscn __P((Elf *__elf, Elf_Scn *__scn)); | |
|
295 | ||
|
296 | /* | |
|
297 | * elf_delscn() is obsolete. Please use elfx_remscn() instead. | |
|
298 | */ | |
|
299 | extern size_t elf_delscn __P((Elf *__elf, Elf_Scn *__scn)); | |
|
300 | ||
|
301 | #ifdef __cplusplus | |
|
302 | } | |
|
303 | #endif /* __cplusplus */ | |
|
304 | ||
|
305 | #endif /* _LIBELF_H */ |
@@ -0,0 +1,48 | |||
|
1 | /* | |
|
2 | * nlist.h - public header file for nlist(3). | |
|
3 | * Copyright (C) 1995 - 2006 Michael Riepe | |
|
4 | * | |
|
5 | * This library is free software; you can redistribute it and/or | |
|
6 | * modify it under the terms of the GNU Library General Public | |
|
7 | * License as published by the Free Software Foundation; either | |
|
8 | * version 2 of the License, or (at your option) any later version. | |
|
9 | * | |
|
10 | * This library is distributed in the hope that it will be useful, | |
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
13 | * Library General Public License for more details. | |
|
14 | * | |
|
15 | * You should have received a copy of the GNU Library General Public | |
|
16 | * License along with this library; if not, write to the Free Software | |
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | |
|
18 | */ | |
|
19 | ||
|
20 | /* @(#) $Id: nlist.h,v 1.10 2008/05/23 08:15:35 michael Exp $ */ | |
|
21 | ||
|
22 | #ifndef _NLIST_H | |
|
23 | #define _NLIST_H | |
|
24 | ||
|
25 | #ifdef __cplusplus | |
|
26 | extern "C" { | |
|
27 | #endif /* __cplusplus */ | |
|
28 | ||
|
29 | struct nlist { | |
|
30 | char* n_name; | |
|
31 | long n_value; | |
|
32 | short n_scnum; | |
|
33 | unsigned short n_type; | |
|
34 | char n_sclass; | |
|
35 | char n_numaux; | |
|
36 | }; | |
|
37 | ||
|
38 | #if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32) | |
|
39 | extern int nlist(const char *__filename, struct nlist *__nl); | |
|
40 | #else /* __STDC__ || defined(__cplusplus) */ | |
|
41 | extern int nlist(); | |
|
42 | #endif /* __STDC__ || defined(__cplusplus) */ | |
|
43 | ||
|
44 | #ifdef __cplusplus | |
|
45 | } | |
|
46 | #endif /* __cplusplus */ | |
|
47 | ||
|
48 | #endif /* _NLIST_H */ |
@@ -0,0 +1,446 | |||
|
1 | /* | |
|
2 | * private.h - private definitions for libelf. | |
|
3 | * Copyright (C) 1995 - 2007 Michael Riepe | |
|
4 | * | |
|
5 | * This library is free software; you can redistribute it and/or | |
|
6 | * modify it under the terms of the GNU Library General Public | |
|
7 | * License as published by the Free Software Foundation; either | |
|
8 | * version 2 of the License, or (at your option) any later version. | |
|
9 | * | |
|
10 | * This library is distributed in the hope that it will be useful, | |
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
13 | * Library General Public License for more details. | |
|
14 | * | |
|
15 | * You should have received a copy of the GNU Library General Public | |
|
16 | * License along with this library; if not, write to the Free Software | |
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | |
|
18 | */ | |
|
19 | ||
|
20 | /* @(#) $Id: private.h,v 1.40 2009/11/01 13:04:19 michael Exp $ */ | |
|
21 | ||
|
22 | #ifndef _PRIVATE_H | |
|
23 | #define _PRIVATE_H | |
|
24 | ||
|
25 | #define __LIBELF_INTERNAL__ 1 | |
|
26 | ||
|
27 | #if HAVE_CONFIG_H | |
|
28 | # include <config.h> | |
|
29 | #endif /* HAVE_CONFIG_H */ | |
|
30 | ||
|
31 | /* | |
|
32 | * Workaround for GLIBC bug: | |
|
33 | * include <stdint.h> before <sys/types.h> | |
|
34 | */ | |
|
35 | #if HAVE_STDINT_H | |
|
36 | #include <stdint.h> | |
|
37 | #endif | |
|
38 | #include <sys/types.h> | |
|
39 | ||
|
40 | #if STDC_HEADERS | |
|
41 | # include <stdlib.h> | |
|
42 | # include <string.h> | |
|
43 | #else /* STDC_HEADERS */ | |
|
44 | extern void *malloc(), *realloc(); | |
|
45 | extern void free(), bcopy(), abort(); | |
|
46 | extern int strcmp(), strncmp(), memcmp(); | |
|
47 | extern void *memcpy(), *memmove(), *memset(); | |
|
48 | #endif /* STDC_HEADERS */ | |
|
49 | ||
|
50 | #if defined(_WIN32) | |
|
51 | #include <io.h> | |
|
52 | #else | |
|
53 | #if HAVE_UNISTD_H | |
|
54 | # include <unistd.h> | |
|
55 | #else /* HAVE_UNISTD_H */ | |
|
56 | extern int read(), write(), close(); | |
|
57 | extern off_t lseek(); | |
|
58 | #if HAVE_FTRUNCATE | |
|
59 | extern int ftruncate(); | |
|
60 | #endif /* HAVE_FTRUNCATE */ | |
|
61 | #endif /* HAVE_UNISTD_H */ | |
|
62 | #endif /* defined(_WIN32) */ | |
|
63 | ||
|
64 | #ifndef SEEK_SET | |
|
65 | #define SEEK_SET 0 | |
|
66 | #endif /* SEEK_SET */ | |
|
67 | #ifndef SEEK_CUR | |
|
68 | #define SEEK_CUR 1 | |
|
69 | #endif /* SEEK_CUR */ | |
|
70 | #ifndef SEEK_END | |
|
71 | #define SEEK_END 2 | |
|
72 | #endif /* SEEK_END */ | |
|
73 | ||
|
74 | #if !HAVE_MEMCMP | |
|
75 | # define memcmp strncmp | |
|
76 | #endif /* !HAVE_MEMCMP */ | |
|
77 | #if !HAVE_MEMCPY | |
|
78 | # define memcpy(d,s,n) bcopy(s,d,n) | |
|
79 | #endif /* !HAVE_MEMCPY */ | |
|
80 | #if !HAVE_MEMMOVE | |
|
81 | # define memmove(d,s,n) bcopy(s,d,n) | |
|
82 | #endif /* !HAVE_MEMMOVE */ | |
|
83 | ||
|
84 | #if !HAVE_MEMSET | |
|
85 | # define memset _elf_memset | |
|
86 | extern void *_elf_memset(); | |
|
87 | #endif /* !HAVE_MEMSET */ | |
|
88 | ||
|
89 | #if HAVE_STRUCT_NLIST_DECLARATION | |
|
90 | # define nlist __override_nlist_declaration | |
|
91 | #endif /* HAVE_STRUCT_NLIST_DECLARATION */ | |
|
92 | ||
|
93 | #if __LIBELF_NEED_LINK_H | |
|
94 | # include <link.h> | |
|
95 | #elif __LIBELF_NEED_SYS_LINK_H | |
|
96 | # include <sys/link.h> | |
|
97 | #endif /* __LIBELF_NEED_LINK_H */ | |
|
98 | ||
|
99 | #if HAVE_AR_H | |
|
100 | #include <ar.h> | |
|
101 | #else /* HAVE_AR_H */ | |
|
102 | ||
|
103 | #define ARMAG "!<arch>\n" | |
|
104 | #define SARMAG 8 | |
|
105 | ||
|
106 | struct ar_hdr { | |
|
107 | char ar_name[16]; | |
|
108 | char ar_date[12]; | |
|
109 | char ar_uid[6]; | |
|
110 | char ar_gid[6]; | |
|
111 | char ar_mode[8]; | |
|
112 | char ar_size[10]; | |
|
113 | char ar_fmag[2]; | |
|
114 | }; | |
|
115 | ||
|
116 | #define ARFMAG "`\n" | |
|
117 | ||
|
118 | #endif /* HAVE_AR_H */ | |
|
119 | ||
|
120 | #include <libelf.h> | |
|
121 | ||
|
122 | #if HAVE_STRUCT_NLIST_DECLARATION | |
|
123 | # undef nlist | |
|
124 | #endif /* HAVE_STRUCT_NLIST_DECLARATION */ | |
|
125 | ||
|
126 | #if __LIBELF64 | |
|
127 | #include <gelf.h> | |
|
128 | #endif /* __LIBELF64 */ | |
|
129 | ||
|
130 | typedef struct Scn_Data Scn_Data; | |
|
131 | ||
|
132 | /* | |
|
133 | * ELF descriptor | |
|
134 | */ | |
|
135 | struct Elf { | |
|
136 | /* common */ | |
|
137 | size_t e_size; /* file/member size */ | |
|
138 | size_t e_dsize; /* size of memory image */ | |
|
139 | Elf_Kind e_kind; /* kind of file */ | |
|
140 | char* e_data; /* file/member data */ | |
|
141 | char* e_rawdata; /* file/member raw data */ | |
|
142 | size_t e_idlen; /* identifier size */ | |
|
143 | int e_fd; /* file descriptor */ | |
|
144 | unsigned e_count; /* activation count */ | |
|
145 | /* archive members (still common) */ | |
|
146 | Elf* e_parent; /* NULL if not an archive member */ | |
|
147 | size_t e_next; /* 0 if not an archive member */ | |
|
148 | size_t e_base; /* 0 if not an archive member */ | |
|
149 | Elf* e_link; /* next archive member or NULL */ | |
|
150 | Elf_Arhdr* e_arhdr; /* archive member header or NULL */ | |
|
151 | /* archives */ | |
|
152 | size_t e_off; /* current member offset (for elf_begin) */ | |
|
153 | Elf* e_members; /* linked list of active archive members */ | |
|
154 | char* e_symtab; /* archive symbol table */ | |
|
155 | size_t e_symlen; /* length of archive symbol table */ | |
|
156 | char* e_strtab; /* archive string table */ | |
|
157 | size_t e_strlen; /* length of archive string table */ | |
|
158 | /* ELF files */ | |
|
159 | unsigned e_class; /* ELF class */ | |
|
160 | unsigned e_encoding; /* ELF data encoding */ | |
|
161 | unsigned e_version; /* ELF version */ | |
|
162 | char* e_ehdr; /* ELF header */ | |
|
163 | char* e_phdr; /* ELF program header table */ | |
|
164 | size_t e_phnum; /* size of program header table */ | |
|
165 | Elf_Scn* e_scn_1; /* first section */ | |
|
166 | Elf_Scn* e_scn_n; /* last section */ | |
|
167 | unsigned e_elf_flags; /* elf flags (ELF_F_*) */ | |
|
168 | unsigned e_ehdr_flags; /* ehdr flags (ELF_F_*) */ | |
|
169 | unsigned e_phdr_flags; /* phdr flags (ELF_F_*) */ | |
|
170 | /* misc flags */ | |
|
171 | unsigned e_readable : 1; /* file is readable */ | |
|
172 | unsigned e_writable : 1; /* file is writable */ | |
|
173 | unsigned e_disabled : 1; /* e_fd has been disabled */ | |
|
174 | unsigned e_cooked : 1; /* e_data was modified */ | |
|
175 | unsigned e_free_syms : 1; /* e_symtab is malloc'ed */ | |
|
176 | unsigned e_unmap_data : 1; /* e_data is mmap'ed */ | |
|
177 | unsigned e_memory : 1; /* created by elf_memory() */ | |
|
178 | /* magic number for debugging */ | |
|
179 | long e_magic; | |
|
180 | }; | |
|
181 | ||
|
182 | #define ELF_MAGIC 0x012b649e | |
|
183 | ||
|
184 | #define INIT_ELF {\ | |
|
185 | /* e_size */ 0,\ | |
|
186 | /* e_dsize */ 0,\ | |
|
187 | /* e_kind */ ELF_K_NONE,\ | |
|
188 | /* e_data */ NULL,\ | |
|
189 | /* e_rawdata */ NULL,\ | |
|
190 | /* e_idlen */ 0,\ | |
|
191 | /* e_fd */ -1,\ | |
|
192 | /* e_count */ 1,\ | |
|
193 | /* e_parent */ NULL,\ | |
|
194 | /* e_next */ 0,\ | |
|
195 | /* e_base */ 0,\ | |
|
196 | /* e_link */ NULL,\ | |
|
197 | /* e_arhdr */ NULL,\ | |
|
198 | /* e_off */ 0,\ | |
|
199 | /* e_members */ NULL,\ | |
|
200 | /* e_symtab */ NULL,\ | |
|
201 | /* e_symlen */ 0,\ | |
|
202 | /* e_strtab */ NULL,\ | |
|
203 | /* e_strlen */ 0,\ | |
|
204 | /* e_class */ ELFCLASSNONE,\ | |
|
205 | /* e_encoding */ ELFDATANONE,\ | |
|
206 | /* e_version */ EV_NONE,\ | |
|
207 | /* e_ehdr */ NULL,\ | |
|
208 | /* e_phdr */ NULL,\ | |
|
209 | /* e_phnum */ 0,\ | |
|
210 | /* e_scn_1 */ NULL,\ | |
|
211 | /* e_scn_n */ NULL,\ | |
|
212 | /* e_elf_flags */ 0,\ | |
|
213 | /* e_ehdr_flags */ 0,\ | |
|
214 | /* e_phdr_flags */ 0,\ | |
|
215 | /* e_readable */ 0,\ | |
|
216 | /* e_writable */ 0,\ | |
|
217 | /* e_disabled */ 0,\ | |
|
218 | /* e_cooked */ 0,\ | |
|
219 | /* e_free_syms */ 0,\ | |
|
220 | /* e_unmap_data */ 0,\ | |
|
221 | /* e_memory */ 0,\ | |
|
222 | /* e_magic */ ELF_MAGIC\ | |
|
223 | } | |
|
224 | ||
|
225 | /* | |
|
226 | * Section descriptor | |
|
227 | */ | |
|
228 | struct Elf_Scn { | |
|
229 | Elf_Scn* s_link; /* pointer to next Elf_Scn */ | |
|
230 | Elf* s_elf; /* pointer to elf descriptor */ | |
|
231 | size_t s_index; /* number of this section */ | |
|
232 | unsigned s_scn_flags; /* section flags (ELF_F_*) */ | |
|
233 | unsigned s_shdr_flags; /* shdr flags (ELF_F_*) */ | |
|
234 | Scn_Data* s_data_1; /* first data buffer */ | |
|
235 | Scn_Data* s_data_n; /* last data buffer */ | |
|
236 | Scn_Data* s_rawdata; /* raw data buffer */ | |
|
237 | /* data copied from shdr */ | |
|
238 | unsigned s_type; /* section type */ | |
|
239 | size_t s_offset; /* section offset */ | |
|
240 | size_t s_size; /* section size */ | |
|
241 | /* misc flags */ | |
|
242 | unsigned s_freeme : 1; /* this Elf_Scn was malloc'ed */ | |
|
243 | /* section header */ | |
|
244 | union { | |
|
245 | #if __LIBELF64 | |
|
246 | Elf64_Shdr u_shdr64; | |
|
247 | #endif /* __LIBELF64 */ | |
|
248 | Elf32_Shdr u_shdr32; | |
|
249 | } s_uhdr; | |
|
250 | /* magic number for debugging */ | |
|
251 | long s_magic; | |
|
252 | }; | |
|
253 | #define s_shdr32 s_uhdr.u_shdr32 | |
|
254 | #define s_shdr64 s_uhdr.u_shdr64 | |
|
255 | ||
|
256 | #define SCN_MAGIC 0x012c747d | |
|
257 | ||
|
258 | #define INIT_SCN {\ | |
|
259 | /* s_link */ NULL,\ | |
|
260 | /* s_elf */ NULL,\ | |
|
261 | /* s_index */ 0,\ | |
|
262 | /* s_scn_flags */ 0,\ | |
|
263 | /* s_shdr_flags */ 0,\ | |
|
264 | /* s_data_1 */ NULL,\ | |
|
265 | /* s_data_n */ NULL,\ | |
|
266 | /* s_rawdata */ NULL,\ | |
|
267 | /* s_type */ SHT_NULL,\ | |
|
268 | /* s_offset */ 0,\ | |
|
269 | /* s_size */ 0,\ | |
|
270 | /* s_freeme */ 0,\ | |
|
271 | /* s_uhdr */ {{0,}},\ | |
|
272 | /* s_magic */ SCN_MAGIC\ | |
|
273 | } | |
|
274 | ||
|
275 | /* | |
|
276 | * Data descriptor | |
|
277 | */ | |
|
278 | struct Scn_Data { | |
|
279 | Elf_Data sd_data; /* must be first! */ | |
|
280 | Scn_Data* sd_link; /* pointer to next Scn_Data */ | |
|
281 | Elf_Scn* sd_scn; /* pointer to section */ | |
|
282 | char* sd_memdata; /* memory image of section */ | |
|
283 | unsigned sd_data_flags; /* data flags (ELF_F_*) */ | |
|
284 | /* misc flags */ | |
|
285 | unsigned sd_freeme : 1; /* this Scn_Data was malloc'ed */ | |
|
286 | unsigned sd_free_data : 1; /* sd_memdata is malloc'ed */ | |
|
287 | /* magic number for debugging */ | |
|
288 | long sd_magic; | |
|
289 | }; | |
|
290 | ||
|
291 | #define DATA_MAGIC 0x01072639 | |
|
292 | ||
|
293 | #define INIT_DATA {\ | |
|
294 | {\ | |
|
295 | /* d_buf */ NULL,\ | |
|
296 | /* d_type */ ELF_T_BYTE,\ | |
|
297 | /* d_size */ 0,\ | |
|
298 | /* d_off */ 0,\ | |
|
299 | /* d_align */ 0,\ | |
|
300 | /* d_version */ EV_NONE\ | |
|
301 | },\ | |
|
302 | /* sd_link */ NULL,\ | |
|
303 | /* sd_scn */ NULL,\ | |
|
304 | /* sd_memdata */ NULL,\ | |
|
305 | /* sd_data_flags */ 0,\ | |
|
306 | /* sd_freeme */ 0,\ | |
|
307 | /* sd_free_data */ 0,\ | |
|
308 | /* sd_magic */ DATA_MAGIC\ | |
|
309 | } | |
|
310 | ||
|
311 | /* | |
|
312 | * Private status variables | |
|
313 | */ | |
|
314 | extern unsigned _elf_version; | |
|
315 | extern int _elf_errno; | |
|
316 | extern int _elf_fill; | |
|
317 | extern int _elf_sanity_checks; | |
|
318 | #define SANITY_CHECK_STRPTR (1u << 0) | |
|
319 | ||
|
320 | /* | |
|
321 | * Private functions | |
|
322 | */ | |
|
323 | extern void *_elf_read __P((Elf*, void*, size_t, size_t)); | |
|
324 | extern void *_elf_mmap __P((Elf*)); | |
|
325 | extern int _elf_cook __P((Elf*)); | |
|
326 | extern char *_elf_getehdr __P((Elf*, unsigned)); | |
|
327 | extern char *_elf_getphdr __P((Elf*, unsigned)); | |
|
328 | extern Elf_Data *_elf_xlatetom __P((const Elf*, Elf_Data*, const Elf_Data*)); | |
|
329 | extern Elf_Type _elf_scn_type __P((unsigned)); | |
|
330 | extern size_t _elf32_xltsize __P((const Elf_Data *__src, unsigned __dv, unsigned __encode, int __tof)); | |
|
331 | extern size_t _elf64_xltsize __P((const Elf_Data *__src, unsigned __dv, unsigned __encode, int __tof)); | |
|
332 | extern int _elf_update_shnum(Elf *__elf, size_t __shnum); | |
|
333 | extern Elf_Scn *_elf_first_scn(Elf *__elf); | |
|
334 | ||
|
335 | /* | |
|
336 | * Special translators | |
|
337 | */ | |
|
338 | extern size_t _elf_verdef_32L11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
339 | extern size_t _elf_verdef_32L11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
340 | extern size_t _elf_verdef_32M11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
341 | extern size_t _elf_verdef_32M11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
342 | extern size_t _elf_verdef_64L11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
343 | extern size_t _elf_verdef_64L11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
344 | extern size_t _elf_verdef_64M11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
345 | extern size_t _elf_verdef_64M11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
346 | extern size_t _elf_verneed_32L11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
347 | extern size_t _elf_verneed_32L11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
348 | extern size_t _elf_verneed_32M11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
349 | extern size_t _elf_verneed_32M11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
350 | extern size_t _elf_verneed_64L11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
351 | extern size_t _elf_verneed_64L11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
352 | extern size_t _elf_verneed_64M11_tof __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
353 | extern size_t _elf_verneed_64M11_tom __P((unsigned char *dst, const unsigned char *src, size_t n)); | |
|
354 | ||
|
355 | /* | |
|
356 | * Private data | |
|
357 | */ | |
|
358 | extern const Elf_Scn _elf_scn_init; | |
|
359 | extern const Scn_Data _elf_data_init; | |
|
360 | extern const size_t _elf_fmsize[2][EV_CURRENT - EV_NONE][ELF_T_NUM][2]; | |
|
361 | ||
|
362 | /* | |
|
363 | * Access macros for _elf_fmsize[] | |
|
364 | */ | |
|
365 | #define _fmsize(c,v,t,w) \ | |
|
366 | (_elf_fmsize[(c)-ELFCLASS32][(v)-EV_NONE-1][(t)-ELF_T_BYTE][(w)]) | |
|
367 | #define _fsize(c,v,t) _fmsize((c),(v),(t),1) | |
|
368 | #define _msize(c,v,t) _fmsize((c),(v),(t),0) | |
|
369 | ||
|
370 | /* | |
|
371 | * Various checks | |
|
372 | */ | |
|
373 | #define valid_class(c) ((c) >= ELFCLASS32 && (c) <= ELFCLASS64) | |
|
374 | #define valid_encoding(e) ((e) >= ELFDATA2LSB && (e) <= ELFDATA2MSB) | |
|
375 | #define valid_version(v) ((v) > EV_NONE && (v) <= EV_CURRENT) | |
|
376 | #define valid_type(t) ((unsigned)(t) < ELF_T_NUM) | |
|
377 | ||
|
378 | /* | |
|
379 | * Error codes | |
|
380 | */ | |
|
381 | enum { | |
|
382 | #define __err__(a,b) a, | |
|
383 | #include <errors.h> /* include constants from errors.h */ | |
|
384 | #undef __err__ | |
|
385 | ERROR_NUM | |
|
386 | }; | |
|
387 | ||
|
388 | #define seterr(err) (_elf_errno = (err)) | |
|
389 | ||
|
390 | /* | |
|
391 | * Sizes of data types (external representation) | |
|
392 | * These definitions should be in <elf.h>, but... | |
|
393 | */ | |
|
394 | #ifndef ELF32_FSZ_ADDR | |
|
395 | # define ELF32_FSZ_ADDR 4 | |
|
396 | # define ELF32_FSZ_HALF 2 | |
|
397 | # define ELF32_FSZ_OFF 4 | |
|
398 | # define ELF32_FSZ_SWORD 4 | |
|
399 | # define ELF32_FSZ_WORD 4 | |
|
400 | #endif /* ELF32_FSZ_ADDR */ | |
|
401 | #ifndef ELF64_FSZ_ADDR | |
|
402 | # define ELF64_FSZ_ADDR 8 | |
|
403 | # define ELF64_FSZ_HALF 2 | |
|
404 | # define ELF64_FSZ_OFF 8 | |
|
405 | # define ELF64_FSZ_SWORD 4 | |
|
406 | # define ELF64_FSZ_SXWORD 8 | |
|
407 | # define ELF64_FSZ_WORD 4 | |
|
408 | # define ELF64_FSZ_XWORD 8 | |
|
409 | #endif /* ELF64_FSZ_ADDR */ | |
|
410 | ||
|
411 | /* | |
|
412 | * More missing pieces, in no particular order | |
|
413 | */ | |
|
414 | #ifndef SHT_SYMTAB_SHNDX | |
|
415 | #define SHT_SYMTAB_SHNDX 18 | |
|
416 | #endif /* SHT_SYMTAB_SHNDX */ | |
|
417 | ||
|
418 | #ifndef SHN_XINDEX | |
|
419 | #define SHN_XINDEX 0xffff | |
|
420 | #endif /* SHN_XINDEX */ | |
|
421 | ||
|
422 | #ifndef PN_XNUM | |
|
423 | #define PN_XNUM 0xffff | |
|
424 | #endif /* PN_XNUM */ | |
|
425 | ||
|
426 | /* | |
|
427 | * Debugging | |
|
428 | */ | |
|
429 | #if ENABLE_DEBUG | |
|
430 | extern void __elf_assert __P((const char*, unsigned, const char*)); | |
|
431 | # if (__STDC__ + 0) | |
|
432 | # define elf_assert(x) do{if(!(x))__elf_assert(__FILE__,__LINE__,#x);}while(0) | |
|
433 | # else /* __STDC__ */ | |
|
434 | # define elf_assert(x) do{if(!(x))__elf_assert(__FILE__,__LINE__,"x");}while(0) | |
|
435 | # endif /* __STDC__ */ | |
|
436 | #else /* ENABLE_DEBUG */ | |
|
437 | # define elf_assert(x) do{}while(0) | |
|
438 | #endif /* ENABLE_DEBUG */ | |
|
439 | ||
|
440 | /* | |
|
441 | * Return values for certain functions | |
|
442 | */ | |
|
443 | #define LIBELF_SUCCESS 1 | |
|
444 | #define LIBELF_FAILURE 0 | |
|
445 | ||
|
446 | #endif /* _PRIVATE_H */ |
@@ -0,0 +1,131 | |||
|
1 | /* lib/sys_elf.h. Generated automatically by configure. */ | |
|
2 | /* | |
|
3 | sys_elf.h.in - configure template for private "switch" file. | |
|
4 | Copyright (C) 1998 - 2001 Michael Riepe | |
|
5 | ||
|
6 | This library is free software; you can redistribute it and/or | |
|
7 | modify it under the terms of the GNU Library General Public | |
|
8 | License as published by the Free Software Foundation; either | |
|
9 | version 2 of the License, or (at your option) any later version. | |
|
10 | ||
|
11 | This library is distributed in the hope that it will be useful, | |
|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
14 | Library General Public License for more details. | |
|
15 | ||
|
16 | You should have received a copy of the GNU Library General Public | |
|
17 | License along with this library; if not, write to the Free Software | |
|
18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | |
|
19 | */ | |
|
20 | ||
|
21 | /* @(#) $Id: sys_elf.h.in,v 1.13 2008/05/23 08:57:07 michael Exp $ */ | |
|
22 | ||
|
23 | /* | |
|
24 | * DO NOT USE THIS IN APPLICATIONS - #include <libelf.h> INSTEAD! | |
|
25 | */ | |
|
26 | ||
|
27 | /* Define to `<elf.h>' or `<sys/elf.h>' if one of them is present */ | |
|
28 | /* #undef __LIBELF_HEADER_ELF_H */ | |
|
29 | ||
|
30 | /* Define if Elf32_Dyn is declared in <link.h> */ | |
|
31 | /* #undef __LIBELF_NEED_LINK_H */ | |
|
32 | ||
|
33 | /* Define if Elf32_Dyn is declared in <sys/link.h> */ | |
|
34 | /* #undef __LIBELF_NEED_SYS_LINK_H */ | |
|
35 | ||
|
36 | /* Define if you want 64-bit support (and your system supports it) */ | |
|
37 | #define __LIBELF64 1 | |
|
38 | ||
|
39 | /* Define if you want 64-bit support, and are running IRIX */ | |
|
40 | /* #undef __LIBELF64_IRIX */ | |
|
41 | ||
|
42 | /* Define if you want 64-bit support, and are running Linux */ | |
|
43 | /* #undef __LIBELF64_LINUX */ | |
|
44 | ||
|
45 | /* Define if you want symbol versioning (and your system supports it) */ | |
|
46 | #define __LIBELF_SYMBOL_VERSIONS 1 | |
|
47 | ||
|
48 | /* Define to a 64-bit signed integer type if one exists */ | |
|
49 | #define __libelf_i64_t __int64 | |
|
50 | ||
|
51 | /* Define to a 64-bit unsigned integer type if one exists */ | |
|
52 | #define __libelf_u64_t unsigned __int64 | |
|
53 | ||
|
54 | /* Define to a 32-bit signed integer type if one exists */ | |
|
55 | #define __libelf_i32_t int | |
|
56 | ||
|
57 | /* Define to a 32-bit unsigned integer type if one exists */ | |
|
58 | #define __libelf_u32_t unsigned int | |
|
59 | ||
|
60 | /* Define to a 16-bit signed integer type if one exists */ | |
|
61 | #define __libelf_i16_t short | |
|
62 | ||
|
63 | /* Define to a 16-bit unsigned integer type if one exists */ | |
|
64 | #define __libelf_u16_t unsigned short | |
|
65 | ||
|
66 | /* | |
|
67 | * Ok, now get the correct instance of elf.h... | |
|
68 | */ | |
|
69 | #ifdef __LIBELF_HEADER_ELF_H | |
|
70 | # include __LIBELF_HEADER_ELF_H | |
|
71 | #else /* __LIBELF_HEADER_ELF_H */ | |
|
72 | # if __LIBELF_INTERNAL__ | |
|
73 | # include <elf_repl.h> | |
|
74 | # else /* __LIBELF_INTERNAL__ */ | |
|
75 | # include <libelf/elf_repl.h> | |
|
76 | # endif /* __LIBELF_INTERNAL__ */ | |
|
77 | #endif /* __LIBELF_HEADER_ELF_H */ | |
|
78 | ||
|
79 | /* | |
|
80 | * On some systems, <elf.h> is severely broken. Try to fix it. | |
|
81 | */ | |
|
82 | #ifdef __LIBELF_HEADER_ELF_H | |
|
83 | ||
|
84 | # ifndef ELF32_FSZ_ADDR | |
|
85 | # define ELF32_FSZ_ADDR 4 | |
|
86 | # define ELF32_FSZ_HALF 2 | |
|
87 | # define ELF32_FSZ_OFF 4 | |
|
88 | # define ELF32_FSZ_SWORD 4 | |
|
89 | # define ELF32_FSZ_WORD 4 | |
|
90 | # endif /* ELF32_FSZ_ADDR */ | |
|
91 | ||
|
92 | # ifndef STN_UNDEF | |
|
93 | # define STN_UNDEF 0 | |
|
94 | # endif /* STN_UNDEF */ | |
|
95 | ||
|
96 | # if __LIBELF64 | |
|
97 | ||
|
98 | # ifndef ELF64_FSZ_ADDR | |
|
99 | # define ELF64_FSZ_ADDR 8 | |
|
100 | # define ELF64_FSZ_HALF 2 | |
|
101 | # define ELF64_FSZ_OFF 8 | |
|
102 | # define ELF64_FSZ_SWORD 4 | |
|
103 | # define ELF64_FSZ_WORD 4 | |
|
104 | # define ELF64_FSZ_SXWORD 8 | |
|
105 | # define ELF64_FSZ_XWORD 8 | |
|
106 | # endif /* ELF64_FSZ_ADDR */ | |
|
107 | ||
|
108 | # ifndef ELF64_ST_BIND | |
|
109 | # define ELF64_ST_BIND(i) ((i)>>4) | |
|
110 | # define ELF64_ST_TYPE(i) ((i)&0xf) | |
|
111 | # define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) | |
|
112 | # endif /* ELF64_ST_BIND */ | |
|
113 | ||
|
114 | # ifndef ELF64_R_SYM | |
|
115 | # define ELF64_R_SYM(i) ((Elf64_Xword)(i)>>32) | |
|
116 | # define ELF64_R_TYPE(i) ((i)&0xffffffffL) | |
|
117 | # define ELF64_R_INFO(s,t) (((Elf64_Xword)(s)<<32)+((t)&0xffffffffL)) | |
|
118 | # endif /* ELF64_R_SYM */ | |
|
119 | ||
|
120 | # if __LIBELF64_LINUX | |
|
121 | typedef __libelf_u64_t Elf64_Addr; | |
|
122 | typedef __libelf_u16_t Elf64_Half; | |
|
123 | typedef __libelf_u64_t Elf64_Off; | |
|
124 | typedef __libelf_i32_t Elf64_Sword; | |
|
125 | typedef __libelf_u32_t Elf64_Word; | |
|
126 | typedef __libelf_i64_t Elf64_Sxword; | |
|
127 | typedef __libelf_u64_t Elf64_Xword; | |
|
128 | # endif /* __LIBELF64_LINUX */ | |
|
129 | ||
|
130 | # endif /* __LIBELF64 */ | |
|
131 | #endif /* __LIBELF_HEADER_ELF_H */ |
@@ -0,0 +1,241 | |||
|
1 | /* | |
|
2 | * verdef.h - copy versioning information. | |
|
3 | * Copyright (C) 2001 - 2006 Michael Riepe | |
|
4 | * | |
|
5 | * This library is free software; you can redistribute it and/or | |
|
6 | * modify it under the terms of the GNU Library General Public | |
|
7 | * License as published by the Free Software Foundation; either | |
|
8 | * version 2 of the License, or (at your option) any later version. | |
|
9 | * | |
|
10 | * This library is distributed in the hope that it will be useful, | |
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
13 | * Library General Public License for more details. | |
|
14 | * | |
|
15 | * You should have received a copy of the GNU Library General Public | |
|
16 | * License along with this library; if not, write to the Free Software | |
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | |
|
18 | */ | |
|
19 | ||
|
20 | #ifndef lint | |
|
21 | static const char verdef_h_rcsid[] = "@(#) $Id: verdef.h,v 1.13 2008/05/23 08:15:35 michael Exp $"; | |
|
22 | #endif /* lint */ | |
|
23 | ||
|
24 | #if VER_DEF_CURRENT != 1 | |
|
25 | #error libelf currently does not support VER_DEF_CURRENT != 1 | |
|
26 | #endif /* VER_DEF_CURRENT != 1 */ | |
|
27 | ||
|
28 | #if TOFILE | |
|
29 | ||
|
30 | static void | |
|
31 | __store_verdaux(verdaux_ftype *dst, const verdaux_mtype *src, unsigned enc) { | |
|
32 | if (enc == ELFDATA2LSB) { | |
|
33 | __store_u32L(dst->vda_name, src->vda_name); | |
|
34 | __store_u32L(dst->vda_next, src->vda_next); | |
|
35 | } | |
|
36 | else { | |
|
37 | __store_u32M(dst->vda_name, src->vda_name); | |
|
38 | __store_u32M(dst->vda_next, src->vda_next); | |
|
39 | } | |
|
40 | } | |
|
41 | ||
|
42 | static void | |
|
43 | __store_verdef(verdef_ftype *dst, const verdef_mtype *src, unsigned enc) { | |
|
44 | if (enc == ELFDATA2LSB) { | |
|
45 | __store_u16L(dst->vd_version, src->vd_version); | |
|
46 | __store_u16L(dst->vd_flags, src->vd_flags); | |
|
47 | __store_u16L(dst->vd_ndx, src->vd_ndx); | |
|
48 | __store_u16L(dst->vd_cnt, src->vd_cnt); | |
|
49 | __store_u32L(dst->vd_hash, src->vd_hash); | |
|
50 | __store_u32L(dst->vd_aux, src->vd_aux); | |
|
51 | __store_u32L(dst->vd_next, src->vd_next); | |
|
52 | } | |
|
53 | else { | |
|
54 | __store_u16M(dst->vd_version, src->vd_version); | |
|
55 | __store_u16M(dst->vd_flags, src->vd_flags); | |
|
56 | __store_u16M(dst->vd_ndx, src->vd_ndx); | |
|
57 | __store_u16M(dst->vd_cnt, src->vd_cnt); | |
|
58 | __store_u32M(dst->vd_hash, src->vd_hash); | |
|
59 | __store_u32M(dst->vd_aux, src->vd_aux); | |
|
60 | __store_u32M(dst->vd_next, src->vd_next); | |
|
61 | } | |
|
62 | } | |
|
63 | ||
|
64 | typedef verdaux_mtype verdaux_stype; | |
|
65 | typedef verdaux_ftype verdaux_dtype; | |
|
66 | typedef verdef_mtype verdef_stype; | |
|
67 | typedef verdef_ftype verdef_dtype; | |
|
68 | typedef align_mtype verdef_atype; | |
|
69 | ||
|
70 | #define copy_verdaux_srctotmp(d, s, e) (*(d) = *(s)) | |
|
71 | #define copy_verdaux_tmptodst(d, s, e) __store_verdaux((d), (s), (e)) | |
|
72 | #define copy_verdef_srctotmp(d, s, e) (*(d) = *(s)) | |
|
73 | #define copy_verdef_tmptodst(d, s, e) __store_verdef((d), (s), (e)) | |
|
74 | ||
|
75 | #define translator_suffix _tof | |
|
76 | ||
|
77 | #else /* TOFILE */ | |
|
78 | ||
|
79 | static void | |
|
80 | __load_verdaux(verdaux_mtype *dst, const verdaux_ftype *src, unsigned enc) { | |
|
81 | if (enc == ELFDATA2LSB) { | |
|
82 | dst->vda_name = __load_u32L(src->vda_name); | |
|
83 | dst->vda_next = __load_u32L(src->vda_next); | |
|
84 | } | |
|
85 | else { | |
|
86 | dst->vda_name = __load_u32M(src->vda_name); | |
|
87 | dst->vda_next = __load_u32M(src->vda_next); | |
|
88 | } | |
|
89 | } | |
|
90 | ||
|
91 | static void | |
|
92 | __load_verdef(verdef_mtype *dst, const verdef_ftype *src, unsigned enc) { | |
|
93 | if (enc == ELFDATA2LSB) { | |
|
94 | dst->vd_version = __load_u16L(src->vd_version); | |
|
95 | dst->vd_flags = __load_u16L(src->vd_flags); | |
|
96 | dst->vd_ndx = __load_u16L(src->vd_ndx); | |
|
97 | dst->vd_cnt = __load_u16L(src->vd_cnt); | |
|
98 | dst->vd_hash = __load_u32L(src->vd_hash); | |
|
99 | dst->vd_aux = __load_u32L(src->vd_aux); | |
|
100 | dst->vd_next = __load_u32L(src->vd_next); | |
|
101 | } | |
|
102 | else { | |
|
103 | dst->vd_version = __load_u16M(src->vd_version); | |
|
104 | dst->vd_flags = __load_u16M(src->vd_flags); | |
|
105 | dst->vd_ndx = __load_u16M(src->vd_ndx); | |
|
106 | dst->vd_cnt = __load_u16M(src->vd_cnt); | |
|
107 | dst->vd_hash = __load_u32M(src->vd_hash); | |
|
108 | dst->vd_aux = __load_u32M(src->vd_aux); | |
|
109 | dst->vd_next = __load_u32M(src->vd_next); | |
|
110 | } | |
|
111 | } | |
|
112 | ||
|
113 | typedef verdaux_ftype verdaux_stype; | |
|
114 | typedef verdaux_mtype verdaux_dtype; | |
|
115 | typedef verdef_ftype verdef_stype; | |
|
116 | typedef verdef_mtype verdef_dtype; | |
|
117 | typedef align_ftype verdef_atype; | |
|
118 | ||
|
119 | #define copy_verdaux_srctotmp(d, s, e) __load_verdaux((d), (s), (e)) | |
|
120 | #define copy_verdaux_tmptodst(d, s, e) (*(d) = *(s)) | |
|
121 | #define copy_verdef_srctotmp(d, s, e) __load_verdef((d), (s), (e)) | |
|
122 | #define copy_verdef_tmptodst(d, s, e) (*(d) = *(s)) | |
|
123 | ||
|
124 | #define translator_suffix _tom | |
|
125 | ||
|
126 | #endif /* TOFILE */ | |
|
127 | ||
|
128 | #define cat3(a,b,c) a##b##c | |
|
129 | #define xlt3(p,e,s) cat3(p,e,s) | |
|
130 | #define xltprefix(x) xlt3(x,_,class_suffix) | |
|
131 | #define translator(x,e) xlt3(xltprefix(_elf_##x),e,translator_suffix) | |
|
132 | ||
|
133 | static size_t | |
|
134 | xlt_verdef(unsigned char *dst, const unsigned char *src, size_t n, unsigned enc) { | |
|
135 | size_t off; | |
|
136 | ||
|
137 | if (sizeof(verdef_stype) != sizeof(verdef_dtype) | |
|
138 | || sizeof(verdaux_stype) != sizeof(verdaux_dtype)) { | |
|
139 | /* never happens for ELF v1 and Verneed v1 */ | |
|
140 | seterr(ERROR_UNIMPLEMENTED); | |
|
141 | return (size_t)-1; | |
|
142 | } | |
|
143 | /* size translation shortcut */ | |
|
144 | if (dst == NULL) { | |
|
145 | return n; | |
|
146 | } | |
|
147 | if (src == NULL) { | |
|
148 | seterr(ERROR_NULLBUF); | |
|
149 | return (size_t)-1; | |
|
150 | } | |
|
151 | off = 0; | |
|
152 | while (off + sizeof(verdef_stype) <= n) { | |
|
153 | const verdef_stype *svd; | |
|
154 | verdef_dtype *dvd; | |
|
155 | verdef_mtype vd; | |
|
156 | size_t acount; | |
|
157 | size_t aoff; | |
|
158 | ||
|
159 | /* | |
|
160 | * check for proper alignment | |
|
161 | */ | |
|
162 | if (off % sizeof(verdef_atype)) { | |
|
163 | seterr(ERROR_VERDEF_FORMAT); | |
|
164 | return (size_t)-1; | |
|
165 | } | |
|
166 | /* | |
|
167 | * copy and check src | |
|
168 | */ | |
|
169 | svd = (verdef_stype*)(src + off); | |
|
170 | dvd = (verdef_dtype*)(dst + off); | |
|
171 | copy_verdef_srctotmp(&vd, svd, enc); | |
|
172 | if (vd.vd_version < 1 | |
|
173 | || vd.vd_version > VER_DEF_CURRENT) { | |
|
174 | seterr(ERROR_VERDEF_VERSION); | |
|
175 | return (size_t)-1; | |
|
176 | } | |
|
177 | if (vd.vd_cnt < 1 | |
|
178 | || vd.vd_aux == 0) { | |
|
179 | seterr(ERROR_VERDEF_FORMAT); | |
|
180 | return (size_t)-1; | |
|
181 | } | |
|
182 | copy_verdef_tmptodst(dvd, &vd, enc); | |
|
183 | /* | |
|
184 | * copy aux array | |
|
185 | */ | |
|
186 | aoff = off + vd.vd_aux; | |
|
187 | for (acount = 0; acount < vd.vd_cnt; acount++) { | |
|
188 | const verdaux_stype *svda; | |
|
189 | verdaux_dtype *dvda; | |
|
190 | verdaux_mtype vda; | |
|
191 | ||
|
192 | /* | |
|
193 | * are we still inside the buffer limits? | |
|
194 | */ | |
|
195 | if (aoff + sizeof(verdaux_stype) > n) { | |
|
196 | break; | |
|
197 | } | |
|
198 | /* | |
|
199 | * check for proper alignment | |
|
200 | */ | |
|
201 | if (aoff % sizeof(verdef_atype)) { | |
|
202 | seterr(ERROR_VERDEF_FORMAT); | |
|
203 | return (size_t)-1; | |
|
204 | } | |
|
205 | /* | |
|
206 | * copy and check src | |
|
207 | */ | |
|
208 | svda = (verdaux_stype*)(src + aoff); | |
|
209 | dvda = (verdaux_dtype*)(dst + aoff); | |
|
210 | copy_verdaux_srctotmp(&vda, svda, enc); | |
|
211 | copy_verdaux_tmptodst(dvda, &vda, enc); | |
|
212 | /* | |
|
213 | * advance to next verdaux | |
|
214 | */ | |
|
215 | if (vda.vda_next == 0) { | |
|
216 | /* end of list */ | |
|
217 | break; | |
|
218 | } | |
|
219 | aoff += vda.vda_next; | |
|
220 | } | |
|
221 | /* | |
|
222 | * advance to next verdef | |
|
223 | */ | |
|
224 | if (vd.vd_next == 0) { | |
|
225 | /* end of list */ | |
|
226 | break; | |
|
227 | } | |
|
228 | off += vd.vd_next; | |
|
229 | } | |
|
230 | return n; | |
|
231 | } | |
|
232 | ||
|
233 | size_t | |
|
234 | translator(verdef,L11)(unsigned char *dst, const unsigned char *src, size_t n) { | |
|
235 | return xlt_verdef(dst, src, n, ELFDATA2LSB); | |
|
236 | } | |
|
237 | ||
|
238 | size_t | |
|
239 | translator(verdef,M11)(unsigned char *dst, const unsigned char *src, size_t n) { | |
|
240 | return xlt_verdef(dst, src, n, ELFDATA2MSB); | |
|
241 | } |
@@ -0,0 +1,245 | |||
|
1 | /* | |
|
2 | * verneed.h - copy versioning information. | |
|
3 | * Copyright (C) 2001 - 2006 Michael Riepe | |
|
4 | * | |
|
5 | * This library is free software; you can redistribute it and/or | |
|
6 | * modify it under the terms of the GNU Library General Public | |
|
7 | * License as published by the Free Software Foundation; either | |
|
8 | * version 2 of the License, or (at your option) any later version. | |
|
9 | * | |
|
10 | * This library is distributed in the hope that it will be useful, | |
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
13 | * Library General Public License for more details. | |
|
14 | * | |
|
15 | * You should have received a copy of the GNU Library General Public | |
|
16 | * License along with this library; if not, write to the Free Software | |
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | |
|
18 | */ | |
|
19 | ||
|
20 | #ifndef lint | |
|
21 | static const char verneed_h_rcsid[] = "@(#) $Id: verneed.h,v 1.13 2008/05/23 08:15:35 michael Exp $"; | |
|
22 | #endif /* lint */ | |
|
23 | ||
|
24 | #if VER_NEED_CURRENT != 1 | |
|
25 | #error libelf currently does not support VER_NEED_CURRENT != 1 | |
|
26 | #endif /* VER_NEED_CURRENT != 1 */ | |
|
27 | ||
|
28 | #if TOFILE | |
|
29 | ||
|
30 | static void | |
|
31 | __store_vernaux(vernaux_ftype *dst, const vernaux_mtype *src, unsigned enc) { | |
|
32 | if (enc == ELFDATA2LSB) { | |
|
33 | __store_u32L(dst->vna_hash, src->vna_hash); | |
|
34 | __store_u16L(dst->vna_flags, src->vna_flags); | |
|
35 | __store_u16L(dst->vna_other, src->vna_other); | |
|
36 | __store_u32L(dst->vna_name, src->vna_name); | |
|
37 | __store_u32L(dst->vna_next, src->vna_next); | |
|
38 | } | |
|
39 | else { | |
|
40 | __store_u32M(dst->vna_hash, src->vna_hash); | |
|
41 | __store_u16M(dst->vna_flags, src->vna_flags); | |
|
42 | __store_u16M(dst->vna_other, src->vna_other); | |
|
43 | __store_u32M(dst->vna_name, src->vna_name); | |
|
44 | __store_u32M(dst->vna_next, src->vna_next); | |
|
45 | } | |
|
46 | } | |
|
47 | ||
|
48 | static void | |
|
49 | __store_verneed(verneed_ftype *dst, const verneed_mtype *src, unsigned enc) { | |
|
50 | if (enc == ELFDATA2LSB) { | |
|
51 | __store_u16L(dst->vn_version, src->vn_version); | |
|
52 | __store_u16L(dst->vn_cnt, src->vn_cnt); | |
|
53 | __store_u32L(dst->vn_file, src->vn_file); | |
|
54 | __store_u32L(dst->vn_aux, src->vn_aux); | |
|
55 | __store_u32L(dst->vn_next, src->vn_next); | |
|
56 | } | |
|
57 | else { | |
|
58 | __store_u16M(dst->vn_version, src->vn_version); | |
|
59 | __store_u16M(dst->vn_cnt, src->vn_cnt); | |
|
60 | __store_u32M(dst->vn_file, src->vn_file); | |
|
61 | __store_u32M(dst->vn_aux, src->vn_aux); | |
|
62 | __store_u32M(dst->vn_next, src->vn_next); | |
|
63 | } | |
|
64 | } | |
|
65 | ||
|
66 | typedef vernaux_mtype vernaux_stype; | |
|
67 | typedef vernaux_ftype vernaux_dtype; | |
|
68 | typedef verneed_mtype verneed_stype; | |
|
69 | typedef verneed_ftype verneed_dtype; | |
|
70 | typedef align_mtype verneed_atype; | |
|
71 | ||
|
72 | #define copy_vernaux_srctotmp(d, s, e) (*(d) = *(s)) | |
|
73 | #define copy_vernaux_tmptodst(d, s, e) __store_vernaux((d), (s), (e)) | |
|
74 | #define copy_verneed_srctotmp(d, s, e) (*(d) = *(s)) | |
|
75 | #define copy_verneed_tmptodst(d, s, e) __store_verneed((d), (s), (e)) | |
|
76 | ||
|
77 | #define translator_suffix _tof | |
|
78 | ||
|
79 | #else /* TOFILE */ | |
|
80 | ||
|
81 | static void | |
|
82 | __load_vernaux(vernaux_mtype *dst, const vernaux_ftype *src, unsigned enc) { | |
|
83 | if (enc == ELFDATA2LSB) { | |
|
84 | dst->vna_hash = __load_u32L(src->vna_hash); | |
|
85 | dst->vna_flags = __load_u16L(src->vna_flags); | |
|
86 | dst->vna_other = __load_u16L(src->vna_other); | |
|
87 | dst->vna_name = __load_u32L(src->vna_name); | |
|
88 | dst->vna_next = __load_u32L(src->vna_next); | |
|
89 | } | |
|
90 | else { | |
|
91 | dst->vna_hash = __load_u32M(src->vna_hash); | |
|
92 | dst->vna_flags = __load_u16M(src->vna_flags); | |
|
93 | dst->vna_other = __load_u16M(src->vna_other); | |
|
94 | dst->vna_name = __load_u32M(src->vna_name); | |
|
95 | dst->vna_next = __load_u32M(src->vna_next); | |
|
96 | } | |
|
97 | } | |
|
98 | ||
|
99 | static void | |
|
100 | __load_verneed(verneed_mtype *dst, const verneed_ftype *src, unsigned enc) { | |
|
101 | if (enc == ELFDATA2LSB) { | |
|
102 | dst->vn_version = __load_u16L(src->vn_version); | |
|
103 | dst->vn_cnt = __load_u16L(src->vn_cnt); | |
|
104 | dst->vn_file = __load_u32L(src->vn_file); | |
|
105 | dst->vn_aux = __load_u32L(src->vn_aux); | |
|
106 | dst->vn_next = __load_u32L(src->vn_next); | |
|
107 | } | |
|
108 | else { | |
|
109 | dst->vn_version = __load_u16M(src->vn_version); | |
|
110 | dst->vn_cnt = __load_u16M(src->vn_cnt); | |
|
111 | dst->vn_file = __load_u32M(src->vn_file); | |
|
112 | dst->vn_aux = __load_u32M(src->vn_aux); | |
|
113 | dst->vn_next = __load_u32M(src->vn_next); | |
|
114 | } | |
|
115 | } | |
|
116 | ||
|
117 | typedef vernaux_ftype vernaux_stype; | |
|
118 | typedef vernaux_mtype vernaux_dtype; | |
|
119 | typedef verneed_ftype verneed_stype; | |
|
120 | typedef verneed_mtype verneed_dtype; | |
|
121 | typedef align_ftype verneed_atype; | |
|
122 | ||
|
123 | #define copy_vernaux_srctotmp(d, s, e) __load_vernaux((d), (s), (e)) | |
|
124 | #define copy_vernaux_tmptodst(d, s, e) (*(d) = *(s)) | |
|
125 | #define copy_verneed_srctotmp(d, s, e) __load_verneed((d), (s), (e)) | |
|
126 | #define copy_verneed_tmptodst(d, s, e) (*(d) = *(s)) | |
|
127 | ||
|
128 | #define translator_suffix _tom | |
|
129 | ||
|
130 | #endif /* TOFILE */ | |
|
131 | ||
|
132 | #define cat3(a,b,c) a##b##c | |
|
133 | #define xlt3(p,e,s) cat3(p,e,s) | |
|
134 | #define xltprefix(x) xlt3(x,_,class_suffix) | |
|
135 | #define translator(x,e) xlt3(xltprefix(_elf_##x),e,translator_suffix) | |
|
136 | ||
|
137 | static size_t | |
|
138 | xlt_verneed(unsigned char *dst, const unsigned char *src, size_t n, unsigned enc) { | |
|
139 | size_t off; | |
|
140 | ||
|
141 | if (sizeof(verneed_stype) != sizeof(verneed_dtype) | |
|
142 | || sizeof(vernaux_stype) != sizeof(vernaux_dtype)) { | |
|
143 | /* never happens for ELF v1 and Verneed v1 */ | |
|
144 | seterr(ERROR_UNIMPLEMENTED); | |
|
145 | return (size_t)-1; | |
|
146 | } | |
|
147 | /* size translation shortcut */ | |
|
148 | if (dst == NULL) { | |
|
149 | return n; | |
|
150 | } | |
|
151 | if (src == NULL) { | |
|
152 | seterr(ERROR_NULLBUF); | |
|
153 | return (size_t)-1; | |
|
154 | } | |
|
155 | off = 0; | |
|
156 | while (off + sizeof(verneed_stype) <= n) { | |
|
157 | const verneed_stype *svn; | |
|
158 | verneed_dtype *dvn; | |
|
159 | verneed_mtype vn; | |
|
160 | size_t acount; | |
|
161 | size_t aoff; | |
|
162 | ||
|
163 | /* | |
|
164 | * check for proper alignment | |
|
165 | */ | |
|
166 | if (off % sizeof(verneed_atype)) { | |
|
167 | seterr(ERROR_VERNEED_FORMAT); | |
|
168 | return (size_t)-1; | |
|
169 | } | |
|
170 | /* | |
|
171 | * copy and check src | |
|
172 | */ | |
|
173 | svn = (verneed_stype*)(src + off); | |
|
174 | dvn = (verneed_dtype*)(dst + off); | |
|
175 | copy_verneed_srctotmp(&vn, svn, enc); | |
|
176 | if (vn.vn_version < 1 | |
|
177 | || vn.vn_version > VER_NEED_CURRENT) { | |
|
178 | seterr(ERROR_VERNEED_VERSION); | |
|
179 | return (size_t)-1; | |
|
180 | } | |
|
181 | if (vn.vn_cnt < 1 | |
|
182 | || vn.vn_aux == 0) { | |
|
183 | seterr(ERROR_VERNEED_FORMAT); | |
|
184 | return (size_t)-1; | |
|
185 | } | |
|
186 | copy_verneed_tmptodst(dvn, &vn, enc); | |
|
187 | /* | |
|
188 | * copy aux array | |
|
189 | */ | |
|
190 | aoff = off + vn.vn_aux; | |
|
191 | for (acount = 0; acount < vn.vn_cnt; acount++) { | |
|
192 | const vernaux_stype *svna; | |
|
193 | vernaux_dtype *dvna; | |
|
194 | vernaux_mtype vna; | |
|
195 | ||
|
196 | /* | |
|
197 | * are we still inside the buffer limits? | |
|
198 | */ | |
|
199 | if (aoff + sizeof(vernaux_stype) > n) { | |
|
200 | break; | |
|
201 | } | |
|
202 | /* | |
|
203 | * check for proper alignment | |
|
204 | */ | |
|
205 | if (aoff % sizeof(verneed_atype)) { | |
|
206 | seterr(ERROR_VERNEED_FORMAT); | |
|
207 | return (size_t)-1; | |
|
208 | } | |
|
209 | /* | |
|
210 | * copy and check src | |
|
211 | */ | |
|
212 | svna = (vernaux_stype*)(src + aoff); | |
|
213 | dvna = (vernaux_dtype*)(dst + aoff); | |
|
214 | copy_vernaux_srctotmp(&vna, svna, enc); | |
|
215 | copy_vernaux_tmptodst(dvna, &vna, enc); | |
|
216 | /* | |
|
217 | * advance to next vernaux | |
|
218 | */ | |
|
219 | if (vna.vna_next == 0) { | |
|
220 | /* end of list */ | |
|
221 | break; | |
|
222 | } | |
|
223 | aoff += vna.vna_next; | |
|
224 | } | |
|
225 | /* | |
|
226 | * advance to next verneed | |
|
227 | */ | |
|
228 | if (vn.vn_next == 0) { | |
|
229 | /* end of list */ | |
|
230 | break; | |
|
231 | } | |
|
232 | off += vn.vn_next; | |
|
233 | } | |
|
234 | return n; | |
|
235 | } | |
|
236 | ||
|
237 | size_t | |
|
238 | translator(verneed,L11)(unsigned char *dst, const unsigned char *src, size_t n) { | |
|
239 | return xlt_verneed(dst, src, n, ELFDATA2LSB); | |
|
240 | } | |
|
241 | ||
|
242 | size_t | |
|
243 | translator(verneed,M11)(unsigned char *dst, const unsigned char *src, size_t n) { | |
|
244 | return xlt_verneed(dst, src, n, ELFDATA2MSB); | |
|
245 | } |
@@ -0,0 +1,403 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | #include "srecfile.h" | |
|
23 | #include <QTextStream> | |
|
24 | #include "binaryfile.h" | |
|
25 | ||
|
26 | srecFile::srecFile() | |
|
27 | { | |
|
28 | } | |
|
29 | ||
|
30 | srecFile::srecFile(const QString &File) | |
|
31 | { | |
|
32 | openFile(File); | |
|
33 | } | |
|
34 | ||
|
35 | srecFile::srecFile(const QStringList &Files) | |
|
36 | { | |
|
37 | openFiles(Files); | |
|
38 | } | |
|
39 | ||
|
40 | srecFile::~srecFile() | |
|
41 | { | |
|
42 | ||
|
43 | } | |
|
44 | ||
|
45 | bool srecFile::openFile(const QString &File) | |
|
46 | { | |
|
47 | return openFiles(QStringList()<<File); | |
|
48 | } | |
|
49 | ||
|
50 | bool srecFile::openFiles(const QStringList &Files) | |
|
51 | { | |
|
52 | for(int i=0;i<Files.count();i++) | |
|
53 | { | |
|
54 | this->p_isSrec=true; | |
|
55 | this->p_isSrec &= isSREC(Files.at(i)); | |
|
56 | this->p_files.append(new QFile(Files.at(i))); | |
|
57 | this->p_files.at(i)->open(QIODevice::ReadOnly); | |
|
58 | parseFile(this->p_files.at(i)); | |
|
59 | } | |
|
60 | return true; | |
|
61 | } | |
|
62 | ||
|
63 | bool srecFile::isopened() | |
|
64 | { | |
|
65 | bool opened = true; | |
|
66 | for(int i=0;i<this->p_files.count();i++) | |
|
67 | { | |
|
68 | opened &= p_files.at(i)->isOpen(); | |
|
69 | } | |
|
70 | return opened; | |
|
71 | } | |
|
72 | ||
|
73 | int srecFile::closeFile() | |
|
74 | { | |
|
75 | for(int i=0;i<p_files.count();i++) | |
|
76 | { | |
|
77 | delete p_files.at(i); | |
|
78 | delete p_fragments.at(i); | |
|
79 | } | |
|
80 | p_fragments.clear(); | |
|
81 | p_files.clear(); | |
|
82 | p_fileName.clear(); | |
|
83 | return 0; | |
|
84 | } | |
|
85 | ||
|
86 | QList<codeFragment *> srecFile::getFragments() | |
|
87 | { | |
|
88 | return p_fragments; | |
|
89 | } | |
|
90 | ||
|
91 | bool srecFile::toSrec(QList<codeFragment *> fragments, const QString &File) | |
|
92 | { | |
|
93 | QString line; | |
|
94 | QFile file(File); | |
|
95 | file.open(QIODevice::WriteOnly); | |
|
96 | if(file.isOpen()) | |
|
97 | { | |
|
98 | QTextStream stream( &file ); | |
|
99 | //First build header | |
|
100 | stream << buildRecord(0,0,File.toStdString().c_str(),File.count()); | |
|
101 | for(int i=0;i<fragments.count();i++) | |
|
102 | { | |
|
103 | codeFragment *fragment = fragments.at(i); | |
|
104 | for(int j=0;j<((int)(fragment->size));j+=16) | |
|
105 | { | |
|
106 | stream << buildRecord(3,fragment->address+j,fragment->data+j,16); | |
|
107 | } | |
|
108 | int rem = fragment->size % 16; | |
|
109 | if(rem) | |
|
110 | { | |
|
111 | stream << buildRecord(3,fragment->address+fragment->size-rem,fragment->data+fragment->size-rem,rem); | |
|
112 | } | |
|
113 | stream << buildRecord(7,fragment->address,NULL,0); | |
|
114 | } | |
|
115 | file.close(); | |
|
116 | return true; | |
|
117 | } | |
|
118 | ||
|
119 | return false; | |
|
120 | } | |
|
121 | ||
|
122 | bool srecFile::toSrec(const QString &File) | |
|
123 | { | |
|
124 | return toSrec(p_fragments,File); | |
|
125 | } | |
|
126 | ||
|
127 | bool srecFile::toBinary(const QString &File) | |
|
128 | { | |
|
129 | return binaryFile::toBinary(p_fragments,File); | |
|
130 | } | |
|
131 | ||
|
132 | int srecFile::lineCount() | |
|
133 | { | |
|
134 | return p_lineCount; | |
|
135 | } | |
|
136 | ||
|
137 | int srecFile::getFragmentsCount() | |
|
138 | { | |
|
139 | return p_fragments.count(); | |
|
140 | } | |
|
141 | ||
|
142 | int srecFile::getFragmentAddress(int index) | |
|
143 | { | |
|
144 | if((index < p_fragments.count()) && (index>=0)) | |
|
145 | { | |
|
146 | return p_fragments.at(index)->address; | |
|
147 | } | |
|
148 | return 0; | |
|
149 | } | |
|
150 | ||
|
151 | int srecFile::getFragmentSize(int index) | |
|
152 | { | |
|
153 | if((index < p_fragments.count()) && (index>=0)) | |
|
154 | { | |
|
155 | return p_fragments.at(index)->size; | |
|
156 | } | |
|
157 | return 0; | |
|
158 | } | |
|
159 | ||
|
160 | codeFragment *srecFile::getFragment(int index) | |
|
161 | { | |
|
162 | if((index < p_fragments.count()) && (index>=0)) | |
|
163 | { | |
|
164 | return p_fragments.at(index); | |
|
165 | } | |
|
166 | return NULL; | |
|
167 | } | |
|
168 | ||
|
169 | QString srecFile::getFragmentHeader(int index) | |
|
170 | { | |
|
171 | if((index < p_fragments.count()) && (index>=0)) | |
|
172 | { | |
|
173 | return p_fragments.at(index)->header; | |
|
174 | } | |
|
175 | return ""; | |
|
176 | } | |
|
177 | ||
|
178 | bool srecFile::getFragmentData(int index, char **buffer) | |
|
179 | { | |
|
180 | ||
|
181 | if((index < p_fragments.count()) && (index>=0)) | |
|
182 | { | |
|
183 | *buffer = (char *)this->p_fragments.at(index)->data; | |
|
184 | return true; | |
|
185 | } | |
|
186 | return false; | |
|
187 | } | |
|
188 | ||
|
189 | bool srecFile::isSREC() | |
|
190 | { | |
|
191 | return p_isSrec & isopened(); | |
|
192 | } | |
|
193 | ||
|
194 | bool srecFile::isSREC(const QString &File) | |
|
195 | { | |
|
196 | QFile file(File); | |
|
197 | file.open(QIODevice::ReadOnly); | |
|
198 | if(file.isOpen()) | |
|
199 | { | |
|
200 | file.seek(0); | |
|
201 | QString line=file.readLine(); | |
|
202 | file.close(); | |
|
203 | return ((line.at(0)=='S')&&(line.at(1)=='0')); | |
|
204 | } | |
|
205 | return false; | |
|
206 | } | |
|
207 | ||
|
208 | void srecFile::parseFile(QFile *file) | |
|
209 | { | |
|
210 | if(file->isOpen()) | |
|
211 | { | |
|
212 | this->p_lineCount = 0; | |
|
213 | file->seek(0); | |
|
214 | codeFragment* fragment=NULL; | |
|
215 | char* data; | |
|
216 | quint64 size=0; | |
|
217 | quint64 address=-1; | |
|
218 | QString header; | |
|
219 | while (!file->atEnd()) | |
|
220 | { | |
|
221 | QString line = file->readLine(); | |
|
222 | p_lineCount++; | |
|
223 | int rectype = parseLine(line,&address,&data,&size); | |
|
224 | if(rectype==0) | |
|
225 | { | |
|
226 | header.clear(); | |
|
227 | header.append(data); | |
|
228 | fragment = new codeFragment(data,size,address); | |
|
229 | fragment->header = header; | |
|
230 | p_fragments.append(fragment); | |
|
231 | } | |
|
232 | else | |
|
233 | { | |
|
234 | if((rectype>=1) && (rectype<=3)) | |
|
235 | { | |
|
236 | bool merged = false; | |
|
237 | //Could I merge it with an other fragment? | |
|
238 | // TODO should make merging optionnal | |
|
239 | for(int i=0;i<p_fragments.count();i++) | |
|
240 | { | |
|
241 | codeFragment* frag = p_fragments.at(i); | |
|
242 | if(((frag->address+frag->size)==address) && (merged==false) && (size!=0)) | |
|
243 | { | |
|
244 | char* mergedData=(char*)malloc(size+frag->size); | |
|
245 | memcpy(mergedData,frag->data,frag->size); | |
|
246 | memcpy(mergedData+frag->size,data,size); | |
|
247 | free(frag->data); | |
|
248 | free(data); | |
|
249 | frag->data = mergedData; | |
|
250 | frag->size = frag->size+size; | |
|
251 | merged = true; | |
|
252 | } | |
|
253 | } | |
|
254 | if(!merged) | |
|
255 | { | |
|
256 | fragment = new codeFragment(data,size,address); | |
|
257 | fragment->header = header; | |
|
258 | p_fragments.append(fragment); | |
|
259 | } | |
|
260 | } | |
|
261 | else | |
|
262 | { | |
|
263 | ||
|
264 | } | |
|
265 | } | |
|
266 | } | |
|
267 | } | |
|
268 | } | |
|
269 | ||
|
270 | int srecFile::parseLine(const QString &record, quint64 *address, char **data, quint64 *size) | |
|
271 | { | |
|
272 | #define newData (*data) | |
|
273 | #define newAddress (*address) | |
|
274 | #define newSize (*size) | |
|
275 | int recType = -1; | |
|
276 | if((record.count()>4) && checkSum(record)) | |
|
277 | { | |
|
278 | if(record.at(0)=='S') | |
|
279 | { | |
|
280 | recType = record.at(1).toLatin1() & 0x0F; | |
|
281 | //Header type | |
|
282 | if(recType==0) | |
|
283 | { | |
|
284 | newAddress = record.mid(4,4).toInt(0,16); | |
|
285 | newSize = record.mid(2,2).toInt(0,16) - 3; | |
|
286 | if(newSize>0) | |
|
287 | { | |
|
288 | newData=(char*)malloc(newSize+1); | |
|
289 | for(int i=0;i<(int)newSize;i++) | |
|
290 | { | |
|
291 | newData[i] = ((char)record.mid((2*i)+8,2).toInt(0,16)); | |
|
292 | } | |
|
293 | newData[newSize] = '\0'; // force string end for header | |
|
294 | } | |
|
295 | } | |
|
296 | //2 address byte record type | |
|
297 | if((recType==1) || (recType==5) || (recType==9)) | |
|
298 | { | |
|
299 | newAddress = record.mid(4,4).toInt(0,16); | |
|
300 | newSize = record.mid(2,2).toInt(0,16) - 3; | |
|
301 | if(newSize>0) | |
|
302 | { | |
|
303 | newData=(char*)malloc(newSize); | |
|
304 | for(int i=0;i<(int)newSize;i++) | |
|
305 | { | |
|
306 | newData[i] = ((char)record.mid((2*i)+8,2).toInt(0,16)); | |
|
307 | } | |
|
308 | } | |
|
309 | } | |
|
310 | //3 address byte record type | |
|
311 | if((recType==2) || (recType==6) || (recType==8)) | |
|
312 | { | |
|
313 | newAddress = record.mid(4,6).toInt(0,16); | |
|
314 | newSize = record.mid(2,2).toInt(0,16) - 4; | |
|
315 | if(newSize>0) | |
|
316 | { | |
|
317 | newData=(char*)malloc(newSize); | |
|
318 | for(int i=0;i<(int)newSize;i++) | |
|
319 | { | |
|
320 | newData[i] = ((char)record.mid((2*i)+10,2).toInt(0,16)); | |
|
321 | } | |
|
322 | } | |
|
323 | } | |
|
324 | //4 address byte record type | |
|
325 | if((recType==3) || (recType==7)) | |
|
326 | { | |
|
327 | newAddress = record.mid(4,8).toInt(0,16); | |
|
328 | newSize = record.mid(2,2).toInt(0,16) - 5; | |
|
329 | if(newSize>0) | |
|
330 | { | |
|
331 | newData=(char*)malloc(newSize); | |
|
332 | for(int i=0;i<(int)newSize;i++) | |
|
333 | { | |
|
334 | newData[i] = ((char)record.mid((2*i)+12,2).toInt(0,16)); | |
|
335 | } | |
|
336 | } | |
|
337 | } | |
|
338 | } | |
|
339 | } | |
|
340 | return recType; | |
|
341 | } | |
|
342 | ||
|
343 | char srecFile::lineCheckSum(const QString &line) | |
|
344 | { | |
|
345 | char sum=0; | |
|
346 | QString localLine = line; | |
|
347 | bool ok; | |
|
348 | if(localLine.at(0)=='S') // then should skip the first two digits | |
|
349 | { | |
|
350 | localLine.remove(0,2); | |
|
351 | } | |
|
352 | for(int i=0;i<localLine.count();i+=2) | |
|
353 | { | |
|
354 | sum+=(char)(localLine.mid(i,2).toInt(&ok,16)); | |
|
355 | } | |
|
356 | return ~sum; | |
|
357 | } | |
|
358 | ||
|
359 | bool srecFile::checkSum(const QString &line) | |
|
360 | { | |
|
361 | QString scp=line; | |
|
362 | scp.remove('\n'); | |
|
363 | scp.remove('\r'); | |
|
364 | char ck2 = (char)scp.mid(scp.count()-2,2).toInt(0,16); | |
|
365 | char ck=lineCheckSum(scp.remove(scp.count()-2,2)); | |
|
366 | return (ck2==ck); | |
|
367 | } | |
|
368 | ||
|
369 | QString srecFile::buildRecord(int recType, int address,const char *data, int size) | |
|
370 | { | |
|
371 | QString record; | |
|
372 | if((recType>=0) && (recType<=9)) | |
|
373 | { | |
|
374 | record.append("S"); | |
|
375 | record.append(QString::number(recType)); | |
|
376 | //2 address byte record type | |
|
377 | if((recType==0) || (recType==1) || (recType==5) || (recType==9)) | |
|
378 | { | |
|
379 | record.append(QString("%1").arg(3+size,2,16).replace(' ','0')); | |
|
380 | record.append(QString("%1").arg(address,4,16).replace(' ','0')); | |
|
381 | } | |
|
382 | //3 address byte record type | |
|
383 | if((recType==2) || (recType==6) || (recType==8)) | |
|
384 | { | |
|
385 | record.append(QString("%1").arg(4+size,2,16).replace(' ','0')); | |
|
386 | record.append(QString("%1").arg(address,6,16).replace(' ','0')); | |
|
387 | } | |
|
388 | //4 address byte record type | |
|
389 | if((recType==3) || (recType==7)) | |
|
390 | { | |
|
391 | record.append(QString("%1").arg(5+size,2,16).replace(' ','0')); | |
|
392 | record.append(QString("%1").arg(address,8,16).replace(' ','0')); | |
|
393 | } | |
|
394 | for(int i=0; i<size;i++) | |
|
395 | { | |
|
396 | record.append(QString("%1").arg((uchar)data[i],2,16).replace(' ','0')); | |
|
397 | } | |
|
398 | record.append(QString("%1").arg((uchar)srecFile::lineCheckSum(record),2,16).replace(' ','0')); | |
|
399 | record.append('\n'); | |
|
400 | } | |
|
401 | return record.toUpper(); | |
|
402 | } | |
|
403 |
@@ -0,0 +1,73 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | #ifndef SRECFILE_H | |
|
23 | #define SRECFILE_H | |
|
24 | ||
|
25 | #include <QObject> | |
|
26 | #include <abstractbinfile.h> | |
|
27 | #include <QFile> | |
|
28 | #include <QStringList> | |
|
29 | ||
|
30 | class srecFile : public abstractBinFile | |
|
31 | { | |
|
32 | Q_OBJECT | |
|
33 | public: | |
|
34 | explicit srecFile(); | |
|
35 | srecFile(const QString& File); | |
|
36 | srecFile(const QStringList& Files); | |
|
37 | ~srecFile(); | |
|
38 | bool openFile(const QString& File); | |
|
39 | bool openFiles(const QStringList& Files); | |
|
40 | bool isopened(); | |
|
41 | int closeFile(); | |
|
42 | QList<codeFragment*> getFragments(); | |
|
43 | static bool toSrec(QList<codeFragment*> fragments,const QString& File); | |
|
44 | bool toSrec(const QString &File); | |
|
45 | bool toBinary(const QString& File); | |
|
46 | int lineCount(); | |
|
47 | int getFragmentsCount(); | |
|
48 | int getFragmentAddress(int index); | |
|
49 | int getFragmentSize(int index); | |
|
50 | codeFragment *getFragment(int index); | |
|
51 | QString getFragmentHeader(int index); | |
|
52 | bool getFragmentData(int index, char **buffer); | |
|
53 | ||
|
54 | bool isSREC(); | |
|
55 | static bool isSREC(const QString& File); | |
|
56 | signals: | |
|
57 | ||
|
58 | public slots: | |
|
59 | private: | |
|
60 | void parseFile(QFile* file); | |
|
61 | static int parseLine(const QString& record, quint64 *address, char** data, quint64 *size); | |
|
62 | static char lineCheckSum(const QString& line); | |
|
63 | static bool checkSum(const QString& line); | |
|
64 | static QString buildRecord(int recType,int address,const char* data,int size); | |
|
65 | QStringList p_fileNames; | |
|
66 | QList<QFile*>p_files; | |
|
67 | QList<codeFragment*> p_fragments; | |
|
68 | int p_lineCount; | |
|
69 | bool p_isSrec; | |
|
70 | ||
|
71 | }; | |
|
72 | ||
|
73 | #endif // SRECFILE_H |
@@ -0,0 +1,144 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | #include "srecfilewidget.h" | |
|
23 | #include "ui_srecfilewidget.h" | |
|
24 | #include <QTableWidgetItem> | |
|
25 | #include <qtablewidgetintitem.h> | |
|
26 | #include <QtWidgets/QFileDialog> | |
|
27 | #include "binaryfile.h" | |
|
28 | ||
|
29 | srecFileWidget::srecFileWidget(QWidget *parent) : | |
|
30 | abstractBinFileWidget(parent), | |
|
31 | ui(new Ui::srecFileWidget) | |
|
32 | { | |
|
33 | ui->setupUi(this); | |
|
34 | connect(this->ui->fragmentsList,SIGNAL(cellActivated(int,int)),this,SLOT(recordCellActivated(int,int))); | |
|
35 | this->setWindowTitle("SocExplorer SREC viewer"); | |
|
36 | exportToSREC_action = new QAction(tr("Export to SREC"),this); | |
|
37 | exportToBIN_action = new QAction(tr("Export to Binary"),this); | |
|
38 | this->ui->fragmentsList->addAction(exportToBIN_action); | |
|
39 | this->ui->fragmentsList->addAction(exportToSREC_action); | |
|
40 | connect(this->exportToBIN_action,SIGNAL(triggered()),this,SLOT(exportToBIN())); | |
|
41 | connect(this->exportToSREC_action,SIGNAL(triggered()),this,SLOT(exportToSREC())); | |
|
42 | } | |
|
43 | ||
|
44 | srecFileWidget::~srecFileWidget() | |
|
45 | { | |
|
46 | delete ui; | |
|
47 | } | |
|
48 | ||
|
49 | void srecFileWidget::setFile(abstractBinFile *file) | |
|
50 | { | |
|
51 | this->p_srec = (srecFile*)file; | |
|
52 | if(p_srec->isopened() && p_srec->isSREC()) | |
|
53 | { | |
|
54 | reloadFile(); | |
|
55 | } | |
|
56 | } | |
|
57 | ||
|
58 | void srecFileWidget::reloadFile() | |
|
59 | { | |
|
60 | this->ui->fragmentsList->clear(); | |
|
61 | this->ui->fragmentsList->setRowCount(p_srec->getFragmentsCount()); | |
|
62 | this->ui->fragmentsList->setHorizontalHeaderLabels(QStringList()<<"Index"<<"Address"<<"Size"<<"Header"); | |
|
63 | for(int i=0;i<p_srec->getFragmentsCount();i++) | |
|
64 | { | |
|
65 | QTableWidgetItem *newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(i),DecimalItem); | |
|
66 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
67 | this->ui->fragmentsList->setItem(i, 0, newItem); | |
|
68 | ||
|
69 | newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("0x%1").arg(p_srec->getFragmentAddress(i),8,16).replace(" ","0"),HexaDecimalItem); | |
|
70 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
71 | this->ui->fragmentsList->setItem(i, 1, newItem); | |
|
72 | ||
|
73 | newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(p_srec->getFragmentSize(i)),DecimalItem); | |
|
74 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
75 | this->ui->fragmentsList->setItem(i, 2, newItem); | |
|
76 | ||
|
77 | newItem = new QTableWidgetItem(p_srec->getFragmentHeader(i)); | |
|
78 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
|
79 | this->ui->fragmentsList->setItem(i, 3, newItem); | |
|
80 | ||
|
81 | } | |
|
82 | this->ui->fragmentsList->resizeColumnsToContents(); | |
|
83 | } | |
|
84 | ||
|
85 | void srecFileWidget::recordCellActivated(int row, int column) | |
|
86 | { | |
|
87 | Q_UNUSED(column) | |
|
88 | char* buff=NULL; | |
|
89 | int index = this->ui->fragmentsList->item(row,0)->text().toInt(); | |
|
90 | if(index!=-1) | |
|
91 | { | |
|
92 | this->p_srec->getFragmentData(index,&buff); | |
|
93 | this->ui->fragmentHexView->setData(QByteArray(buff,this->p_srec->getFragmentSize(index))); | |
|
94 | this->ui->fragmentHexView->setAddressOffset(this->p_srec->getFragmentAddress(index)); | |
|
95 | } | |
|
96 | ||
|
97 | } | |
|
98 | ||
|
99 | void srecFileWidget::exportToSREC() | |
|
100 | { | |
|
101 | QList<codeFragment *> SelectedFragmentsList=getSelectedFragments(); | |
|
102 | if(SelectedFragmentsList.count()>0) | |
|
103 | { | |
|
104 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), | |
|
105 | NULL, | |
|
106 | tr("SREC Files (*.srec)")); | |
|
107 | if(!fileName.isEmpty()) | |
|
108 | { | |
|
109 | srecFile::toSrec(SelectedFragmentsList,fileName); | |
|
110 | } | |
|
111 | } | |
|
112 | } | |
|
113 | ||
|
114 | void srecFileWidget::exportToBIN() | |
|
115 | { | |
|
116 | QList<codeFragment *> SelectedFragmentsList=getSelectedFragments(); | |
|
117 | if(SelectedFragmentsList.count()>0) | |
|
118 | { | |
|
119 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), | |
|
120 | NULL, | |
|
121 | tr("Binary Files (*.bin)")); | |
|
122 | if(!fileName.isEmpty()) | |
|
123 | { | |
|
124 | binaryFile::toBinary(SelectedFragmentsList,fileName); | |
|
125 | } | |
|
126 | } | |
|
127 | } | |
|
128 | ||
|
129 | QList<codeFragment *> srecFileWidget::getSelectedFragments() | |
|
130 | { | |
|
131 | QList<codeFragment *> SelectedFragmentsList; | |
|
132 | QList<QTableWidgetItem*> items = this->ui->fragmentsList->selectedItems(); | |
|
133 | for(int i=0;i<items.count();i++) | |
|
134 | { | |
|
135 | codeFragment * fragment = p_srec->getFragment(items.at(i)->row()); | |
|
136 | if(!SelectedFragmentsList.contains(fragment)) | |
|
137 | { | |
|
138 | SelectedFragmentsList.append(fragment); | |
|
139 | } | |
|
140 | } | |
|
141 | return SelectedFragmentsList; | |
|
142 | } | |
|
143 | ||
|
144 |
@@ -0,0 +1,58 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
|
4 | -- | |
|
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 | |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
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 | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | -------------------------------------------------------------------------------*/ | |
|
19 | /*-- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | #ifndef SRECFILEWIDGET_H | |
|
23 | #define SRECFILEWIDGET_H | |
|
24 | ||
|
25 | #include <QWidget> | |
|
26 | #include "srecfile.h" | |
|
27 | #include <QAction> | |
|
28 | ||
|
29 | namespace Ui { | |
|
30 | class srecFileWidget; | |
|
31 | } | |
|
32 | ||
|
33 | class srecFileWidget : public abstractBinFileWidget | |
|
34 | { | |
|
35 | Q_OBJECT | |
|
36 | ||
|
37 | public: | |
|
38 | explicit srecFileWidget(QWidget *parent = 0); | |
|
39 | ~srecFileWidget(); | |
|
40 | ||
|
41 | public slots: | |
|
42 | void setFile(abstractBinFile* file); | |
|
43 | void reloadFile(); | |
|
44 | ||
|
45 | private slots: | |
|
46 | void recordCellActivated(int row, int column); | |
|
47 | void exportToSREC(); | |
|
48 | void exportToBIN(); | |
|
49 | ||
|
50 | private: | |
|
51 | QList<codeFragment *> getSelectedFragments(); | |
|
52 | Ui::srecFileWidget *ui; | |
|
53 | srecFile* p_srec; | |
|
54 | QAction* exportToSREC_action; | |
|
55 | QAction* exportToBIN_action; | |
|
56 | }; | |
|
57 | ||
|
58 | #endif // SRECFILEWIDGET_H |
@@ -0,0 +1,87 | |||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
|
2 | <ui version="4.0"> | |
|
3 | <class>srecFileWidget</class> | |
|
4 | <widget class="QWidget" name="srecFileWidget"> | |
|
5 | <property name="geometry"> | |
|
6 | <rect> | |
|
7 | <x>0</x> | |
|
8 | <y>0</y> | |
|
9 | <width>740</width> | |
|
10 | <height>516</height> | |
|
11 | </rect> | |
|
12 | </property> | |
|
13 | <property name="windowTitle"> | |
|
14 | <string>Form</string> | |
|
15 | </property> | |
|
16 | <layout class="QGridLayout" name="gridLayout"> | |
|
17 | <item row="0" column="0"> | |
|
18 | <widget class="QSplitter" name="splitter"> | |
|
19 | <property name="orientation"> | |
|
20 | <enum>Qt::Horizontal</enum> | |
|
21 | </property> | |
|
22 | <widget class="QGroupBox" name="groupBox"> | |
|
23 | <property name="title"> | |
|
24 | <string>Hexadecimal Viewer</string> | |
|
25 | </property> | |
|
26 | <layout class="QVBoxLayout" name="verticalLayout"> | |
|
27 | <item> | |
|
28 | <widget class="QHexEdit" name="fragmentHexView" native="true"> | |
|
29 | <property name="minimumSize"> | |
|
30 | <size> | |
|
31 | <width>256</width> | |
|
32 | <height>0</height> | |
|
33 | </size> | |
|
34 | </property> | |
|
35 | </widget> | |
|
36 | </item> | |
|
37 | </layout> | |
|
38 | </widget> | |
|
39 | <widget class="QGroupBox" name="groupBox_2"> | |
|
40 | <property name="title"> | |
|
41 | <string>SREC records list</string> | |
|
42 | </property> | |
|
43 | <layout class="QVBoxLayout" name="verticalLayout_2"> | |
|
44 | <item> | |
|
45 | <widget class="QTableWidget" name="fragmentsList"> | |
|
46 | <property name="contextMenuPolicy"> | |
|
47 | <enum>Qt::ActionsContextMenu</enum> | |
|
48 | </property> | |
|
49 | <column> | |
|
50 | <property name="text"> | |
|
51 | <string>Index</string> | |
|
52 | </property> | |
|
53 | </column> | |
|
54 | <column> | |
|
55 | <property name="text"> | |
|
56 | <string>Address</string> | |
|
57 | </property> | |
|
58 | </column> | |
|
59 | <column> | |
|
60 | <property name="text"> | |
|
61 | <string>Size</string> | |
|
62 | </property> | |
|
63 | </column> | |
|
64 | <column> | |
|
65 | <property name="text"> | |
|
66 | <string>Header</string> | |
|
67 | </property> | |
|
68 | </column> | |
|
69 | </widget> | |
|
70 | </item> | |
|
71 | </layout> | |
|
72 | </widget> | |
|
73 | </widget> | |
|
74 | </item> | |
|
75 | </layout> | |
|
76 | </widget> | |
|
77 | <customwidgets> | |
|
78 | <customwidget> | |
|
79 | <class>QHexEdit</class> | |
|
80 | <extends>QWidget</extends> | |
|
81 | <header location="global">qhexedit.h</header> | |
|
82 | <container>1</container> | |
|
83 | </customwidget> | |
|
84 | </customwidgets> | |
|
85 | <resources/> | |
|
86 | <connections/> | |
|
87 | </ui> |
@@ -8,12 +8,12 TARGET = socexplorercommon$${DEBUG_EXT} | |||
|
8 | 8 | win32:CONFIG += dll |
|
9 | 9 | win32:CONFIG -= static |
|
10 | 10 | |
|
11 | win32:INCLUDEPATH += $${PWD}/elf/libelfWin32/include | |
|
12 | win32:INCLUDEPATH += $${PWD}/elf/libelfWin32/include/libelf | |
|
11 | win32:INCLUDEPATH += $${PWD}/genericBinaryFiles/elf/libelfWin32/include | |
|
12 | win32:INCLUDEPATH += $${PWD}/genericBinaryFiles/elf/libelfWin32/include/libelf | |
|
13 | 13 | win32:DEFINES+=_ELF_WINDOWS_ |
|
14 | 14 | DEFINES+=RS232_debug |
|
15 | 15 | |
|
16 | win32:LIBS += $${PWD}/elf/libelfWin32/bin/libelf.a | |
|
16 | win32:LIBS += $${PWD}/genericBinaryFiles/elf/libelfWin32/bin/libelf.a | |
|
17 | 17 | unix:LIBS += -lelf |
|
18 | 18 | |
|
19 | 19 | QMAKE_LFLAGS_RELEASE += --enable-auto-import |
@@ -35,33 +35,33 header.files = \ | |||
|
35 | 35 | QCustomPlot/qcustomplot.h \ |
|
36 | 36 | SocExplorerPlot.h \ |
|
37 | 37 | tcp_terminal_client.h \ |
|
38 | elf/elfinfowdgt.h \ | |
|
39 | elf/elfparser.h \ | |
|
40 | elf/elffile.h \ | |
|
41 | elf/elffilewidget.h \ | |
|
38 | genericBinaryFiles/elf/elfinfowdgt.h \ | |
|
39 | genericBinaryFiles/elf/elfparser.h \ | |
|
40 | genericBinaryFiles/elf/elffile.h \ | |
|
41 | genericBinaryFiles/elf/elffilewidget.h \ | |
|
42 | 42 | qipdialogbox.h \ |
|
43 | 43 | lppserial/src/RS232.h \ |
|
44 | 44 | qtablewidgetintitem.h \ |
|
45 | srec/srecfile.h \ | |
|
46 | srec/srecfilewidget.h \ | |
|
47 | BinFile/binaryfile.h \ | |
|
48 | BinFile/binaryfilewidget.h \ | |
|
49 | abstractbinfile.h | |
|
45 | genericBinaryFiles/srec/srecfile.h \ | |
|
46 | genericBinaryFiles/srec/srecfilewidget.h \ | |
|
47 | genericBinaryFiles/BinFile/binaryfile.h \ | |
|
48 | genericBinaryFiles/BinFile/binaryfilewidget.h \ | |
|
49 | genericBinaryFiles/abstractbinfile.h | |
|
50 | 50 | |
|
51 | 51 | win32{ |
|
52 | elfheader.path = $$[QT_INSTALL_HEADERS]/SocExplorer/common/libelf | |
|
52 | elfheader.path = $$[QT_INSTALL_HEADERS]/SocExplorer/common/genericBinaryFiles/libelf | |
|
53 | 53 | elfheader.files += \ |
|
54 | elf/libelfWin32/include/libelf/byteswap.h \ | |
|
55 | elf/libelfWin32/include/libelf/errors.h \ | |
|
56 | elf/libelfWin32/include/libelf/gelf.h \ | |
|
57 | elf/libelfWin32/include/libelf/nlist.h \ | |
|
58 | elf/libelfWin32/include/libelf/sys_elf.h \ | |
|
59 | elf/libelfWin32/include/libelf/verneed.h \ | |
|
60 | elf/libelfWin32/include/libelf/elf_repl.h \ | |
|
61 | elf/libelfWin32/include/libelf/ext_types.h \ | |
|
62 | elf/libelfWin32/include/libelf/libelf.h \ | |
|
63 | elf/libelfWin32/include/libelf/private.h \ | |
|
64 | elf/libelfWin32/include/libelf/verdef.h | |
|
54 | genericBinaryFiles/elf/libelfWin32/include/libelf/byteswap.h \ | |
|
55 | genericBinaryFiles/elf/libelfWin32/include/libelf/errors.h \ | |
|
56 | genericBinaryFiles/elf/libelfWin32/include/libelf/gelf.h \ | |
|
57 | genericBinaryFiles/elf/libelfWin32/include/libelf/nlist.h \ | |
|
58 | genericBinaryFiles/elf/libelfWin32/include/libelf/sys_elf.h \ | |
|
59 | genericBinaryFiles/elf/libelfWin32/include/libelf/verneed.h \ | |
|
60 | genericBinaryFiles/elf/libelfWin32/include/libelf/elf_repl.h \ | |
|
61 | genericBinaryFiles/elf/libelfWin32/include/libelf/ext_types.h \ | |
|
62 | genericBinaryFiles/elf/libelfWin32/include/libelf/libelf.h \ | |
|
63 | genericBinaryFiles/elf/libelfWin32/include/libelf/private.h \ | |
|
64 | genericBinaryFiles/elf/libelfWin32/include/libelf/verdef.h | |
|
65 | 65 | INSTALLS += elfheader |
|
66 | 66 | } |
|
67 | 67 | |
@@ -72,7 +72,7 isEmpty(header.path) { | |||
|
72 | 72 | |
|
73 | 73 | INSTALLS += target header |
|
74 | 74 | |
|
75 | INCLUDEPATH += QCustomPlot qhexedit srec BinFile | |
|
75 | INCLUDEPATH += QCustomPlot qhexedit genericBinaryFiles genericBinaryFiles/srec genericBinaryFiles/BinFile | |
|
76 | 76 | |
|
77 | 77 | HEADERS += \ |
|
78 | 78 | memsizewdgt.h \ |
@@ -84,19 +84,19 HEADERS += \ | |||
|
84 | 84 | qhexedit/commands.h \ |
|
85 | 85 | QCustomPlot/qcustomplot.h \ |
|
86 | 86 | tcp_terminal_client.h \ |
|
87 | elf/elfinfowdgt.h \ | |
|
88 | elf/elfparser.h \ | |
|
89 | elf/elffile.h \ | |
|
87 | genericBinaryFiles/elf/elfinfowdgt.h \ | |
|
88 | genericBinaryFiles/elf/elfparser.h \ | |
|
89 | genericBinaryFiles/elf/elffile.h \ | |
|
90 | 90 | qipdialogbox.h \ |
|
91 | 91 | PySocExplorer.h \ |
|
92 | 92 | SocExplorerPlot.h \ |
|
93 | elf/elffilewidget.h \ | |
|
93 | genericBinaryFiles/elf/elffilewidget.h \ | |
|
94 | 94 | qtablewidgetintitem.h \ |
|
95 | srec/srecfile.h \ | |
|
96 | srec/srecfilewidget.h \ | |
|
97 | abstractbinfile.h \ | |
|
98 | BinFile/binaryfile.h \ | |
|
99 | BinFile/binaryfilewidget.h | |
|
95 | genericBinaryFiles/srec/srecfile.h \ | |
|
96 | genericBinaryFiles/srec/srecfilewidget.h \ | |
|
97 | genericBinaryFiles/abstractbinfile.h \ | |
|
98 | genericBinaryFiles/BinFile/binaryfile.h \ | |
|
99 | genericBinaryFiles/BinFile/binaryfilewidget.h | |
|
100 | 100 | |
|
101 | 101 | |
|
102 | 102 | SOURCES += \ |
@@ -109,23 +109,23 SOURCES += \ | |||
|
109 | 109 | qhexedit/commands.cpp \ |
|
110 | 110 | QCustomPlot/qcustomplot.cpp \ |
|
111 | 111 | tcp_terminal_client.cpp \ |
|
112 | elf/elfinfowdgt.cpp \ | |
|
113 | elf/elfparser.cpp \ | |
|
114 | elf/elffile.cpp \ | |
|
112 | genericBinaryFiles/elf/elfinfowdgt.cpp \ | |
|
113 | genericBinaryFiles/elf/elfparser.cpp \ | |
|
114 | genericBinaryFiles/elf/elffile.cpp \ | |
|
115 | 115 | qipdialogbox.cpp \ |
|
116 | 116 | SocExplorerPlot.cpp \ |
|
117 | elf/elffilewidget.cpp \ | |
|
117 | genericBinaryFiles/elf/elffilewidget.cpp \ | |
|
118 | 118 | qtablewidgetintitem.cpp \ |
|
119 | srec/srecfile.cpp \ | |
|
120 | srec/srecfilewidget.cpp \ | |
|
121 | abstractbinfile.cpp \ | |
|
122 | BinFile/binaryfile.cpp \ | |
|
123 | BinFile/binaryfilewidget.cpp | |
|
119 | genericBinaryFiles/srec/srecfile.cpp \ | |
|
120 | genericBinaryFiles/srec/srecfilewidget.cpp \ | |
|
121 | genericBinaryFiles/abstractbinfile.cpp \ | |
|
122 | genericBinaryFiles/BinFile/binaryfile.cpp \ | |
|
123 | genericBinaryFiles/BinFile/binaryfilewidget.cpp | |
|
124 | 124 | |
|
125 | 125 | FORMS += \ |
|
126 | elf/elffilewidget.ui \ | |
|
127 | srec/srecfilewidget.ui \ | |
|
128 | BinFile/binaryfilewidget.ui | |
|
126 | genericBinaryFiles/elf/elffilewidget.ui \ | |
|
127 | genericBinaryFiles/srec/srecfilewidget.ui \ | |
|
128 | genericBinaryFiles/BinFile/binaryfilewidget.ui | |
|
129 | 129 | |
|
130 | 130 | OTHER_FILES += \ |
|
131 | 131 | ./pythongenerator.sh \ |
@@ -3,4 +3,4 | |||
|
3 | 3 | #export QTDIR=/usr/include |
|
4 | 4 | #export QTDIR=/usr/include/qt5 |
|
5 | 5 | |
|
6 | pythonqt_generator --include-paths=./elf:./srec:./BinFile:/usr/include/qt5:/usr/include/qt5/QtCore:/usr/include/qt5/QtWidgets --output-directory=pythonQtOut PySocExplorer.h pythonQtgeneratorCfg.txt | |
|
6 | pythonqt_generator --include-paths=./genericBinaryFiles/elf:./genericBinaryFiles/srec:./genericBinaryFiles/BinFile:/usr/include/qt5:/usr/include/qt5/QtCore:/usr/include/qt5/QtWidgets --output-directory=pythonQtOut PySocExplorer.h pythonQtgeneratorCfg.txt |
@@ -21,9 +21,10 INCLUDEPATH+=$${PWD} \ | |||
|
21 | 21 | $${PWD}/common \ |
|
22 | 22 | $${PWD}/common/qhexedit \ |
|
23 | 23 | $${PWD}/common/QCustomPlot \ |
|
24 |
$${PWD}/common/ |
|
|
25 |
$${PWD}/common/ |
|
|
26 | $${PWD}/common/BinFile \ | |
|
24 | $${PWD}/common/genericBinaryFiles \ | |
|
25 | $${PWD}/common/genericBinaryFiles/elf \ | |
|
26 | $${PWD}/common/genericBinaryFiles/srec \ | |
|
27 | $${PWD}/common/genericBinaryFiles/BinFile \ | |
|
27 | 28 | SocExplorerEngine/engine \ |
|
28 | 29 | SocExplorerEngine/pluginloader \ |
|
29 | 30 | SocExplorerEngine/pluginsInterface \ |
@@ -36,8 +37,8 INCLUDEPATH+=$${PWD} \ | |||
|
36 | 37 | SocExplorerEngine/PeripheralWidget/src |
|
37 | 38 | |
|
38 | 39 | win32:INCLUDEPATH+= \ |
|
39 | $${PWD}/common/elf/libelfWin32/include \ | |
|
40 | $${PWD}/common/elf/libelfWin32/include/libelf \ | |
|
40 | $${PWD}/common/genericBinaryFiles/elf/libelfWin32/include \ | |
|
41 | $${PWD}/common/genericBinaryFiles/elf/libelfWin32/include/libelf \ | |
|
41 | 42 | |
|
42 | 43 | |
|
43 | 44 | RC_FILE = ../win32cfg/socexplorer.rc |
General Comments 0
You need to be logged in to leave comments.
Login now