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
//! Pointer-authentication (arm64e) helpers.
//!
//! arm64e encodes a signature in the top 16 bits of a pointer. When dyld
//! applies fixups it replaces the signature with the authenticated target,
//! so pointers read from memory in a live process are plain VAs. Static
//! analysis, though, often sees the raw on-disk form and must strip the
//! signature bits before dereferencing the pointer or comparing it against
//! a VA.
//!
//! This module exposes the stripping operation as a single, testable helper
//! rather than scattering bit-masking through metadata readers. Call
//! [`strip_ptrauth`] on any `u64` that was read directly from the binary on
//! an arm64e image and is meant to be interpreted as a VA.
/// Mask covering the 48 virtual-address bits used by iOS / macOS arm64e.
///
/// Apple silicon uses 48-bit usable VAs and reserves bits 48..=63 for
/// pointer-auth metadata. Any arm64e pointer with those high bits set is
/// signed; clearing them yields the VA.
const PTRAUTH_MASK: u64 = 0x0000_FFFF_FFFF_FFFF;
/// Strip the pointer-authentication signature from an arm64e pointer.
///
/// Returns the raw VA with all pointer-auth metadata cleared. Do not use on
/// non-arm64e pointers: a plain value on x86_64 or arm64 may legitimately
/// occupy the top bits, and stripping would corrupt it.
/// Whether a `u64` has any bits set that arm64e would interpret as
/// pointer-auth metadata. A `false` return means [`strip_ptrauth`] is a no-op.