16#ifndef LIEF_MACHO_CHAINED_PTR_ANALYSIS_H
17#define LIEF_MACHO_CHAINED_PTR_ANALYSIS_H
32 struct dyld_chained_ptr_arm64e_rebase_t
41 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_arm64e_rebase_t& chain);
44 return uint64_t(high8) | target;
49 struct dyld_chained_ptr_arm64e_bind_t
51 uint64_t ordinal : 16,
59 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_arm64e_bind_t& chain);
63 struct dyld_chained_ptr_arm64e_auth_rebase_t
74 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_arm64e_auth_rebase_t& chain);
78 struct dyld_chained_ptr_arm64e_auth_bind_t
80 uint64_t ordinal : 16,
90 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_arm64e_auth_bind_t& chain);
94 struct dyld_chained_ptr_64_rebase_t
103 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_64_rebase_t& chain);
106 return uint64_t(high8) | target;
111 struct dyld_chained_ptr_arm64e_bind24_t
113 uint64_t ordinal : 24,
121 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_arm64e_bind24_t& chain);
125 struct dyld_chained_ptr_arm64e_auth_bind24_t
127 uint64_t ordinal : 24,
137 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_arm64e_auth_bind24_t& chain);
141 struct dyld_chained_ptr_64_bind_t
143 uint64_t ordinal : 24,
150 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_64_bind_t& chain);
154 struct dyld_chained_ptr_64_kernel_cache_rebase_t
156 uint64_t target : 30,
165 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_64_kernel_cache_rebase_t& chain);
169 struct dyld_chained_ptr_32_rebase_t
171 uint32_t target : 26,
176 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_32_rebase_t& chain);
180 struct dyld_chained_ptr_32_bind_t
182 uint32_t ordinal : 20,
188 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_32_bind_t& chain);
192 struct dyld_chained_ptr_32_cache_rebase_t
194 uint32_t target : 30,
198 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_32_cache_rebase_t& chain);
202 struct dyld_chained_ptr_32_firmware_rebase_t
204 uint32_t target : 26,
208 std::ostream&
operator<<(std::ostream& os,
const dyld_chained_ptr_32_firmware_rebase_t& chain);
211 enum class PTR_TYPE {
213 DYLD_CHAINED_PTR_ARM64E_REBASE,
214 DYLD_CHAINED_PTR_ARM64E_BIND,
215 DYLD_CHAINED_PTR_ARM64E_AUTH_REBASE,
216 DYLD_CHAINED_PTR_ARM64E_AUTH_BIND,
217 DYLD_CHAINED_PTR_64_REBASE,
218 DYLD_CHAINED_PTR_ARM64E_BIND24,
219 DYLD_CHAINED_PTR_ARM64E_AUTH_BIND24,
220 DYLD_CHAINED_PTR_64_BIND,
221 DYLD_CHAINED_PTR_64_KERNEL_CACHE_REBASE,
222 DYLD_CHAINED_PTR_32_REBASE,
223 DYLD_CHAINED_PTR_32_BIND,
224 DYLD_CHAINED_PTR_32_CACHE_REBASE,
225 DYLD_CHAINED_PTR_32_FIRMWARE_REBASE
228 static std::unique_ptr<ChainedPointerAnalysis>
from_value(uint64_t value,
231 return std::unique_ptr<ChainedPointerAnalysis>(
232 new ChainedPointerAnalysis(value, size));
235 static size_t stride(DYLD_CHAINED_PTR_FORMAT fmt) {
237 case DYLD_CHAINED_PTR_FORMAT::NONE:
239 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E:
240 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_USERLAND:
241 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_USERLAND24:
242 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_SHARED_CACHE:
245 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_KERNEL:
246 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_FIRMWARE:
247 case DYLD_CHAINED_PTR_FORMAT::PTR_32_FIRMWARE:
248 case DYLD_CHAINED_PTR_FORMAT::PTR_64:
249 case DYLD_CHAINED_PTR_FORMAT::PTR_64_OFFSET:
250 case DYLD_CHAINED_PTR_FORMAT::PTR_32:
251 case DYLD_CHAINED_PTR_FORMAT::PTR_32_CACHE:
252 case DYLD_CHAINED_PTR_FORMAT::PTR_64_KERNEL_CACHE:
255 case DYLD_CHAINED_PTR_FORMAT::PTR_X86_64_KERNEL_CACHE:
261 static size_t ptr_size(DYLD_CHAINED_PTR_FORMAT fmt) {
263 case DYLD_CHAINED_PTR_FORMAT::NONE:
265 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E:
266 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_USERLAND:
267 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_USERLAND24:
268 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_KERNEL:
269 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_FIRMWARE:
270 case DYLD_CHAINED_PTR_FORMAT::PTR_64:
271 case DYLD_CHAINED_PTR_FORMAT::PTR_64_OFFSET:
272 case DYLD_CHAINED_PTR_FORMAT::PTR_64_KERNEL_CACHE:
273 case DYLD_CHAINED_PTR_FORMAT::PTR_X86_64_KERNEL_CACHE:
274 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_SHARED_CACHE:
275 return sizeof(uint64_t);
277 case DYLD_CHAINED_PTR_FORMAT::PTR_32_FIRMWARE:
278 case DYLD_CHAINED_PTR_FORMAT::PTR_32:
279 case DYLD_CHAINED_PTR_FORMAT::PTR_32_CACHE:
280 return sizeof(uint32_t);
291 ChainedPointerAnalysis&
operator=(
const ChainedPointerAnalysis&) =
default;
294 ChainedPointerAnalysis& operator=(ChainedPointerAnalysis&&) noexcept = default;
296 ~ChainedPointerAnalysis() = default;
298 uint64_t value()
const {
307 return *
reinterpret_cast<const dyld_chained_ptr_arm64e_rebase_t*
>(&value_);
311 return *
reinterpret_cast<const dyld_chained_ptr_arm64e_bind_t*
>(&value_);
315 return *
reinterpret_cast<const dyld_chained_ptr_arm64e_auth_rebase_t*
>(&value_);
319 return *
reinterpret_cast<const dyld_chained_ptr_arm64e_auth_bind_t*
>(&value_);
323 return *
reinterpret_cast<const dyld_chained_ptr_64_rebase_t*
>(&value_);
327 return *
reinterpret_cast<const dyld_chained_ptr_arm64e_bind24_t*
>(&value_);
331 return *
reinterpret_cast<const dyld_chained_ptr_arm64e_auth_bind24_t*
>(&value_);
335 return *
reinterpret_cast<const dyld_chained_ptr_64_bind_t*
>(&value_);
339 return *
reinterpret_cast<const dyld_chained_ptr_64_kernel_cache_rebase_t*
>(&value_);
343 return *
reinterpret_cast<const dyld_chained_ptr_32_rebase_t*
>(&value_);
347 return *
reinterpret_cast<const dyld_chained_ptr_32_bind_t*
>(&value_);
351 return *
reinterpret_cast<const dyld_chained_ptr_32_cache_rebase_t*
>(&value_);
355 return *
reinterpret_cast<const dyld_chained_ptr_32_firmware_rebase_t*
>(&value_);
358 struct union_pointer_t {
359 PTR_TYPE type = PTR_TYPE::UNKNOWN;
361 dyld_chained_ptr_arm64e_rebase_t arm64e_rebase;
362 dyld_chained_ptr_arm64e_bind_t arm64e_bind;
363 dyld_chained_ptr_arm64e_auth_rebase_t arm64e_auth_rebase;
364 dyld_chained_ptr_arm64e_auth_bind_t arm64e_auth_bind;
365 dyld_chained_ptr_64_rebase_t ptr_64_rebase;
366 dyld_chained_ptr_arm64e_bind24_t arm64e_bind24;
367 dyld_chained_ptr_arm64e_auth_bind24_t arm64e_auth_bind24;
368 dyld_chained_ptr_64_bind_t ptr_64_bind;
369 dyld_chained_ptr_64_kernel_cache_rebase_t ptr_64_kernel_cache_rebase;
370 dyld_chained_ptr_32_rebase_t ptr_32_rebase;
371 dyld_chained_ptr_32_bind_t ptr_32_bind;
372 dyld_chained_ptr_32_cache_rebase_t ptr_32_cache_rebase;
373 dyld_chained_ptr_32_firmware_rebase_t ptr_32_firmware_rebase;
382 return (
bool)ordinal();
387 std::ostream&
operator<<(std::ostream& os,
const union_pointer_t& ptr);
390 static_assert(
sizeof(union_pointer_t) == 16);
392 union_pointer_t
get_as(DYLD_CHAINED_PTR_FORMAT fmt)
const;
395 BinaryStream& stream, DYLD_CHAINED_PTR_FORMAT format,
396 const std::function<
int(uint64_t,
const union_pointer_t& ptr)>& callback);
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
Definition ChainedPointerAnalysis.hpp:29
union_pointer_t get_as(DYLD_CHAINED_PTR_FORMAT fmt) const
ChainedPointerAnalysis(uint64_t value, size_t size)
Definition ChainedPointerAnalysis.hpp:285
const dyld_chained_ptr_32_bind_t dyld_chained_ptr_32_bind() const
Definition ChainedPointerAnalysis.hpp:346
const dyld_chained_ptr_64_bind_t dyld_chained_ptr_64_bind() const
Definition ChainedPointerAnalysis.hpp:334
const dyld_chained_ptr_64_rebase_t dyld_chained_ptr_64_rebase() const
Definition ChainedPointerAnalysis.hpp:322
size_t size() const
Definition ChainedPointerAnalysis.hpp:302
const dyld_chained_ptr_arm64e_rebase_t dyld_chained_ptr_arm64e_rebase() const
Definition ChainedPointerAnalysis.hpp:306
const dyld_chained_ptr_arm64e_auth_rebase_t dyld_chained_ptr_arm64e_auth_rebase() const
Definition ChainedPointerAnalysis.hpp:314
const dyld_chained_ptr_64_kernel_cache_rebase_t dyld_chained_ptr_64_kernel_cache_rebase() const
Definition ChainedPointerAnalysis.hpp:338
ChainedPointerAnalysis & operator=(const ChainedPointerAnalysis &)=default
const dyld_chained_ptr_arm64e_bind24_t dyld_chained_ptr_arm64e_bind24() const
Definition ChainedPointerAnalysis.hpp:326
const dyld_chained_ptr_arm64e_bind_t & dyld_chained_ptr_arm64e_bind() const
Definition ChainedPointerAnalysis.hpp:310
const dyld_chained_ptr_32_rebase_t dyld_chained_ptr_32_rebase() const
Definition ChainedPointerAnalysis.hpp:342
static size_t stride(DYLD_CHAINED_PTR_FORMAT fmt)
Definition ChainedPointerAnalysis.hpp:235
const dyld_chained_ptr_32_firmware_rebase_t dyld_chained_ptr_32_firmware_rebase() const
Definition ChainedPointerAnalysis.hpp:354
const dyld_chained_ptr_arm64e_auth_bind_t dyld_chained_ptr_arm64e_auth_bind() const
Definition ChainedPointerAnalysis.hpp:318
ChainedPointerAnalysis(ChainedPointerAnalysis &&) noexcept=default
static std::unique_ptr< ChainedPointerAnalysis > from_value(uint64_t value, size_t size)
Definition ChainedPointerAnalysis.hpp:228
const dyld_chained_ptr_32_cache_rebase_t dyld_chained_ptr_32_cache_rebase() const
Definition ChainedPointerAnalysis.hpp:350
static size_t ptr_size(DYLD_CHAINED_PTR_FORMAT fmt)
Definition ChainedPointerAnalysis.hpp:261
ChainedPointerAnalysis(const ChainedPointerAnalysis &)=default
const dyld_chained_ptr_arm64e_auth_bind24_t dyld_chained_ptr_arm64e_auth_bind24() const
Definition ChainedPointerAnalysis.hpp:330
static uint64_t walk_chain(BinaryStream &stream, DYLD_CHAINED_PTR_FORMAT format, const std::function< int(uint64_t, const union_pointer_t &ptr)> &callback)
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
@ UNKNOWN
Definition MachO/enums.hpp:25
LIEF namespace.
Definition Abstract/Binary.hpp:36
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_32_bind_t &chain)
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_32_cache_rebase_t &chain)
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_32_firmware_rebase_t &chain)
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_32_rebase_t &chain)
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_64_bind_t &chain)
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_64_kernel_cache_rebase_t &chain)
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_64_rebase_t &chain)
uint64_t unpack_target() const
Definition ChainedPointerAnalysis.hpp:105
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_arm64e_auth_bind24_t &chain)
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_arm64e_auth_bind_t &chain)
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_arm64e_auth_rebase_t &chain)
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_arm64e_bind24_t &chain)
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_arm64e_bind_t &chain)
friend std::ostream & operator<<(std::ostream &os, const dyld_chained_ptr_arm64e_rebase_t &chain)
uint64_t unpack_target() const
Definition ChainedPointerAnalysis.hpp:43
friend std::ostream & operator<<(std::ostream &os, const union_pointer_t &ptr)
bool is_bind() const
Definition ChainedPointerAnalysis.hpp:381
result< uint64_t > target() const
result< uint32_t > ordinal() const
#define LIEF_API
Definition visibility.h:41