Line data Source code
1 : use lief_ffi as ffi;
2 :
3 : /// Structure used to configure the [`crate::elf::Binary::write_with_config`] operation
4 0 : #[derive(Debug)]
5 : pub struct Config {
6 : /// Rebuild `DT_HASH`
7 : pub dt_hash: bool,
8 :
9 : /// Rebuild `DT_STRTAB`
10 : pub dyn_str: bool,
11 :
12 : /// Rebuild `PT_DYNAMIC` segment
13 : pub dynamic_section: bool,
14 :
15 : /// Rebuild `DT_FINI_ARRAY`
16 : pub fini_array: bool,
17 :
18 : /// Rebuild `DT_GNU_HASH`
19 : pub gnu_hash: bool,
20 :
21 : /// Rebuild `DT_INIT_ARRAY`
22 : pub init_array: bool,
23 :
24 : /// Rebuild `PT_INTERPRETER`
25 : pub interpreter: bool,
26 :
27 : /// Rebuild `DT_JMPREL`
28 : pub jmprel: bool,
29 :
30 : /// Rebuild notes sections
31 : pub notes: bool,
32 :
33 : /// Rebuild `DT_PREINIT_ARRAY`
34 : pub preinit_array: bool,
35 :
36 : /// Rebuild `DT_RELR`
37 : pub relr: bool,
38 :
39 : /// Rebuild `DT_ANDROID_REL[A]`
40 : pub android_rela: bool,
41 :
42 : /// Rebuild `DT_REL[A]`
43 : pub rela: bool,
44 :
45 : /// Rebuild `.symtab`
46 : pub static_symtab: bool,
47 :
48 : /// Rebuild `DT_VERDEF`
49 : pub sym_verdef: bool,
50 :
51 : /// Rebuild `DT_VERNEED`
52 : pub sym_verneed: bool,
53 :
54 : /// Rebuild `DT_VERSYM`
55 : pub sym_versym: bool,
56 :
57 : /// Rebuild `DT_SYMTAB`
58 : pub symtab: bool,
59 :
60 : /// Rebuild the Coredump notes
61 : pub coredump_notes: bool,
62 :
63 : /// Force to relocating all the ELF structures that are supported by LIEF (mostly for testing)
64 : pub force_relocate: bool,
65 :
66 : /// Remove entries in `.gnu.version_r` if they are not associated with at least one version
67 : pub keep_empty_version_requirement: bool,
68 :
69 : /// Skip relocating the `PT_DYNAMIC` segment (only relevant if [`Config::keep_empty_version_requirement`] is set)
70 : pub skip_dynamic: bool,
71 : }
72 :
73 : impl Default for Config {
74 12 : fn default() -> Config {
75 12 : Config {
76 12 : dt_hash: true,
77 12 : dyn_str: true,
78 12 : dynamic_section: true,
79 12 : fini_array: true,
80 12 : gnu_hash: true,
81 12 : init_array: true,
82 12 : interpreter: true,
83 12 : jmprel: true,
84 12 : notes: false,
85 12 : preinit_array: true,
86 12 : relr: true,
87 12 : android_rela: true,
88 12 : rela: true,
89 12 : static_symtab: true,
90 12 : sym_verdef: true,
91 12 : sym_verneed: true,
92 12 : sym_versym: true,
93 12 : symtab: true,
94 12 : coredump_notes: true,
95 12 : force_relocate: false,
96 12 : keep_empty_version_requirement: false,
97 12 : skip_dynamic: false,
98 12 : }
99 12 : }
100 : }
101 :
102 : impl Config {
103 : #[doc(hidden)]
104 12 : pub fn to_ffi(&self) -> ffi::ELF_Binary_write_config_t {
105 12 : ffi::ELF_Binary_write_config_t {
106 12 : dt_hash: self.dt_hash,
107 12 : dyn_str: self.dyn_str,
108 12 : dynamic_section: self.dynamic_section,
109 12 : fini_array: self.fini_array,
110 12 : gnu_hash: self.gnu_hash,
111 12 : init_array: self.init_array,
112 12 : interpreter: self.interpreter,
113 12 : jmprel: self.jmprel,
114 12 : notes: self.notes,
115 12 : preinit_array: self.preinit_array,
116 12 : relr: self.relr,
117 12 : android_rela: self.android_rela,
118 12 : rela: self.rela,
119 12 : static_symtab: self.static_symtab,
120 12 : sym_verdef: self.sym_verdef,
121 12 : sym_verneed: self.sym_verneed,
122 12 : sym_versym: self.sym_versym,
123 12 : symtab: self.symtab,
124 12 : coredump_notes: self.coredump_notes,
125 12 : force_relocate: self.force_relocate,
126 12 : keep_empty_version_requirement: self.keep_empty_version_requirement,
127 12 : skip_dynamic: self.skip_dynamic
128 12 : }
129 12 : }
130 : }
131 :
132 :
|