Line data Source code
1 : use std::marker::PhantomData;
2 :
3 : use std::pin::Pin;
4 : use lief_ffi as ffi;
5 : use bitflags::bitflags;
6 :
7 : use crate::common::FromFFI;
8 : use crate::declare_iterator;
9 :
10 :
11 : #[allow(non_camel_case_types)]
12 1788 : #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
13 : pub enum Tag {
14 : DT_NULL_,
15 : NEEDED,
16 : PLTRELSZ,
17 : PLTGOT,
18 : HASH,
19 : STRTAB,
20 : SYMTAB,
21 : RELA,
22 : RELASZ,
23 : RELAENT,
24 : STRSZ,
25 : SYMENT,
26 : INIT,
27 : FINI,
28 : SONAME,
29 : RPATH,
30 : SYMBOLIC,
31 : REL,
32 : RELSZ,
33 : RELENT,
34 : PLTREL,
35 : DEBUG_TAG,
36 : TEXTREL,
37 : JMPREL,
38 : BIND_NOW,
39 : INIT_ARRAY,
40 : FINI_ARRAY,
41 : INIT_ARRAYSZ,
42 : FINI_ARRAYSZ,
43 : RUNPATH,
44 : FLAGS,
45 : PREINIT_ARRAY,
46 : PREINIT_ARRAYSZ,
47 : SYMTAB_SHNDX,
48 : RELRSZ,
49 : RELR,
50 : RELRENT,
51 : GNU_HASH,
52 : RELACOUNT,
53 : RELCOUNT,
54 : FLAGS_1,
55 : VERSYM,
56 : VERDEF,
57 : VERDEFNUM,
58 : VERNEED,
59 : VERNEEDNUM,
60 : ANDROID_REL_OFFSET,
61 : ANDROID_REL_SIZE,
62 : ANDROID_REL,
63 : ANDROID_RELSZ,
64 : ANDROID_RELA,
65 : ANDROID_RELASZ,
66 : ANDROID_RELR,
67 : ANDROID_RELRSZ,
68 : ANDROID_RELRENT,
69 : ANDROID_RELRCOUNT,
70 : MIPS_RLD_VERSION,
71 : MIPS_TIME_STAMP,
72 : MIPS_ICHECKSUM,
73 : MIPS_IVERSION,
74 : MIPS_FLAGS,
75 : MIPS_BASE_ADDRESS,
76 : MIPS_MSYM,
77 : MIPS_CONFLICT,
78 : MIPS_LIBLIST,
79 : MIPS_LOCAL_GOTNO,
80 : MIPS_CONFLICTNO,
81 : MIPS_LIBLISTNO,
82 : MIPS_SYMTABNO,
83 : MIPS_UNREFEXTNO,
84 : MIPS_GOTSYM,
85 : MIPS_HIPAGENO,
86 : MIPS_RLD_MAP,
87 : MIPS_DELTA_CLASS,
88 : MIPS_DELTA_CLASS_NO,
89 : MIPS_DELTA_INSTANCE,
90 : MIPS_DELTA_INSTANCE_NO,
91 : MIPS_DELTA_RELOC,
92 : MIPS_DELTA_RELOC_NO,
93 : MIPS_DELTA_SYM,
94 : MIPS_DELTA_SYM_NO,
95 : MIPS_DELTA_CLASSSYM,
96 : MIPS_DELTA_CLASSSYM_NO,
97 : MIPS_CXX_FLAGS,
98 : MIPS_PIXIE_INIT,
99 : MIPS_SYMBOL_LIB,
100 : MIPS_LOCALPAGE_GOTIDX,
101 : MIPS_LOCAL_GOTIDX,
102 : MIPS_HIDDEN_GOTIDX,
103 : MIPS_PROTECTED_GOTIDX,
104 : MIPS_OPTIONS,
105 : MIPS_INTERFACE,
106 : MIPS_DYNSTR_ALIGN,
107 : MIPS_INTERFACE_SIZE,
108 : MIPS_RLD_TEXT_RESOLVE_ADDR,
109 : MIPS_PERF_SUFFIX,
110 : MIPS_COMPACT_SIZE,
111 : MIPS_GP_VALUE,
112 : MIPS_AUX_DYNAMIC,
113 : MIPS_PLTGOT,
114 : MIPS_RWPLT,
115 : MIPS_RLD_MAP_REL,
116 : MIPS_XHASH,
117 : AARCH64_BTI_PLT,
118 : AARCH64_PAC_PLT,
119 : AARCH64_VARIANT_PCS,
120 : AARCH64_MEMTAG_MODE,
121 : AARCH64_MEMTAG_HEAP,
122 : AARCH64_MEMTAG_STACK,
123 : AARCH64_MEMTAG_GLOBALS,
124 : AARCH64_MEMTAG_GLOBALSSZ,
125 : HEXAGON_SYMSZ,
126 : HEXAGON_VER,
127 : HEXAGON_PLT,
128 : PPC_GOT,
129 : PPC_OPT,
130 : PPC64_GLINK,
131 : PPC64_OPT,
132 : RISCV_VARIANT_CC,
133 : X86_64_PLT,
134 : X86_64_PLTSZ,
135 : X86_64_PLTENT,
136 : IA_64_PLT_RESERVE,
137 : IA_64_VMS_SUBTYPE,
138 : IA_64_VMS_IMGIOCNT,
139 : IA_64_VMS_LNKFLAGS,
140 : IA_64_VMS_VIR_MEM_BLK_SIZ,
141 : IA_64_VMS_IDENT,
142 : IA_64_VMS_NEEDED_IDENT,
143 : IA_64_VMS_IMG_RELA_CNT,
144 : IA_64_VMS_SEG_RELA_CNT,
145 : IA_64_VMS_FIXUP_RELA_CNT,
146 : IA_64_VMS_FIXUP_NEEDED,
147 : IA_64_VMS_SYMVEC_CNT,
148 : IA_64_VMS_XLATED,
149 : IA_64_VMS_STACKSIZE,
150 : IA_64_VMS_UNWINDSZ,
151 : IA_64_VMS_UNWIND_CODSEG,
152 : IA_64_VMS_UNWIND_INFOSEG,
153 : IA_64_VMS_LINKTIME,
154 : IA_64_VMS_SEG_NO,
155 : IA_64_VMS_SYMVEC_OFFSET,
156 : IA_64_VMS_SYMVEC_SEG,
157 : IA_64_VMS_UNWIND_OFFSET,
158 : IA_64_VMS_UNWIND_SEG,
159 : IA_64_VMS_STRTAB_OFFSET,
160 : IA_64_VMS_SYSVER_OFFSET,
161 : IA_64_VMS_IMG_RELA_OFF,
162 : IA_64_VMS_SEG_RELA_OFF,
163 : IA_64_VMS_FIXUP_RELA_OFF,
164 : IA_64_VMS_PLTGOT_OFFSET,
165 : IA_64_VMS_PLTGOT_SEG,
166 : IA_64_VMS_FPMODE,
167 : UNKNOWN(u64),
168 : }
169 :
170 : impl From<u64> for Tag {
171 1788 : fn from(value: u64) -> Self {
172 1788 : match value {
173 60 : 0x00000000 => Tag::DT_NULL_,
174 216 : 0x00000001 => Tag::NEEDED,
175 60 : 0x00000002 => Tag::PLTRELSZ,
176 60 : 0x00000003 => Tag::PLTGOT,
177 24 : 0x00000004 => Tag::HASH,
178 60 : 0x00000005 => Tag::STRTAB,
179 60 : 0x00000006 => Tag::SYMTAB,
180 48 : 0x00000007 => Tag::RELA,
181 48 : 0x00000008 => Tag::RELASZ,
182 48 : 0x00000009 => Tag::RELAENT,
183 60 : 0x0000000a => Tag::STRSZ,
184 60 : 0x0000000b => Tag::SYMENT,
185 60 : 0x0000000c => Tag::INIT,
186 60 : 0x0000000d => Tag::FINI,
187 12 : 0x0000000e => Tag::SONAME,
188 12 : 0x0000000f => Tag::RPATH,
189 12 : 0x00000010 => Tag::SYMBOLIC,
190 12 : 0x00000011 => Tag::REL,
191 12 : 0x00000012 => Tag::RELSZ,
192 12 : 0x00000013 => Tag::RELENT,
193 60 : 0x00000014 => Tag::PLTREL,
194 48 : 0x00000015 => Tag::DEBUG_TAG,
195 0 : 0x00000016 => Tag::TEXTREL,
196 60 : 0x00000017 => Tag::JMPREL,
197 0 : 0x00000018 => Tag::BIND_NOW,
198 48 : 0x00000019 => Tag::INIT_ARRAY,
199 36 : 0x0000001a => Tag::FINI_ARRAY,
200 48 : 0x0000001b => Tag::INIT_ARRAYSZ,
201 36 : 0x0000001c => Tag::FINI_ARRAYSZ,
202 12 : 0x0000001d => Tag::RUNPATH,
203 12 : 0x0000001e => Tag::FLAGS,
204 0 : 0x00000020 => Tag::PREINIT_ARRAY,
205 0 : 0x00000021 => Tag::PREINIT_ARRAYSZ,
206 0 : 0x00000022 => Tag::SYMTAB_SHNDX,
207 0 : 0x00000023 => Tag::RELRSZ,
208 0 : 0x00000024 => Tag::RELR,
209 0 : 0x00000025 => Tag::RELRENT,
210 48 : 0x6ffffef5 => Tag::GNU_HASH,
211 24 : 0x6ffffff9 => Tag::RELACOUNT,
212 0 : 0x6ffffffa => Tag::RELCOUNT,
213 12 : 0x6ffffffb => Tag::FLAGS_1,
214 60 : 0x6ffffff0 => Tag::VERSYM,
215 12 : 0x6ffffffc => Tag::VERDEF,
216 12 : 0x6ffffffd => Tag::VERDEFNUM,
217 60 : 0x6ffffffe => Tag::VERNEED,
218 60 : 0x6fffffff => Tag::VERNEEDNUM,
219 0 : 0x6000000d => Tag::ANDROID_REL_OFFSET,
220 0 : 0x6000000e => Tag::ANDROID_REL_SIZE,
221 0 : 0x6000000f => Tag::ANDROID_REL,
222 0 : 0x60000010 => Tag::ANDROID_RELSZ,
223 0 : 0x60000011 => Tag::ANDROID_RELA,
224 0 : 0x60000012 => Tag::ANDROID_RELASZ,
225 0 : 0x6fffe000 => Tag::ANDROID_RELR,
226 0 : 0x6fffe001 => Tag::ANDROID_RELRSZ,
227 0 : 0x6fffe003 => Tag::ANDROID_RELRENT,
228 0 : 0x6fffe005 => Tag::ANDROID_RELRCOUNT,
229 12 : 0x170000001 => Tag::MIPS_RLD_VERSION,
230 0 : 0x170000002 => Tag::MIPS_TIME_STAMP,
231 0 : 0x170000003 => Tag::MIPS_ICHECKSUM,
232 0 : 0x170000004 => Tag::MIPS_IVERSION,
233 12 : 0x170000005 => Tag::MIPS_FLAGS,
234 12 : 0x170000006 => Tag::MIPS_BASE_ADDRESS,
235 0 : 0x170000007 => Tag::MIPS_MSYM,
236 0 : 0x170000008 => Tag::MIPS_CONFLICT,
237 0 : 0x170000009 => Tag::MIPS_LIBLIST,
238 12 : 0x17000000a => Tag::MIPS_LOCAL_GOTNO,
239 0 : 0x17000000b => Tag::MIPS_CONFLICTNO,
240 0 : 0x170000010 => Tag::MIPS_LIBLISTNO,
241 12 : 0x170000011 => Tag::MIPS_SYMTABNO,
242 12 : 0x170000012 => Tag::MIPS_UNREFEXTNO,
243 12 : 0x170000013 => Tag::MIPS_GOTSYM,
244 0 : 0x170000014 => Tag::MIPS_HIPAGENO,
245 12 : 0x170000016 => Tag::MIPS_RLD_MAP,
246 0 : 0x170000017 => Tag::MIPS_DELTA_CLASS,
247 0 : 0x170000018 => Tag::MIPS_DELTA_CLASS_NO,
248 0 : 0x170000019 => Tag::MIPS_DELTA_INSTANCE,
249 0 : 0x17000001a => Tag::MIPS_DELTA_INSTANCE_NO,
250 0 : 0x17000001b => Tag::MIPS_DELTA_RELOC,
251 0 : 0x17000001c => Tag::MIPS_DELTA_RELOC_NO,
252 0 : 0x17000001d => Tag::MIPS_DELTA_SYM,
253 0 : 0x17000001e => Tag::MIPS_DELTA_SYM_NO,
254 0 : 0x170000020 => Tag::MIPS_DELTA_CLASSSYM,
255 0 : 0x170000021 => Tag::MIPS_DELTA_CLASSSYM_NO,
256 0 : 0x170000022 => Tag::MIPS_CXX_FLAGS,
257 0 : 0x170000023 => Tag::MIPS_PIXIE_INIT,
258 0 : 0x170000024 => Tag::MIPS_SYMBOL_LIB,
259 0 : 0x170000025 => Tag::MIPS_LOCALPAGE_GOTIDX,
260 0 : 0x170000026 => Tag::MIPS_LOCAL_GOTIDX,
261 0 : 0x170000027 => Tag::MIPS_HIDDEN_GOTIDX,
262 0 : 0x170000028 => Tag::MIPS_PROTECTED_GOTIDX,
263 0 : 0x170000029 => Tag::MIPS_OPTIONS,
264 0 : 0x17000002a => Tag::MIPS_INTERFACE,
265 0 : 0x17000002b => Tag::MIPS_DYNSTR_ALIGN,
266 0 : 0x17000002c => Tag::MIPS_INTERFACE_SIZE,
267 0 : 0x17000002d => Tag::MIPS_RLD_TEXT_RESOLVE_ADDR,
268 0 : 0x17000002e => Tag::MIPS_PERF_SUFFIX,
269 0 : 0x17000002f => Tag::MIPS_COMPACT_SIZE,
270 0 : 0x170000030 => Tag::MIPS_GP_VALUE,
271 0 : 0x170000031 => Tag::MIPS_AUX_DYNAMIC,
272 12 : 0x170000032 => Tag::MIPS_PLTGOT,
273 0 : 0x170000034 => Tag::MIPS_RWPLT,
274 12 : 0x170000035 => Tag::MIPS_RLD_MAP_REL,
275 0 : 0x170000036 => Tag::MIPS_XHASH,
276 0 : 0x270000001 => Tag::AARCH64_BTI_PLT,
277 0 : 0x270000003 => Tag::AARCH64_PAC_PLT,
278 0 : 0x270000005 => Tag::AARCH64_VARIANT_PCS,
279 0 : 0x270000009 => Tag::AARCH64_MEMTAG_MODE,
280 0 : 0x27000000b => Tag::AARCH64_MEMTAG_HEAP,
281 0 : 0x27000000c => Tag::AARCH64_MEMTAG_STACK,
282 0 : 0x27000000d => Tag::AARCH64_MEMTAG_GLOBALS,
283 0 : 0x27000000f => Tag::AARCH64_MEMTAG_GLOBALSSZ,
284 0 : 0x370000000 => Tag::HEXAGON_SYMSZ,
285 0 : 0x370000001 => Tag::HEXAGON_VER,
286 0 : 0x370000002 => Tag::HEXAGON_PLT,
287 0 : 0x470000000 => Tag::PPC_GOT,
288 0 : 0x470000001 => Tag::PPC_OPT,
289 0 : 0x570000000 => Tag::PPC64_GLINK,
290 0 : 0x570000003 => Tag::PPC64_OPT,
291 0 : 0x670000003 => Tag::RISCV_VARIANT_CC,
292 0 : 0x770000000 => Tag::X86_64_PLT,
293 0 : 0x770000001 => Tag::X86_64_PLTSZ,
294 0 : 0x770000003 => Tag::X86_64_PLTENT,
295 0 : 0x870000000 => Tag::IA_64_PLT_RESERVE,
296 0 : 0x860000000 => Tag::IA_64_VMS_SUBTYPE,
297 0 : 0x860000002 => Tag::IA_64_VMS_IMGIOCNT,
298 0 : 0x860000008 => Tag::IA_64_VMS_LNKFLAGS,
299 0 : 0x86000000a => Tag::IA_64_VMS_VIR_MEM_BLK_SIZ,
300 0 : 0x86000000c => Tag::IA_64_VMS_IDENT,
301 0 : 0x860000010 => Tag::IA_64_VMS_NEEDED_IDENT,
302 0 : 0x860000012 => Tag::IA_64_VMS_IMG_RELA_CNT,
303 0 : 0x860000014 => Tag::IA_64_VMS_SEG_RELA_CNT,
304 0 : 0x860000016 => Tag::IA_64_VMS_FIXUP_RELA_CNT,
305 0 : 0x860000018 => Tag::IA_64_VMS_FIXUP_NEEDED,
306 0 : 0x86000001a => Tag::IA_64_VMS_SYMVEC_CNT,
307 0 : 0x86000001e => Tag::IA_64_VMS_XLATED,
308 0 : 0x860000020 => Tag::IA_64_VMS_STACKSIZE,
309 0 : 0x860000022 => Tag::IA_64_VMS_UNWINDSZ,
310 0 : 0x860000024 => Tag::IA_64_VMS_UNWIND_CODSEG,
311 0 : 0x860000026 => Tag::IA_64_VMS_UNWIND_INFOSEG,
312 0 : 0x860000028 => Tag::IA_64_VMS_LINKTIME,
313 0 : 0x86000002a => Tag::IA_64_VMS_SEG_NO,
314 0 : 0x86000002c => Tag::IA_64_VMS_SYMVEC_OFFSET,
315 0 : 0x86000002e => Tag::IA_64_VMS_SYMVEC_SEG,
316 0 : 0x860000030 => Tag::IA_64_VMS_UNWIND_OFFSET,
317 0 : 0x860000032 => Tag::IA_64_VMS_UNWIND_SEG,
318 0 : 0x860000034 => Tag::IA_64_VMS_STRTAB_OFFSET,
319 0 : 0x860000036 => Tag::IA_64_VMS_SYSVER_OFFSET,
320 0 : 0x860000038 => Tag::IA_64_VMS_IMG_RELA_OFF,
321 0 : 0x86000003a => Tag::IA_64_VMS_SEG_RELA_OFF,
322 0 : 0x86000003c => Tag::IA_64_VMS_FIXUP_RELA_OFF,
323 0 : 0x86000003e => Tag::IA_64_VMS_PLTGOT_OFFSET,
324 0 : 0x860000040 => Tag::IA_64_VMS_PLTGOT_SEG,
325 0 : 0x860000042 => Tag::IA_64_VMS_FPMODE,
326 24 : _ => Tag::UNKNOWN(value),
327 :
328 : }
329 1788 : }
330 : }
331 :
332 : impl From<Tag> for u64 {
333 288 : fn from(value: Tag) -> u64 {
334 288 : match value {
335 0 : Tag::DT_NULL_ => 0x00000000,
336 0 : Tag::NEEDED => 0x00000001,
337 0 : Tag::PLTRELSZ => 0x00000002,
338 0 : Tag::PLTGOT => 0x00000003,
339 0 : Tag::HASH => 0x00000004,
340 0 : Tag::STRTAB => 0x00000005,
341 0 : Tag::SYMTAB => 0x00000006,
342 0 : Tag::RELA => 0x00000007,
343 0 : Tag::RELASZ => 0x00000008,
344 0 : Tag::RELAENT => 0x00000009,
345 0 : Tag::STRSZ => 0x0000000a,
346 0 : Tag::SYMENT => 0x0000000b,
347 0 : Tag::INIT => 0x0000000c,
348 0 : Tag::FINI => 0x0000000d,
349 0 : Tag::SONAME => 0x0000000e,
350 0 : Tag::RPATH => 0x0000000f,
351 0 : Tag::SYMBOLIC => 0x00000010,
352 0 : Tag::REL => 0x00000011,
353 0 : Tag::RELSZ => 0x00000012,
354 0 : Tag::RELENT => 0x00000013,
355 0 : Tag::PLTREL => 0x00000014,
356 0 : Tag::DEBUG_TAG => 0x00000015,
357 0 : Tag::TEXTREL => 0x00000016,
358 0 : Tag::JMPREL => 0x00000017,
359 0 : Tag::BIND_NOW => 0x00000018,
360 96 : Tag::INIT_ARRAY => 0x00000019,
361 96 : Tag::FINI_ARRAY => 0x0000001a,
362 0 : Tag::INIT_ARRAYSZ => 0x0000001b,
363 0 : Tag::FINI_ARRAYSZ => 0x0000001c,
364 0 : Tag::RUNPATH => 0x0000001d,
365 0 : Tag::FLAGS => 0x0000001e,
366 96 : Tag::PREINIT_ARRAY => 0x00000020,
367 0 : Tag::PREINIT_ARRAYSZ => 0x00000021,
368 0 : Tag::SYMTAB_SHNDX => 0x00000022,
369 0 : Tag::RELRSZ => 0x00000023,
370 0 : Tag::RELR => 0x00000024,
371 0 : Tag::RELRENT => 0x00000025,
372 0 : Tag::GNU_HASH => 0x6ffffef5,
373 0 : Tag::RELACOUNT => 0x6ffffff9,
374 0 : Tag::RELCOUNT => 0x6ffffffa,
375 0 : Tag::FLAGS_1 => 0x6ffffffb,
376 0 : Tag::VERSYM => 0x6ffffff0,
377 0 : Tag::VERDEF => 0x6ffffffc,
378 0 : Tag::VERDEFNUM => 0x6ffffffd,
379 0 : Tag::VERNEED => 0x6ffffffe,
380 0 : Tag::VERNEEDNUM => 0x6fffffff,
381 0 : Tag::ANDROID_REL_OFFSET => 0x6000000d,
382 0 : Tag::ANDROID_REL_SIZE => 0x6000000e,
383 0 : Tag::ANDROID_REL => 0x6000000f,
384 0 : Tag::ANDROID_RELSZ => 0x60000010,
385 0 : Tag::ANDROID_RELA => 0x60000011,
386 0 : Tag::ANDROID_RELASZ => 0x60000012,
387 0 : Tag::ANDROID_RELR => 0x6fffe000,
388 0 : Tag::ANDROID_RELRSZ => 0x6fffe001,
389 0 : Tag::ANDROID_RELRENT => 0x6fffe003,
390 0 : Tag::ANDROID_RELRCOUNT => 0x6fffe005,
391 0 : Tag::MIPS_RLD_VERSION => 0x170000001,
392 0 : Tag::MIPS_TIME_STAMP => 0x170000002,
393 0 : Tag::MIPS_ICHECKSUM => 0x170000003,
394 0 : Tag::MIPS_IVERSION => 0x170000004,
395 0 : Tag::MIPS_FLAGS => 0x170000005,
396 0 : Tag::MIPS_BASE_ADDRESS => 0x170000006,
397 0 : Tag::MIPS_MSYM => 0x170000007,
398 0 : Tag::MIPS_CONFLICT => 0x170000008,
399 0 : Tag::MIPS_LIBLIST => 0x170000009,
400 0 : Tag::MIPS_LOCAL_GOTNO => 0x17000000a,
401 0 : Tag::MIPS_CONFLICTNO => 0x17000000b,
402 0 : Tag::MIPS_LIBLISTNO => 0x170000010,
403 0 : Tag::MIPS_SYMTABNO => 0x170000011,
404 0 : Tag::MIPS_UNREFEXTNO => 0x170000012,
405 0 : Tag::MIPS_GOTSYM => 0x170000013,
406 0 : Tag::MIPS_HIPAGENO => 0x170000014,
407 0 : Tag::MIPS_RLD_MAP => 0x170000016,
408 0 : Tag::MIPS_DELTA_CLASS => 0x170000017,
409 0 : Tag::MIPS_DELTA_CLASS_NO => 0x170000018,
410 0 : Tag::MIPS_DELTA_INSTANCE => 0x170000019,
411 0 : Tag::MIPS_DELTA_INSTANCE_NO => 0x17000001a,
412 0 : Tag::MIPS_DELTA_RELOC => 0x17000001b,
413 0 : Tag::MIPS_DELTA_RELOC_NO => 0x17000001c,
414 0 : Tag::MIPS_DELTA_SYM => 0x17000001d,
415 0 : Tag::MIPS_DELTA_SYM_NO => 0x17000001e,
416 0 : Tag::MIPS_DELTA_CLASSSYM => 0x170000020,
417 0 : Tag::MIPS_DELTA_CLASSSYM_NO => 0x170000021,
418 0 : Tag::MIPS_CXX_FLAGS => 0x170000022,
419 0 : Tag::MIPS_PIXIE_INIT => 0x170000023,
420 0 : Tag::MIPS_SYMBOL_LIB => 0x170000024,
421 0 : Tag::MIPS_LOCALPAGE_GOTIDX => 0x170000025,
422 0 : Tag::MIPS_LOCAL_GOTIDX => 0x170000026,
423 0 : Tag::MIPS_HIDDEN_GOTIDX => 0x170000027,
424 0 : Tag::MIPS_PROTECTED_GOTIDX => 0x170000028,
425 0 : Tag::MIPS_OPTIONS => 0x170000029,
426 0 : Tag::MIPS_INTERFACE => 0x17000002a,
427 0 : Tag::MIPS_DYNSTR_ALIGN => 0x17000002b,
428 0 : Tag::MIPS_INTERFACE_SIZE => 0x17000002c,
429 0 : Tag::MIPS_RLD_TEXT_RESOLVE_ADDR => 0x17000002d,
430 0 : Tag::MIPS_PERF_SUFFIX => 0x17000002e,
431 0 : Tag::MIPS_COMPACT_SIZE => 0x17000002f,
432 0 : Tag::MIPS_GP_VALUE => 0x170000030,
433 0 : Tag::MIPS_AUX_DYNAMIC => 0x170000031,
434 0 : Tag::MIPS_PLTGOT => 0x170000032,
435 0 : Tag::MIPS_RWPLT => 0x170000034,
436 0 : Tag::MIPS_RLD_MAP_REL => 0x170000035,
437 0 : Tag::MIPS_XHASH => 0x170000036,
438 0 : Tag::AARCH64_BTI_PLT => 0x270000001,
439 0 : Tag::AARCH64_PAC_PLT => 0x270000003,
440 0 : Tag::AARCH64_VARIANT_PCS => 0x270000005,
441 0 : Tag::AARCH64_MEMTAG_MODE => 0x270000009,
442 0 : Tag::AARCH64_MEMTAG_HEAP => 0x27000000b,
443 0 : Tag::AARCH64_MEMTAG_STACK => 0x27000000c,
444 0 : Tag::AARCH64_MEMTAG_GLOBALS => 0x27000000d,
445 0 : Tag::AARCH64_MEMTAG_GLOBALSSZ => 0x27000000f,
446 0 : Tag::HEXAGON_SYMSZ => 0x370000000,
447 0 : Tag::HEXAGON_VER => 0x370000001,
448 0 : Tag::HEXAGON_PLT => 0x370000002,
449 0 : Tag::PPC_GOT => 0x470000000,
450 0 : Tag::PPC_OPT => 0x470000001,
451 0 : Tag::PPC64_GLINK => 0x570000000,
452 0 : Tag::PPC64_OPT => 0x570000003,
453 0 : Tag::RISCV_VARIANT_CC => 0x670000003,
454 0 : Tag::X86_64_PLT => 0x770000000,
455 0 : Tag::X86_64_PLTSZ => 0x770000001,
456 0 : Tag::X86_64_PLTENT => 0x770000003,
457 0 : Tag::IA_64_PLT_RESERVE => 0x870000000,
458 0 : Tag::IA_64_VMS_SUBTYPE => 0x860000000,
459 0 : Tag::IA_64_VMS_IMGIOCNT => 0x860000002,
460 0 : Tag::IA_64_VMS_LNKFLAGS => 0x860000008,
461 0 : Tag::IA_64_VMS_VIR_MEM_BLK_SIZ => 0x86000000a,
462 0 : Tag::IA_64_VMS_IDENT => 0x86000000c,
463 0 : Tag::IA_64_VMS_NEEDED_IDENT => 0x860000010,
464 0 : Tag::IA_64_VMS_IMG_RELA_CNT => 0x860000012,
465 0 : Tag::IA_64_VMS_SEG_RELA_CNT => 0x860000014,
466 0 : Tag::IA_64_VMS_FIXUP_RELA_CNT => 0x860000016,
467 0 : Tag::IA_64_VMS_FIXUP_NEEDED => 0x860000018,
468 0 : Tag::IA_64_VMS_SYMVEC_CNT => 0x86000001a,
469 0 : Tag::IA_64_VMS_XLATED => 0x86000001e,
470 0 : Tag::IA_64_VMS_STACKSIZE => 0x860000020,
471 0 : Tag::IA_64_VMS_UNWINDSZ => 0x860000022,
472 0 : Tag::IA_64_VMS_UNWIND_CODSEG => 0x860000024,
473 0 : Tag::IA_64_VMS_UNWIND_INFOSEG => 0x860000026,
474 0 : Tag::IA_64_VMS_LINKTIME => 0x860000028,
475 0 : Tag::IA_64_VMS_SEG_NO => 0x86000002a,
476 0 : Tag::IA_64_VMS_SYMVEC_OFFSET => 0x86000002c,
477 0 : Tag::IA_64_VMS_SYMVEC_SEG => 0x86000002e,
478 0 : Tag::IA_64_VMS_UNWIND_OFFSET => 0x860000030,
479 0 : Tag::IA_64_VMS_UNWIND_SEG => 0x860000032,
480 0 : Tag::IA_64_VMS_STRTAB_OFFSET => 0x860000034,
481 0 : Tag::IA_64_VMS_SYSVER_OFFSET => 0x860000036,
482 0 : Tag::IA_64_VMS_IMG_RELA_OFF => 0x860000038,
483 0 : Tag::IA_64_VMS_SEG_RELA_OFF => 0x86000003a,
484 0 : Tag::IA_64_VMS_FIXUP_RELA_OFF => 0x86000003c,
485 0 : Tag::IA_64_VMS_PLTGOT_OFFSET => 0x86000003e,
486 0 : Tag::IA_64_VMS_PLTGOT_SEG => 0x860000040,
487 0 : Tag::IA_64_VMS_FPMODE => 0x860000042,
488 0 : Tag::UNKNOWN(value) => value,
489 : }
490 288 : }
491 : }
492 :
493 1788 : #[derive(Debug)]
494 : /// Enum that represents the different variants of a dynamic entry
495 : pub enum Entries<'a> {
496 : /// Entry for `DT_NEEDED`
497 : Library(Library<'a>),
498 :
499 : /// Entry for `DT_INIT_ARRAY, DT_FINI_ARRAY`, ...
500 : Array(Array<'a>),
501 :
502 : /// Entry for `DT_RPATH`
503 : Rpath(Rpath<'a>),
504 :
505 : /// Entry for `DT_RUNPATH`
506 : RunPath(RunPath<'a>),
507 :
508 : /// Entry for `DT_SONAME`
509 : SharedObject(SharedObject<'a>),
510 :
511 : /// Entry for `DT_FLAGS` and `DT_FLAGS_1`
512 : Flags(Flags<'a>),
513 :
514 : /// Generic value
515 : Generic(Generic<'a>),
516 : }
517 :
518 : impl Entries<'_> {
519 : /// Create a new dynamic entry with the given Tag
520 0 : pub fn with_tag(tag: Tag) -> Entries<'static> {
521 0 : Entries::from_ffi(lief_ffi::ELF_DynamicEntry::create(tag.into()))
522 0 : }
523 : }
524 :
525 : /// Trait shared by all the [`Entries`]
526 : pub trait DynamicEntry {
527 : #[doc(hidden)]
528 : fn as_base(&self) -> &ffi::ELF_DynamicEntry;
529 :
530 : #[doc(hidden)]
531 : fn as_mut_base(&mut self) -> Pin<&mut ffi::ELF_DynamicEntry>;
532 :
533 : /// Dynamic TAG associated with the entry
534 149 : fn tag(&self) -> Tag {
535 149 : Tag::from(self.as_base().tag())
536 149 : }
537 :
538 : /// Raw value which should be interpreted according to the [`DynamicEntry::tag`]
539 144 : fn value(&self) -> u64 {
540 144 : self.as_base().value()
541 144 : }
542 :
543 0 : fn set_value(&mut self, value: u64) {
544 0 : self.as_mut_base().set_value(value);
545 0 : }
546 : }
547 :
548 : impl DynamicEntry for Entries<'_> {
549 0 : fn as_base(&self) -> &ffi::ELF_DynamicEntry {
550 0 : match &self {
551 0 : Entries::Library(entry) => {
552 0 : entry.as_base()
553 : }
554 :
555 0 : Entries::Array(entry) => {
556 0 : entry.as_base()
557 : }
558 :
559 0 : Entries::Rpath(entry) => {
560 0 : entry.as_base()
561 : }
562 :
563 0 : Entries::RunPath(entry) => {
564 0 : entry.as_base()
565 : }
566 :
567 0 : Entries::SharedObject(entry) => {
568 0 : entry.as_base()
569 : }
570 :
571 0 : Entries::Flags(entry) => {
572 0 : entry.as_base()
573 : }
574 :
575 0 : Entries::Generic(entry) => {
576 0 : entry.as_base()
577 : }
578 : }
579 0 : }
580 :
581 0 : fn as_mut_base(&mut self) -> Pin<&mut ffi::ELF_DynamicEntry> {
582 0 : match self {
583 0 : Entries::Library(entry) => {
584 0 : entry.as_mut_base()
585 : }
586 :
587 0 : Entries::Array(entry) => {
588 0 : entry.as_mut_base()
589 : }
590 :
591 0 : Entries::Rpath(entry) => {
592 0 : entry.as_mut_base()
593 : }
594 :
595 0 : Entries::RunPath(entry) => {
596 0 : entry.as_mut_base()
597 : }
598 :
599 0 : Entries::SharedObject(entry) => {
600 0 : entry.as_mut_base()
601 : }
602 :
603 0 : Entries::Flags(entry) => {
604 0 : entry.as_mut_base()
605 : }
606 :
607 0 : Entries::Generic(entry) => {
608 0 : entry.as_mut_base()
609 : }
610 : }
611 0 : }
612 :
613 :
614 : }
615 :
616 :
617 : impl FromFFI<ffi::ELF_DynamicEntry> for Entries<'_> {
618 1788 : fn from_ffi(ffi_entry: cxx::UniquePtr<ffi::ELF_DynamicEntry>) -> Self {
619 1788 : unsafe {
620 1788 : let cmd_ref = ffi_entry.as_ref().unwrap();
621 1788 :
622 1788 : if ffi::ELF_DynamicEntryLibrary::classof(cmd_ref) {
623 216 : let raw = {
624 216 : type From = cxx::UniquePtr<ffi::ELF_DynamicEntry>;
625 216 : type To = cxx::UniquePtr<ffi::ELF_DynamicEntryLibrary>;
626 216 : std::mem::transmute::<From, To>(ffi_entry)
627 216 : };
628 216 : Entries::Library(Library::from_ffi(raw))
629 : }
630 1572 : else if ffi::ELF_DynamicEntryArray::classof(cmd_ref) {
631 84 : let raw = {
632 84 : type From = cxx::UniquePtr<ffi::ELF_DynamicEntry>;
633 84 : type To = cxx::UniquePtr<ffi::ELF_DynamicEntryArray>;
634 84 : std::mem::transmute::<From, To>(ffi_entry)
635 84 : };
636 84 : Entries::Array(Array::from_ffi(raw))
637 : }
638 1488 : else if ffi::ELF_DynamicEntryRpath::classof(cmd_ref) {
639 12 : let raw = {
640 12 : type From = cxx::UniquePtr<ffi::ELF_DynamicEntry>;
641 12 : type To = cxx::UniquePtr<ffi::ELF_DynamicEntryRpath>;
642 12 : std::mem::transmute::<From, To>(ffi_entry)
643 12 : };
644 12 : Entries::Rpath(Rpath::from_ffi(raw))
645 : }
646 1476 : else if ffi::ELF_DynamicEntryRunPath::classof(cmd_ref) {
647 12 : let raw = {
648 12 : type From = cxx::UniquePtr<ffi::ELF_DynamicEntry>;
649 12 : type To = cxx::UniquePtr<ffi::ELF_DynamicEntryRunPath>;
650 12 : std::mem::transmute::<From, To>(ffi_entry)
651 12 : };
652 12 : Entries::RunPath(RunPath::from_ffi(raw))
653 : }
654 1464 : else if ffi::ELF_DynamicSharedObject::classof(cmd_ref) {
655 12 : let raw = {
656 12 : type From = cxx::UniquePtr<ffi::ELF_DynamicEntry>;
657 12 : type To = cxx::UniquePtr<ffi::ELF_DynamicSharedObject>;
658 12 : std::mem::transmute::<From, To>(ffi_entry)
659 12 : };
660 12 : Entries::SharedObject(SharedObject::from_ffi(raw))
661 : }
662 1452 : else if ffi::ELF_DynamicEntryFlags::classof(cmd_ref) {
663 24 : let raw = {
664 24 : type From = cxx::UniquePtr<ffi::ELF_DynamicEntry>;
665 24 : type To = cxx::UniquePtr<ffi::ELF_DynamicEntryFlags>;
666 24 : std::mem::transmute::<From, To>(ffi_entry)
667 24 : };
668 24 : Entries::Flags(Flags::from_ffi(raw))
669 : }
670 : else {
671 1428 : Entries::Generic(Generic::from_ffi(ffi_entry))
672 : }
673 : }
674 1788 : }
675 : }
676 :
677 :
678 : /// Generic structure for the dynamic entries whose [`DynamicEntry::value`] can be interpreted
679 : /// as is.
680 : pub struct Generic<'a> {
681 : ptr: cxx::UniquePtr<ffi::ELF_DynamicEntry>,
682 : _owner: PhantomData<&'a ffi::ELF_Binary>
683 : }
684 :
685 : impl FromFFI<ffi::ELF_DynamicEntry> for Generic<'_> {
686 1428 : fn from_ffi(ptr: cxx::UniquePtr<ffi::ELF_DynamicEntry>) -> Self {
687 1428 : Self {
688 1428 : ptr,
689 1428 : _owner: PhantomData
690 1428 : }
691 1428 : }
692 :
693 : }
694 :
695 : impl DynamicEntry for Generic<'_> {
696 2856 : fn as_base(&self) -> &ffi::ELF_DynamicEntry {
697 2856 : self.ptr.as_ref().unwrap()
698 2856 : }
699 :
700 0 : fn as_mut_base(&mut self) -> Pin<&mut ffi::ELF_DynamicEntry> {
701 0 : unsafe {
702 0 : Pin::new_unchecked({
703 0 : (self.ptr.as_ref().unwrap() as *const ffi::ELF_DynamicEntry
704 0 : as *mut ffi::ELF_DynamicEntry)
705 0 : .as_mut()
706 0 : .unwrap()
707 0 : })
708 0 : }
709 0 : }
710 : }
711 :
712 :
713 : impl std::fmt::Debug for Generic<'_> {
714 1428 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
715 1428 : f.debug_struct("Generic").finish()
716 1428 : }
717 : }
718 :
719 : /// Structure that represents a dynamic entry associated with a library name (e.g. `DT_NEEDED`)
720 : pub struct Library<'a> {
721 : ptr: cxx::UniquePtr<ffi::ELF_DynamicEntryLibrary>,
722 : _owner: PhantomData<&'a ffi::ELF_Binary>
723 : }
724 :
725 : impl Library<'_> {
726 : /// Name of the library (e.g. `libc.so.6`)
727 216 : pub fn name(&self) -> String {
728 216 : self.ptr.name().to_string()
729 216 : }
730 :
731 : /// Set a new library name
732 0 : pub fn set_name(&mut self, new_name: &str) {
733 0 : self.ptr.pin_mut().set_name(new_name.to_string());
734 0 : }
735 : }
736 :
737 : impl FromFFI<ffi::ELF_DynamicEntryLibrary> for Library<'_> {
738 240 : fn from_ffi(ptr: cxx::UniquePtr<ffi::ELF_DynamicEntryLibrary>) -> Self {
739 240 : Self {
740 240 : ptr,
741 240 : _owner: PhantomData
742 240 : }
743 240 : }
744 : }
745 :
746 :
747 : impl DynamicEntry for Library<'_> {
748 432 : fn as_base(&self) -> &ffi::ELF_DynamicEntry {
749 432 : self.ptr.as_ref().unwrap().as_ref()
750 432 : }
751 :
752 0 : fn as_mut_base(&mut self) -> Pin<&mut ffi::ELF_DynamicEntry> {
753 0 : unsafe {
754 0 : Pin::new_unchecked({
755 0 : (self.ptr.as_ref().unwrap().as_ref() as *const ffi::ELF_DynamicEntry
756 0 : as *mut ffi::ELF_DynamicEntry)
757 0 : .as_mut()
758 0 : .unwrap()
759 0 : })
760 0 : }
761 0 : }
762 : }
763 :
764 : impl std::fmt::Debug for Library<'_> {
765 216 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
766 216 : f.debug_struct("Library").finish()
767 216 : }
768 : }
769 :
770 : /// Structure that represents a dynamic entry associated with an array (e.g. `DT_INIT_ARRAY`)
771 : pub struct Array<'a> {
772 : ptr: cxx::UniquePtr<ffi::ELF_DynamicEntryArray>,
773 : _owner: PhantomData<&'a ffi::ELF_Binary>
774 : }
775 :
776 : impl Array<'_> {
777 84 : pub fn array(&self) -> Vec<u64> {
778 84 : Vec::from(self.ptr.array().as_slice())
779 84 : }
780 : }
781 :
782 : impl FromFFI<ffi::ELF_DynamicEntryArray> for Array<'_> {
783 84 : fn from_ffi(ptr: cxx::UniquePtr<ffi::ELF_DynamicEntryArray>) -> Self {
784 84 : Self {
785 84 : ptr,
786 84 : _owner: PhantomData
787 84 : }
788 84 : }
789 : }
790 :
791 : impl DynamicEntry for Array<'_> {
792 168 : fn as_base(&self) -> &ffi::ELF_DynamicEntry {
793 168 : self.ptr.as_ref().unwrap().as_ref()
794 168 : }
795 :
796 0 : fn as_mut_base(&mut self) -> Pin<&mut ffi::ELF_DynamicEntry> {
797 0 : unsafe {
798 0 : Pin::new_unchecked({
799 0 : (self.ptr.as_ref().unwrap().as_ref() as *const ffi::ELF_DynamicEntry
800 0 : as *mut ffi::ELF_DynamicEntry)
801 0 : .as_mut()
802 0 : .unwrap()
803 0 : })
804 0 : }
805 0 : }
806 : }
807 :
808 : impl std::fmt::Debug for Array<'_> {
809 84 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
810 84 : f.debug_struct("Array").finish()
811 84 : }
812 : }
813 :
814 : /// Structure that represents a dynamic entry associated with the rpath info
815 : pub struct Rpath<'a> {
816 : ptr: cxx::UniquePtr<ffi::ELF_DynamicEntryRpath>,
817 : _owner: PhantomData<&'a ffi::ELF_Binary>
818 : }
819 :
820 : impl Rpath<'_> {
821 : /// Create a new Rpath entry with the given path(s)
822 : ///
823 : /// For instance:
824 : ///
825 : /// ```
826 : /// Rpath::new("$ORIGIN/../:/lib64")
827 : /// ```
828 0 : pub fn new(value: &str) -> Rpath<'static> {
829 0 : Rpath::from_ffi(lief_ffi::ELF_DynamicEntryRpath::create(value.to_string()))
830 0 : }
831 :
832 : /// Create a new Rpath entry from a slice of paths
833 : ///
834 : /// For instance:
835 : ///
836 : /// ```
837 : /// Rpath::with_paths(&vec!["$ORIGIN/../", "/lib64"])
838 : /// ```
839 0 : pub fn with_paths(values: &[&str]) -> Rpath<'static> {
840 0 : Rpath::new(&values.join(":"))
841 0 : }
842 :
843 : /// The actual rpath as a string
844 12 : pub fn rpath(&self) -> String {
845 12 : self.ptr.rpath().to_string()
846 12 : }
847 :
848 : /// Change the rpath value
849 0 : pub fn set_rpath(&mut self, value: &str) {
850 0 : self.ptr.pin_mut().set_rpath(value.to_string());
851 0 : }
852 :
853 : /// Change the rpath value with the given slice
854 0 : pub fn set_rpath_with_value(&mut self, values: &[&str]) {
855 0 : self.ptr.pin_mut().set_rpath(&values.join(":"));
856 0 : }
857 :
858 : /// The specified paths as a list of string
859 0 : pub fn paths(&self) -> Vec<String> {
860 0 : let mut result = Vec::new();
861 0 : for entry in self.ptr.paths().into_iter() {
862 0 : result.push(entry.to_string());
863 0 : }
864 0 : result
865 0 : }
866 :
867 : /// Insert a `path` at the given `position`
868 0 : pub fn insert(&mut self, pos: u32, path: &str) {
869 0 : self.ptr.pin_mut().insert(pos, path.to_string());
870 0 : }
871 :
872 : /// Append the given path
873 0 : pub fn append(&mut self, path: &str) {
874 0 : self.ptr.pin_mut().append(path.to_string());
875 0 : }
876 :
877 : /// The given path
878 0 : pub fn remove(&mut self, path: &str) {
879 0 : self.ptr.pin_mut().remove(path.to_string());
880 0 : }
881 : }
882 :
883 : impl FromFFI<ffi::ELF_DynamicEntryRpath> for Rpath<'_> {
884 12 : fn from_ffi(ptr: cxx::UniquePtr<ffi::ELF_DynamicEntryRpath>) -> Self {
885 12 : Self {
886 12 : ptr,
887 12 : _owner: PhantomData
888 12 : }
889 12 : }
890 : }
891 :
892 :
893 : impl DynamicEntry for Rpath<'_> {
894 12 : fn as_base(&self) -> &ffi::ELF_DynamicEntry {
895 12 : self.ptr.as_ref().unwrap().as_ref()
896 12 : }
897 :
898 0 : fn as_mut_base(&mut self) -> Pin<&mut ffi::ELF_DynamicEntry> {
899 0 : unsafe {
900 0 : Pin::new_unchecked({
901 0 : (self.ptr.as_ref().unwrap().as_ref() as *const ffi::ELF_DynamicEntry
902 0 : as *mut ffi::ELF_DynamicEntry)
903 0 : .as_mut()
904 0 : .unwrap()
905 0 : })
906 0 : }
907 0 : }
908 : }
909 :
910 : impl std::fmt::Debug for Rpath<'_> {
911 12 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
912 12 : f.debug_struct("Rpath").finish()
913 12 : }
914 : }
915 :
916 : /// Structure that represents a dynamic entry associated with the runpath info
917 : pub struct RunPath<'a> {
918 : ptr: cxx::UniquePtr<ffi::ELF_DynamicEntryRunPath>,
919 : _owner: PhantomData<&'a ffi::ELF_Binary>
920 : }
921 :
922 : impl RunPath<'_> {
923 : /// Create a new RunPath entry with the given path(s)
924 : ///
925 : /// For instance:
926 : ///
927 : /// ```
928 : /// RunPath::new("$ORIGIN/../:/lib64")
929 : /// ```
930 0 : pub fn new(value: &str) -> RunPath<'static> {
931 0 : RunPath::from_ffi(lief_ffi::ELF_DynamicEntryRunPath::create(value.to_string()))
932 0 : }
933 :
934 : /// Create a new RunPath entry from a slice of paths
935 : ///
936 : /// For instance:
937 : ///
938 : /// ```
939 : /// RunPath::with_paths(&vec!["$ORIGIN/../", "/lib64"])
940 : /// ```
941 0 : pub fn with_paths(values: &[&str]) -> RunPath<'static> {
942 0 : RunPath::new(&values.join(":"))
943 0 : }
944 :
945 12 : pub fn runpath(&self) -> String {
946 12 : self.ptr.runpath().to_string()
947 12 : }
948 :
949 : /// The specified paths as a list of string
950 0 : pub fn paths(&self) -> Vec<String> {
951 0 : let mut result = Vec::new();
952 0 : for entry in self.ptr.paths().into_iter() {
953 0 : result.push(entry.to_string());
954 0 : }
955 0 : result
956 0 : }
957 :
958 : /// Change the runpath value
959 0 : pub fn set_runpath(&mut self, value: &str) {
960 0 : self.ptr.pin_mut().set_runpath(value.to_string());
961 0 : }
962 :
963 : /// Change the runpath value with the given slice
964 0 : pub fn set_runpath_with_value(&mut self, values: &[&str]) {
965 0 : self.ptr.pin_mut().set_runpath(&values.join(":"));
966 0 : }
967 :
968 : /// Insert a `path` at the given `position`
969 0 : pub fn insert(&mut self, pos: u32, path: &str) {
970 0 : self.ptr.pin_mut().insert(pos, path.to_string());
971 0 : }
972 :
973 : /// Append the given path
974 0 : pub fn append(&mut self, path: &str) {
975 0 : self.ptr.pin_mut().append(path.to_string());
976 0 : }
977 :
978 : /// The given path
979 0 : pub fn remove(&mut self, path: &str) {
980 0 : self.ptr.pin_mut().remove(path.to_string());
981 0 : }
982 : }
983 :
984 : impl FromFFI<ffi::ELF_DynamicEntryRunPath> for RunPath<'_> {
985 12 : fn from_ffi(ptr: cxx::UniquePtr<ffi::ELF_DynamicEntryRunPath>) -> Self {
986 12 : Self {
987 12 : ptr,
988 12 : _owner: PhantomData
989 12 : }
990 12 : }
991 : }
992 :
993 :
994 : impl DynamicEntry for RunPath<'_> {
995 12 : fn as_base(&self) -> &ffi::ELF_DynamicEntry {
996 12 : self.ptr.as_ref().unwrap().as_ref()
997 12 : }
998 :
999 0 : fn as_mut_base(&mut self) -> Pin<&mut ffi::ELF_DynamicEntry> {
1000 0 : unsafe {
1001 0 : Pin::new_unchecked({
1002 0 : (self.ptr.as_ref().unwrap().as_ref() as *const ffi::ELF_DynamicEntry
1003 0 : as *mut ffi::ELF_DynamicEntry)
1004 0 : .as_mut()
1005 0 : .unwrap()
1006 0 : })
1007 0 : }
1008 0 : }
1009 : }
1010 :
1011 : impl std::fmt::Debug for RunPath<'_> {
1012 12 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1013 12 : f.debug_struct("RunPath").finish()
1014 12 : }
1015 : }
1016 :
1017 : /// Structure that represents a dynamic entry associated with the name of a library (`DT_SONAME`)
1018 : pub struct SharedObject<'a> {
1019 : ptr: cxx::UniquePtr<ffi::ELF_DynamicSharedObject>,
1020 : _owner: PhantomData<&'a ffi::ELF_Binary>
1021 : }
1022 :
1023 : impl SharedObject<'_> {
1024 0 : pub fn new(name: &str) -> SharedObject<'static> {
1025 0 : SharedObject::from_ffi(lief_ffi::ELF_DynamicSharedObject::create(name.to_string()))
1026 0 : }
1027 :
1028 12 : pub fn name(&self) -> String {
1029 12 : self.ptr.name().to_string()
1030 12 : }
1031 :
1032 0 : pub fn set_name(&mut self, name: &str) {
1033 0 : self.ptr.pin_mut().set_name(name.to_string());
1034 0 : }
1035 : }
1036 :
1037 : impl FromFFI<ffi::ELF_DynamicSharedObject> for SharedObject<'_> {
1038 12 : fn from_ffi(ptr: cxx::UniquePtr<ffi::ELF_DynamicSharedObject>) -> Self {
1039 12 : Self {
1040 12 : ptr,
1041 12 : _owner: PhantomData
1042 12 : }
1043 12 : }
1044 : }
1045 :
1046 : impl DynamicEntry for SharedObject<'_> {
1047 12 : fn as_base(&self) -> &ffi::ELF_DynamicEntry {
1048 12 : self.ptr.as_ref().unwrap().as_ref()
1049 12 : }
1050 :
1051 0 : fn as_mut_base(&mut self) -> Pin<&mut ffi::ELF_DynamicEntry> {
1052 0 : unsafe {
1053 0 : Pin::new_unchecked({
1054 0 : (self.ptr.as_ref().unwrap().as_ref() as *const ffi::ELF_DynamicEntry
1055 0 : as *mut ffi::ELF_DynamicEntry)
1056 0 : .as_mut()
1057 0 : .unwrap()
1058 0 : })
1059 0 : }
1060 0 : }
1061 : }
1062 :
1063 : impl std::fmt::Debug for SharedObject<'_> {
1064 12 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1065 12 : f.debug_struct("SharedObject").finish()
1066 12 : }
1067 : }
1068 :
1069 : /// Structure that represents a dynamic flag entry: `DT_FLAGS` or `DT_FLAGS_1`
1070 : pub struct Flags<'a> {
1071 : ptr: cxx::UniquePtr<ffi::ELF_DynamicEntryFlags>,
1072 : _owner: PhantomData<&'a ffi::ELF_Binary>
1073 : }
1074 :
1075 : impl Flags<'_> {
1076 24 : pub fn flags(&self) -> DtFlags {
1077 24 : DtFlags::from(self.ptr.flags())
1078 24 : }
1079 :
1080 0 : pub fn create_dt_flag(value: u64) -> Self {
1081 0 : Self::from_ffi(ffi::ELF_DynamicEntryFlags::create_dt_flag(value))
1082 0 : }
1083 :
1084 0 : pub fn create_dt_flag_1(value: u64) -> Self {
1085 0 : Self::from_ffi(ffi::ELF_DynamicEntryFlags::create_dt_flag_1(value))
1086 0 : }
1087 : }
1088 :
1089 : impl FromFFI<ffi::ELF_DynamicEntryFlags> for Flags<'_> {
1090 24 : fn from_ffi(ptr: cxx::UniquePtr<ffi::ELF_DynamicEntryFlags>) -> Self {
1091 24 : Self {
1092 24 : ptr,
1093 24 : _owner: PhantomData
1094 24 : }
1095 24 : }
1096 : }
1097 :
1098 : impl DynamicEntry for Flags<'_> {
1099 24 : fn as_base(&self) -> &ffi::ELF_DynamicEntry {
1100 24 : self.ptr.as_ref().unwrap().as_ref()
1101 24 : }
1102 :
1103 0 : fn as_mut_base(&mut self) -> Pin<&mut ffi::ELF_DynamicEntry> {
1104 0 : unsafe {
1105 0 : Pin::new_unchecked({
1106 0 : (self.ptr.as_ref().unwrap().as_ref() as *const ffi::ELF_DynamicEntry
1107 0 : as *mut ffi::ELF_DynamicEntry)
1108 0 : .as_mut()
1109 0 : .unwrap()
1110 0 : })
1111 0 : }
1112 0 : }
1113 : }
1114 :
1115 : impl std::fmt::Debug for Flags<'_> {
1116 24 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1117 24 : f.debug_struct("Flags").finish()
1118 24 : }
1119 : }
1120 :
1121 :
1122 0 : bitflags! {
1123 24 : #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1124 0 : pub struct DtFlags: u64 {
1125 0 : const ORIGIN = 0x1;
1126 0 : const SYMBOLIC = 0x2;
1127 0 : const TEXTREL = 0x4;
1128 0 : const BIND_NOW = 0x8;
1129 0 : const STATIC_TLS = 0x10;
1130 0 : const NOW = 0x100000001;
1131 0 : const GLOBAL = 0x100000002;
1132 0 : const GROUP = 0x100000004;
1133 0 : const NODELETE = 0x100000008;
1134 0 : const LOADFLTR = 0x100000010;
1135 0 : const INITFIRST = 0x100000020;
1136 0 : const NOOPEN = 0x100000040;
1137 0 : const HANDLE_ORIGIN = 0x100000080;
1138 0 : const DIRECT = 0x100000100;
1139 0 : const TRANS = 0x100000200;
1140 0 : const INTERPOSE = 0x100000400;
1141 0 : const NODEFLIB = 0x100000800;
1142 0 : const NODUMP = 0x100001000;
1143 0 : const CONFALT = 0x100002000;
1144 0 : const ENDFILTEE = 0x100004000;
1145 0 : const DISPRELDNE = 0x100008000;
1146 0 : const DISPRELPND = 0x100010000;
1147 0 : const NODIRECT = 0x100020000;
1148 0 : const IGNMULDEF = 0x100040000;
1149 0 : const NOKSYMS = 0x100080000;
1150 0 : const NOHDR = 0x100100000;
1151 0 : const EDITED = 0x100200000;
1152 0 : const NORELOC = 0x100400000;
1153 0 : const SYMINTPOSE = 0x100800000;
1154 0 : const GLOBAUDIT = 0x101000000;
1155 0 : const SINGLETON = 0x102000000;
1156 0 : const PIE = 0x108000000;
1157 0 : const KMOD = 0x110000000;
1158 0 : const WEAKFILTER = 0x120000000;
1159 0 : const NOCOMMON = 0x140000000;
1160 0 : }
1161 0 : }
1162 :
1163 :
1164 : impl From<u64> for DtFlags {
1165 24 : fn from(value: u64) -> Self {
1166 24 : DtFlags::from_bits_truncate(value)
1167 24 : }
1168 : }
1169 : impl From<DtFlags> for u64 {
1170 0 : fn from(value: DtFlags) -> Self {
1171 0 : value.bits()
1172 0 : }
1173 : }
1174 : impl std::fmt::Display for DtFlags {
1175 0 : fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1176 0 : bitflags::parser::to_writer(self, f)
1177 0 : }
1178 : }
1179 :
1180 1788 : declare_iterator!(DynamicEntries, Entries<'a>, ffi::ELF_DynamicEntry, ffi::ELF_Binary, ffi::ELF_Binary_it_dynamic_entries);
|