LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
DynamicFixup.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_FIXUP_H
17#define LIEF_PE_LOAD_CONFIGURATION_DYNAMIC_FIXUP_H
18
19#include <ostream>
20#include <memory>
21#include <string>
22
23#include "LIEF/visibility.h"
24#include "LIEF/errors.hpp"
25
26namespace LIEF {
27class SpanStream;
28
29namespace PE {
30class Parser;
35 public:
36 enum KIND { UNKNOWN = 0,
40 GENERIC,
43 ARM64X,
46 FUNCTION_OVERRIDE,
49 ARM64_KERNEL_IMPORT_CALL_TRANSFER,
52 GUARD_IMPORT_CONTROL_TRANSFER,
55 };
56
57 DynamicFixup() = delete;
58 DynamicFixup(KIND kind) :
59 kind_(kind)
60 {}
61
62 DynamicFixup(const DynamicFixup&) = default;
63 DynamicFixup& operator=(const DynamicFixup&) = default;
64
65 DynamicFixup(DynamicFixup&&) = default;
66 DynamicFixup& operator=(DynamicFixup&&) = default;
67
68 virtual std::unique_ptr<DynamicFixup> clone() const = 0;
69
70 virtual std::string to_string() const = 0;
71 KIND kind() const {
74 return kind_;
75 }
76
77 template<class T>
78 T* as() {
79 static_assert(std::is_base_of<DynamicFixup, T>::value,
80 "Require DynamicFixup inheritance");
81 if (T::classof(this)) {
82 return static_cast<T*>(this);
83 }
84 return nullptr;
85 }
86
87 template<class T>
88 const T* as() const {
89 return const_cast<DynamicFixup*>(this)->as<T>();
90 }
91
92 LIEF_API friend
93 std::ostream& operator<<(std::ostream& os, const DynamicFixup& fixup)
94 {
95 os << fixup.to_string();
96 return os;
97 }
98
99 virtual ~DynamicFixup() = default;
103 parse(Parser& ctx, SpanStream& stream, DynamicRelocation& R);
104
105 protected:
106 KIND kind_ = KIND::UNKNOWN;
107
108};
109
110
111}
112}
113
114#endif
This is the base class for any fixups located in DynamicRelocation.
Definition DynamicFixup.hpp:34
const T * as() const
Definition DynamicFixup.hpp:88
DynamicFixup()=delete
T * as()
Definition DynamicFixup.hpp:78
DynamicFixup & operator=(const DynamicFixup &)=default
KIND kind() const
Encoding of the fixups.
Definition DynamicFixup.hpp:73
friend std::ostream & operator<<(std::ostream &os, const DynamicFixup &fixup)
Definition DynamicFixup.hpp:93
virtual std::unique_ptr< DynamicFixup > clone() const =0
DynamicFixup(const DynamicFixup &)=default
virtual std::string to_string() const =0
DynamicFixup & operator=(DynamicFixup &&)=default
DynamicFixup(DynamicFixup &&)=default
virtual ~DynamicFixup()=default
DynamicFixup(KIND kind)
Definition DynamicFixup.hpp:58
This is the base class for any IMAGE_DYNAMIC_RELOCATION32, IMAGE_DYNAMIC_RELOCATION32_V2,...
Definition DynamicRelocationBase.hpp:33
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
Definition SpanStream.hpp:32
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
@ T
Definition AcceleratorCodes.hpp:97
LIEF namespace.
Definition Abstract/Binary.hpp:36
result< ok_t > ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:109
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42