Repository navigation
Multi-format loader PR-12+13: PE/Mach-O entry discovery (stripped binaries find their functions) - #63
Merged
Merged
Conversation
…aries find their functions) Port the PE and Mach-O analogs of the ELF entry oracles so a STRIPPED PE/Mach-O recovers its function starts automatically (no `--addr`), exactly as a stripped ELF does. `EntryDiscoveryPass` now dispatches its oracle selection on the object format via the ObjectFormat seam; the ELF oracles stay unchanged and the new PE/Mach-O oracles are no-ops on ELF. PE (s1_entry/pe_entry.rs): the entry point, the `.pdata` RUNTIME_FUNCTION table (the `.eh_frame` analog — 97 records recover `main` in the stripped fixture), TLS callbacks, and exports. Mach-O (s1_entry/macho_entry.rs): the `LC_MAIN`/`LC_UNIXTHREAD` entry (`__TEXT.vmaddr + entryoff` — `object`'s `file.entry()` returns the un-rebased entryoff for Mach-O), `LC_FUNCTION_STARTS` (the ULEB128 delta table — the richest, stripped-surviving source), `__mod_init_func`, and exports. `executable_sections` learned the PE COFF / Mach-O instruction-attribute exec tests. The discovery stays purely additive (union -> exec-section filter -> funcsym-dedup); only the oracle selection branches on the format. Before/after: a stripped PE finds `main`@0x140001592 via `.pdata` -> `sub_140001592` decompiles by name (no --addr, 0.11s) with its IAT-named `puts`; a stripped Mach-O finds the symbol-removed `helper`@0x100000590 via LC_FUNCTION_STARTS -> `sub_100000590` decompiles (0.16s). New e2e gate `verify_multiformat_entry` (3 tests) RUNS (not skipped). Gates: make test 675/675 PARITY OK, make test-stages 159/159 PARITY OK, make rust-test green (incl. the new e2e + 4 new kuna-analysis unit tests). The ELF gates verify_s1_entry / verify_crossarch_entry_main pass unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
…try-disc # Conflicts: # docs/analysis-port-log.md
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
Ports the PE and Mach-O analogs of the ELF entry oracles so a stripped
PE/Mach-O finds its functions automatically (no
--addr), exactly as a strippedELF does today.
EntryDiscoveryPass(s1_entry) now dispatches its oracleselection on the object format via the
ObjectFormatseam; the ELF oracles areunchanged and the new PE/Mach-O oracles are no-ops on ELF.
Design
docs/multiformat-loader-design.md§4.1 / §5.3 / §8 PR-12 + PR-13.Entry sources implemented per format
s1_entry/pe_entry.rs): the entry point (AddressOfEntryPoint+ImageBase,via
file.entry());.pdataRUNTIME_FUNCTIONBeginAddresses (the.eh_frameanalog — the richest source, 97 records in the fixture); TLScallbacks (
AddressOfCallBacks); and exports. The glibc_start→mainidiomis not reused (
.pdatarecoversmaindirectly).s1_entry/macho_entry.rs): the entry (LC_MAIN/LC_UNIXTHREAD—note
LC_MAIN'sentryoffis__TEXT-relative, so the VMA is__TEXT.vmaddr + entryoff;object'sfile.entry()returns the un-rebasedoffset for Mach-O);
LC_FUNCTION_STARTS(the ULEB128 delta table — therichest, stripped-surviving source);
__mod_init_func; and exports.executable_sectionslearned the PE COFF (IMAGE_SCN_MEM_EXECUTE) and Mach-O(
S_ATTR_*_INSTRUCTIONS) executable tests. Discovery stays purely additive(union → exec-section filter → funcsym-dedup); only the oracle selection
branches on format.
Before → after (the payoff)
pe_imports_stripped.exe, 0 symbols / 0 exports):--option entry_disc off):no function "sub_140001592"— findsnothing by name.
.pdatarecover dozens incl.main@0x140001592→kuna decompile … sub_140001592(no--addr) yieldssub_140001592(uint a0){ … puts(…); … }— discovered by name and itsIAT-named
putsimport renders (PR-12 + PR-4 together).macho_func_starts_stripped,helperis file-local sold64.lld -xremoved its symbol):LC_FUNCTION_STARTS=[0x100000550 (_main, the entry), 0x100000590 (helper, stripped)]. Before,helperis invisible; after,collect_entriesskips the symboled_mainand discovers
0x100000590→kuna decompile … sub_100000590(no--addr)yields
int4 sub_100000590(int4 a0){ return a0 * 7 + 3; }— provingLC_FUNCTION_STARTS, not the symtab, is the source.e2e
kuna-console/tests/verify_multiformat_entry.rs(3 tests) asserts the discovery--addr) on stripped PE + stripped Mach-O,plus the default-off rejection. It RUNS, not skipped (1.64s,
.slabuilt).Plus 4 new
kuna-analysisunit tests + 2 newcollect_entriescore tests.Speed
Full
kuna decompileof a discovered function, no--addr(
--experimental-formats, release): stripped-PEmain(
sub_140001592,.pdata-discovered) 0.11s (51 MB RSS); stripped-Mach-Ohelper(sub_100000590, FUNCTION_STARTS-discovered) 0.16s.Gates
make test— 675/675 PARITY OKmake test-stages— 159/159 PARITY OKmake rust-test— green (incl. the new e2e)Default-off ⇒ ELF byte-identical: the new oracles are no-ops on ELF and PE/Mach-O
only load under
--experimental-formats.verify_s1_entry+verify_crossarch_entry_mainpass unchanged; discovery is gateable(
--option entry_disc off).🤖 Generated with Claude Code
https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb