-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathxelf_def.h
312 lines (282 loc) · 13.7 KB
/
xelf_def.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
// copyright (c) 2017-2021 hors<horsicq@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#ifndef XELF_DEF_H
#define XELF_DEF_H
#include <QtGlobal>
#define S_ELF32_R_SYM(info) ((info)>>8)
#define S_ELF32_R_TYPE(info) ((quint8)(info))
#define S_ELF32_R_INFO(sym,type) (((sym)<<8)+(quint8)(type))
#define S_ELF64_R_SYM(info) ((info)>>32)
#define S_ELF64_R_TYPE(info) ((info)&0xFFFFFFFFL)
#define S_ELF64_R_INFO(sym,type) (((sym)<<32)+((type)&0xFFFFFFFFL))
#define S_ELF32_ST_BIND(info) ((info)>>4)
#define S_ELF32_ST_TYPE(info) ((info)&0xF)
#define S_ELF32_ST_INFO(bind,type) (((bind)<<4)+((type)&0xF))
#define S_ELF64_ST_BIND(info) ((info)>>4)
#define S_ELF64_ST_TYPE(info) ((info)&0xF)
#define S_ELF64_ST_INFO(bind,type) (((bind)<<4)+((type)&0xF))
namespace XELF_DEF
{
//typedef quint32 Elf32_Addr;
//typedef quint16 Elf32_Half;
//typedef quint32 Elf32_Off;
//typedef qint32 Elf32_Sword;
//typedef quint32 Elf32_Word;
//typedef quint32 Elf32_Size;
//typedef quint64 Elf64_Addr;
//typedef quint16 Elf64_Half;
//typedef quint64 Elf64_Off;
//typedef qint32 Elf64_Sword;
//typedef quint32 Elf64_Word;
//typedef quint64 Elf64_Size;
//typedef int64_t Elf64_Sxword;
//typedef uint32_t Elf64_Word;
//typedef uint64_t Elf64_Lword;
//typedef uint64_t Elf64_Xword;
const quint8 EI_NIDENT =16;
const quint8 EI_MAG0 =0;
const quint8 ELFMAG0 =0x7F;
const quint8 EI_MAG1 =1;
const quint8 ELFMAG1 ='E';
const quint8 EI_MAG2 =2;
const quint8 ELFMAG2 ='L';
const quint8 EI_MAG3 =3;
const quint8 ELFMAG3 ='F';
//const quint8 ELFMAG "\177ELF"
const quint32 ELFMAG =0x464C457F;
const quint8 SELFMAG =4;
const quint8 EI_CLASS =4; /* File class byte index */
const quint8 ELFCLASSNONE =0; /* Invalid class */
const quint8 ELFCLASS32 =1; /* 32-bit objects */
const quint8 ELFCLASS64 =2; /* 64-bit objects */
const quint8 EI_DATA =5; /* Data encodeing byte index */
const quint8 ELFDATANONE =0; /* Invalid data encoding */
const quint8 ELFDATA2LSB =1; /* 2's complement little endian */
const quint8 ELFDATA2MSB =2; /* 2's complement big endian */
const quint8 EI_VERSION =6; /* File version byte index */
const quint8 EV_NONE =0; /* Invalid ELF Version */
const quint8 EV_CURRENT =1; /* Current version */
const quint8 EI_OSABI =7; /* Operating system/ABI identification */
const quint8 EI_ABIVERSION =8; /* ABI version */
const quint8 SHN_UNDEF =0;
const quint16 ET_NONE =0;
const quint16 ET_REL =1;
const quint16 ET_EXEC =2;
const quint16 ET_DYN =3;
const quint16 ET_CORE =4;
const quint16 ET_NUM =5;
const quint16 ET_LOPROC =0xFF00;
const quint16 ET_HIPROC =0xFFFF;
const quint32 DT_NULL =0; /* Marks end of dynamic section */
const quint32 DT_NEEDED =1; /* Name of needed library */
const quint32 DT_PLTRELSZ =2; /* Size in bytes of PLT relocs */
const quint32 DT_PLTGOT =3; /* Processor defined value */
const quint32 DT_HASH =4; /* Address of symbol hash table */
const quint32 DT_STRTAB =5; /* Address of string table */
const quint32 DT_SYMTAB =6; /* Address of symbol table */
const quint32 DT_RELA =7; /* Address of Rela relocs */
const quint32 DT_RELASZ =8; /* Total size of Rela relocs */
const quint32 DT_RELAENT =9; /* Size of one Rela reloc */
const quint32 DT_STRSZ =10; /* Size of string table */
const quint32 DT_RUNPATH =29; // Run path
const quint32 PT_LOAD =1;
const quint32 PT_DYNAMIC =2;
const quint32 PT_INTERP =3;
const quint32 PT_NOTE =4;
const quint32 ELFOSABI_HPUX =1;
const quint32 ELFOSABI_NETBSD =2;
const quint32 ELFOSABI_LINUX =3;
const quint32 ELFOSABI_HURD =4;
const quint32 ELFOSABI_86OPEN =5;
const quint32 ELFOSABI_SOLARIS =6;
const quint32 ELFOSABI_AIX =7;
const quint32 ELFOSABI_IRIX =8;
const quint32 ELFOSABI_FREEBSD =9;
const quint32 ELFOSABI_TRU64 =10;
const quint32 ELFOSABI_MODESTO =11;
const quint32 ELFOSABI_OPENBSD =12;
const quint32 ELFOSABI_OPENVMS =13;
const quint32 ELFOSABI_NSK =14;
const quint32 ELFOSABI_AROS =15;
const quint32 ELFOSABI_FENIXOS =16;
struct Elf32_Ehdr
{
quint8 e_ident[EI_NIDENT]; /* ident bytes */
quint16 e_type; /* file type */
quint16 e_machine; /* target machine */
quint32 e_version; /* file version */
quint32 e_entry; /* start address */
quint32 e_phoff; /* phdr file offset */
quint32 e_shoff; /* shdr file offset */
quint32 e_flags; /* file flags */
quint16 e_ehsize; /* sizeof ehdr */
quint16 e_phentsize; /* sizeof phdr */
quint16 e_phnum; /* number phdrs */
quint16 e_shentsize; /* sizeof shdr */
quint16 e_shnum; /* number shdrs */
quint16 e_shstrndx; /* shdr string index */
};
struct Elf64_Ehdr
{
quint8 e_ident[EI_NIDENT]; /* ident bytes */
quint16 e_type; /* file type */
quint16 e_machine; /* target machine */
quint32 e_version; /* file version */
quint64 e_entry; /* start address */
quint64 e_phoff; /* phdr file offset */
quint64 e_shoff; /* shdr file offset */
quint32 e_flags; /* file flags */
quint16 e_ehsize; /* sizeof ehdr */
quint16 e_phentsize; /* sizeof phdr */
quint16 e_phnum; /* number phdrs */
quint16 e_shentsize; /* sizeof shdr */
quint16 e_shnum; /* number shdrs */
quint16 e_shstrndx; /* shdr string index */
};
struct Elf_Ehdr
{
quint8 e_ident[EI_NIDENT]; /* ident bytes */
quint16 e_type; /* file type */
quint16 e_machine; /* target machine */
quint32 e_version; /* file version */
quint64 e_entry; /* start address */
quint64 e_phoff; /* phdr file offset */
quint64 e_shoff; /* shdr file offset */
quint32 e_flags; /* file flags */
quint16 e_ehsize; /* sizeof ehdr */
quint16 e_phentsize; /* sizeof phdr */
quint16 e_phnum; /* number phdrs */
quint16 e_shentsize; /* sizeof shdr */
quint16 e_shnum; /* number shdrs */
quint16 e_shstrndx; /* shdr string index */
};
struct Elf32_Shdr
{
quint32 sh_name; /* Section name (index into the section header string table). */
quint32 sh_type; /* Section type. */
quint32 sh_flags; /* Section flags. */
quint32 sh_addr; /* Address in memory image. */
quint32 sh_offset; /* Offset in file. */
quint32 sh_size; /* Size in bytes. */
quint32 sh_link; /* Index of a related section. */
quint32 sh_info; /* Depends on section type. */
quint32 sh_addralign; /* Alignment in bytes. */
quint32 sh_entsize; /* Size of each entry in section. */
};
struct Elf64_Shdr
{
quint32 sh_name; /* Section name (index into the section header string table). */
quint32 sh_type; /* Section type. */
quint64 sh_flags; /* Section flags. */
quint64 sh_addr; /* Address in memory image. */
quint64 sh_offset; /* Offset in file. */
quint64 sh_size; /* Size in bytes. */
quint32 sh_link; /* Index of a related section. */
quint32 sh_info; /* Depends on section type. */
quint64 sh_addralign; /* Alignment in bytes. */
quint64 sh_entsize; /* Size of each entry in section. */
};
struct Elf_Shdr
{
quint32 sh_name; /* Section name (index into the section header string table). */
quint32 sh_type; /* Section type. */
quint64 sh_flags; /* Section flags. */
quint64 sh_addr; /* Address in memory image. */
quint64 sh_offset; /* Offset in file. */
quint64 sh_size; /* Size in bytes. */
quint32 sh_link; /* Index of a related section. */
quint32 sh_info; /* Depends on section type. */
quint64 sh_addralign; /* Alignment in bytes. */
quint64 sh_entsize; /* Size of each entry in section. */
};
struct Elf32_Phdr
{
quint32 p_type; /* entry type */
quint32 p_offset; /* offset */
quint32 p_vaddr; /* virtual address */
quint32 p_paddr; /* physical address */
quint32 p_filesz; /* file size */
quint32 p_memsz; /* memory size */
quint32 p_flags; /* flags */
quint32 p_align; /* memory & file alignment */
};
struct Elf64_Phdr
{
quint32 p_type; /* entry type */
quint32 p_flags; /* flags */
quint64 p_offset; /* offset */
quint64 p_vaddr; /* virtual address */
quint64 p_paddr; /* physical address */
quint64 p_filesz; /* file size */
quint64 p_memsz; /* memory size */
quint64 p_align; /* memory & file alignment */
};
struct Elf_Phdr
{
quint32 p_type; /* entry type */
quint32 p_flags; /* flags */
quint64 p_offset; /* offset */
quint64 p_vaddr; /* virtual address */
quint64 p_paddr; /* physical address */
quint64 p_filesz; /* file size */
quint64 p_memsz; /* memory size */
quint64 p_align; /* memory & file alignment */
};
struct Elf32_Sym
{
quint32 st_name; /* String table index of name. */
quint32 st_value; /* Symbol value. */
quint32 st_size; /* Size of associated object. */
quint8 st_info; /* Type and binding information. */
quint8 st_other; /* Reserved (not used). */
quint16 st_shndx; /* Section index of symbol. */
};
struct Elf64_Sym
{
quint32 st_name;
quint8 st_info;
quint8 st_other;
quint16 st_shndx;
quint64 st_value;
quint64 st_size;
};
struct Elf32_Rel
{
quint32 r_offset;
quint32 r_info;
};
struct Elf32_Rela
{
quint32 r_offset;
quint32 r_info;
qint32 r_addend;
};
struct Elf64_Rel
{
quint64 r_offset;
quint64 r_info;
};
struct Elf64_Rela
{
quint64 r_offset;
quint64 r_info;
qint64 r_addend;
};
}
#endif // XELF_DEF_H