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:
244 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_KERNEL:
245 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_FIRMWARE:
246 case DYLD_CHAINED_PTR_FORMAT::PTR_32_FIRMWARE:
247 case DYLD_CHAINED_PTR_FORMAT::PTR_64:
248 case DYLD_CHAINED_PTR_FORMAT::PTR_64_OFFSET:
249 case DYLD_CHAINED_PTR_FORMAT::PTR_32:
250 case DYLD_CHAINED_PTR_FORMAT::PTR_32_CACHE:
251 case DYLD_CHAINED_PTR_FORMAT::PTR_64_KERNEL_CACHE:
254 case DYLD_CHAINED_PTR_FORMAT::PTR_X86_64_KERNEL_CACHE:
260 static size_t ptr_size(DYLD_CHAINED_PTR_FORMAT fmt) {
262 case DYLD_CHAINED_PTR_FORMAT::NONE:
264 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E:
265 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_USERLAND:
266 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_USERLAND24:
267 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_KERNEL:
268 case DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_FIRMWARE:
269 case DYLD_CHAINED_PTR_FORMAT::PTR_64:
270 case DYLD_CHAINED_PTR_FORMAT::PTR_64_OFFSET:
271 case DYLD_CHAINED_PTR_FORMAT::PTR_64_KERNEL_CACHE:
272 case DYLD_CHAINED_PTR_FORMAT::PTR_X86_64_KERNEL_CACHE:
273 return sizeof(uint64_t);
275 case DYLD_CHAINED_PTR_FORMAT::PTR_32_FIRMWARE:
276 case DYLD_CHAINED_PTR_FORMAT::PTR_32:
277 case DYLD_CHAINED_PTR_FORMAT::PTR_32_CACHE:
278 return sizeof(uint32_t);
289 ChainedPointerAnalysis&
operator=(
const ChainedPointerAnalysis&) =
default;
292 ChainedPointerAnalysis& operator=(ChainedPointerAnalysis&&) noexcept = default;
294 ~ChainedPointerAnalysis() = default;
296 uint64_t value()
const {
305 return *
reinterpret_cast<const dyld_chained_ptr_arm64e_rebase_t*
>(&value_);
309 return *
reinterpret_cast<const dyld_chained_ptr_arm64e_bind_t*
>(&value_);
313 return *
reinterpret_cast<const dyld_chained_ptr_arm64e_auth_rebase_t*
>(&value_);
317 return *
reinterpret_cast<const dyld_chained_ptr_arm64e_auth_bind_t*
>(&value_);
321 return *
reinterpret_cast<const dyld_chained_ptr_64_rebase_t*
>(&value_);
325 return *
reinterpret_cast<const dyld_chained_ptr_arm64e_bind24_t*
>(&value_);
329 return *
reinterpret_cast<const dyld_chained_ptr_arm64e_auth_bind24_t*
>(&value_);
333 return *
reinterpret_cast<const dyld_chained_ptr_64_bind_t*
>(&value_);
337 return *
reinterpret_cast<const dyld_chained_ptr_64_kernel_cache_rebase_t*
>(&value_);
341 return *
reinterpret_cast<const dyld_chained_ptr_32_rebase_t*
>(&value_);
345 return *
reinterpret_cast<const dyld_chained_ptr_32_bind_t*
>(&value_);
349 return *
reinterpret_cast<const dyld_chained_ptr_32_cache_rebase_t*
>(&value_);
353 return *
reinterpret_cast<const dyld_chained_ptr_32_firmware_rebase_t*
>(&value_);
356 struct union_pointer_t {
357 PTR_TYPE type = PTR_TYPE::UNKNOWN;
359 dyld_chained_ptr_arm64e_rebase_t arm64e_rebase;
360 dyld_chained_ptr_arm64e_bind_t arm64e_bind;
361 dyld_chained_ptr_arm64e_auth_rebase_t arm64e_auth_rebase;
362 dyld_chained_ptr_arm64e_auth_bind_t arm64e_auth_bind;
363 dyld_chained_ptr_64_rebase_t ptr_64_rebase;
364 dyld_chained_ptr_arm64e_bind24_t arm64e_bind24;
365 dyld_chained_ptr_arm64e_auth_bind24_t arm64e_auth_bind24;
366 dyld_chained_ptr_64_bind_t ptr_64_bind;
367 dyld_chained_ptr_64_kernel_cache_rebase_t ptr_64_kernel_cache_rebase;
368 dyld_chained_ptr_32_rebase_t ptr_32_rebase;
369 dyld_chained_ptr_32_bind_t ptr_32_bind;
370 dyld_chained_ptr_32_cache_rebase_t ptr_32_cache_rebase;
371 dyld_chained_ptr_32_firmware_rebase_t ptr_32_firmware_rebase;
380 return (
bool)ordinal();
385 std::ostream&
operator<<(std::ostream& os,
const union_pointer_t& ptr);
388 static_assert(
sizeof(union_pointer_t) == 16);
390 union_pointer_t
get_as(DYLD_CHAINED_PTR_FORMAT fmt)
const;
393 BinaryStream& stream, DYLD_CHAINED_PTR_FORMAT format,
394 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:283
const dyld_chained_ptr_32_bind_t dyld_chained_ptr_32_bind() const
Definition ChainedPointerAnalysis.hpp:344
const dyld_chained_ptr_64_bind_t dyld_chained_ptr_64_bind() const
Definition ChainedPointerAnalysis.hpp:332
const dyld_chained_ptr_64_rebase_t dyld_chained_ptr_64_rebase() const
Definition ChainedPointerAnalysis.hpp:320
size_t size() const
Definition ChainedPointerAnalysis.hpp:300
const dyld_chained_ptr_arm64e_rebase_t dyld_chained_ptr_arm64e_rebase() const
Definition ChainedPointerAnalysis.hpp:304
const dyld_chained_ptr_arm64e_auth_rebase_t dyld_chained_ptr_arm64e_auth_rebase() const
Definition ChainedPointerAnalysis.hpp:312
const dyld_chained_ptr_64_kernel_cache_rebase_t dyld_chained_ptr_64_kernel_cache_rebase() const
Definition ChainedPointerAnalysis.hpp:336
ChainedPointerAnalysis & operator=(const ChainedPointerAnalysis &)=default
const dyld_chained_ptr_arm64e_bind24_t dyld_chained_ptr_arm64e_bind24() const
Definition ChainedPointerAnalysis.hpp:324
const dyld_chained_ptr_arm64e_bind_t & dyld_chained_ptr_arm64e_bind() const
Definition ChainedPointerAnalysis.hpp:308
const dyld_chained_ptr_32_rebase_t dyld_chained_ptr_32_rebase() const
Definition ChainedPointerAnalysis.hpp:340
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:352
const dyld_chained_ptr_arm64e_auth_bind_t dyld_chained_ptr_arm64e_auth_bind() const
Definition ChainedPointerAnalysis.hpp:316
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:348
static size_t ptr_size(DYLD_CHAINED_PTR_FORMAT fmt)
Definition ChainedPointerAnalysis.hpp:260
ChainedPointerAnalysis(const ChainedPointerAnalysis &)=default
const dyld_chained_ptr_arm64e_auth_bind24_t dyld_chained_ptr_arm64e_auth_bind24() const
Definition ChainedPointerAnalysis.hpp:328
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:379
result< uint64_t > target() const
result< uint32_t > ordinal() const
#define LIEF_API
Definition visibility.h:41