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