8000 feat(kernel): recreate a KDK from a kernelcache (`kernel extract --kdk`) by mpass99 · Pull Request #1372 · blacktop/ipsw · GitHub
[go: up one dir, main page]

Skip to content

feat(kernel): recreate a KDK from a kernelcache (kernel extract --kdk) - #1372

Open
mpass99 wants to merge 1 commit into
blacktop:masterfrom
mpass99:feature/kernel-extract-kdk
Open

mpass99 wants to merge 1 commit into
blacktop:masterfrom
mpass99:feature/kernel-extract-kdk

Conversation

@mpass99
@mpass99 mpass99 commented Oct 22, 2026
Copy link
Copy Markdown

Summary

ipsw kernel extract --kdk <kernelcache> writes the kernel and every KEXT of an MH_FILESET kernelcache as standalone Mach-Os that kmutil can link into a new kernelcache. The output is laid out like a KDK (KDK_<version>_<build>.kdk/System/Library/{Kernels,Extensions}), with the KEXTs' Info.plists, the codeless KEXTs, the kernel's pseudo-extensions and a SystemVersion.plist.

This makes it possible to build kernelcaches Apple does not ship, for example the cloudOS research kernel mixed with KEXTs taken from another kernelcache.

How it works: the kernel collection builder resolves every reference between images and strips their chained fixups and split-segment info. For each image, the new package pkg/kernelcache/kdk recovers those references:

  • pointers, from the collection's chained fixups;
  • ADRP pages and the ADD/LDR/STR that complete them, followed across branches, jump tables, calls that preserve the register, and functions that do not return;
  • branches leaving a section;
  • deltas in __eh_frame, __static_if and __copyio_vectors;
  • image offsets in __unwind_info.

It then passes them to go-macho's File.Export(..., WithReferences(...)), which rebuilds the image as ld64 would have.

Stripped kernelcaches lack the symbols the KEXTs link against. Link symbols are then synthesised from the dependency graph, and --symbols <map.json> adds known names, for example from ipsw kernel symbolicate --json.

--all and single-KEXT extraction are unchanged.

Dependencies

This needs these changes in three libraries:

go.mod still points at the released versions; I'll bump it once those are merged and tagged. Until then, the branch builds with a local -modfile that replaces the three modules.

Testing

  • go test ./pkg/kernelcache/kdk/...
  • Regression check: KDKs extracted from six kernelcaches are byte-identical to the output before the review refactoring. The kernelcaches are the cloudOS research kernels of iOS 18.1, 18.7, 26.4 and 26.7, the vma2 kernelcache and the vphone600 kernelcache of the 26.4 beta.
  • End to end:
    • kmutil links the extractions (with --symbols) into mixed kernelcaches.
    • With Apple's own bundle list, a base's extraction links back to a kernelcache identical to the one Apple shipped.
    • VMs built on the mixed kernelcaches boot: iOS 18.x, 26.x and watchOS.

`ipsw kernel extract --kdk <kernelcache>` writes the kernel and every KEXT
of an MH_FILESET kernelcache as standalone Mach-Os that kmutil can link
into a new kernelcache, laid out like a KDK
(KDK_<version>_<build>.kdk/System/Library/{Kernels,Extensions}) with the
KEXTs' Info.plists, codeless KEXTs, the kernel's pseudo-extensions and a
SystemVersion.plist.

The kernel collection builder resolves every reference between the
images and strips their chained fixups and split-segment info. For each
image, the new package pkg/kernelcache/kdk recovers its references
(pointers from the collection's chained fixups; ADRP pages and the
ADD/LDR/STR that complete them, followed across branches, jump tables,
calls that preserve the register and functions that do not return;
branches leaving a section; deltas in __eh_frame, __static_if and
__copyio_vectors; image offsets in __unwind_info) and passes them to
go-macho's File.Export, which rebuilds the image like ld64.

Stripped kernelcaches lack the symbols the KEXTs link against: link
symbols are then synthesized from the dependency graph, and --symbols
takes known names from `ipsw kernel symbolicate --json`.

--all and single KEXT extraction are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@blacktop
Copy link
Copy Markdown
Owner

Are you still interested in pushing this forward? I think I saw that you guys implemented your own solution in Swift now or something.

@mpass99
mpass99 commented Oct 31, 2026
Copy link
Copy Markdown
Author

I think it is a cool functionality fitting nicely to ipsw. You're right that Jacky ported the functionality to Swift, so we have no pressure to merge it anymore. However, your suggestions for improving this PR towards merging it into ipsw are welcome.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0