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 - 2024 R. Thomas
2 * Copyright 2017 - 2024 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
46 enum class TAG : uint64_t {
47 UNKNOWN = uint64_t(-1),
48 DT_NULL_ = 0,
49 NEEDED = 1,
50 PLTRELSZ = 2,
51 PLTGOT = 3,
52 HASH = 4,
53 STRTAB = 5,
54 SYMTAB = 6,
55 RELA = 7,
56 RELASZ = 8,
57 RELAENT = 9,
58 STRSZ = 10,
59 SYMENT = 11,
60 INIT = 12,
61 FINI = 13,
62 SONAME = 14,
63 RPATH = 15,
64 SYMBOLIC = 16,
65 REL = 17,
66 RELSZ = 18,
67 RELENT = 19,
68 PLTREL = 20,
69 DEBUG_TAG = 21,
70 TEXTREL = 22,
71 JMPREL = 23,
72 BIND_NOW = 24,
73 INIT_ARRAY = 25,
74 FINI_ARRAY = 26,
75 INIT_ARRAYSZ = 27,
76 FINI_ARRAYSZ = 28,
77 RUNPATH = 29,
78 FLAGS = 30,
79 PREINIT_ARRAY = 32,
80 PREINIT_ARRAYSZ = 33,
81 SYMTAB_SHNDX = 34,
82 RELRSZ = 35,
83 RELR = 36,
84 RELRENT = 37,
85
86 // GNU Extensions
87 GNU_HASH = 0x6FFFFEF5,
88 RELACOUNT = 0x6FFFFFF9,
89 RELCOUNT = 0x6FFFFFFA,
90 FLAGS_1 = 0x6FFFFFFB,
91 VERSYM = 0x6FFFFFF0,
92 VERDEF = 0x6FFFFFFC,
93 VERDEFNUM = 0x6FFFFFFD,
94 VERNEED = 0x6FFFFFFE,
95 VERNEEDNUM = 0x6FFFFFFF,
96
97 // Android Extensions
98 ANDROID_REL_OFFSET = 0x6000000D,
99 ANDROID_REL_SIZE = 0x6000000E,
100 ANDROID_REL = 0x6000000F,
101 ANDROID_RELSZ = 0x60000010,
102 ANDROID_RELA = 0x60000011,
103 ANDROID_RELASZ = 0x60000012,
104 ANDROID_RELR = 0x6FFFE000,
105 ANDROID_RELRSZ = 0x6FFFE001,
106 ANDROID_RELRENT = 0x6FFFE003,
107 ANDROID_RELRCOUNT = 0x6FFFE005,
108
109 /* Mips specific dynamic table entry tags. */
110 MIPS_RLD_VERSION = MIPS_DISC + 0x70000001,
111 MIPS_TIME_STAMP = MIPS_DISC + 0x70000002,
112 MIPS_ICHECKSUM = MIPS_DISC + 0x70000003,
113 MIPS_IVERSION = MIPS_DISC + 0x70000004,
114 MIPS_FLAGS = MIPS_DISC + 0x70000005,
115 MIPS_BASE_ADDRESS = MIPS_DISC + 0x70000006,
116 MIPS_MSYM = MIPS_DISC + 0x70000007,
117 MIPS_CONFLICT = MIPS_DISC + 0x70000008,
118 MIPS_LIBLIST = MIPS_DISC + 0x70000009,
119 MIPS_LOCAL_GOTNO = MIPS_DISC + 0x7000000a,
120 MIPS_CONFLICTNO = MIPS_DISC + 0x7000000b,
121 MIPS_LIBLISTNO = MIPS_DISC + 0x70000010,
122 MIPS_SYMTABNO = MIPS_DISC + 0x70000011,
123 MIPS_UNREFEXTNO = MIPS_DISC + 0x70000012,
124 MIPS_GOTSYM = MIPS_DISC + 0x70000013,
125 MIPS_HIPAGENO = MIPS_DISC + 0x70000014,
126 MIPS_RLD_MAP = MIPS_DISC + 0x70000016,
127 MIPS_DELTA_CLASS = MIPS_DISC + 0x70000017,
128 MIPS_DELTA_CLASS_NO = MIPS_DISC + 0x70000018,
129 MIPS_DELTA_INSTANCE = MIPS_DISC + 0x70000019,
130 MIPS_DELTA_INSTANCE_NO = MIPS_DISC + 0x7000001A,
131 MIPS_DELTA_RELOC = MIPS_DISC + 0x7000001B,
132 MIPS_DELTA_RELOC_NO = MIPS_DISC + 0x7000001C,
133 MIPS_DELTA_SYM = MIPS_DISC + 0x7000001D,
134 MIPS_DELTA_SYM_NO = MIPS_DISC + 0x7000001E,
135 MIPS_DELTA_CLASSSYM = MIPS_DISC + 0x70000020,
136 MIPS_DELTA_CLASSSYM_NO = MIPS_DISC + 0x70000021,
137 MIPS_CXX_FLAGS = MIPS_DISC + 0x70000022,
138 MIPS_PIXIE_INIT = MIPS_DISC + 0x70000023,
139 MIPS_SYMBOL_LIB = MIPS_DISC + 0x70000024,
140 MIPS_LOCALPAGE_GOTIDX = MIPS_DISC + 0x70000025,
141 MIPS_LOCAL_GOTIDX = MIPS_DISC + 0x70000026,
142 MIPS_HIDDEN_GOTIDX = MIPS_DISC + 0x70000027,
143 MIPS_PROTECTED_GOTIDX = MIPS_DISC + 0x70000028,
144 MIPS_OPTIONS = MIPS_DISC + 0x70000029,
145 MIPS_INTERFACE = MIPS_DISC + 0x7000002A,
146 MIPS_DYNSTR_ALIGN = MIPS_DISC + 0x7000002B,
147 MIPS_INTERFACE_SIZE = MIPS_DISC + 0x7000002C,
148 MIPS_RLD_TEXT_RESOLVE_ADDR = MIPS_DISC + 0x7000002D,
149 MIPS_PERF_SUFFIX = MIPS_DISC + 0x7000002E,
150 MIPS_COMPACT_SIZE = MIPS_DISC + 0x7000002F,
151 MIPS_GP_VALUE = MIPS_DISC + 0x70000030,
152 MIPS_AUX_DYNAMIC = MIPS_DISC + 0x70000031,
153 MIPS_PLTGOT = MIPS_DISC + 0x70000032,
154 MIPS_RWPLT = MIPS_DISC + 0x70000034,
155 MIPS_RLD_MAP_REL = MIPS_DISC + 0x70000035,
156 MIPS_XHASH = MIPS_DISC + 0x70000036,
157
158 AARCH64_BTI_PLT = AARCH64_DISC + 0x70000001,
159 AARCH64_PAC_PLT = AARCH64_DISC + 0x70000003,
160 AARCH64_VARIANT_PCS = AARCH64_DISC + 0x70000005,
161 AARCH64_MEMTAG_MODE = AARCH64_DISC + 0x70000009,
162 AARCH64_MEMTAG_HEAP = AARCH64_DISC + 0x7000000b,
163 AARCH64_MEMTAG_STACK = AARCH64_DISC + 0x7000000c,
164 AARCH64_MEMTAG_GLOBALS = AARCH64_DISC + 0x7000000d,
165 AARCH64_MEMTAG_GLOBALSSZ = AARCH64_DISC + 0x7000000f,
166
167 HEXAGON_SYMSZ = HEXAGON_DISC + 0x70000000,
168 HEXAGON_VER = HEXAGON_DISC + 0x70000001,
169 HEXAGON_PLT = HEXAGON_DISC + 0x70000002,
170
171 PPC_GOT = PPC_DISC + 0x70000000,
172 PPC_OPT = PPC_DISC + 0x70000001,
173
174 PPC64_GLINK = PPC64_DISC + 0x70000000,
175 PPC64_OPT = PPC64_DISC + 0x70000003,
176
177 RISCV_VARIANT_CC = RISCV_DISC + 0x70000003,
178
179 X86_64_PLT = X86_64_DISC + 0x70000000,
180 X86_64_PLTSZ = X86_64_DISC + 0x70000001,
181 X86_64_PLTENT = X86_64_DISC + 0x70000003,
182 };
183
184 static TAG from_value(uint64_t value, ARCH arch);
185 static uint64_t to_value(TAG tag);
186
187 DynamicEntry() = default;
188 DynamicEntry(const details::Elf64_Dyn& header, ARCH arch);
189 DynamicEntry(const details::Elf32_Dyn& header, ARCH arch);
190
191 DynamicEntry(TAG tag, uint64_t value) :
192 tag_(tag), value_(value)
193 {}
194
195 DynamicEntry& operator=(const DynamicEntry&) = default;
196 DynamicEntry(const DynamicEntry&) = default;
197 ~DynamicEntry() override = default;
198
199 virtual std::unique_ptr<DynamicEntry> clone() const {
200 return std::unique_ptr<DynamicEntry>(new DynamicEntry(*this));
201 }
202 TAG tag() const {
206 return tag_;
207 }
208 uint64_t value() const {
214 return value_;
215 }
216
217 void tag(TAG tag) {
218 tag_ = tag;
219 }
220
221 void value(uint64_t value) {
222 value_ = value;
223 }
224
225 void accept(Visitor& visitor) const override;
226
227 virtual std::ostream& print(std::ostream& os) const;
228
229 LIEF_API friend
230 std::ostream& operator<<(std::ostream& os, const DynamicEntry& entry) {
231 return entry.print(os);
232 }
233
234 template<class T>
235 const T* cast() const {
236 static_assert(std::is_base_of<DynamicEntry, T>::value,
237 "Require DynamicEntry inheritance");
238 if (T::classof(this)) {
239 return static_cast<const T*>(this);
240 }
241 return nullptr;
242 }
243
244 template<class T>
245 T* cast() {
246 return const_cast<T*>(static_cast<const DynamicEntry*>(this)->cast<T>());
247 }
248
249 protected:
250 TAG tag_ = TAG::DT_NULL_;
251 uint64_t value_ = 0;
252};
253
254LIEF_API const char* to_string(DynamicEntry::TAG e);
255
256}
257}
258#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:46
LIEF::ELF::DynamicEntry::cast
const T * cast() const
Definition DynamicEntry.hpp:235
LIEF::ELF::DynamicEntry::print
virtual std::ostream & print(std::ostream &os) const
LIEF::ELF::DynamicEntry::tag
void tag(TAG tag)
Definition DynamicEntry.hpp:217
LIEF::ELF::DynamicEntry::clone
virtual std::unique_ptr< DynamicEntry > clone() const
Definition DynamicEntry.hpp:199
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:205
LIEF::ELF::DynamicEntry::value
void value(uint64_t value)
Definition DynamicEntry.hpp:221
LIEF::ELF::DynamicEntry::cast
T * cast()
Definition DynamicEntry.hpp:245
LIEF::ELF::DynamicEntry::value
uint64_t value() const
Return the entry's value.
Definition DynamicEntry.hpp:213
LIEF::ELF::DynamicEntry::operator<<
friend std::ostream & operator<<(std::ostream &os, const DynamicEntry &entry)
Definition DynamicEntry.hpp:230
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:191
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