LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
DynamicEntry.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 Quarkslab
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef LIEF_ELF_DYNAMIC_ENTRY_H
17#define LIEF_ELF_DYNAMIC_ENTRY_H
18
19#include <ostream>
20#include <memory>
21#include <cstdint>
22
23#include "LIEF/visibility.h"
24#include "LIEF/Object.hpp"
25#include "LIEF/ELF/enums.hpp"
26
27namespace LIEF {
28namespace ELF {
29namespace details {
30struct Elf64_Dyn;
31struct Elf32_Dyn;
32}
33class LIEF_API DynamicEntry : public Object {
37 public:
38 static constexpr uint64_t MIPS_DISC = 0x100000000;
39 static constexpr uint64_t AARCH64_DISC = 0x200000000;
40 static constexpr uint64_t HEXAGON_DISC = 0x300000000;
41 static constexpr uint64_t PPC_DISC = 0x400000000;
42 static constexpr uint64_t PPC64_DISC = 0x500000000;
43 static constexpr uint64_t RISCV_DISC = 0x600000000;
44 static constexpr uint64_t X86_64_DISC = 0x700000000;
45 static constexpr uint64_t IA_64_DISC = 0x800000000;
46
47 enum class TAG : uint64_t {
48 UNKNOWN = uint64_t(-1),
49 DT_NULL_ = 0,
50 NEEDED = 1,
51 PLTRELSZ = 2,
52 PLTGOT = 3,
53 HASH = 4,
54 STRTAB = 5,
55 SYMTAB = 6,
56 RELA = 7,
57 RELASZ = 8,
58 RELAENT = 9,
59 STRSZ = 10,
60 SYMENT = 11,
61 INIT = 12,
62 FINI = 13,
63 SONAME = 14,
64 RPATH = 15,
65 SYMBOLIC = 16,
66 REL = 17,
67 RELSZ = 18,
68 RELENT = 19,
69 PLTREL = 20,
70 DEBUG_TAG = 21,
71 TEXTREL = 22,
72 JMPREL = 23,
73 BIND_NOW = 24,
74 INIT_ARRAY = 25,
75 FINI_ARRAY = 26,
76 INIT_ARRAYSZ = 27,
77 FINI_ARRAYSZ = 28,
78 RUNPATH = 29,
79 FLAGS = 30,
80 PREINIT_ARRAY = 32,
81 PREINIT_ARRAYSZ = 33,
82 SYMTAB_SHNDX = 34,
83 RELRSZ = 35,
84 RELR = 36,
85 RELRENT = 37,
86
87 // GNU Extensions
88 GNU_HASH = 0x6FFFFEF5,
89 RELACOUNT = 0x6FFFFFF9,
90 RELCOUNT = 0x6FFFFFFA,
91 FLAGS_1 = 0x6FFFFFFB,
92 VERSYM = 0x6FFFFFF0,
93 VERDEF = 0x6FFFFFFC,
94 VERDEFNUM = 0x6FFFFFFD,
95 VERNEED = 0x6FFFFFFE,
96 VERNEEDNUM = 0x6FFFFFFF,
97
98 // Android Extensions
99 ANDROID_REL_OFFSET = 0x6000000D,
100 ANDROID_REL_SIZE = 0x6000000E,
101 ANDROID_REL = 0x6000000F,
102 ANDROID_RELSZ = 0x60000010,
103 ANDROID_RELA = 0x60000011,
104 ANDROID_RELASZ = 0x60000012,
105 ANDROID_RELR = 0x6FFFE000,
106 ANDROID_RELRSZ = 0x6FFFE001,
107 ANDROID_RELRENT = 0x6FFFE003,
108 ANDROID_RELRCOUNT = 0x6FFFE005,
109
110 /* Mips specific dynamic table entry tags. */
111 MIPS_RLD_VERSION = MIPS_DISC + 0x70000001,
112 MIPS_TIME_STAMP = MIPS_DISC + 0x70000002,
113 MIPS_ICHECKSUM = MIPS_DISC + 0x70000003,
114 MIPS_IVERSION = MIPS_DISC + 0x70000004,
115 MIPS_FLAGS = MIPS_DISC + 0x70000005,
116 MIPS_BASE_ADDRESS = MIPS_DISC + 0x70000006,
117 MIPS_MSYM = MIPS_DISC + 0x70000007,
118 MIPS_CONFLICT = MIPS_DISC + 0x70000008,
119 MIPS_LIBLIST = MIPS_DISC + 0x70000009,
120 MIPS_LOCAL_GOTNO = MIPS_DISC + 0x7000000a,
121 MIPS_CONFLICTNO = MIPS_DISC + 0x7000000b,
122 MIPS_LIBLISTNO = MIPS_DISC + 0x70000010,
123 MIPS_SYMTABNO = MIPS_DISC + 0x70000011,
124 MIPS_UNREFEXTNO = MIPS_DISC + 0x70000012,
125 MIPS_GOTSYM = MIPS_DISC + 0x70000013,
126 MIPS_HIPAGENO = MIPS_DISC + 0x70000014,
127 MIPS_RLD_MAP = MIPS_DISC + 0x70000016,
128 MIPS_DELTA_CLASS = MIPS_DISC + 0x70000017,
129 MIPS_DELTA_CLASS_NO = MIPS_DISC + 0x70000018,
130 MIPS_DELTA_INSTANCE = MIPS_DISC + 0x70000019,
131 MIPS_DELTA_INSTANCE_NO = MIPS_DISC + 0x7000001A,
132 MIPS_DELTA_RELOC = MIPS_DISC + 0x7000001B,
133 MIPS_DELTA_RELOC_NO = MIPS_DISC + 0x7000001C,
134 MIPS_DELTA_SYM = MIPS_DISC + 0x7000001D,
135 MIPS_DELTA_SYM_NO = MIPS_DISC + 0x7000001E,
136 MIPS_DELTA_CLASSSYM = MIPS_DISC + 0x70000020,
137 MIPS_DELTA_CLASSSYM_NO = MIPS_DISC + 0x70000021,
138 MIPS_CXX_FLAGS = MIPS_DISC + 0x70000022,
139 MIPS_PIXIE_INIT = MIPS_DISC + 0x70000023,
140 MIPS_SYMBOL_LIB = MIPS_DISC + 0x70000024,
141 MIPS_LOCALPAGE_GOTIDX = MIPS_DISC + 0x70000025,
142 MIPS_LOCAL_GOTIDX = MIPS_DISC + 0x70000026,
143 MIPS_HIDDEN_GOTIDX = MIPS_DISC + 0x70000027,
144 MIPS_PROTECTED_GOTIDX = MIPS_DISC + 0x70000028,
145 MIPS_OPTIONS = MIPS_DISC + 0x70000029,
146 MIPS_INTERFACE = MIPS_DISC + 0x7000002A,
147 MIPS_DYNSTR_ALIGN = MIPS_DISC + 0x7000002B,
148 MIPS_INTERFACE_SIZE = MIPS_DISC + 0x7000002C,
149 MIPS_RLD_TEXT_RESOLVE_ADDR = MIPS_DISC + 0x7000002D,
150 MIPS_PERF_SUFFIX = MIPS_DISC + 0x7000002E,
151 MIPS_COMPACT_SIZE = MIPS_DISC + 0x7000002F,
152 MIPS_GP_VALUE = MIPS_DISC + 0x70000030,
153 MIPS_AUX_DYNAMIC = MIPS_DISC + 0x70000031,
154 MIPS_PLTGOT = MIPS_DISC + 0x70000032,
155 MIPS_RWPLT = MIPS_DISC + 0x70000034,
156 MIPS_RLD_MAP_REL = MIPS_DISC + 0x70000035,
157 MIPS_XHASH = MIPS_DISC + 0x70000036,
158
159 AARCH64_BTI_PLT = AARCH64_DISC + 0x70000001,
160 AARCH64_PAC_PLT = AARCH64_DISC + 0x70000003,
161 AARCH64_VARIANT_PCS = AARCH64_DISC + 0x70000005,
162 AARCH64_MEMTAG_MODE = AARCH64_DISC + 0x70000009,
163 AARCH64_MEMTAG_HEAP = AARCH64_DISC + 0x7000000b,
164 AARCH64_MEMTAG_STACK = AARCH64_DISC + 0x7000000c,
165 AARCH64_MEMTAG_GLOBALS = AARCH64_DISC + 0x7000000d,
166 AARCH64_MEMTAG_GLOBALSSZ = AARCH64_DISC + 0x7000000f,
167
168 HEXAGON_SYMSZ = HEXAGON_DISC + 0x70000000,
169 HEXAGON_VER = HEXAGON_DISC + 0x70000001,
170 HEXAGON_PLT = HEXAGON_DISC + 0x70000002,
171
172 PPC_GOT = PPC_DISC + 0x70000000,
173 PPC_OPT = PPC_DISC + 0x70000001,
174
175 PPC64_GLINK = PPC64_DISC + 0x70000000,
176 PPC64_OPT = PPC64_DISC + 0x70000003,
177
178 RISCV_VARIANT_CC = RISCV_DISC + 0x70000003,
179
180 X86_64_PLT = X86_64_DISC + 0x70000000,
181 X86_64_PLTSZ = X86_64_DISC + 0x70000001,
182 X86_64_PLTENT = X86_64_DISC + 0x70000003,
183
184 IA_64_PLT_RESERVE = IA_64_DISC + (0x70000000 + 0),
185 IA_64_VMS_SUBTYPE = IA_64_DISC + (0x60000000 + 0),
186 IA_64_VMS_IMGIOCNT = IA_64_DISC + (0x60000000 + 2),
187 IA_64_VMS_LNKFLAGS = IA_64_DISC + (0x60000000 + 8),
188 IA_64_VMS_VIR_MEM_BLK_SIZ = IA_64_DISC + (0x60000000 + 10),
189 IA_64_VMS_IDENT = IA_64_DISC + (0x60000000 + 12),
190 IA_64_VMS_NEEDED_IDENT = IA_64_DISC + (0x60000000 + 16),
191 IA_64_VMS_IMG_RELA_CNT = IA_64_DISC + (0x60000000 + 18),
192 IA_64_VMS_SEG_RELA_CNT = IA_64_DISC + (0x60000000 + 20),
193 IA_64_VMS_FIXUP_RELA_CNT = IA_64_DISC + (0x60000000 + 22),
194 IA_64_VMS_FIXUP_NEEDED = IA_64_DISC + (0x60000000 + 24),
195 IA_64_VMS_SYMVEC_CNT = IA_64_DISC + (0x60000000 + 26),
196 IA_64_VMS_XLATED = IA_64_DISC + (0x60000000 + 30),
197 IA_64_VMS_STACKSIZE = IA_64_DISC + (0x60000000 + 32),
198 IA_64_VMS_UNWINDSZ = IA_64_DISC + (0x60000000 + 34),
199 IA_64_VMS_UNWIND_CODSEG = IA_64_DISC + (0x60000000 + 36),
200 IA_64_VMS_UNWIND_INFOSEG = IA_64_DISC + (0x60000000 + 38),
201 IA_64_VMS_LINKTIME = IA_64_DISC + (0x60000000 + 40),
202 IA_64_VMS_SEG_NO = IA_64_DISC + (0x60000000 + 42),
203 IA_64_VMS_SYMVEC_OFFSET = IA_64_DISC + (0x60000000 + 44),
204 IA_64_VMS_SYMVEC_SEG = IA_64_DISC + (0x60000000 + 46),
205 IA_64_VMS_UNWIND_OFFSET = IA_64_DISC + (0x60000000 + 48),
206 IA_64_VMS_UNWIND_SEG = IA_64_DISC + (0x60000000 + 50),
207 IA_64_VMS_STRTAB_OFFSET = IA_64_DISC + (0x60000000 + 52),
208 IA_64_VMS_SYSVER_OFFSET = IA_64_DISC + (0x60000000 + 54),
209 IA_64_VMS_IMG_RELA_OFF = IA_64_DISC + (0x60000000 + 56),
210 IA_64_VMS_SEG_RELA_OFF = IA_64_DISC + (0x60000000 + 58),
211 IA_64_VMS_FIXUP_RELA_OFF = IA_64_DISC + (0x60000000 + 60),
212 IA_64_VMS_PLTGOT_OFFSET = IA_64_DISC + (0x60000000 + 62),
213 IA_64_VMS_PLTGOT_SEG = IA_64_DISC + (0x60000000 + 64),
214 IA_64_VMS_FPMODE = IA_64_DISC + (0x60000000 + 66),
215 };
216
217 static TAG from_value(uint64_t value, ARCH arch);
218 static uint64_t to_value(TAG tag);
219
220 DynamicEntry() = default;
221 DynamicEntry(const details::Elf64_Dyn& header, ARCH arch);
222 DynamicEntry(const details::Elf32_Dyn& header, ARCH arch);
223
224 DynamicEntry(TAG tag, uint64_t value) :
225 tag_(tag), value_(value)
226 {}
227
228 DynamicEntry& operator=(const DynamicEntry&) = default;
229 DynamicEntry(const DynamicEntry&) = default;
230 ~DynamicEntry() override = default;
231
232 virtual std::unique_ptr<DynamicEntry> clone() const {
233 return std::unique_ptr<DynamicEntry>(new DynamicEntry(*this));
234 }
235 TAG tag() const {
239 return tag_;
240 }
241 uint64_t value() const {
247 return value_;
248 }
249
250 void tag(TAG tag) {
251 tag_ = tag;
252 }
253
254 void value(uint64_t value) {
255 value_ = value;
256 }
257
258 void accept(Visitor& visitor) const override;
259
260 virtual std::ostream& print(std::ostream& os) const;
261
262 LIEF_API friend
263 std::ostream& operator<<(std::ostream& os, const DynamicEntry& entry) {
264 return entry.print(os);
265 }
266
267 template<class T>
268 const T* cast() const {
269 static_assert(std::is_base_of<DynamicEntry, T>::value,
270 "Require DynamicEntry inheritance");
271 if (T::classof(this)) {
272 return static_cast<const T*>(this);
273 }
274 return nullptr;
275 }
276
277 template<class T>
278 T* cast() {
279 return const_cast<T*>(static_cast<const DynamicEntry*>(this)->cast<T>());
280 }
281
282 protected:
283 TAG tag_ = TAG::DT_NULL_;
284 uint64_t value_ = 0;
285};
286
287LIEF_API const char* to_string(DynamicEntry::TAG e);
288
289}
290}
291#endif
enums.hpp
Object.hpp
LIEF::ELF::DynamicEntry
Class which represents an entry in the dynamic table These entries are located in the ....
Definition DynamicEntry.hpp:36
LIEF::ELF::DynamicEntry::DynamicEntry
DynamicEntry(const details::Elf32_Dyn &header, ARCH arch)
LIEF::ELF::DynamicEntry::DynamicEntry
DynamicEntry(const details::Elf64_Dyn &header, ARCH arch)
LIEF::ELF::DynamicEntry::TAG
TAG
Definition DynamicEntry.hpp:47
LIEF::ELF::DynamicEntry::cast
const T * cast() const
Definition DynamicEntry.hpp:268
LIEF::ELF::DynamicEntry::print
virtual std::ostream & print(std::ostream &os) const
LIEF::ELF::DynamicEntry::tag
void tag(TAG tag)
Definition DynamicEntry.hpp:250
LIEF::ELF::DynamicEntry::clone
virtual std::unique_ptr< DynamicEntry > clone() const
Definition DynamicEntry.hpp:232
LIEF::ELF::DynamicEntry::~DynamicEntry
~DynamicEntry() override=default
LIEF::ELF::DynamicEntry::operator=
DynamicEntry & operator=(const DynamicEntry &)=default
LIEF::ELF::DynamicEntry::accept
void accept(Visitor &visitor) const override
LIEF::ELF::DynamicEntry::to_value
static uint64_t to_value(TAG tag)
LIEF::ELF::DynamicEntry::tag
TAG tag() const
Tag of the current entry. The most common tags are: DT_NEEDED, DT_INIT, ...
Definition DynamicEntry.hpp:238
LIEF::ELF::DynamicEntry::value
void value(uint64_t value)
Definition DynamicEntry.hpp:254
LIEF::ELF::DynamicEntry::cast
T * cast()
Definition DynamicEntry.hpp:278
LIEF::ELF::DynamicEntry::value
uint64_t value() const
Return the entry's value.
Definition DynamicEntry.hpp:246
LIEF::ELF::DynamicEntry::operator<<
friend std::ostream & operator<<(std::ostream &os, const DynamicEntry &entry)
Definition DynamicEntry.hpp:263
LIEF::ELF::DynamicEntry::from_value
static TAG from_value(uint64_t value, ARCH arch)
LIEF::ELF::DynamicEntry::DynamicEntry
DynamicEntry(const DynamicEntry &)=default
LIEF::ELF::DynamicEntry::DynamicEntry
DynamicEntry(TAG tag, uint64_t value)
Definition DynamicEntry.hpp:224
LIEF::ELF::DynamicEntry::DynamicEntry
DynamicEntry()=default
LIEF::ELF::details
Definition DynamicEntry.hpp:29
LIEF::ELF
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
LIEF::ELF::to_string
const char * to_string(DynamicEntry::TAG e)
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41