Repository navigation
Multi-format loader PR-10: un-gate the format-agnostic passes (string literals + typed args on PE/Mach-O) - #62
Merged
Conversation
Generalize the string-literal scan's section selection from the ELF-only
`SHF_ALLOC` test to a per-format `is_loaded_initialized` (the
`getLoadedAndInitializedAddressSet` analog): the ELF arm is byte-identical
(`SHF_ALLOC`, the only path on the default pipeline), with new PE/COFF
(mapped + readable, not uninitialized) and Mach-O (non-zero-fill) arms
reachable under --experimental-formats.
Headline: a PE `puts("hello")` (the literal is in `.rdata`,
`SectionKind::ReadOnlyData` / `SectionFlags::Coff`) now recovers its string
literal — was `puts(0x140009000)`. ELF section selection proven unchanged by
a parity unit test over fauxware.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
Drop the `BinaryFormat::Elf` gate on the library-prototype seeder and union
`present_function_names` with the §3 import resolver's names, so a PE
IAT/INT `puts`/`printf` and a Mach-O `__stubs` `printf` get their prototypes
seeded (matters on a stripped PE — no symtab `puts` — and on Mach-O, where the
import is named by the stub walk, not a `SymbolKind::Text` entry). The ELF
union is a no-op (elf_plt names the same `.dynsym` names), so ELF is unchanged.
Also mark Mach-O `__cstring` (`SectionKind::ReadOnlyString`) READONLY in
`MachOFormat::section_bits` — the prerequisite that lets the printer's
constant-string route read a typed `char *` arg's bytes.
Headline (PE): `printf(0x140009006, a0)` -> `printf("%d\n", a0)`. The PE now
renders BOTH `puts("hello")` and the typed `printf("%d\n", …)`. Mach-O:
`printf((char *)0x1000005ee, …)` -> `printf("%d\n", …)`.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
Drop the `BinaryFormat::Elf` gate on the known-no-return scan and select a per-format base list: ELF keeps the vendored ELF list (+ the per-compiler Rust/Go widening); PE/COFF/Mach-O get a new vendored PeMacFunctionsThatDoNotReturn (the shared C names exit/abort/quick_exit + the Windows-CRT specifics __fastfail/_invoke_watson/…). Names are format-neutral; only which shipped list applies differs (the kuna analog of noReturnFunctionConstraints.xml's per-executable-format arms). ELF behavior is unchanged. Per-pass proof (PE): `__tmainCRTStartup`'s tail `exit(…)` is marked `/* WARNING: Subroutine does not return */` and the dead fall-through after it is elided; `--option noreturn_known off` restores the dead code (`*dat… = 1; v14 = __tmainCRTStartup(); return v14;`). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
Drop the `BinaryFormat::Elf` gate on the call-fixup installer. A cspec `<callfixup>` `<target>` is a function NAME matched against the object's FUNC symbols — neutral data on every format — and the fixup map comes from the loaded arch's cspec (the Windows cspec ships its own fixups). So the install half is format-agnostic; the gate was the only thing keeping it ELF-only. ELF behavior unchanged (the mcount fixture still injects out its `-pg` stub). A unit test proves the FUNC-symbol scan now reaches the matcher on a PE (no ELF early return) by flagging a synthetic target matching a real PE symbol. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
Drop the `BinaryFormat::Elf` gate and generalize the exec/searchable section checks (`is_executable_section`/`is_searchable_section`) with per-format arms: ELF `SHF_EXECINSTR`/`SHF_ALLOC` (unchanged), PE/COFF `IMAGE_SCN_MEM_EXECUTE` / mapped-readable, Mach-O `S_ATTR_PURE_INSTRUCTIONS`/`SectionKind::Text`. The relocation guard already keys on the neutral `file.kind()`. Still off by default (registered commented-out, Ghidra parity). ELF scan unchanged (the switchtab 8-entry table + fauxware negative tests still pass). A unit test proves the scan runs to completion over a PE + Mach-O (exec ranges resolve, no ELF early return). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
The discovered-no-return consumer is already format-neutral (it reads the built
Listing, which builds on a PE/Mach-O: `s1_entry::executable_sections` already
falls through to `SectionKind::Text` for non-ELF). This confirms it via an e2e
that drives `listing on` + `noreturn_disc on` over a PE to completion.
Adds `verify_multiformat_passes.rs` — the PR-10 payoff e2e:
- PE renders BOTH `puts("hello")` (s1_strings) and `printf("%d\n", …)`
(s1_protos typed char* arg) — was `puts(0x140009000)` / `printf(0x140009006,…)`.
- Mach-O renders `printf("%d\n", …)` (typed char* + READONLY __cstring).
- PE `exit(…)` (PeMac no-return list) elides dead code; `noreturn_known off`
restores it.
- s1_noreturn_disc runs on a PE (Listing builds, consumer completes).
Also drops a stray `mut` in the per-format noreturn base-list selection.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
The un-gate-the-agnostic-passes increment: headline before/after
(puts(0x…) -> puts("hello") on a PE), the per-pass status table, the one
Mach-O __cstring READONLY loader touch-up, residual gaps, speed, and gate
results.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
coleleavitt
added a commit
to coleleavitt/kuna
that referenced
this pull request
Oct 29, 2026
trap_edges kept one (guard, edge) pair per trap block, so a CBRANCH whose two arms are both pointer-auth traps (tbz x0, Noelo-Lab#62, 1f; brk #0xc471; 1: brk #0xc472) was saved twice. The first remove_branch dropped the CBRANCH, the second cut the arm that was left, and the function decompiled to an empty body. A guard is now cut only when exactly one of its arms traps; stage test case `both` pins it.
coleleavitt
added a commit
to coleleavitt/kuna
that referenced
this pull request
Oct 29, 2026
A CPU without FEAT_FPAC does not trap on a failed aut*, so Apple's clang checks the result inline and branches to brk #0xc470+key when it is bad. Before a tail call it tests bits 62 and 61 of the authenticated x30 (eor x16, x30, x30, lsl #1; tbz x16, Noelo-Lab#62). SLEIGH hides the autibsp (ShowPAC is off), so that test reads the incoming return address and printed if ((v1 ^ v1 << 1) >> 0x3e & 1) { (*(void *)SoftwareBreakpoint(0xc471,0x100031fc8))(); // jump-as-call return; } ahead of nearly every tail call of an Apple binary. The data-pointer form (compare with the xpac-stripped copy) already folds on its own. p2_lift/kuna_ptrauthtrap.rs anchors on the trap block, a block lifted from one brk whose SoftwareBreakpoint immediate is 0xc470..0xc473, and removes every CBRANCH edge into it pre-SSA (the gomorestack window). New option ptrauthtrap, default on; off keeps the checks. Stage test tests/stages/kuna-ptrauthtrap.xml over the macho_arm64e_auth fixture; spec prose in docs/spec/02-lift-and-flow.md (2.11, which also records how the PAC instructions lift); catalog 341 -> 342 settables. [AUTOMATED] iOS 16.4.1 trustd decompile-all: 205 -> 0 traps, 58,805 -> 57,792 lines, only the 189 functions that held a trap change; 12.73/13.22 s off vs 12.83/12.96 s on. make test PARITY OK.
coleleavitt
added a commit
to coleleavitt/kuna
that referenced
this pull request
Oct 29, 2026
trap_edges kept one (guard, edge) pair per trap block, so a CBRANCH whose two arms are both pointer-auth traps (tbz x0, Noelo-Lab#62, 1f; brk #0xc471; 1: brk #0xc472) was saved twice. The first remove_branch dropped the CBRANCH, the second cut the arm that was left, and the function decompiled to an empty body. A guard is now cut only when exactly one of its arms traps; stage test case `both` pins it.
coleleavitt
added a commit
to coleleavitt/kuna
that referenced
this pull request
Nov 3, 2026
A CPU without FEAT_FPAC does not trap on a failed aut*, so Apple's clang checks the result inline and branches to brk #0xc470+key when it is bad. Before a tail call it tests bits 62 and 61 of the authenticated x30 (eor x16, x30, x30, lsl #1; tbz x16, Noelo-Lab#62). SLEIGH hides the autibsp (ShowPAC is off), so that test reads the incoming return address and printed if ((v1 ^ v1 << 1) >> 0x3e & 1) { (*(void *)SoftwareBreakpoint(0xc471,0x100031fc8))(); // jump-as-call return; } ahead of nearly every tail call of an Apple binary. The data-pointer form (compare with the xpac-stripped copy) already folds on its own. p2_lift/kuna_ptrauthtrap.rs anchors on the trap block, a block lifted from one brk whose SoftwareBreakpoint immediate is 0xc470..0xc473, and removes every CBRANCH edge into it pre-SSA (the gomorestack window). New option ptrauthtrap, default on; off keeps the checks. Stage test tests/stages/kuna-ptrauthtrap.xml over the macho_arm64e_auth fixture; spec prose in docs/spec/02-lift-and-flow.md (2.11, which also records how the PAC instructions lift); catalog 341 -> 342 settables. [AUTOMATED] iOS 16.4.1 trustd decompile-all: 205 -> 0 traps, 58,805 -> 57,792 lines, only the 189 functions that held a trap change; 12.73/13.22 s off vs 12.83/12.96 s on. make test PARITY OK.
coleleavitt
added a commit
to coleleavitt/kuna
that referenced
this pull request
Nov 3, 2026
trap_edges kept one (guard, edge) pair per trap block, so a CBRANCH whose two arms are both pointer-auth traps (tbz x0, Noelo-Lab#62, 1f; brk #0xc471; 1: brk #0xc472) was saved twice. The first remove_branch dropped the CBRANCH, the second cut the arm that was left, and the function decompiled to an empty body. A guard is now cut only when exactly one of its arms traps; stage test case `both` pins it.
mahaloz
added a commit
to coleleavitt/kuna
that referenced
this pull request
Nov 9, 2026
…rn-address test ptrauthtrap (default on, now on every AArch64 path) cut the CBRANCH edge into a brk #0xc470..0xc473 block whenever the guard was the x30 bit test, without asking which arm the trap sat on or where x30 came from: - Polarity: `tbz x16, Noelo-Lab#62, trap` (trap when bits 62 and 61 agree, i.e. on every authentic return address) lost its trap, so a function that always crashes printed as its never-taken arm (`secret(); return 7;`). The condition's polarity is now followed through the INT_EQUAL/NOTEQUAL/ BOOL_NEGATE chain and the CBRANCH's boolean flip, and only the arm taken when the bits disagree is cut. - Provenance: "unwritten in the block" let a `mov x30, x1` (or arithmetic) one block earlier through, and any LOAD counted as the frame reload, so `ldr x30, [x0]` passed too. x30 must now be unwritten anywhere in the function, or reloaded by a LOAD whose address is sp or x29 plus constants. The real shapes (ldp x29,x30 post-index or offset, ldr x30 [sp],Noelo-Lab#16, ldur x30 [x29,#8], mov sp,x29 epilogue, tbz and tbnz forms, leaf with x30 untouched) are still cut; all 52 AArch64 repo samples decompile byte- identically to the previous head. Tests: tests/stages/kuna-ptrauthtrap.xml #14 (inverted polarity), Noelo-Lab#15 (forgery in an earlier block), Noelo-Lab#16 (non-frame load); all three fail on the previous head. Stages baseline: the 3 new keys. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKS1xSN6UHyTiGivmGe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
PR-10 of the multi-format-loader expansion: un-gate the format-agnostic S1
analysis passes for PE/Mach-O, so a non-ELF binary renders string literals,
typed libc args, and no dead code after a no-return call — not just named imports.
Each pass had format-agnostic logic but was gated
BinaryFormat::Elf(or keyedon a raw
SHF_*flagobjectonly fills for ELF). One pass per commit; every ELFflag arm is unchanged, so the default (non-experimental) path is byte-identical.
The headline before/after (PE —
pe_imports.exe,puts("hello"); printf("%d\n", argc))Mach-O (
macho_imports):printf(0x1000005ee, …)→printf("%d\n", …)(typedchar *arg + the now-READONLY__cstring). PE no-return:__tmainCRTStartup'stail
exit(…)is on the new PeMac no-return list → marked/* Subroutine does not return */and the dead fall-through after it is elided (--option noreturn_known offrestores it).Per-pass status
s1_stringsSectionFlags::Elf & SHF_ALLOCis_loaded_initialized(ELF unchanged; PE/COFF mapped+readable; Mach-O non-zero-fill)s1_protosBinaryFormat::Elfresolve_imports(stripped-PE / Mach-O__stubs)noreturn.rs(Known)BinaryFormat::ElfPeMacFunctionsThatDoNotReturn(exit/abort/quick_exit +__fastfail/_invoke_watson)s1_callfixupBinaryFormat::Elfs1_addrtableBinaryFormat::Elf+SectionFlags::Elfs1_noreturn_discexecutable_sectionsalready falls through toSectionKind::Text)One small loader touch-up (not a gate-drop, folded into the
s1_protoscommit):Mach-O
__cstring(SectionKind::ReadOnlyString) was not marked READONLY byMachOFormat::section_bits, so the printer couldn't read a typedchar *arg'sbytes. Adding the
ReadOnlyStringarm completes the Mach-O literal.Residual gaps (documented, not forced)
%d\nis below the string-scan min-5, so no Mach-O fixture carries a≥5-char literal to prove the string-literal half of
s1_stringson Mach-Odirectly; the PE literal + the shared
is_loaded_initializedMach-O arm coverthe logic. The Mach-O headline rides the typed-
char *route.s1_addrtablestays off by default (no default output change on any format).s1_entryentry-oracles (.pdata/LC_MAIN/__eh_frame) remain §5.3 /PR-12+13 — out of scope; the Listing tier only needs
executable_sections.Speed
pe_imports.exe main~0.25–0.44 s wall (incl.decomp_dbgspawn +.slaload);ELF
fauxware main~0.22–0.46 s — on par. No measurable overhead (the only addedwork is one
resolve_importscall already computed for naming + O(sections) flagbranches).
Gates
make test— 675/675 PARITY OKmake test-stages— 159/159 PARITY OKmake rust-test— green (exit 0), incl. the new e2everify_multiformat_passes(4 tests, all RAN not skipped) + the per-pass unit tests. ELF byte-identical.
🤖 Generated with Claude Code
https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb