LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
DynamicEntry.hpp
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 <string>
20#include <ostream>
21#include <memory>
22#include <cstdint>
23
24#include "LIEF/visibility.h"
25#include "LIEF/Object.hpp"
26#include "LIEF/ELF/enums.hpp"
27
28namespace LIEF {
29namespace ELF {
30namespace details {
31struct Elf64_Dyn;
32struct Elf32_Dyn;
33}
34
37class LIEF_API DynamicEntry : public Object {
38 public:
39 static constexpr uint64_t MIPS_DISC = 0x100000000;
40 static constexpr uint64_t AARCH64_DISC = 0x200000000;
41 static constexpr uint64_t HEXAGON_DISC = 0x300000000;
42 static constexpr uint64_t PPC_DISC = 0x400000000;
43 static constexpr uint64_t PPC64_DISC = 0x500000000;
44 static constexpr uint64_t RISCV_DISC = 0x600000000;
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 = 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,
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,
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,
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
180 static TAG from_value(uint64_t value, ARCH arch);
181 static uint64_t to_value(TAG tag);
182
183 DynamicEntry() = default;
184 DynamicEntry(const details::Elf64_Dyn& header, ARCH arch);
185 DynamicEntry(const details::Elf32_Dyn& header, ARCH arch);
186
187 DynamicEntry(TAG tag, uint64_t value) :
188 tag_(tag), value_(value)
189 {}
190
191 DynamicEntry& operator=(const DynamicEntry&) = default;
192 DynamicEntry(const DynamicEntry&) = default;
193 ~DynamicEntry() override = default;
194
195 virtual std::unique_ptr<DynamicEntry> clone() const {
196 return std::unique_ptr<DynamicEntry>(new DynamicEntry(*this));
197 }
198
201 TAG tag() const {
202 return tag_;
203 }
204
209 uint64_t value() const {
210 return value_;
211 }
212
213 void tag(TAG tag) {
214 tag_ = tag;
215 }
216
217 void value(uint64_t value) {
218 value_ = value;
219 }
220
221 void accept(Visitor& visitor) const override;
222
223 virtual std::ostream& print(std::ostream& os) const;
224
225 LIEF_API friend
226 std::ostream& operator<<(std::ostream& os, const DynamicEntry& entry) {
227 return entry.print(os);
228 }
229
230 protected:
231 TAG tag_ = TAG::DT_NULL;
232 uint64_t value_ = 0;
233};
234
235LIEF_API const char* to_string(DynamicEntry::TAG e);
236
237}
238}
239#endif
Class which represents an entry in the dynamic table These entries are located in the ....
Definition DynamicEntry.hpp:37
TAG
Definition DynamicEntry.hpp:46
TAG tag() const
Tag of the current entry. The most common tags are: DT_NEEDED, DT_INIT, ...
Definition DynamicEntry.hpp:201
uint64_t value() const
Return the entry's value.
Definition DynamicEntry.hpp:209
Definition Object.hpp:25
ARCH
Machine architectures See current registered ELF machine architectures at: http://www....
Definition ELF/enums.hpp:30
LIEF namespace.
Definition Abstract/Binary.hpp:32