LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
ChainedBindingInfo.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_CHAINED_BINDING_INFO_H
17#define LIEF_MACHO_CHAINED_BINDING_INFO_H
18#include <ostream>
19
20#include "LIEF/visibility.h"
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
47
48 friend class BinaryParser;
49 friend class Builder;
50
51 public:
52
54 explicit ChainedBindingInfo(DYLD_CHAINED_FORMAT fmt, bool is_weak);
55
59
60 void swap(ChainedBindingInfo& other) noexcept;
61
63 DYLD_CHAINED_FORMAT format() const {
64 return format_;
65 }
66
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
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:74
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:55
This class represents a symbol binding operation associated with the LC_DYLD_CHAINED_FIXUPS command.
Definition ChainedBindingInfo.hpp:46
static bool classof(const BindingInfo *info)
Definition ChainedBindingInfo.hpp:95
details::dyld_chained_ptr_64_bind * p64_bind_
Definition ChainedBindingInfo.hpp:144
void accept(Visitor &visitor) const override
void offset(uint32_t offset)
Definition ChainedBindingInfo.hpp:77
friend std::ostream & operator<<(std::ostream &os, const ChainedBindingInfo &info)
Definition ChainedBindingInfo.hpp:106
ChainedBindingInfo(const ChainedBindingInfo &other)
ChainedBindingInfo(ChainedBindingInfo &&) noexcept
DYLD_CHAINED_PTR_FORMAT ptr_format() const
Format of the pointer.
Definition ChainedBindingInfo.hpp:68
uint64_t address() const override
Address of the binding.
Definition ChainedBindingInfo.hpp:81
void address(uint64_t address) override
Definition ChainedBindingInfo.hpp:85
details::dyld_chained_ptr_arm64e_auth_bind24 * arm64_auth_bind24_
Definition ChainedBindingInfo.hpp:143
uint64_t sign_extended_addend() const
details::dyld_chained_ptr_arm64e_auth_bind * arm64_auth_bind_
Definition ChainedBindingInfo.hpp:141
~ChainedBindingInfo() override
Definition ChainedBindingInfo.hpp:99
details::dyld_chained_ptr_32_bind * p32_bind_
Definition ChainedBindingInfo.hpp:145
ChainedBindingInfo(DYLD_CHAINED_FORMAT fmt, bool is_weak)
ChainedBindingInfo & operator=(ChainedBindingInfo other)
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
details::dyld_chained_ptr_arm64e_bind24 * arm64_bind24_
Definition ChainedBindingInfo.hpp:142
uint32_t offset() const
Original offset in the chain of this binding.
Definition ChainedBindingInfo.hpp:73
Definition Visitor.hpp:224
DYLD_CHAINED_FORMAT
Definition DyldChainedFormat.hpp:22
DYLD_CHAINED_PTR_FORMAT
Definition DyldChainedFormat.hpp:29
LIEF namespace.
Definition Abstract/Binary.hpp:32
#define LIEF_API
Definition visibility.h:41