LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
DynamicRelocationBase.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_PE_LOAD_CONFIGURATION_DYNAMIC_RELOCATION_H
16#define LIEF_PE_LOAD_CONFIGURATION_DYNAMIC_RELOCATION_H
17
18#include <cstdint>
19#include <memory>
20#include <ostream>
21#include <string>
22
23#include "LIEF/visibility.h"
24
25
26namespace LIEF::PE {
27class DynamicFixup;
28
33 public:
62
65
68
71
72 virtual std::unique_ptr<DynamicRelocation> clone() const = 0;
73
75 uint32_t version() const {
76 return version_;
77 }
78
81 uint64_t symbol() const {
82 return symbol_;
83 }
84
86 return fixups_.get();
87 }
88
92 return fixups_.get();
93 }
94
96 symbol_ = value;
97 return *this;
98 }
99
100 DynamicRelocation& fixups(std::unique_ptr<DynamicFixup> F) LIEF_LIFETIMEBOUND;
101
102 virtual std::string to_string() const = 0;
103
104 template<class T>
105 T* as() {
106 static_assert(std::is_base_of_v<DynamicRelocation, T>,
107 "Require DynamicRelocation inheritance");
108 if (T::classof(this)) {
109 return static_cast<T*>(this);
110 }
111 return nullptr;
112 }
113
114 template<class T>
115 const T* as() const {
116 return const_cast<DynamicRelocation*>(this)->as<T>();
117 }
118
119 LIEF_API friend std::ostream& operator<<(std::ostream& os,
120 const DynamicRelocation& reloc) {
121 os << reloc.to_string();
122 return os;
123 }
124
126
127 protected:
128 uint32_t version_ = 0;
129 uint64_t symbol_ = 0;
130 std::unique_ptr<DynamicFixup> fixups_;
131};
132
134
135}
136
137
138#endif
This is the base class for any fixups located in DynamicRelocation.
Definition DynamicFixup.hpp:33
DynamicRelocation & operator=(DynamicRelocation &&)
uint32_t version() const
Version of the structure.
Definition DynamicRelocationBase.hpp:75
friend std::ostream & operator<<(std::ostream &os, const DynamicRelocation &reloc)
Definition DynamicRelocationBase.hpp:119
DynamicRelocation & fixups(std::unique_ptr< DynamicFixup > F)
DynamicRelocation & symbol(uint64_t value)
Definition DynamicRelocationBase.hpp:95
uint64_t symbol() const
Symbol address. Some values have a special meaning (c.f. IMAGE_DYNAMIC_RELOCATION) and define how fix...
Definition DynamicRelocationBase.hpp:81
virtual std::unique_ptr< DynamicRelocation > clone() const =0
DynamicRelocation(const DynamicRelocation &)
T * as()
Definition DynamicRelocationBase.hpp:105
DynamicFixup * fixups()
Return fixups information, where the interpretation may depend on the symbol's value.
Definition DynamicRelocationBase.hpp:91
DynamicRelocation(uint32_t version)
DynamicRelocation & operator=(const DynamicRelocation &)
virtual std::string to_string() const =0
IMAGE_DYNAMIC_RELOCATION
Special symbol values as defined in link.exe - GetDVRTSpecialSymbolName.
Definition DynamicRelocationBase.hpp:35
@ RELOCATION_GUARD_INDIR_CONTROL_TRANSFER
Mirror IMAGE_DYNAMIC_RELOCATION_GUARD_INDIR_CONTROL_TRANSFER.
Definition DynamicRelocationBase.hpp:46
@ RELOCATION_GUARD_RF_PROLOGUE
Mirror IMAGE_DYNAMIC_RELOCATION_GUARD_RF_PROLOGUE.
Definition DynamicRelocationBase.hpp:37
@ RELOCATION_ARM64_KERNEL_IMPORT_CALL_TRANSFER
Mirror IMAGE_DYNAMIC_RELOCATION_ARM64_KERNEL_IMPORT_CALL_TRANSFER.
Definition DynamicRelocationBase.hpp:58
@ RELOCATION_FUNCTION_OVERRIDE
Mirror IMAGE_DYNAMIC_RELOCATION_FUNCTION_OVERRIDE.
Definition DynamicRelocationBase.hpp:55
@ RELOCATION_GUARD_SWITCHTABLE_BRANCH
Mirror IMAGE_DYNAMIC_RELOCATION_GUARD_SWITCHTABLE_BRANCH.
Definition DynamicRelocationBase.hpp:49
@ _RELOC_LAST_ENTRY
Definition DynamicRelocationBase.hpp:60
@ RELOCATION_ARM64X
Mirror IMAGE_DYNAMIC_RELOCATION_ARM64X.
Definition DynamicRelocationBase.hpp:52
@ RELOCATION_GUARD_IMPORT_CONTROL_TRANSFER
Mirror IMAGE_DYNAMIC_RELOCATION_GUARD_IMPORT_CONTROL_TRANSFER.
Definition DynamicRelocationBase.hpp:43
@ RELOCATION_GUARD_RF_EPILOGUE
Mirror IMAGE_DYNAMIC_RELOCATION_GUARD_RF_EPILOGUE.
Definition DynamicRelocationBase.hpp:40
DynamicRelocation(DynamicRelocation &&)
const T * as() const
Definition DynamicRelocationBase.hpp:115
const DynamicFixup * fixups() const
Definition DynamicRelocationBase.hpp:85
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:31
const char * to_string(CODE_PAGES e)
@ T
Definition AcceleratorCodes.hpp:96
#define LIEF_API
Definition visibility.h:44