forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChainedBindingInfo.cpp
More file actions
137 lines (117 loc) · 5.06 KB
/
Copy pathChainedBindingInfo.cpp
File metadata and controls
137 lines (117 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* Copyright 2017 - 2025 R. Thomas
* Copyright 2017 - 2025 Quarkslab
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "LIEF/Visitor.hpp"
#include "LIEF/MachO/ChainedBindingInfo.hpp"
#include "MachO/ChainedFixup.hpp"
namespace LIEF {
namespace MachO {
ChainedBindingInfo::ChainedBindingInfo(ChainedBindingInfo&&) noexcept = default;
ChainedBindingInfo& ChainedBindingInfo::operator=(ChainedBindingInfo&&) noexcept = default;
ChainedBindingInfo::ChainedBindingInfo(const ChainedBindingInfo& other) :
BindingInfo(other),
format_{other.format_},
ptr_format_{other.ptr_format_},
offset_{other.offset_},
btypes_{other.btypes_}
{
switch (btypes_) {
case BIND_TYPES::ARM64E_AUTH_BIND: arm64_auth_bind_ = new details::dyld_chained_ptr_arm64e_auth_bind{*other.arm64_auth_bind_}; break;
case BIND_TYPES::ARM64E_BIND: arm64_bind_ = new details::dyld_chained_ptr_arm64e_bind{*other.arm64_bind_}; break;
case BIND_TYPES::ARM64E_BIND24: arm64_bind24_ = new details::dyld_chained_ptr_arm64e_bind24{*other.arm64_bind24_}; break;
case BIND_TYPES::ARM64E_AUTH_BIND24: arm64_auth_bind24_ = new details::dyld_chained_ptr_arm64e_auth_bind24{*other.arm64_auth_bind24_}; break;
case BIND_TYPES::PTR32_BIND: p32_bind_ = new details::dyld_chained_ptr_32_bind{*other.p32_bind_}; break;
case BIND_TYPES::PTR64_BIND: p64_bind_ = new details::dyld_chained_ptr_64_bind{*other.p64_bind_}; break;
case BIND_TYPES::UNKNOWN: {}
}
}
ChainedBindingInfo::ChainedBindingInfo(DYLD_CHAINED_FORMAT fmt, bool is_weak) :
format_{fmt}
{
is_weak_import_ = is_weak;
}
ChainedBindingInfo::~ChainedBindingInfo() {
clear();
}
ChainedBindingInfo& ChainedBindingInfo::operator=(ChainedBindingInfo other) {
swap(other);
return *this;
}
void ChainedBindingInfo::swap(ChainedBindingInfo& other) noexcept {
BindingInfo::swap(other);
std::swap(format_, other.format_);
std::swap(ptr_format_, other.ptr_format_);
std::swap(offset_, other.offset_);
std::swap(btypes_, other.btypes_);
}
void ChainedBindingInfo::accept(Visitor& visitor) const {
visitor.visit(*this);
}
uint64_t ChainedBindingInfo::sign_extended_addend() const {
switch (btypes_) {
case BIND_TYPES::ARM64E_AUTH_BIND: return 0;
case BIND_TYPES::ARM64E_BIND: return details::sign_extended_addend(*arm64_bind_);
case BIND_TYPES::ARM64E_BIND24: return details::sign_extended_addend(*arm64_bind24_);
case BIND_TYPES::ARM64E_AUTH_BIND24: return 0;
case BIND_TYPES::PTR32_BIND: return p32_bind_->addend;
case BIND_TYPES::PTR64_BIND: return details::sign_extended_addend(*p64_bind_);
case BIND_TYPES::UNKNOWN: return 0;
}
return 0;
}
void ChainedBindingInfo::set(const details::dyld_chained_ptr_arm64e_bind& bind) {
clear();
btypes_ = BIND_TYPES::ARM64E_BIND;
arm64_bind_ = new details::dyld_chained_ptr_arm64e_bind(bind);
}
void ChainedBindingInfo::set(const details::dyld_chained_ptr_arm64e_auth_bind& bind) {
clear();
btypes_ = BIND_TYPES::ARM64E_AUTH_BIND;
arm64_auth_bind_ = new details::dyld_chained_ptr_arm64e_auth_bind(bind);
}
void ChainedBindingInfo::set(const details::dyld_chained_ptr_arm64e_bind24& bind) {
clear();
btypes_ = BIND_TYPES::ARM64E_BIND24;
arm64_bind24_ = new details::dyld_chained_ptr_arm64e_bind24(bind);
}
void ChainedBindingInfo::set(const details::dyld_chained_ptr_arm64e_auth_bind24& bind) {
clear();
btypes_ = BIND_TYPES::ARM64E_AUTH_BIND24;
arm64_auth_bind24_ = new details::dyld_chained_ptr_arm64e_auth_bind24(bind);
}
void ChainedBindingInfo::set(const details::dyld_chained_ptr_64_bind& bind) {
clear();
btypes_ = BIND_TYPES::PTR64_BIND;
p64_bind_ = new details::dyld_chained_ptr_64_bind(bind);
}
void ChainedBindingInfo::set(const details::dyld_chained_ptr_32_bind& bind) {
clear();
btypes_ = BIND_TYPES::PTR32_BIND;
p32_bind_ = new details::dyld_chained_ptr_32_bind(bind);
}
void ChainedBindingInfo::clear() {
switch (btypes_) {
case BIND_TYPES::ARM64E_AUTH_BIND: delete arm64_auth_bind_; break;
case BIND_TYPES::ARM64E_BIND: delete arm64_bind_; break;
case BIND_TYPES::ARM64E_BIND24: delete arm64_bind24_; break;
case BIND_TYPES::ARM64E_AUTH_BIND24: delete arm64_auth_bind24_; break;
case BIND_TYPES::PTR32_BIND: delete p32_bind_; break;
case BIND_TYPES::PTR64_BIND: delete p64_bind_; break;
case BIND_TYPES::UNKNOWN: {}
}
btypes_ = BIND_TYPES::UNKNOWN;
}
}
}