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