Apple Internals & Low-Level Architecture Guide
Understanding low-level Apple operating system mechanics is essential for vulnerability research, tweak development, and dynamic instrumentation. This guide documents the Mach kernel, code signing enforcement, and the dyld shared cache architecture.
1. Mach Kernel Architecture & IPC
The XNU kernel combines Mach microkernel primitives with BSD POSIX APIs:
- Tasks and Threads: A Mach task represents the unit of resource allocation (virtual address space, port rights). Threads represent the unit of execution.
- Mach Ports: Kernel-protected communication channels. Inter-Process Communication (IPC) operates via
mach_msgwith message headers (mach_msg_header_t) containing send and receive port rights. - IOKit UserClients: Object-oriented driver interfaces based on C++ RTTI (
OSMetaClass). User applications invoke driver methods usingIOConnectCallMethod.
2. AMFI & Code Signing Architecture
AppleMobileFileIntegrity (AMFI) enforces code signing requirements across userland execution:
- SuperBlob Structure: Embedded signatures reside in an
LC_CODE_SIGNATUREload command structured as anEmbeddedSignatureSuperBlob with magic0xfade0cc0. - CodeDirectory (CS_CodeDirectory): Holds cryptographic hashes (SHA-1, SHA-256) of every executable page in the binary. The hash of the CodeDirectory slice itself is the CDHash.
- Page Fault Verification: When a page is mapped into memory with
VM_PROT_EXECUTE, the kernel computes the page hash and asserts that it matches the corresponding CodeDirectory slot. Mismatches trigger immediateSIGKILL. - Trust Caches: Approved CDHashes stored in kernel memory. If a CDHash exists in the static or dynamic Trust Cache, AMFI approves execution without evaluating certificates or consulting the
amfiddaemon.
3. Dyld Shared Cache (DSC) Extraction
Starting with iOS 3.1 and continuing through iOS 17+, Apple does not ship individual framework dynamic libraries on disk. All system dynamic libraries and private frameworks are pre-linked into monolithic Dyld Shared Cache files located in Cryptex volumes.
To inspect embedded frameworks within a shared cache:
ipsw dsc info dyld_shared_cache_arm64e
ipsw dsc image dyld_shared_cache_arm64e | grep -i "SpringBoard"
To extract a target framework into a standalone Mach-O file:
ipsw dsc macho dyld_shared_cache_arm64e -e SpringBoardServices -o ./extracted/
To resolve unexported symbols and call cross-references directly across the cache:
ipsw dsc symaddr dyld_shared_cache_arm64e _OBJC_CLASS_$_SBIconController
ipsw dsc xrefs dyld_shared_cache_arm64e -i SpringBoardServices _SBSLaunchApplicationWithIdentifier
4. Code Signing & Entitlement Commands
To display SHA-1 and SHA-256 CDHashes of a target binary:
codesign -dvvv TargetBinary 2>&1 | grep "CDHash="
To extract embedded entitlements:
codesign -d --entitlements :- TargetBinary
To ad-hoc re-sign a binary for research devices:
codesign --force --sign - --timestamp=none TargetBinary