Repository navigation
Multi-format loader PR-3+4: PE linked-exe + IAT import naming (puts/printf on a Windows PE) - #40
Merged
Merged
Conversation
…rintf on a Windows PE)
The PE headline: a linked Windows PE32+ executable loads and decompiles a
function with its libc imports NAMED (puts/printf, not sub_<addr>) — the first
non-ELF binary kuna names imports on.
PR-3 (loader proof) needed no new loadimage fix: `object` surfaces the PE
ImageBase+RVA transparently, so the linked exe loads through the same
`bootstrap_from_object` path PR-2's PE object did. PR-4 (IAT naming) is the real
new logic, in a new `s1_loader/pe_iat.rs`:
- Walk the PE Import Directory pairing the INT (names) and IAT (slot addresses)
in lockstep — the i-th name belongs to the slot at
image_base + first_thunk_rva + i*ptr (re-parsed with the typed
PeFile32/PeFile64, since the neutral object::File view gives no slot address).
Each slot -> ImportSym{addr: slot_va, name}: the ELF GOT-slot analog, so the
engine constant-folds a `call [slot]` to the name (arch-independent).
- MinGW thunk wrinkle: MinGW routes a direct `call thunk` to a one-instruction
`jmp [rip+disp]` (FF 25) veneer through the IAT slot. So pe_iat ALSO decodes
the FF 25 veneers over .text and names the thunk entry with its slot's import
name (the same FF 25 recovery as elf_plt::decode_x86_64). x86 only.
- Import::Ordinal(n) -> <DLL>_Ordinal_<n>; file.exports() registered additively.
Pure/total/never-error: non-PE / no-import-dir / unparsable -> empty Vec.
Before -> after on the stripped fixture (the clean PR-4 delta):
sub_140007240(0x140009000); -> puts(0x140009000);
Fixtures (MinGW, x86_64-w64-mingw32-gcc in kuna-dev): pe_imports.exe
(non-stripped, the headline) + pe_imports_stripped.exe (the PR-4 proof — symbols
gone, so the puts thunk is named only by the IAT walk). e2e
verify_pe_imports.rs (2) + pe_iat synthetic unit tests (4, mirroring elf_plt).
Default-off (--experimental-formats unset) => ELF byte-identical. Gates:
make test 675/675 PARITY OK, make test-stages 159/159 PARITY OK, make rust-test
green. Decompile speed ~0.12-0.25s, on par with ELF.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
mahaloz
added a commit
to borancar/kuna
that referenced
this pull request
Nov 16, 2026
…s cleanups Two cases the cleanup scans read differently from before this PR: - A C table call through ECX whose cleanup MSVC defers past the next __cdecl call (`push 5; call [eax+0x40]; push 6; call cfn; add esp,8`) got ECX as a stray receiver once the virtual-call check stopped at the next call. Past a later call the check now counts a run of pops that starts below where the virtual call returns (it removes both calls' pushes); a run starting at or above it is still frame teardown or follows a later callee popping earlier pushes, so vepilog/vouter keep their receiver. The helper is renamed own_cleanup. Fixture gains vdefer (0x4012c0), stage assertion CALLEEREGINPUTS Noelo-Lab#40. - The FS stop now applies only to a store that leaves ESP alone (`mov fs:[0],ecx`). Delphi's constructor epilogue (`call AfterConstruction; pop dword ptr fs:[0]; add esp,0xc`) reads as before; stopping there moved a constructor's pushed arguments onto the call before it (`sub_4054ec(0,a2); sub_41ce0c();`) in three Delphi images. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
mahaloz
added a commit
to borancar/kuna
that referenced
this pull request
Nov 16, 2026
Resolves docs/baseline-stages.json with a key-level 3-way merge (main's SPARC64 spill assertions plus CALLEEREGINPUTS Noelo-Lab#31-Noelo-Lab#40). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
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.
The PE headline
A linked Windows PE32+ executable now loads and decompiles a function with its libc imports NAMED (
puts/printf, notsub_<addr>) — the first non-ELF binary kuna names imports on. PR-2 proved a PE object parses; this proves a full linked exe loads (ImageBase +AddressOfEntryPoint), decompiles, and names the imports.objectsurfaces the PEImageBase+RVAtransparently, so the linked exe rides the samebootstrap_from_objectpath the PE object did.s1_loader/pe_iat.rs.BEFORE → AFTER (the headline)
The clean PR-4 delta is on the stripped PE (
pe_imports_stripped.exe), where the symbols are gone so theputscall is named only by the IAT walk + thunk decode.main(no symbol) decompiled by address (0x140001592 --addr):On the non-stripped
pe_imports.exe(kuna decompile … main), the headline renders:How
maincalls the imports (and how each is named)puts—maindoes a directcall 0x140007240to a MinGW thunk veneer (jmp [rip+0x60f6]=FF 25→ the__imp_putsIAT slot at0x14000d33c). PR-4 names it by walking the Import Directory (slot0x14000d33c→puts) and decoding theFF 25veneer over.textso the thunk entry0x140007240(the actualcalltarget) is namedputs. This is the load-bearing MinGW case.printf— a local MinGW wrapper function at0x140001550(it internally callsvfprintf), not an import. In the non-stripped exe it's named from the COFF symtab (printf); in the stripped exe it correctly stayssub_140001550(we name only genuine imports).What PR-4 implements (
s1_loader/pe_iat.rs, design §3.2)FileKind::Pe32/Pe64, re-parse with the typedPeFile32/PeFile64(the neutralobject::File::imports()gives no slot address). Walk the Import Directory pairing the INT (names) and IAT (slots) in lockstep →ImportSym{addr: image_base + first_thunk_rva + i*ptr, name}— the ELF GOT-slot analog, arch-independent (the engine constant-foldscall [slot]).FF 25thunk veneers over the executable sections and name the thunk entry with its slot's import (same recovery aself_plt::decode_x86_64; x86 only).Import::Ordinal(n)→<DLL>_Ordinal_<n>;file.exports()registered additively. Pure/total/never-error: unknown → emptyVec.Decompile speed
pe_imports.exe main: ~0.12–0.25 s wall (end-to-end incl. thedecomp_dbgsubprocess spawn); the strippedmainby addr is the same range. On par with the ELF baseline (fauxware main, ~0.15 s on the same box) — both dominated by process startup + the tiny function. PE loading is not materially slower than ELF: the IAT walk is one Import-Directory scan + oneFF 25sweep over.text, once at load.Tests (the e2e RAN — not skipped; specs built)
kuna-console/tests/verify_pe_imports.rs(2): the non-stripped linked exe loads (Windows x86-64 spec), resolvesmain/puts, decompilesmaintoputs(/printf(; the stripped exe names theputsthunk via the IAT walk (puts(, notsub_140007240) while leaving the localprintfwrappersub_<addr>. Test 1 also proves the default-off path (PE rejected without the flag).pe_iatunit tests (4, synthetic, mirroringelf_plt's decoder tests):FF 25decode both widths (x64 RIP-relative + x86 absolute), an unknown-slot veneer left alone, ordinal-name synthesis.Gates
make test— 675/675 PARITY OKmake test-stages— 159/159 PARITY OKmake rust-test— green (exit 0; incl. the 2 e2e + 4pe_iatunit tests, 0 failures)Default-off (
--experimental-formatsunset) ⇒ the ELF path is byte-identical (the PE path is unreachable without the flag; the XML/datatest oracles never reach the object loader — Invariant 1).🤖 Generated with Claude Code
https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb