LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
ChainedBindingInfo.hpp
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_CHAINED_BINDING_INFO_H
17#define LIEF_MACHO_CHAINED_BINDING_INFO_H
18#include <ostream>
19
20#include "LIEF/visibility.h"
21#include "LIEF/MachO/BindingInfo.hpp"
22#include "LIEF/MachO/DyldChainedFormat.hpp"
23
24namespace LIEF {
25namespace MachO {
26class Symbol;
27class BinaryParser;
28class Builder;
29
30namespace details {
31struct dyld_chained_ptr_arm64e_bind;
32struct dyld_chained_ptr_arm64e_auth_bind;
33struct dyld_chained_ptr_arm64e_bind24;
34struct dyld_chained_ptr_arm64e_auth_bind24;
35struct dyld_chained_ptr_64_bind;
36struct dyld_chained_ptr_32_bind;
37}
38
46class LIEF_API ChainedBindingInfo : public BindingInfo {
47
48 friend class BinaryParser;
49 friend class Builder;
50
51 public:
52
53 ChainedBindingInfo() = delete;
54 explicit ChainedBindingInfo(DYLD_CHAINED_FORMAT fmt, bool is_weak);
55
56 ChainedBindingInfo& operator=(ChainedBindingInfo other);
59
60 void swap(ChainedBindingInfo& other) noexcept;
61
63 DYLD_CHAINED_FORMAT format() const {
64 return format_;
65 }
66
68 DYLD_CHAINED_PTR_FORMAT ptr_format() const {
69 return ptr_format_;
70 }
71
73 uint32_t offset() const {
74 return offset_;
75 }
76
77 void offset(uint32_t offset) {
78 offset_ = offset;
79 }
80
81 uint64_t address() const override {
82 return /* imagebase */ address_ + offset_;
83 }
84
85 void address(uint64_t address) override {
86 offset_ = address - /* imagebase */ address_;
87 }
88
89 uint64_t sign_extended_addend() const;
90
91 BindingInfo::TYPES type() const override {
92 return BindingInfo::TYPES::CHAINED;
93 }
94
95 static bool classof(const BindingInfo* info) {
96 return info->type() == BindingInfo::TYPES::CHAINED;
97 }
98
99 ~ChainedBindingInfo() override {
100 clear();
101 }
102
103 void accept(Visitor& visitor) const override;
104
105 LIEF_API friend
106 std::ostream& operator<<(std::ostream& os, const ChainedBindingInfo& info) {
107 os << static_cast<const BindingInfo&>(info);
108 return os;
109 }
110
111 private:
112 void clear();
113 enum class BIND_TYPES {
114 UNKNOWN = 0,
115
116 ARM64E_BIND,
117 ARM64E_AUTH_BIND,
118
119 ARM64E_BIND24,
120 ARM64E_AUTH_BIND24,
121
122 PTR64_BIND,
123 PTR32_BIND,
124 };
125
126 void set(const details::dyld_chained_ptr_arm64e_bind& bind);
127 void set(const details::dyld_chained_ptr_arm64e_auth_bind& bind);
128 void set(const details::dyld_chained_ptr_arm64e_bind24& bind);
129 void set(const details::dyld_chained_ptr_arm64e_auth_bind24& bind);
130 void set(const details::dyld_chained_ptr_64_bind& bind);
131 void set(const details::dyld_chained_ptr_32_bind& bind);
132
133 DYLD_CHAINED_FORMAT format_;
134 DYLD_CHAINED_PTR_FORMAT ptr_format_;
135 uint32_t offset_ = 0;
136
137 BIND_TYPES btypes_ = BIND_TYPES::UNKNOWN;
138
139 union {
140 details::dyld_chained_ptr_arm64e_bind* arm64_bind_ = nullptr;
141 details::dyld_chained_ptr_arm64e_auth_bind* arm64_auth_bind_;
142 details::dyld_chained_ptr_arm64e_bind24* arm64_bind24_;
143 details::dyld_chained_ptr_arm64e_auth_bind24* arm64_auth_bind24_;
144 details::dyld_chained_ptr_64_bind* p64_bind_;
145 details::dyld_chained_ptr_32_bind* p32_bind_;
146 };
147};
148
149}
150}
151#endif
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:73
Class that provides an interface over a binding operation.
Definition BindingInfo.hpp:38
TYPES
Definition BindingInfo.hpp:43
virtual TYPES type() const =0
The type of the binding. This type provides the origin of the binding (LC_DYLD_INFO or LC_DYLD_CHAINE...
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:54
This class represents a symbol binding operation associated with the LC_DYLD_CHAINED_FIXUPS command.
Definition ChainedBindingInfo.hpp:46
DYLD_CHAINED_PTR_FORMAT ptr_format() const
Format of the pointer.
Definition ChainedBindingInfo.hpp:68
DYLD_CHAINED_FORMAT format() const
Format of the imports.
Definition ChainedBindingInfo.hpp:63
uint64_t address() const override
Address of the binding.
Definition ChainedBindingInfo.hpp:81
BindingInfo::TYPES type() const override
The type of the binding. This type provides the origin of the binding (LC_DYLD_INFO or LC_DYLD_CHAINE...
Definition ChainedBindingInfo.hpp:91
uint32_t offset() const
Original offset in the chain of this binding.
Definition ChainedBindingInfo.hpp:73
LIEF namespace.
Definition Abstract/Binary.hpp:32