Repository navigation
Multi-format loader PR-2: object features + format dispatch (--experimental-formats) - #38
Merged
Merged
Conversation
…patch (--experimental-formats)
Enable object's pe/macho/coff readers, add the three ObjectFormat skeletons,
and wire is_object_binary to route their magics to the object loader — all
behind --experimental-formats so the default path stays ELF-only and
byte-identical. Builds on the PR-1 ObjectFormat seam (Increment 35).
- decompiler/Cargo.toml: object features +["pe","macho","coff"]. Cargo.lock
unchanged (no new transitive crates — the offline-safe outcome); confirmed
via `cargo build --offline` (zero downloads).
- s1_loader/format/{pe,macho,coff}.rs: skeletons. compiler_model per §2
(PE→windows, Mach-O→gcc[x86-64]/default[arm64], COFF→windows); section_bits
(PE/COFF share a Characteristics-keyed helper, Mach-O keys on SectionKind +
S_ATTR_PURE_INSTRUCTIONS); resolve_imports empty (IAT/__stubs naming is
PR-4/PR-7). detect() now constructs all four.
- engine.rs: bootstrap_from_elf → bootstrap_from_object (format-neutral; all
callers + verify_* imports updated). ELF_MAGIC test → is_object_binary per
§1.4 — admits ONLY ELF by default; PE/Mach-O/COFF/COFF magics are gated on
KUNA_EXPERIMENTAL_FORMATS. The XML/bootstrap_program branch (Invariant 1) is
untouched.
- --experimental-formats exposed via the KUNA_EXPERIMENTAL_FORMATS env var
(read live in bootstrap_from_file) + a `kuna decompile --experimental-formats`
CLI flag that exports it onto the decomp_dbg subprocess.
- §2.2 compiler-model fallback: ObjectLoadImage::fallback_arch_id() (the
default-model id); bootstrap_from_object retries with it when the primary
doesn't resolve and no --target was given. ELF carries no fallback.
Fixtures (built in-container, no new packages): pe_min.obj (clang
x86_64-pc-windows-gnu → Intel amd64 COFF), macho_min.o (clang
x86_64-apple-macos11 → relocatable Mach-O).
Tests (all ran, not skipped — x86 .sla built): 8 format unit tests; the
language-id resolves gate extended (PE/Mach-O/COFF ids resolve directly:
PE→x86:LE:64:default:windows, Mach-O→x86:LE:64:default:gcc); a §2.2 fallback
unit test; e2e verify_object_formats.rs (2 tests) — each fixture parses, maps
CODE|READONLY sections, selects the right spec, disassembles real x86-64, and
is rejected with the flag off (the default-off proof).
Gates: make test 675/675 PARITY OK; make test-stages 159/159 PARITY OK;
make rust-test green. Default `kuna decompile` on an ELF is byte-identical with
and without --experimental-formats (the flag is a no-op on ELF).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ad, before a call Adds e_bcall (call on a branch), e_lcall (after a loop of loads) and e_arg (the call takes the global's old value) to storealias_x86_64.c, rebuilds the three fixtures (SHAs in the README), round-trips them in store_alias.rs and adds stage assertions #33-#38. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ad, before a call Adds e_bcall (call on a branch), e_lcall (after a loop of loads) and e_arg (the call takes the global's old value) to storealias_x86_64.c, rebuilds the three fixtures (SHAs in the README), round-trips them in store_alias.rs and adds stage assertions #33-#38. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
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.
PR-2 of the multi-format-loader expansion (
docs/multiformat-loader-design.md§1.2/§1.4/§8/§2). Builds on PR-1'sObjectFormatseam: turn onobject's PE/Mach-O/COFF readers, add the three format skeletons, and wire the engine dispatch — all behind--experimental-formats, default-off ⇒ byte-identical.BEFORE → AFTER
load fileis rejected — it never reaches the object loader (theELF_MAGICdispatch routes it to the XML branch, which fails to parse it; the object loader's hard reject would say "not an ELF object" anyway, andobjectcouldn't even parse it —pe/macho/cofffeatures off).--experimental-formats): PE/Mach-O/COFF objects load, map their sections with the right exec/readonly bits, and select the right SLEIGH spec —x86:LE:64:default:windowsfor PE/COFF,x86:LE:64:default:gccfor Mach-O (macOS x86-64 is System V AMD64).disassembleyields real x86-64 instructions out of.text/__text. Imports are empty (IAT/__stubsnaming is PR-4/PR-7).How
--experimental-formatsis exposedOne mechanism, two surfaces: the
KUNA_EXPERIMENTAL_FORMATSenv var (read live inbootstrap_from_file, sodecomp_dbg/decomp_test_dbgand the in-process e2e all honor it), and akuna decompile --experimental-formatsCLI flag that exports it onto the spawneddecomp_dbgsubprocess. By defaultis_object_binaryadmits only ELF — the non-ELF magics (Mach-O0xfeedfac*/fat, PEMZ, bare-COFF machine prefix) are gated on the flag.Per-format spec selection (proven)
The extended
verify_elf_language_ids.rsgate asserts every produced id resolves inscan_language_database, with the headline ids resolving directly:x86:LE:64:default:windowsAARCH64:LE:64:v8A:windowsx86:LE:64:default:gccAARCH64:LE:64:v8A:defaultThe §2.2 compiler-model fallback (
fallback_arch_id()→ the default-model id;bootstrap_from_objectretries with it when the primary doesn't resolve and no--targetwas given) is the safety net — for every headline arch the primary resolves directly, so the fallback isn't hit in practice.Default-off byte-identical proof
kuna decompile fauxware main(a real x86-64 ELF) produces identical output with and without--experimental-formats— the flag is a pure no-op on ELF (ELF is always admitted). The XML/datatest dispatch branch andbootstrap_programare untouched (Invariant 1).Gate results
make test— 675/675 PARITY OKmake test-stages— 159/159 PARITY OKmake rust-test— green (incl. 8 format unit tests + 2 language-id gate tests + a §2.2 fallback unit + the 2-testverify_object_formatse2e; the e2e RAN, not skipped — thex86.slais built)Cargo.locknotedecompiler/Cargo.toml:objectfeatures["read_core","elf","std"]→+["pe","macho","coff"].Cargo.lockis unchanged — enabling theseobjectfeatures pulls no new crate versions or transitive deps (the PE/Mach-O/COFF readers shareobject's existing deps). Confirmed offline-safe viacargo build --offline(zero downloads). An unchanged lock is the correct offline-gate outcome.Fixtures
Built in-container with the existing toolchain (no new packages):
pe_min.obj(clang -target x86_64-pc-windows-gnu -c→ Intel amd64 COFF object) andmacho_min.o(clang -target x86_64-apple-macos11 -c→ relocatable Mach-O). VMAs/section bits pinned from theobject-crate view.🤖 Generated with Claude Code
https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb