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