LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
RelocationFixup.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_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
53
54 friend class BinaryParser;
55 friend class Builder;
57
58 public:
59 RelocationFixup() = delete;
60 RelocationFixup(DYLD_CHAINED_PTR_FORMAT fmt, uint64_t imagebase);
61
64
66 RelocationFixup(RelocationFixup&&) noexcept = default;
67
68 ~RelocationFixup() override;
69
70 std::unique_ptr<Relocation> clone() const override {
71 return std::unique_ptr<RelocationFixup>(new RelocationFixup(*this));
72 }
73
75 bool is_pc_relative() const override {
76 return false;
77 }
78
81 ORIGIN origin() const override {
83 }
84
86 return ptr_fmt_;
87 }
88
92 uint64_t target() const;
93 void target(uint64_t target);
94
96 void pc_relative(bool) override {}
97
98 uint32_t offset() const {
99 return offset_;
100 }
101
102 void offset(uint32_t offset) {
103 offset_ = offset;
104 }
105
107 uint64_t address() const override {
108 return address_;
109 }
110
112 void address(uint64_t address) override {
113 address_ = address;
114 }
115
117 uint32_t next() const;
118
120 void next(uint32_t value);
121
122 void accept(Visitor& visitor) const override;
123
124 static bool classof(const Relocation& r) {
126 }
127
128 std::ostream& print(std::ostream& os) const override;
129
130 private:
131 enum class REBASE_TYPES {
132 UNKNOWN = 0,
133
134 ARM64E_REBASE,
135 ARM64E_AUTH_REBASE,
136 PTR64_REBASE,
137 PTR32_REBASE,
138 SEGMENTED,
139 AUTH_SEGMENTED,
140 };
141
142 LIEF_LOCAL void set(const details::dyld_chained_ptr_arm64e_rebase& fixup);
143 LIEF_LOCAL void set(const details::dyld_chained_ptr_arm64e_auth_rebase& fixup);
144 LIEF_LOCAL void set(const details::dyld_chained_ptr_64_rebase& fixup);
145 LIEF_LOCAL void set(const details::dyld_chained_ptr_32_rebase& fixup);
146 LIEF_LOCAL void set(const details::dyld_chained_ptr_arm64e_segmented_rebase& fixup);
147 LIEF_LOCAL void set(const details::dyld_chained_ptr_arm64e_auth_segmented_rebase& fixup);
148
150 uint64_t imagebase_ = 0;
151 uint32_t offset_ = 0;
152
153 REBASE_TYPES rtypes_ = REBASE_TYPES::UNKNOWN;
154
155 union {
156 details::dyld_chained_ptr_arm64e_rebase* arm64_rebase_ = nullptr;
157 details::dyld_chained_ptr_arm64e_auth_rebase* arm64_auth_rebase_;
158 details::dyld_chained_ptr_64_rebase* p64_rebase_;
159 details::dyld_chained_ptr_32_rebase* p32_rebase_;
160 details::dyld_chained_ptr_arm64e_segmented_rebase* segmented_rebase_;
161 details::dyld_chained_ptr_arm64e_auth_segmented_rebase* auth_segmented_rebase_;
162 };
163};
164
165}
166}
167#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:158
details::dyld_chained_ptr_32_rebase * p32_rebase_
Definition RelocationFixup.hpp:159
RelocationFixup & operator=(RelocationFixup &&) noexcept=default
RelocationFixup(DYLD_CHAINED_PTR_FORMAT fmt, uint64_t imagebase)
void offset(uint32_t offset)
Definition RelocationFixup.hpp:102
details::dyld_chained_ptr_arm64e_segmented_rebase * segmented_rebase_
Definition RelocationFixup.hpp:160
details::dyld_chained_ptr_arm64e_rebase * arm64_rebase_
Definition RelocationFixup.hpp:156
std::ostream & print(std::ostream &os) const override
friend class BinaryParser
Definition RelocationFixup.hpp:54
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:56
ORIGIN origin() const override
Origin of the relocation. For this concrete object, it should be Relocation::ORIGIN::CHAINED_FIXUPS.
Definition RelocationFixup.hpp:81
uint32_t offset() const
Definition RelocationFixup.hpp:98
void pc_relative(bool) override
Not relevant for this kind of relocation.
Definition RelocationFixup.hpp:96
friend class Builder
Definition RelocationFixup.hpp:55
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:107
details::dyld_chained_ptr_arm64e_auth_rebase * arm64_auth_rebase_
Definition RelocationFixup.hpp:157
static bool classof(const Relocation &r)
Definition RelocationFixup.hpp:124
details::dyld_chained_ptr_arm64e_auth_segmented_rebase * auth_segmented_rebase_
Definition RelocationFixup.hpp:161
bool is_pc_relative() const override
Not relevant for this kind of relocation.
Definition RelocationFixup.hpp:75
RelocationFixup & operator=(const RelocationFixup &)
void address(uint64_t address) override
Changing the address means changing the offset.
Definition RelocationFixup.hpp:112
RelocationFixup(const RelocationFixup &)
std::unique_ptr< Relocation > clone() const override
Definition RelocationFixup.hpp:70
DYLD_CHAINED_PTR_FORMAT ptr_format() const
Definition RelocationFixup.hpp:85
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:210
Definition endianness_support.hpp:59
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
DYLD_CHAINED_PTR_FORMAT
Definition DyldChainedFormat.hpp:29
@ PTR_32
Definition DyldChainedFormat.hpp:33
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42