LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
RelocationFixup.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 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;
34}
35
36class BinaryParser;
37class Builder;
39class LIEF_API RelocationFixup : public Relocation {
51
52 friend class BinaryParser;
53 friend class Builder;
54 friend class DyldChainedFixupsCreator;
55
56 public:
57 RelocationFixup() = delete;
58 RelocationFixup(DYLD_CHAINED_PTR_FORMAT fmt, uint64_t imagebase);
59
60 RelocationFixup& operator=(const RelocationFixup&);
61 RelocationFixup(const RelocationFixup&);
62
63 RelocationFixup& operator=(RelocationFixup&&) noexcept = default;
64 RelocationFixup(RelocationFixup&&) noexcept = default;
65
66 ~RelocationFixup() override;
67
68 std::unique_ptr<Relocation> clone() const override {
69 return std::unique_ptr<RelocationFixup>(new RelocationFixup(*this));
70 }
71 bool is_pc_relative() const override {
74 return false;
75 }
76 ORIGIN origin() const override {
80 return ORIGIN::CHAINED_FIXUPS;
81 }
82
84 return ptr_fmt_;
85 }
86 uint64_t target() const;
91 void target(uint64_t target);
92 void pc_relative(bool) override {}
95
96 uint32_t offset() const {
97 return offset_;
98 }
99
100 void offset(uint32_t offset) {
101 offset_ = offset;
102 }
103 uint64_t address() const override {
106 return address_;
107 }
108 void address(uint64_t address) override {
111 address_ = address;
112 }
113 uint32_t next() const;
116 void next(uint32_t value);
119
120 void accept(Visitor& visitor) const override;
121
122 static bool classof(const Relocation& r) {
123 return r.origin() == Relocation::ORIGIN::CHAINED_FIXUPS;
124 }
125
126 std::ostream& print(std::ostream& os) const override;
127
128 private:
129 enum class REBASE_TYPES {
130 UNKNOWN = 0,
131
132 ARM64E_REBASE,
133 ARM64E_AUTH_REBASE,
134 PTR64_REBASE,
135 PTR32_REBASE,
136 };
137
138 LIEF_LOCAL void set(const details::dyld_chained_ptr_arm64e_rebase& fixup);
139 LIEF_LOCAL void set(const details::dyld_chained_ptr_arm64e_auth_rebase& fixup);
140 LIEF_LOCAL void set(const details::dyld_chained_ptr_64_rebase& fixup);
141 LIEF_LOCAL void set(const details::dyld_chained_ptr_32_rebase& fixup);
142
143 DYLD_CHAINED_PTR_FORMAT ptr_fmt_ = DYLD_CHAINED_PTR_FORMAT::PTR_32;
144 uint64_t imagebase_ = 0;
145 uint32_t offset_ = 0;
146
147 REBASE_TYPES rtypes_ = REBASE_TYPES::UNKNOWN;
148
149 union {
150 details::dyld_chained_ptr_arm64e_rebase* arm64_rebase_ = nullptr;
151 details::dyld_chained_ptr_arm64e_auth_rebase* arm64_auth_rebase_;
152 details::dyld_chained_ptr_64_rebase* p64_rebase_;
153 details::dyld_chained_ptr_32_rebase* p32_rebase_;
154 };
155};
156
157}
158}
159#endif
DyldChainedFormat.hpp
Relocation.hpp
LIEF::MachO::BinaryParser
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:74
LIEF::MachO::Builder
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:57
LIEF::MachO::DyldChainedFixupsCreator
Definition DyldChainedFixupsCreator.hpp:41
LIEF::MachO::RelocationFixup
Class that represents a rebase relocation found in the LC_DYLD_CHAINED_FIXUPS command.
Definition RelocationFixup.hpp:50
LIEF::MachO::RelocationFixup::operator=
RelocationFixup & operator=(RelocationFixup &&) noexcept=default
LIEF::MachO::RelocationFixup::RelocationFixup
RelocationFixup(DYLD_CHAINED_PTR_FORMAT fmt, uint64_t imagebase)
LIEF::MachO::RelocationFixup::offset
void offset(uint32_t offset)
Definition RelocationFixup.hpp:100
LIEF::MachO::RelocationFixup::print
std::ostream & print(std::ostream &os) const override
LIEF::MachO::RelocationFixup::target
void target(uint64_t target)
LIEF::MachO::RelocationFixup::next
uint32_t next() const
Return the (unscaled) next offset in the chain.
LIEF::MachO::RelocationFixup::target
uint64_t target() const
The value that should be set at the address pointed by LIEF::Relocation::address if the imagebase cho...
LIEF::MachO::RelocationFixup::origin
ORIGIN origin() const override
Origin of the relocation. For this concrete object, it should be Relocation::ORIGIN::CHAINED_FIXUPS.
Definition RelocationFixup.hpp:79
LIEF::MachO::RelocationFixup::offset
uint32_t offset() const
Definition RelocationFixup.hpp:96
LIEF::MachO::RelocationFixup::pc_relative
void pc_relative(bool) override
Not relevant for this kind of relocation.
Definition RelocationFixup.hpp:94
LIEF::MachO::RelocationFixup::next
void next(uint32_t value)
Change next offset of the current element.
LIEF::MachO::RelocationFixup::address
uint64_t address() const override
The address of this relocation is bound to its offset.
Definition RelocationFixup.hpp:105
LIEF::MachO::RelocationFixup::classof
static bool classof(const Relocation &r)
Definition RelocationFixup.hpp:122
LIEF::MachO::RelocationFixup::RelocationFixup
RelocationFixup()=delete
LIEF::MachO::RelocationFixup::is_pc_relative
bool is_pc_relative() const override
Not relevant for this kind of relocation.
Definition RelocationFixup.hpp:73
LIEF::MachO::RelocationFixup::operator=
RelocationFixup & operator=(const RelocationFixup &)
LIEF::MachO::RelocationFixup::address
void address(uint64_t address) override
Changing the address means changing the offset.
Definition RelocationFixup.hpp:110
LIEF::MachO::RelocationFixup::RelocationFixup
RelocationFixup(const RelocationFixup &)
LIEF::MachO::RelocationFixup::ptr_format
DYLD_CHAINED_PTR_FORMAT ptr_format() const
Definition RelocationFixup.hpp:83
LIEF::MachO::RelocationFixup::accept
void accept(Visitor &visitor) const override
LIEF::MachO::Relocation
Class that represents a Mach-O relocation.
Definition MachO/Relocation.hpp:40
LIEF::MachO::Relocation::origin
virtual ORIGIN origin() const =0
Origin of the relocation.
LIEF::MachO::details
Definition endianness_support.hpp:59
LIEF::MachO
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF::MachO::MACHO_TYPES::UNKNOWN
@ UNKNOWN
Definition MachO/enums.hpp:25
LIEF::MachO::DYLD_CHAINED_PTR_FORMAT
DYLD_CHAINED_PTR_FORMAT
Definition DyldChainedFormat.hpp:29
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41
LIEF_LOCAL
#define LIEF_LOCAL
Definition visibility.h:42