LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
DynamicRelocationBase.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_PE_LOAD_CONFIGURATION_DYNAMIC_RELOCATION_H
17#define LIEF_PE_LOAD_CONFIGURATION_DYNAMIC_RELOCATION_H
18
19#include <ostream>
20#include <cstdint>
21#include <memory>
22#include <string>
23
24#include "LIEF/visibility.h"
25
26namespace LIEF {
27namespace PE {
28class DynamicFixup;
34 public: enum IMAGE_DYNAMIC_RELOCATION { RELOCATION_GUARD_RF_PROLOGUE = 1,
39 RELOCATION_GUARD_RF_EPILOGUE = 2,
42 RELOCATION_GUARD_IMPORT_CONTROL_TRANSFER = 3,
45 RELOCATION_GUARD_INDIR_CONTROL_TRANSFER = 4,
48 RELOCATION_GUARD_SWITCHTABLE_BRANCH = 5,
51 RELOCATION_ARM64X = 6,
54 RELOCATION_FUNCTION_OVERRIDE = 7,
57 RELOCATION_ARM64_KERNEL_IMPORT_CALL_TRANSFER = 8,
60
61 _RELOC_LAST_ENTRY,
62 };
63
65 DynamicRelocation(uint32_t version);
66
67 DynamicRelocation(const DynamicRelocation&);
68 DynamicRelocation& operator=(const DynamicRelocation&);
69
70 DynamicRelocation(DynamicRelocation&&);
71 DynamicRelocation& operator=(DynamicRelocation&&);
72
73 virtual std::unique_ptr<DynamicRelocation> clone() const = 0;
74 uint32_t version() const {
77 return version_;
78 }
79 uint64_t symbol() const {
83 return symbol_;
84 }
85
86 const DynamicFixup* fixups() const {
87 return fixups_.get();
88 }
89 DynamicFixup* fixups() {
93 return fixups_.get();
94 }
95
96 DynamicRelocation& symbol(uint64_t value) {
97 symbol_ = value;
98 return *this;
99 }
100
101 DynamicRelocation& fixups(std::unique_ptr<DynamicFixup> F);
102
103 virtual std::string to_string() const = 0;
104
105 template<class T>
106 T* as() {
107 static_assert(std::is_base_of<DynamicRelocation, T>::value,
108 "Require DynamicRelocation inheritance");
109 if (T::classof(this)) {
110 return static_cast<T*>(this);
111 }
112 return nullptr;
113 }
114
115 template<class T>
116 const T* as() const {
117 return const_cast<DynamicRelocation*>(this)->as<T>();
118 }
119
120 LIEF_API friend
121 std::ostream& operator<<(std::ostream& os, const DynamicRelocation& reloc)
122 {
123 os << reloc.to_string();
124 return os;
125 }
126
127 virtual ~DynamicRelocation();
128
129 protected:
130 uint32_t version_ = 0;
131 uint64_t symbol_ = 0;
132 std::unique_ptr<DynamicFixup> fixups_;
133};
134
135LIEF_API const char* to_string(DynamicRelocation::IMAGE_DYNAMIC_RELOCATION e);
136
137}
138}
139
140#endif
LIEF::PE::DynamicFixup
This is the base class for any fixups located in DynamicRelocation.
Definition DynamicFixup.hpp:34
LIEF::PE::DynamicRelocation
This is the base class for any IMAGE_DYNAMIC_RELOCATION32, IMAGE_DYNAMIC_RELOCATION32_V2,...
Definition DynamicRelocationBase.hpp:33
LIEF::PE::DynamicRelocation::operator=
DynamicRelocation & operator=(DynamicRelocation &&)
LIEF::PE::DynamicRelocation::version
uint32_t version() const
Version of the structure.
Definition DynamicRelocationBase.hpp:76
LIEF::PE::DynamicRelocation::operator<<
friend std::ostream & operator<<(std::ostream &os, const DynamicRelocation &reloc)
Definition DynamicRelocationBase.hpp:121
LIEF::PE::DynamicRelocation::fixups
DynamicRelocation & fixups(std::unique_ptr< DynamicFixup > F)
LIEF::PE::DynamicRelocation::DynamicRelocation
DynamicRelocation()=delete
LIEF::PE::DynamicRelocation::symbol
DynamicRelocation & symbol(uint64_t value)
Definition DynamicRelocationBase.hpp:96
LIEF::PE::DynamicRelocation::symbol
uint64_t symbol() const
Symbol address. Some values have a special meaning (c.f. IMAGE_DYNAMIC_RELOCATION) and define how fix...
Definition DynamicRelocationBase.hpp:82
LIEF::PE::DynamicRelocation::clone
virtual std::unique_ptr< DynamicRelocation > clone() const =0
LIEF::PE::DynamicRelocation::DynamicRelocation
DynamicRelocation(const DynamicRelocation &)
LIEF::PE::DynamicRelocation::IMAGE_DYNAMIC_RELOCATION
IMAGE_DYNAMIC_RELOCATION
Special symbol values as defined in link.exe - GetDVRTSpecialSymbolName
Definition DynamicRelocationBase.hpp:36
LIEF::PE::DynamicRelocation::as
T * as()
Definition DynamicRelocationBase.hpp:106
LIEF::PE::DynamicRelocation::fixups
DynamicFixup * fixups()
Return fixups information, where the interpretation may depend on the symbol's value.
Definition DynamicRelocationBase.hpp:92
LIEF::PE::DynamicRelocation::DynamicRelocation
DynamicRelocation(uint32_t version)
LIEF::PE::DynamicRelocation::operator=
DynamicRelocation & operator=(const DynamicRelocation &)
LIEF::PE::DynamicRelocation::~DynamicRelocation
virtual ~DynamicRelocation()
LIEF::PE::DynamicRelocation::to_string
virtual std::string to_string() const =0
LIEF::PE::DynamicRelocation::DynamicRelocation
DynamicRelocation(DynamicRelocation &&)
LIEF::PE::DynamicRelocation::as
const T * as() const
Definition DynamicRelocationBase.hpp:116
LIEF::PE::DynamicRelocation::fixups
const DynamicFixup * fixups() const
Definition DynamicRelocationBase.hpp:86
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::ACCELERATOR_CODES::T
@ T
Definition AcceleratorCodes.hpp:97
LIEF::PE::to_string
const char * to_string(AuxiliaryWeakExternal::CHARACTERISTICS e)
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41