Skip to content

Listing/xref tier PR2: engine-invoke (flag-gated build at bootstrap) - #27

Merged
mahaloz merged 2 commits into
mainfrom
listing-tier-engine-invoke
Jun 24, 2026
Merged

mahaloz merged 2 commits into
mainfrom
listing-tier-engine-invoke

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

PR2 of the Listing/xref tier (docs/listing-tier-design.md §1.3, §7 PR2): invoke the keystone from the engine at bootstrap, flag-gated. PR0 built Listing::build; PR1 wired the --option listing flag with AnalysisCtx.listing always None. PR2 makes the build fire — behind the default-OFF flag — and populates ctx.listing.

What's wired

  • kuna-analysis/src/passes.rs — threaded translate: &dyn Translate into both drivers: the live run_default_analyses_per_pass and (for signature symmetry) run_default_analyses. In each, before the pass loop:
    let seeds = listing_seeds(&file);
    let listing = arch.analysis_listing
        .then(|| crate::listing::Listing::build(&file, image, arch, translate, &seeds));
    let ctx = AnalysisCtx { file: &file, image, arch, listing: listing.as_ref() };
    The Listing is owned by the driver and outlives the pass loop (same lifetime shape as file), borrowed read-only via ctx.listing (replacing the listing: None PR1 inserted).
  • New pub fn listing_seeds(file) = existing_function_addrs(file) ∪ collect_entries(file), in_executable_section-filtered, sorted/deduped (design §3.1), built from the pub(crate) s1_entry helpers. pub so the cross-crate verify_listing_* gates build the exact seed set the live driver uses.
  • kuna-console/src/engine.rs — the bootstrap_from_elf driver call passes the engine's real decoder as the 4th arg: sleigh.base().unwrap().translate() (a &Sleigh; Sleigh: Translate; coerced to &dyn Translate). The .sla is loaded and the loadimage attached at that point, so a flag-gated build decodes through it.

The parity proof: flag on == flag off == today

arch.analysis_listing defaults false ⇒ .then(...) is None ⇒ no decode work, ctx.listing == None, byte-identical to today. With the flag on the Listing is built but no pass consumes it yet (the first consumer is PR6), so the decompiler output is unchanged. The build runs only on the real-ELF bootstrap path; the XML datatest path never reaches the analysis driver, so the 675/675 and 159/159 oracles are structurally untouched.

verify_listing_parity.rs::listing_on_is_byte_identical_to_off decompiles fauxware main → print C with the flag off (default) and with --option listing on and asserts the C is byte-identical (437 bytes, identical).

Build-at-load timing (honest note): the analysis driver runs once inside bootstrap_from_elf (load file), and the live CLI emits option listing on after load file, so the build-at-load does not fire through the live CLI today — wiring it to fire is PR6's concern (the first consumer). The build-at-load body is exercised directly through the engine's real Translate below.

The build-through-engine proof

verify_listing_core.rs::listing_build_through_engine_driver_seeds bootstraps fauxware, builds the driver's exact seed set via listing_seeds, and runs Listing::build through the engine's real &dyn Translate (which reads bytes through the loader the bootstrap attached, vs PR0's throwaway loadimage). Result: 21 seeds → 21 functions, 228 instructions; function_count() > 0 and instruction_at(entry).is_some() (and instruction_at(main).is_some()) all hold.

The runtime Listing

The runtime Listing is now built behind --option listing on (default-off). The payoff comes with the first consumer (PR6, FindNoReturnFunctionsAnalyzer); PR2 is the wiring + the parity/build proofs.

Gates

  • make test — 675/675 PARITY OK
  • make test-stages — 159/159 PARITY OK
  • make rust-test — green
  • kuna catalog --check — OK

🤖 Generated with Claude Code

https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb

mahaloz and others added 2 commits June 24, 2026 21:11
PR2 of the Listing/xref tier (docs/listing-tier-design.md §1.3, §7 PR2): invoke
the keystone from the engine at bootstrap, flag-gated on `arch.analysis_listing`
(default OFF). PR0 built `Listing::build`; PR1 wired `--option listing` with
`AnalysisCtx.listing` always `None`. PR2 makes the build fire behind the flag and
populates `ctx.listing`.

Wiring:
- passes.rs: threaded `translate: &dyn Translate` into both drivers
  (`run_default_analyses_per_pass` — the live one — and, for signature symmetry,
  `run_default_analyses`). In each, before the pass loop:
  `let listing = arch.analysis_listing.then(|| Listing::build(&file, image, arch,
  translate, &seeds)); ctx.listing = listing.as_ref()`. The Listing is owned by
  the driver and outlives the pass loop (same lifetime shape as `file`).
- New `pub fn listing_seeds(file)` = `existing_function_addrs ∪ collect_entries`,
  exec-section-filtered, sorted/deduped (design §3.1), from the pub(crate)
  s1_entry helpers. `pub` so the cross-crate verify gates use the exact driver set.
- engine.rs: the `bootstrap_from_elf` driver call passes the engine's decoder as
  the 4th arg — `sleigh.base().unwrap().translate()` (a `&Sleigh`, `Sleigh:
  Translate`, coerced to `&dyn Translate`).

Default-off ⇒ `.then(...)` is `None` ⇒ no decode work, `ctx.listing == None`,
byte-identical to today. With the flag on the Listing is built but consumed by no
pass yet (first consumer is PR6), so the decompiler output is unchanged. The build
runs only on the real-ELF path; the XML datatest path never reaches the driver, so
the 675/675 and 159/159 oracles are structurally untouched.

Proof (specs built; tests ran, not skipped):
- verify_listing_core.rs `listing_build_through_engine_driver_seeds`: bootstraps
  fauxware, builds the driver seed set via `listing_seeds`, runs `Listing::build`
  through the engine's real `&dyn Translate` — 21 seeds -> 21 functions, 228
  instructions; `function_count() > 0`, `instruction_at(entry).is_some()`.
- verify_listing_parity.rs `listing_on_is_byte_identical_to_off`: decompiles
  fauxware main with the flag off and with `--option listing on`, asserts the C is
  byte-identical (437 bytes).

Gates: `make test` 675/675 PARITY OK; `make test-stages` 159/159 PARITY OK;
`make rust-test` green; `kuna catalog --check` OK.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
…nvoke

# Conflicts:
#	docs/analysis-port-log.md
@mahaloz
mahaloz merged commit 7cf19bc into main Jun 24, 2026
@mahaloz
mahaloz deleted the listing-tier-engine-invoke branch July 29, 2026 08:01
mahaloz added a commit to borancar/kuna that referenced this pull request Nov 14, 2026
…ious call

The vtable's object was followed back through copies past intervening
calls, so `mov esi,ecx; call f; mov eax,[esi]; push esi; call [eax+k]`
(COM calls through ESI, and a C table through ESI) took ECX as the
receiver although the earlier call clobbered it; the COM push check also
compared two scans of different reach and missed the pushed interface.
The object, the last push and EAX are now compared as values over the run
of ops since the previous call, carried forward through copies. The
vcall fixture gains comesi and crosscall (stage Noelo-Lab#26, Noelo-Lab#27, the custom test).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
sjkim1127 added a commit to sjkim1127/kuna that referenced this pull request Nov 20, 2026
…type

A caller that hands its own entry argument registers straight to a direct
callee printed the call with no arguments and became `(void)` whenever the
callee had no `protoorder` statement: every single-function decompile, every
stage test, and callees decompile-all had not reached yet. `passthrough`
read only the statement.

With nothing stated, `passthrough` now reads the callee's own body: the
leading run of the call model's general-purpose argument registers whose low
byte the complete entry walk reads for a value that reaches something (a
register only spilled ends the run, so a variadic register-save prologue
adds nothing), or that one of its direct calls' targets takes on the same
terms. A call is extended only when the finished list reaches the end of
that run, and not when the caller loaded the register after it with a value
it may be passing (the `calleearitycut`/`calleearityscratch` boundary). The
function's own variadic test no longer counts a register that is only
pushed (clang's `push %rax`).

Stage assertions that pinned the dropped spelling are corrected; the stages
baseline is re-recorded for the renamed `passthrough` and `LIBCTYPES Noelo-Lab#27`
assertions. No datatest assertion moves (675/675).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
mahaloz added a commit that referenced this pull request Nov 22, 2026
libpng's png_decompress_chunk (Ultra, plain VMProtect and Themida builds)
lost `if (*a3 != size) ret = -7` and `if (ret == 1 && a1 - a2 != avail)
png_chunk_benign_error(...)` after the second png_inflate call, with no
warning. png_inflate gets &avail and the pointer parameter a3 in its 5th and
7th arguments, which Windows x86-64 passes on the stack.

Exploration: the call summary looked at no stack-passed argument on x86-64
(eight words on x86) and made only the 16 bytes behind each pointer argument
unknown, so both reads after the call folded to the values before it and the
paths to -7 and to png_chunk_benign_error were pruned (the overlay had 23
CBRANCH and no call to it). Now the argument registers and the 16 words of
the outgoing argument area (past the home space on Win64) are the pointers;
every frame offset among them escapes, and a round that escapes a new one is
followed by another. State::clobber_call leaves the call's output in all
mutable image memory, in every region under a symbolic base but the entry
stack pointer, and in the frame from the lowest escaped local up to the
return address (and from the lowest escaped incoming argument up), the
same bytes the emitter keeps alive across a call. CallOutputAt carries the
base.

Decompiler: with the paths back (25 CBRANCH, the call present), the
benign-error test still folded. The store that passed &avail has no reader
in the body and is gone before the stack alias mapping, which then marked
avail `nolocalalias`, and RuleIndirectCollapse removed the call's INDIRECT
on it. The exploration's escaped offsets are now kept on the Funcdata
(kuna_call_escapes), and syncVarnodesWithSymbols never gives a slot from the
lowest escaped local up to the return address `nolocalalias`
(kuna_pushan::frame_escaped).

Fixture: pushan_vm2_x86_64 gets ext7 (writes through its stack-passed 7th
argument and 32 bytes past its pointer argument) and f_out; stage
kuna-pushan-sound #26/#27 pin both tests (before: `ext7(); return 3;`).
Stage baseline 5035 -> 5037.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
mahaloz added a commit that referenced this pull request Nov 22, 2026
[AUTOMATED] Re-recorded after adding PUSHAN-SOUND #26 and #27 and merging main.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
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.

1 participant