Skip to content

[AUTOMATED] dyld cache: load several images as one program and follow a callee into its image - #1685

Merged
mahaloz merged 27 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/dyld-multi-image
Nov 19, 2026
Merged

mahaloz merged 27 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/dyld-multi-image

Conversation

@coleleavitt

Copy link
Copy Markdown
Contributor

[AUTOMATED]

kuna loads one image of a dyld shared cache per run, so a callee in another image cannot be decompiled next to its caller: its address is "not mapped", and --image takes one name.

On the committed two-image cache, libcaller calls callee_add (0x180002800, in libcallee) through the stub island at 0x180008800:

$ C=decompiler/crates/kuna-analysis/tests/fixtures/dyld_cache_arm64e/dyld_shared_cache_arm64e
$ kuna decompile $C 0x180002800 --addr --image libcaller
error: address 0x180002800 is not mapped in this input
$ kuna decompile $C 0x180002800 --addr --image libcaller+libcallee
error: ... no image named "libcaller+libcallee" in the dyld shared cache

After, the first command prints (and 0x180008800, the island, gives the same function):

[kuna] 0x180002800 lies in /usr/lib/libcallee.dylib; loading that image too
int _callee_add(int a0,int a1)
{
  return a0 + a1;
}

On the iOS 16.4 arm64e cache, --image Foundation+CoreFoundation lists 61,908 functions, exactly the 50,742 and 11,166 the two images list alone, and __NSLogv and __CFLogvEx3 decompile in one run.

The change

  • dyldimage (and --image) takes several names joined by +. Each image is rebuilt as before and the results are joined into one thin Mach-O: every segment at its cache address, one symbol table with section ordinals renumbered, one indirect-symbol table, one function-starts table, one cross-image reference note. One name is rebuilt exactly as before.
  • The joined file gets a header page of its own: the segment commands of two images need not fit in the padding before the first section of one (the rebuilt Foundation has 2,808 bytes spare, CoreFoundation's segment commands take 4,904).
  • decompile, disassemble and xrefs look each 0x address of the request up in the cache's image ranges and add the image that holds it, bounded by a global --follow-images N (default 2, 0 = off). decompile and disassemble first follow a stub island to the function it jumps to; xrefs does not, since the island is what call sites reference.
  • The ObjC, CFString and Swift passes read every section of a name, not the first, so the second image keeps its CFSTR(...) literals and class references.
  • No new option: this is a new value form of dyldimage plus one CLI flag. Limits: the joined images may hold 255 sections together (a Mach-O symbol names its section in one byte), and a call through a stub island still renders as a named import, so xrefs --to the callee's own address lists direct calls only.

Tests

  • tests/stages/kuna-dyldimage-merge.xml: libcaller+libcallee decompiles callee_add in the same script as its caller.
  • kuna-cli dyld_follow_images: A+B, an address in another image, a stub island, and --follow-images 0 (which keeps today's error). The first three fail without the change.
  • kuna_dyldcache unit tests: symbol sections, stub imports and function starts of a joined image, the 255-section refusal, and follow_images with and without stubs.
  • Speed: a single-image load is unchanged within noise on a busy machine. decompile <cache> __NSLogv --image Foundation takes 1.17 s before and 1.09 s after (best of 30), with identical output and a byte-identical unpack. Joined output was compared with single-image output on 24 sampled functions; it differs only where a reference into the other image now resolves, and in one local renamed by a name collision.

Fixes #1622

coleleavitt and others added 18 commits November 18, 2026 15:48
…nstruction

`--assert 'callproto [<func>::]<callsite> <C declaration>'` states the
arguments and return of the call made by one instruction. A call through a
pointer or a register has no callee symbol to carry a signature, and a
variadic callback takes different arguments at each call, so `prototype`
and `data` cannot say it. The directive goes through the per-call-site
prototype override the engine already has (the console's `override
prototype`), on both the script surface and the in-process one.

A parameter may be followed by `@<storage>` to be read from that storage
rather than the place the calling convention gives it, and a `@<storage>`
after the parameter list places the return. `override prototype` takes the
same declaration, and no longer needs the trailing `;`.

An address at which the function makes no call is rejected with `No call
is made at this address`.

Fixes Noelo-Lab#1643
…ta through the cache

In an image loaded from a dyld shared cache the objc pass recovered
nothing: methods kept only the names the .symbols file has, self and _cmd
were untyped, and every objc_msgSend$<sel> stub stayed sub_<addr>.

- kuna_dyldcache: objc_selector_base() from the header's
  ObjCOptimizationHeader, else libobjc's objc_opt_t (__objc_opt_ro,
  version 16 on).
- analyzers/objc/kuna_objccache.rs: the pass reads addresses outside the
  image's own sections through the cache, a slid page at a time, each
  read charged to the walk budget.
- methods.rs: direct selectors (0x40000000) and type strings relative to
  the selector base (0x20000000). The entry size is entsizeAndFlags &
  0xfffc: the two low bits are the uniqued and sorted flags a cache
  carries on disk.
- classt.rs: baseMethods with its low bit set is a relative list of
  lists. A preattached category method whose IMP is in another image is
  named there as an import.
- A symbol at the IMP spelling the same class and selector under another
  category name is kept as the label, so the prototype reaches a function
  the symbol table already named (the linker merges categories).

Foundation out of an iOS 16.4 arm64e cache: 3,979 objc_msgSend$<sel>
stubs named (0 before); every selector, class, super and protocol
reference slot named; self and _cmd typed. No option: it rides objc and
is inert off a cache image. make test and make test-stages move no
existing expectation.

Stage test kuna-dyldcacheobjc.xml on two synthetic caches built by
dyld_cache_objc.py (header selector base; objc_opt_t only).

Fixes Noelo-Lab#1623
…dimage A+B, --follow-images)

A callee in another image of a dyld shared cache could not be decompiled in
the same run as its caller: its address was "not mapped", and `--image` took
one name.

`dyldimage` (and `--image`) now takes several names joined by `+`. Each image
is rebuilt as before and the results are joined into one thin Mach-O with a
header page of its own: every segment at its cache address, one symbol table
with section ordinals renumbered, one indirect-symbol table, one
function-starts table and one cross-image reference note. One name is rebuilt
exactly as before.

`decompile`, `disassemble` and `xrefs` look each 0x address of the request up
in the cache's image ranges and add the image that holds it, bounded by the
global `--follow-images N` (default 2, 0 turns it off). `decompile` and
`disassemble` first follow a stub island to the function it jumps to.

The ObjC, CFString and Swift passes read every section of a name instead of
the first, and function starts count from the first __TEXT command, so each
image of a joined Mach-O keeps its metadata.

Fixes Noelo-Lab#1622
The header-room reason and the same-text claim were worded as general facts.
They rest on one measured pair (Foundation and CoreFoundation, iOS 16.4.1) and
a sample of 24 functions, in which one local was also renamed by a name
collision. Say so in the spec and the module header.

Fixes Noelo-Lab#1622
…the collections it links

A macOS Auxiliary or System kernel collection points into the boot
collection (and an Auxiliary one into the System collection) with
kernel-cache chained fixups that are offsets from the other file's base.
Those slots kept their packed chain words, so a kext's calls into the
kernel printed as indirect calls through a data word.

The new load-time option kernelcache-boot (auto|off|<path>, default auto)
finds the collection whose LC_UUID or _PrelinkKCID is the UUID the input's
__PRELINK_INFO names (_BootKCID, _PageableKCID), beside the input or at the
given path, rebases the level-0 and level-1 slots against its base and
names the functions they reach from its symbol tables. A symbol-pointer or
__auth_ptr slot of a collection kext that holds a bound import's address
is that import's slot. When no file matches, the load note counts the
unresolved slots and names the missing UUID.

Fixes Noelo-Lab#1624
… one, refuse a named convention

- calltargettype skipped every call with a locked prototype, so stating the
  prototype a call already had turned `(*(int (*)(int,int))cb)(a,b)` into the
  uncompilable `(*(void *)cb)(a,b)`. A prototype stated at the call itself
  (`override prototype` / `callproto`, not a format string's) is now typed
  from its arguments like an unlocked call, with the stated parameters'
  storage standing in for the recovered storage it does not have.
- Two callproto directives for one call both reported `applied` while only
  the later took effect; the earlier is now rejected on both surfaces.
- The override is built under the default model, so a declaration naming
  another calling convention is rejected by name instead of a syntax error.
- The fixture recipe gains -fcf-protection=full (the committed binary has
  endbr64); docs example now carries the `data` assertion its output needs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…ed prototype

Building the type from the arguments' recovered types spelled a stated
`long f(long, long)` as `unsigned long (*)(unsigned long,unsigned long)` and a
string-literal parameter as `void *`. A call whose prototype was stated at the
call now takes its return and parameter types from that declaration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…ffset

objc_opt_t.relativeMethodSelectorBaseAddressOffset is an int64_t from the
record (dyld objc-shared-cache.h, relativeMethodListsBaseAddress()), so a
selector base below libobjc's __objc_opt_ro is a negative offset; the unsigned
add overflowed and lost the base. The fixture test now also checks the
header path and the objc_opt_t path each on their own (the fallback hid a
broken header read).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Resolves the stage corpus count (783 + kuna-dyldcacheobjc = 784) and
re-synthesizes docs/baseline-stages.json (main's 4,524 + this PR's 7).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…part of that name

dyldimage A+B split the value at every +, so --image libc++.1.dylib,
libc++abi.dylib or libstdc++.6.dylib (which load on main) failed with
"no image named \".1.dylib\"". select_all now takes, from each piece, the
longest run of +-joined pieces that names an image; a run ends only at the
end of the value or before a non-empty piece, so libc++ is never read as
libc. A value without + resolves exactly as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
A call-site prototype is laid out under the default model, and a
declaration naming any other convention is rejected. The check compared
names only, so on x86-64 Windows `__cdecl` and `__stdcall`, which the
compiler spec declares as aliases of the default `__fastcall`
(`<modelalias>`), were rejected with a message saying they are not the
default. A named model is now accepted when it is the default or an alias
of it with the same `this` handling (`ProtoModel::is_compatible`).

The CLI test helper passed `--assert-strict` as a directive, so the
strict-exit check passed on a usage error; it is now a flag, and the
check pins exit code 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
A prototype stated at an indirect call types the call's target so the
call stays one C can make, but a variadic statement was still skipped,
so `callproto <site> void f(char *, ...)` printed the call through
`(void *)`, which no C compiler accepts, where the unstated call had been
compilable. A stated variadic prototype now types the target with its
fixed parameters and `...` when the call passes at least those, laid out
in the storage the stated parameters were given. Calls without a stated
prototype take exactly the path they took before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Count-only conflicts: the stage corpus count in xml.rs (main 783 + this
branch's kuna-callproto = 784) and docs/baseline-stages.json, synthesized
from both sides (main 4524 + 4 = 4528).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Resolves the stage corpus count in kuna-base/src/xml.rs (both comment
lines kept) and docs/baseline-stages.json (synthesized from both sides).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…input, and say which file text decompile used

A linked collection named by path is read only if it is a regular file, so a
FIFO no longer blocks the load and a device such as /dev/zero is not read
until memory runs out. The input itself is never a candidate: it was read
whole a second time on every load, and an input naming its own UUID was
taken as its own boot collection. Text `kuna decompile` now forwards the
engine's MH_FILESET load note, as `functions` and `decompile --json` already
print it, so the file that resolved the pointers is visible.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
The first 4096 directory entries are taken in listing order and then tried in
name order; only regular files other than the input are candidates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
@mahaloz

mahaloz commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed two commits on top of this branch:

  • c6991b4 keeps a + that belongs to an image's own name. Splitting dyldimage at every + broke --image libc++.1.dylib, libc++abi.dylib and libstdc++.6.dylib, which all load on main. Repro on a cache holding /usr/lib/libc++.1.dylib:
    $ kuna functions dyld_shared_cache_arm64e --image libc++.1.dylib
    before: error: ... no image named ".1.dylib" in the dyld shared cache; close: /usr/lib/libc++.1.dylib
    after:  the functions of /usr/lib/libc++.1.dylib, as on main
    
    From each piece, select_all now takes the longest run of +-joined pieces that names an image. A run ends only at the end of the value or before a non-empty piece, so libc++ is not read as libc, and libc++.1.dylib+libc++abi loads two images. A value without + resolves exactly as before. The commit adds a unit test and notes in docs/cli.md and the spec.
  • 5a09c68 merges main: the corpus count in xml.rs and docs/baseline-stages.json conflicted.

mahaloz and others added 8 commits November 19, 2026 04:21
Resolves the stage corpus count (kuna-base/src/xml.rs), the tier counts in
kuna_phases/tests.rs, docs/baseline-stages.json (synthesized from both sides)
and docs/cli.md (the kernelcache-boot subsection stays under the kernelcache
section, before main's new `--member` section).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Both sides added one option, so the settable, catalog-record and
KUNA-CATALOG Noelo-Lab#15 counts each move by two from the merge base.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Resolves kuna-cli/src/main.rs against the ar-member loader (Noelo-Lab#1675):
--follow-images is taken before armember::resolve, and the image
selection is exported and widened after it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Main gained callee (Noelo-Lab#1676) and format/isolate (Noelo-Lab#1679) beside callproto in
the same assertion files: every directive list, Body variant and match arm
keeps both sides, assertions.rs keeps record_rejected_callee_overrides and
record_unbound_call_prototypes whole, project.rs calls both, and
assertion_outcomes runs both restatement passes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
@mahaloz
mahaloz merged commit b5d9f85 into Noelo-Lab:main Nov 19, 2026
@coleleavitt
coleleavitt deleted the fix/dyld-multi-image branch November 21, 2026 06:26
coleleavitt added a commit to coleleavitt/kuna that referenced this pull request Nov 22, 2026
[AUTOMATED] Resync of the combined branch with Noelo-Lab/kuna main.

Superseded by upstream (fork copy dropped, upstream's version kept):
- gortti -> upstream gotypes (itabs + typeglobals); the fork's Go
  fieldtypes/structorder/itabs copies and the go_rtti stream removed.
- tailcontract -> upstream protoorder bootstrap.
- unmergecall -> upstream `returndup calls`.
- treeswitch/linearswitch -> upstream `loweredswitch tree|linear`.
- whilecontinue -> upstream continue_points.
- compacttable -> upstream AArch64 compact-table fold in kuna_switchtable.
- repstring: upstream's version (Noelo-Lab#1650, adds repz cmpsb); fork copyrun kept.
- dyld cache: upstream Noelo-Lab#1684/Noelo-Lab#1685 (select_all/extract_merged, ObjC
  methods/stubs, hardening); fork-only 32-bit caches, slide v4 and the
  exporttrie cross-image names ported onto it.
- kernelcache linked collections, Mach-O data slots, panicloc, calltable,
  gotonext, postinc, typevote, condexe/extrapop/kernelcache stage tests:
  upstream's versions.
- kuna_gomoduledata: upstream's module (pclntab extent); the fork's
  full-record locator renamed kuna_gomodlayout.

Fork-only tracks kept and adapted to upstream's API (engine commit,
architecture fields, option dispatch, passes, xrefs storage, userop ids
renumbered after upstream's new builtins, chained-fixup linked targets).
switchtrim now runs after switchextent. codestrings also keeps a string
after an x86 call-over-data (callpopret CLI test).

Stage/CLI/web tests from upstream that a fork default-on option changes pin
that option off (calleeretpurge, gotosink, looprotate, rangefold,
bitidioms, fdeflowbound, formatcallees, globalwidth, dwarfscopes).
copyrun's i386 case gets its own fixture (copyrun_i386); repstring's i386
fixture is upstream's.

Generated files regenerated, not hand-merged: docs/options.md, catalog
counts (308 settables), phase_catalog.json, list_action snapshot, corpus
count (941). docs/baseline-stages.json re-recorded at the merge
(sanctioned re-pin for an upstream sync, 5403/5403); docs/baseline.json
is upstream's (675/675).
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.

[AUTOMATED] dyld cache: a callee in another image cannot be decompiled without reloading the cache on that image

2 participants