LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
DynamicEntryFlags.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 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_FLAGS_H
17#define LIEF_ELF_DYNAMIC_ENTRY_FLAGS_H
18
19#include <memory>
20#include <numeric>
21#include <ostream>
22#include <vector>
23
25#include "LIEF/visibility.h"
26
27
28namespace LIEF::ELF {
29
31 public:
32 static constexpr uint64_t BASE = 0x100000000;
33
34 // clang-format off
35 enum class FLAG : uint64_t {
36 ORIGIN = 0x00000001,
37 SYMBOLIC = 0x00000002,
38 TEXTREL = 0x00000004,
39 BIND_NOW = 0x00000008,
40 STATIC_TLS = 0x00000010,
41
42 NOW = BASE + 0x000000001,
43 GLOBAL = BASE + 0x000000002,
44 GROUP = BASE + 0x000000004,
45 NODELETE = BASE + 0x000000008,
46 LOADFLTR = BASE + 0x000000010,
47 INITFIRST = BASE + 0x000000020,
48 NOOPEN = BASE + 0x000000040,
49 HANDLE_ORIGIN = BASE + 0x000000080,
50 DIRECT = BASE + 0x000000100,
51 TRANS = BASE + 0x000000200,
52 INTERPOSE = BASE + 0x000000400,
53 NODEFLIB = BASE + 0x000000800,
54 NODUMP = BASE + 0x000001000,
55 CONFALT = BASE + 0x000002000,
56 ENDFILTEE = BASE + 0x000004000,
57 DISPRELDNE = BASE + 0x000008000,
58 DISPRELPND = BASE + 0x000010000,
59 NODIRECT = BASE + 0x000020000,
60 IGNMULDEF = BASE + 0x000040000,
61 NOKSYMS = BASE + 0x000080000,
62 NOHDR = BASE + 0x000100000,
63 EDITED = BASE + 0x000200000,
64 NORELOC = BASE + 0x000400000,
65 SYMINTPOSE = BASE + 0x000800000,
66 GLOBAUDIT = BASE + 0x001000000,
67 SINGLETON = BASE + 0x002000000,
68 PIE = BASE + 0x008000000,
69 KMOD = BASE + 0x010000000,
70 WEAKFILTER = BASE + 0x020000000,
71 NOCOMMON = BASE + 0x040000000,
72 };
73 // clang-format on
74
75 using flags_list_t = std::vector<FLAG>;
76
77 public:
80
84
88
91
92 std::unique_ptr<DynamicEntry> clone() const override {
93 return std::make_unique<DynamicEntryFlags>(*this);
94 }
95
97 bool has(FLAG f) const;
98
101
102 uint64_t raw_flags() const {
103 flags_list_t flags = this->flags();
104 return std::accumulate(flags.begin(), flags.end(), uint64_t(0),
105 [](uint64_t value, FLAG f) {
106 return value + (uint64_t)f;
107 });
108 }
109
111 void add(FLAG f);
112
114 void remove(FLAG f);
115
117 add(f);
118 return *this;
119 }
120
122 remove(f);
123 return *this;
124 }
125
126 void accept(Visitor& visitor) const override;
127
128 static bool classof(const DynamicEntry* entry) {
129 return entry->tag() == DynamicEntry::TAG::FLAGS ||
131 }
132
133 ~DynamicEntryFlags() override = default;
134
135 std::ostream& print(std::ostream& os) const override;
136
137 private:
140};
141
143
144}
145
146
147#endif
static DynamicEntryFlags create_dt_flag_1(uint64_t value)
Definition DynamicEntryFlags.hpp:85
FLAG
Definition DynamicEntryFlags.hpp:35
DynamicEntryFlags & operator-=(FLAG f)
Definition DynamicEntryFlags.hpp:121
static constexpr uint64_t BASE
Definition DynamicEntryFlags.hpp:32
bool has(FLAG f) const
If the current entry has the given FLAG.
std::ostream & print(std::ostream &os) const override
static bool classof(const DynamicEntry *entry)
Definition DynamicEntryFlags.hpp:128
std::vector< FLAG > flags_list_t
Definition DynamicEntryFlags.hpp:75
void add(FLAG f)
Add the given FLAG.
~DynamicEntryFlags() override=default
void remove(FLAG f)
Remove the given FLAG.
uint64_t raw_flags() const
Definition DynamicEntryFlags.hpp:102
std::unique_ptr< DynamicEntry > clone() const override
Definition DynamicEntryFlags.hpp:92
DynamicEntryFlags & operator+=(FLAG f)
Definition DynamicEntryFlags.hpp:116
DynamicEntryFlags & operator=(const DynamicEntryFlags &)=default
flags_list_t flags() const
Return flags as a list of integers.
DynamicEntryFlags(const DynamicEntryFlags &)=default
void accept(Visitor &visitor) const override
static DynamicEntryFlags create_dt_flag(uint64_t value)
Definition DynamicEntryFlags.hpp:81
TAG
Definition DynamicEntry.hpp:49
@ FLAGS
Definition DynamicEntry.hpp:81
@ FLAGS_1
Definition DynamicEntry.hpp:95
TAG tag() const
Tag of the current entry. The most common tags are: DT_NEEDED, DT_INIT, ...
Definition DynamicEntry.hpp:252
uint64_t value() const
Return the entry's value.
Definition DynamicEntry.hpp:260
Definition Visitor.hpp:212
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
const char * to_string(DynamicEntry::TAG e)
#define LIEF_API
Definition visibility.h:45