Format:Kernelcache
| Vendor | Apple |
|---|---|
| Platforms | iOS, macOS |
| Magic | CF FA ED FE (Mach-O) after any IM4P wrapper |
| On this wiki | Facts · Code · Notes · Topics |
The Apple kernel as shipped on iOS, iPadOS, tvOS and macOS: a Mach-O (MH_FILESET on current systems, with one LC_FILESET_ENTRY per kernel and kext; older kernelcaches use __PRELINK_* segments with a plist of kext info), wrapped in an IMG4/IM4P on iOS firmware.
Overview
A kernelcache holds the XNU kernel and (almost all of) the kernel extensions in one file, linked together so that no kext has to be loaded separately at boot. Two generations exist:
- Prelinked kernel (older): an ordinary Format:Mach-O executable with extra segments named
__PRELINK_TEXT,__PRELINK_DATAand__PRELINK_INFO; the__infosection of__PRELINK_INFOholds an XML property list describing each kext. The segment, section and dictionary key names are#defined in xnulibkern/libkern/prelink.h(kPrelinkTextSegment,kPrelinkInfoSegment,kPrelinkBundlePathKey=_PrelinkBundlePath,kPrelinkExecutableLoadKey=_PrelinkExecutableLoadAddr,kPrelinkKmodInfoKey=_PrelinkKmodInfo, and so on). Kernel-collection builds add_PrelinkKCID,_BootKCIDand_PageableKCIDkeys, a__RECEIPT_INFOsegment with an__aux_kc_receiptsection, and a__BRANCH_STUBSname (same header). - Kernel collection / fileset (newer): the file type is
MH_FILESET(0xC, "set of mach-o's"), and the load commands include oneLC_FILESET_ENTRY(0x80000035) per member.
LC_FILESET_ENTRY
struct fileset_entry_command {
uint32_t cmd; // LC_FILESET_ENTRY
uint32_t cmdsize; // includes the id string
uint64_t vmaddr; // memory address of the member dylib
uint64_t fileoff; // file offset of the member dylib
union lc_str entry_id; // offset of the entry id string inside the command
uint32_t reserved; // padding after the 32-bit lc_str
};
Each member is a complete Mach-O header at fileoff (and vmaddr once mapped), so a loader or disassembler can treat every kext as its own image inside the shared segments. Unverified: entry ids are bundle identifiers such as com.apple.kernel and com.apple.driver.* (not read in a sample; check by listing the LC_FILESET_ENTRY commands of a kernelcache).
Pointers
Kernel collections use Format:Mach-O/Chained fixups formats DYLD_CHAINED_PTR_ARM64E_KERNEL (7), DYLD_CHAINED_PTR_64_KERNEL_CACHE (8) and DYLD_CHAINED_PTR_X86_64_KERNEL_CACHE (11); the cacheLevel field of format 8/11 distinguishes the kernel collection levels. Unverified: which load command or section carries the chains for each collection (the firmware-style __TEXT,__chain_starts section with dyld_chained_starts_offsets is described on the chained fixups page).
On iOS firmware
In an IPSW or OTA the kernelcache is not a bare Mach-O but an IM4P (Format:IMG4) whose data is usually compressed; extract and decompress it first. ipsw (MIT) has a kernelcache package with a NOTES file pointing to a write-up on iOS 12 tagged pointers in kernelcaches. Unverified: the compression algorithm is reported in the IM4P itself (see Format:IMG4).
Reversing notes
- Identify the layout by
filetypein the mach_header: 0xC means fileset, anything else with a__PRELINK_INFOsegment is the old prelinked layout. - Kexts inside a kernelcache are listed by
LC_FILESET_ENTRY(new) or by the plist in__PRELINK_INFO,__info(old). - The system call tables,
sysent, and the XNU symbols are not in this page: see Platform:IOS and Platform:MacOS.
Code & repositories
- {{Repo|url=https://github.com/apple-oss-distributions/xnu%7Ccommit=f6217f891ac0bb64f3d375211650a4c1ff8ca1ea%7Clicense=APSL-2.0 (declared by the contributor; GitHub's detector did not recognize a license file)|description=XNU source: EXTERNAL_HEADERS/mach-o/loader.h (MH_FILESET, fileset_entry_command), libkern/libkern/prelink.h (_PRELINK* names) and osfmk/kern/cs_blobs.h (code signature blobs and CodeDirectory)|tested_on=source read, not run: source read, not run: headers read only|checked=checked 2026-10-19; last activity 2026-06-18}}
- {{Repo|url=https://github.com/blacktop/ipsw%7Ccommit=a9eae76e8b1e901e4a03dd530defac8a1b33f91a%7Clicense=MIT%7Cdescription=ipsw (MIT): pkg/img4 (IMG4/IM4P/IM4M/IM4R parser), pkg/ota/pbzx (pbzx reader), pkg/dyld (shared cache reader), pkg/kernelcache|tested_on=source read, not run: source read, not run: Go sources read only|checked=checked 2026-10-19; last activity 2026-10-16; Note: the latest release ships binaries; the wiki links only the source, never the binaries}}