LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
RelocationFixup.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_MACHO_RELOCATION_FIXUP_H
16#define LIEF_MACHO_RELOCATION_FIXUP_H
17#include <memory>
18#include <ostream>
19
20#include "LIEF/visibility.h"
21
24
25
26namespace LIEF::MachO {
27
28namespace details {
29struct dyld_chained_ptr_arm64e_rebase;
30struct dyld_chained_ptr_arm64e_auth_rebase;
31struct dyld_chained_ptr_64_rebase;
32struct dyld_chained_ptr_32_rebase;
33struct dyld_chained_ptr_arm64e_segmented_rebase;
34struct dyld_chained_ptr_arm64e_auth_segmented_rebase;
35}
36
37class BinaryParser;
38class Builder;
40
55
56 friend class BinaryParser;
57 friend class Builder;
59
60 public:
61 RelocationFixup() = delete;
62 RelocationFixup(DYLD_CHAINED_PTR_FORMAT fmt, uint64_t imagebase);
63
66
68 RelocationFixup(RelocationFixup&&) noexcept = default;
69
70 ~RelocationFixup() override;
71
72 std::unique_ptr<Relocation> clone() const override {
73 return std::make_unique<RelocationFixup>(*this);
74 }
75
77 bool is_pc_relative() const override {
78 return false;
79 }
80
83 ORIGIN origin() const override {
85 }
86
88 return ptr_fmt_;
89 }
90
95 uint64_t target() const;
96 void target(uint64_t target);
97
99 void pc_relative(bool) override {}
100
101 uint32_t offset() const {
102 return offset_;
103 }
104
105 void offset(uint32_t offset) {
106 offset_ = offset;
107 }
108
110 uint64_t address() const override {
111 return address_;
112 }
113
115 void address(uint64_t address) override {
116 address_ = address;
117 }
118
120 uint32_t next() const;
121
123 void next(uint32_t value);
124
125 void accept(Visitor& visitor) const override;
126
127 static bool classof(const Relocation& r) {
129 }
130
131 std::ostream& print(std::ostream& os) const override;
132
133 private:
134 enum class REBASE_TYPES {
135 UNKNOWN = 0,
136
137 ARM64E_REBASE,
138 ARM64E_AUTH_REBASE,
139 PTR64_REBASE,
140 PTR32_REBASE,
141 SEGMENTED,
142 AUTH_SEGMENTED,
143 };
144
145 LIEF_LOCAL void set(const details::dyld_chained_ptr_arm64e_rebase& fixup);
146 LIEF_LOCAL void set(const details::dyld_chained_ptr_arm64e_auth_rebase& fixup);
147 LIEF_LOCAL void set(const details::dyld_chained_ptr_64_rebase& fixup);
148 LIEF_LOCAL void set(const details::dyld_chained_ptr_32_rebase& fixup);
149 LIEF_LOCAL void
150 set(const details::dyld_chained_ptr_arm64e_segmented_rebase& fixup);
151 LIEF_LOCAL void
152 set(const details::dyld_chained_ptr_arm64e_auth_segmented_rebase& fixup);
153
155 uint64_t imagebase_ = 0;
156 uint32_t offset_ = 0;
157
158 REBASE_TYPES rtypes_ = REBASE_TYPES::UNKNOWN;
159
160 union {
161 details::dyld_chained_ptr_arm64e_rebase* arm64_rebase_ = nullptr;
162 details::dyld_chained_ptr_arm64e_auth_rebase* arm64_auth_rebase_;
163 details::dyld_chained_ptr_64_rebase* p64_rebase_;
164 details::dyld_chained_ptr_32_rebase* p32_rebase_;
165 details::dyld_chained_ptr_arm64e_segmented_rebase* segmented_rebase_;
166 details::dyld_chained_ptr_arm64e_auth_segmented_rebase* auth_segmented_rebase_;
167 };
168};
169
170}
171
172#endif
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:80
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:63
Definition DyldChainedFixupsCreator.hpp:41
RelocationFixup & operator=(RelocationFixup &&) noexcept=default
RelocationFixup(DYLD_CHAINED_PTR_FORMAT fmt, uint64_t imagebase)
void offset(uint32_t offset)
Definition RelocationFixup.hpp:105
std::ostream & print(std::ostream &os) const override
friend class BinaryParser
Definition RelocationFixup.hpp:56
void target(uint64_t target)
uint32_t next() const
Return the (unscaled) next offset in the chain.
uint64_t target() const
The value that should be set at the address pointed by LIEF::Relocation::address if the imagebase cho...
friend class DyldChainedFixupsCreator
Definition RelocationFixup.hpp:58
ORIGIN origin() const override
Origin of the relocation. For this concrete object, it should be Relocation::ORIGIN::CHAINED_FIXUPS.
Definition RelocationFixup.hpp:83
uint32_t offset() const
Definition RelocationFixup.hpp:101
void pc_relative(bool) override
Not relevant for this kind of relocation.
Definition RelocationFixup.hpp:99
friend class Builder
Definition RelocationFixup.hpp:57
void next(uint32_t value)
Change next offset of the current element.
uint64_t address() const override
The address of this relocation is bound to its offset.
Definition RelocationFixup.hpp:110
static bool classof(const Relocation &r)
Definition RelocationFixup.hpp:127
bool is_pc_relative() const override
Not relevant for this kind of relocation.
Definition RelocationFixup.hpp:77
RelocationFixup & operator=(const RelocationFixup &)
void address(uint64_t address) override
Changing the address means changing the offset.
Definition RelocationFixup.hpp:115
RelocationFixup(const RelocationFixup &)
std::unique_ptr< Relocation > clone() const override
Definition RelocationFixup.hpp:72
DYLD_CHAINED_PTR_FORMAT ptr_format() const
Definition RelocationFixup.hpp:87
void accept(Visitor &visitor) const override
virtual ORIGIN origin() const =0
Origin of the relocation.
ORIGIN
Definition MachO/Relocation.hpp:47
@ CHAINED_FIXUPS
Definition MachO/Relocation.hpp:51
Definition Visitor.hpp:211
Definition endianness_support.hpp:62
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:35
@ UNKNOWN
Definition MachO/enums.hpp:25
DYLD_CHAINED_PTR_FORMAT
Definition DyldChainedFormat.hpp:34
@ PTR_32
Definition DyldChainedFormat.hpp:40
#define LIEF_API
Definition visibility.h:44
#define LIEF_LOCAL
Definition visibility.h:45