Repository navigation
[AUTOMATED] feat(p1): peimportcall - bind a Windows call [IAT slot] to its import (DIV-57) - #254
Merged
Merged
Conversation
… to its import (DIV-57) A PE reaches its imports through an Import Address Table slot, which is *data*, so `call dword ptr [slot]` lifts to a CALLIND through a global. The only pass that resolves such a target - ActionDeindirect - gates on `Varnode::externref`, and that flag was set NOWHERE in the workspace: Ghidra sets it from an ExternRefSymbol (`Scope::addExternalRef`) the port never carried. So every Windows API call in every PE stayed an unnamed `(*dat_4112c4)(0)` with no name, no prototype and no no-return flow effect - a function ending in ExitThread kept its fall-through and swallowed the whole of the next function. Three parts behind one option (`peimportcall`, P1, default-ON, DIV-57): 1. A new PE/COFF-only analysis pass reports one `[slot, slot+ptr)` range per import-descriptor entry and the commit ORs `Varnode::externref` over each in the symbol-table property map - the same `set_property_range` the loader's read-only ranges use. No second symbol is mapped: kuna's `query_function` keys on the varnode's own address where upstream indirects through `ExternRefSymbol::refaddr`, and the import FunctionSymbol's 1-byte map entry never covers a pointer-width read, so `queryProperties` always takes the property branch. 2. `build_global_query` now carries the callee's no-return flag into `GlobalEntry`, which `query_function` puts on the prototype handed to ActionDeindirect. Without it `deindirect` took its lateRestriction success path and never scheduled the restart whose re-flow plants the artificial halt, so the boundary stayed wrong even once the call was named. 3. Upstream's PE-only `PEFunctionsThatDoNotReturn` is vendored verbatim and matched against a PE/COFF object only - kuna merged the PE and Mach-O name sets where upstream keeps them separate, and these names are Windows-only. ActionDeindirect and FuncCallSpecs::deindirect are unchanged consumers. The mechanism the triage record filed (a new P2 pass matching the CALLIND shape) was refuted first: at that seam the target is a free unique temp and raw flow IR carries no def-use links, so the backward walk it needs is unavailable. Measurements: decbench `O0-mydoom-mydoom-mmsender_th` GED 37 -> 0 (perfect) and its un-triaged sibling `sync_visual_th` 39 -> 0 (perfect); over both corpus PEs 927 unnamed IAT-slot calls -> 8 with 71/90 distinct Win32 API names recovered, 8 boundary overruns fixed, no function gained or lost, gotos never increase; ELF/Mach-O byte-identical; timeit -1.9%, whole-binary -7.2% / -2.1%. Rebased onto 6554346 (after #252/DIV-55 and #253/DIV-56): corpus file count 190, settables 87 (transform tier 41, live-value 29), phase_catalog.json re-captured and docs/baseline-stages.json re-recorded (386 keys) on the rebased tree rather than hand-merged. Every measurement above re-run on that base; the PE and ELF witnesses are bit-for-bit unchanged by either merge. Gates: make test 675/675 PARITY OK (no re-pin, no per-test opt-out); make test-stages 386/386 PARITY OK; make rust-test green; make check-spec OK (lenient + strict); kuna catalog --check OK. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL
mahaloz
force-pushed
the
fix/decbench-peimportcall
branch
from
August 3, 2026 10:16
c775bb8 to
c619246
Compare
call [IAT slot] to its import (DIV-55)call [IAT slot] to its import (DIV-57)
mahaloz
added a commit
that referenced
this pull request
Aug 3, 2026
…n entries on containment evidence Step 2 of the approved ARM entry-recall sequence ([PROPOSAL] #239) and the one it called the prize: 1,671 missed function entries, 56.8% of the whole ARM entry-recall gap, every one of them reachable only through a code-pointer word that `aif::code_pointer_table_seeds` already finds and then throws away. The shipped Stage-3 scan requires a pointer's target to open with a Thumb stack-frame prologue and to disassemble into more than two instructions. On bare-metal firmware that is the wrong population: 93.3% of the missed entries establish no frame at all and 41% are <= 8-byte leaves (`movs r0,#0; bx lr`, or a bare `bx lr`, which is a valid Cortex-M exception handler every rival recovers). Those two predicates reject 1,632 of the 1,671. Deleting them is not shippable - the proposal measured the naive relaxation at 62% ground truth with 21% of the new entries splitting a real function body, a failure mode decbench structurally cannot see. So the whole of this change is the precision model, and the model is CONTAINMENT rather than shape: reject a target when any word that references it overlaps a decoded instruction (it is operand bytes, not a table slot) or lies in the same discovered function as the target itself (that pairing IS the `ldr pc,[pc,r]` switch table). Measured over 3,462 validated candidates the two guards take splits from 1,261 to 0 for 17 ground-truth entries. The `MIN_SUBROUTINE_INSNS` floor is replaced, not deleted, by a terminating-routine check: the same speculative walk with the strict escape policy and no minimum length. This is kuna's form of the line Ghidra draws between `OperandReferenceAnalyzer` (creates functions, from instruction operands) and `DataOperandReferenceAnalyzer`, which overrides `createFunctions` to a no-op - "don't ever create a function from a data pointer". kuna cannot use Ghidra's version directly because the Listing tier records only control-flow references, so the containment pair recovers the same discrimination from the code/data partition the walk leaves behind. Measured on the 48-image decbench Cortex-M corpus (41,378 DWARF ground-truth addresses), `kuna functions`: recall 38,238 (92.4%) -> 39,851 (96.3%), +1,613 1,694 new entries, 1,613 ground truth (95.2%) 0 splitting a real function body, 81 outside any DWARF body 0 entries lost, 0 ground-truth entries lost `--option listing off` is structurally inert (ptrentry is a Listing consumer): 0 new, 0 lost. Whole-binary `decompile-all --json` is sha256-identical off vs on for x86-64, ARM Linux and the Cortex-M images with no admissible candidate. Two things the proposal asked for that measurement rejected, both built and measured rather than argued (tables in docs/features/ptrentry/): - table-run corroboration: a switch table IS a run, so it removes no additional split, and it costs 311 ground-truth functions (1,302 vs 1,613); - re-seeding the recursive-descent walk (what Stages 2-3 do): +13 ground-truth entries but 974 split bodies and 734 dropped entries, through the same tail-call absorption that constrained step 1. The pass therefore emits entry facts only, which makes "never removes an entry" a property of the wiring rather than of a heuristic. That also settles the proposal's optional AIF gap-start re-walk fold-in: closing it IS a walk re-seed, so it stays with step 3. Default-OFF and not auto-injected by any driver: it discovers more functions, so it changes emitted C by construction, and the precision numbers want a human read before a flip. No DIV row (default output is byte-identical). Tests: `kuna-console/tests/verify_ptrentry.rs` is the two-pass e2e over a new hand-assembled fixture carrying both shapes - the pointer-only leaf that must be recovered and the switch-table case that must stay rejected with the option ON - plus three unit tests and a superset-property pin. No `tests/stages/*.xml`: the harness embeds raw `<bytechunk>`s and never builds a load image or a Listing, the same reason every sibling analysis-tier discovery flag ships a cross-crate `verify_*` gate. Gates on the rebased tree (origin/main 208bb15, after #252/#253/#254): make test PARITY OK 675/675; make test-stages PARITY OK 386/386; make rust-test green (295/295 result blocks); make check-spec green in strict mode; kuna catalog --check OK. Every shared counter is derived from a fresh `phase catalog` capture and a green run on the rebased tree, not by arithmetic: settables 87 -> 88, analysis tier 26 -> 27, catalog JSON rows 86 -> 87, bytecompat fixture 87 -> 88, and the live-value count stays at 29 because this row declares no codegen live_field. The `kuna-base/src/xml.rs` corpus count was verified by counting the files (83 datatests + 107 stages = 190, unchanged), and `docs/baseline-stages.json` is untouched because this PR adds no stages XML. The recall/precision table and the off-vs-on sha256 ablation were re-measured on the rebased build and are unchanged, with 0 of 48 per-binary entry sets differing from the pre-rebase run. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL
mahaloz
added a commit
that referenced
this pull request
Aug 3, 2026
…n entries on containment evidence (#255) Step 2 of the approved ARM entry-recall sequence ([PROPOSAL] #239) and the one it called the prize: 1,671 missed function entries, 56.8% of the whole ARM entry-recall gap, every one of them reachable only through a code-pointer word that `aif::code_pointer_table_seeds` already finds and then throws away. The shipped Stage-3 scan requires a pointer's target to open with a Thumb stack-frame prologue and to disassemble into more than two instructions. On bare-metal firmware that is the wrong population: 93.3% of the missed entries establish no frame at all and 41% are <= 8-byte leaves (`movs r0,#0; bx lr`, or a bare `bx lr`, which is a valid Cortex-M exception handler every rival recovers). Those two predicates reject 1,632 of the 1,671. Deleting them is not shippable - the proposal measured the naive relaxation at 62% ground truth with 21% of the new entries splitting a real function body, a failure mode decbench structurally cannot see. So the whole of this change is the precision model, and the model is CONTAINMENT rather than shape: reject a target when any word that references it overlaps a decoded instruction (it is operand bytes, not a table slot) or lies in the same discovered function as the target itself (that pairing IS the `ldr pc,[pc,r]` switch table). Measured over 3,462 validated candidates the two guards take splits from 1,261 to 0 for 17 ground-truth entries. The `MIN_SUBROUTINE_INSNS` floor is replaced, not deleted, by a terminating-routine check: the same speculative walk with the strict escape policy and no minimum length. This is kuna's form of the line Ghidra draws between `OperandReferenceAnalyzer` (creates functions, from instruction operands) and `DataOperandReferenceAnalyzer`, which overrides `createFunctions` to a no-op - "don't ever create a function from a data pointer". kuna cannot use Ghidra's version directly because the Listing tier records only control-flow references, so the containment pair recovers the same discrimination from the code/data partition the walk leaves behind. Measured on the 48-image decbench Cortex-M corpus (41,378 DWARF ground-truth addresses), `kuna functions`: recall 38,238 (92.4%) -> 39,851 (96.3%), +1,613 1,694 new entries, 1,613 ground truth (95.2%) 0 splitting a real function body, 81 outside any DWARF body 0 entries lost, 0 ground-truth entries lost `--option listing off` is structurally inert (ptrentry is a Listing consumer): 0 new, 0 lost. Whole-binary `decompile-all --json` is sha256-identical off vs on for x86-64, ARM Linux and the Cortex-M images with no admissible candidate. Two things the proposal asked for that measurement rejected, both built and measured rather than argued (tables in docs/features/ptrentry/): - table-run corroboration: a switch table IS a run, so it removes no additional split, and it costs 311 ground-truth functions (1,302 vs 1,613); - re-seeding the recursive-descent walk (what Stages 2-3 do): +13 ground-truth entries but 974 split bodies and 734 dropped entries, through the same tail-call absorption that constrained step 1. The pass therefore emits entry facts only, which makes "never removes an entry" a property of the wiring rather than of a heuristic. That also settles the proposal's optional AIF gap-start re-walk fold-in: closing it IS a walk re-seed, so it stays with step 3. Default-OFF and not auto-injected by any driver: it discovers more functions, so it changes emitted C by construction, and the precision numbers want a human read before a flip. No DIV row (default output is byte-identical). Tests: `kuna-console/tests/verify_ptrentry.rs` is the two-pass e2e over a new hand-assembled fixture carrying both shapes - the pointer-only leaf that must be recovered and the switch-table case that must stay rejected with the option ON - plus three unit tests and a superset-property pin. No `tests/stages/*.xml`: the harness embeds raw `<bytechunk>`s and never builds a load image or a Listing, the same reason every sibling analysis-tier discovery flag ships a cross-crate `verify_*` gate. Gates on the rebased tree (origin/main 208bb15, after #252/#253/#254): make test PARITY OK 675/675; make test-stages PARITY OK 386/386; make rust-test green (295/295 result blocks); make check-spec green in strict mode; kuna catalog --check OK. Every shared counter is derived from a fresh `phase catalog` capture and a green run on the rebased tree, not by arithmetic: settables 87 -> 88, analysis tier 26 -> 27, catalog JSON rows 86 -> 87, bytecompat fixture 87 -> 88, and the live-value count stays at 29 because this row declares no codegen live_field. The `kuna-base/src/xml.rs` corpus count was verified by counting the files (83 datatests + 107 stages = 190, unchanged), and `docs/baseline-stages.json` is untouched because this PR adds no stages XML. The recall/precision table and the off-vs-on sha256 ablation were re-measured on the rebased build and are unchanged, with 0 of 48 per-binary entry sets differing from the pre-rebase run. Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
mahaloz
added a commit
that referenced
this pull request
Aug 3, 2026
…cost this round Docs-only. No .rs, no phases.toml, no baselines, no tests. Round 2 shipped, and the benchmark signal was refreshed on 2026-08-03 (all three opt levels re-decompiled from pinned kuna 9623dc2). Several documented claims were provably stale and several hard-won operational facts existed only in agent transcripts. Both fixed, every number re-verified against the live tree. docs/decbench-loop.md - Standings replaced and widened: GED ida 36.06 / kuna 35.93 / angr 34.20, overall ida 38.01 / kuna 37.91 / angr 36.98, byte_match kuna 3.41 (first). Stated plainly that kuna's column is current while the rivals' are from their own last runs, so the tree is a MINING INSTRUMENT, not a leaderboard. - Recall pool: 6,540 (7.3%) -> 1,420 vs angr / 1,552 vs ida, 0 whole-binary failures, now almost entirely embedded ARM Cortex-M. All three named causes corrected: "u-boot 100% / freertos 100%" was a decbench .text-filter artifact and never a kuna discovery failure (angr and ida score nothing there); "betaflight 22%" is 6.0%; the coreutils `main` empty-body/panic is fixed (comm/join/timeout/uniq all produce full bodies today). - The `--mode auto` degrades-to-fast warning is moot for this corpus: the largest stripped binary is O0 bash at 1,513,904 B (1.44 MiB), so all 803 binaries resolve 768 aggressive / 35 reliable / 0 fast. The aggressive-vs- reliable distinction is kept and sharpened; the stale 21-of-24 default-off count is now 20 of 25, with the five exclusions named. - Two operational traps recorded for the first time: (a) byte_match RECOMPILES with an arch-matched toolchain and this box has neither arm-none-eabi-gcc nor MinGW, so deleting kuna's (never auto-invalidated) checkpoints destroys kuna's ARM/PE scores while every rival keeps theirs. The coverage guard caught 34 slices; O2 and O2-noinline are still damaged from an earlier DECBENCH_ALLOW_DROPS=1 run with no surviving copy. Rule: never pass DECBENCH_ALLOW_DROPS=1 without reading every [guard] line. (b) The pools store a PE address as an RVA where kuna uses the VA, so scripts.decbench.rescore fails on every PE case (119 across the three pools). Recorded with a fix direction. - Pointed at the durable refresh recipe at ~/decbench-campaign-state/ and its two pinning rules, plus the non-obvious one: the GED baseline must drop kuna's published scores for EVERY re-decompiled opt level, not just the one being refreshed (an O0-only baseline died with "cannot reproduce published fallback 58.0" on an O2 slice). Method corrections (decbench-loop.md + improvement-pipeline.md standing rules) - "Not a no-op" is not "correct". On paramcopyhoist a refuter proved the proposed hook reached the printer and it was still the wrong site: it deleted an assignment, lost an early return, and made another function return the wrong parameter. The refute brief now carries an explicit "would this produce WRONG output?" axis. - Diff every changed function, not the witness. Those designs all passed on their witness. Round 2's PRs swept 3,031 / 12,241 / 14,720 / 15,386 functions; two caught real problems that way. - The tally, honestly: round 1's filed mechanisms were 2-for-5, round 2's refuters overturned the filed diagnosis on 3 of 8, and the symptom stood in every case. docs/decbench/features.md - Round-1 menu replaced by round-2 outcomes, keeping the file's shape and its rank-by-correctness thesis: #248 cortexmvectors, #249 funcptralign, #250 paramcopyhoist, #251 subright, #252 returncopysplit, #253 itecondlist (merged) and #254 peimportcall (IN FLIGHT), each with its measured effect. - Named the structural finding that outlives them: three separate ported passes were dead -- RuleSubRight (stub body), RuleFuncPtrEncoding (live body, stubbed input) and ActionDeindirect (live body, a gate bit set nowhere). Each was invisible to every test and each had large breadth, so "grep for registered-but-unreachable passes" is now a mining route of its own. - Carried forward what did not ship: undefname-leak (283 functions, 221 with uninitialised reads) and catalog-upstream-options (38 upstream-inherited ArchOptions invisible to `kuna catalog`). Re-mined pool tables regenerated against the refreshed tree (snapshot 2026-08-03): backlog.md, backlog-ida.md, novel.md, triage-queue*.json. Gates: make check-spec OK (lenient and strict); make test 675/675 PARITY OK; make test-stages 381/381 PARITY OK. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL
mahaloz
added a commit
that referenced
this pull request
Aug 3, 2026
…cost this round Docs-only. No .rs, no phases.toml, no baselines, no tests. Rebased onto origin/main 4c2b59b (after #254, #255 and #257). Round 2 shipped, and the benchmark signal was refreshed on 2026-08-03 (all three opt levels re-decompiled from pinned kuna 9623dc2). Several documented claims were provably stale and several hard-won operational facts existed only in agent transcripts. Both fixed, every number re-verified against the live tree. docs/decbench-loop.md - Standings replaced and widened: GED ida 36.06 / kuna 35.93 / angr 34.20, overall ida 38.01 / kuna 37.91 / angr 36.98, byte_match kuna 3.41 (first). Stated plainly that kuna's column is current while the rivals' are from their own last runs, so the tree is a MINING INSTRUMENT, not a leaderboard. - Recall pool: 6,540 (7.3%) -> 1,420 vs angr / 1,552 vs ida, 0 whole-binary failures, now almost entirely embedded ARM Cortex-M. All three named causes corrected: "u-boot 100% / freertos 100%" was a decbench .text-filter artifact and never a kuna discovery failure (angr and ida score nothing there); "betaflight 22%" is 6.0%; the coreutils `main` empty-body/panic is fixed (comm/join/timeout/uniq all produce full bodies today). - The `--mode auto` degrades-to-fast warning is moot for this corpus: the largest stripped binary is O0 bash at 1,513,904 B (1.44 MiB), so all 803 binaries resolve 768 aggressive / 35 reliable / 0 fast. The aggressive-vs- reliable distinction is kept and sharpened; the stale 21-of-24 default-off count is now 20 of 25, with the five exclusions named. - Two operational traps recorded for the first time: (a) byte_match RECOMPILES with an arch-matched toolchain and this box has neither arm-none-eabi-gcc nor MinGW, so deleting kuna's (never auto-invalidated) checkpoints destroys kuna's ARM/PE scores while every rival keeps theirs. The coverage guard caught 34 slices; O2 and O2-noinline are still damaged from an earlier DECBENCH_ALLOW_DROPS=1 run with no surviving copy. Rule: never pass DECBENCH_ALLOW_DROPS=1 without reading every [guard] line. (b) The pools store a PE address as an RVA where kuna uses the VA, so scripts.decbench.rescore fails on every PE case (119 across the three pools). Recorded with a fix direction. - Pointed at the durable refresh recipe at ~/decbench-campaign-state/ and its two pinning rules, plus the non-obvious one: the GED baseline must drop kuna's published scores for EVERY re-decompiled opt level, not just the one being refreshed (an O0-only baseline died with "cannot reproduce published fallback 58.0" on an O2 slice). Method corrections (decbench-loop.md + improvement-pipeline.md standing rules) - "Not a no-op" is not "correct". On paramcopyhoist a refuter proved the proposed hook reached the printer and it was still the wrong site: it deleted an assignment, lost an early return, and made another function return the wrong parameter. The refute brief now carries an explicit "would this produce WRONG output?" axis. - Diff every changed function, not the witness. Those designs all passed on their witness. Round 2's PRs swept 3,031 / 12,241 / 14,720 / 15,386 functions; two caught real problems that way. - The tally, honestly: round 1's filed mechanisms were 2-for-5, round 2's refuters overturned the filed diagnosis on 3 of 8, and the symptom stood in every case. Shared counters in a busy queue (decbench-loop.md + improvement-pipeline.md) - Round 2 ran up to four output-changing PRs over the same hard-coded counters and produced three failure shapes, only one of which announced itself: a conflict (#257's DIV number raced 55 -> 56 -> 57 -> 58); a SILENT identical-edit auto-merge (catalog_bytecompat.rs kept 86 because both sides made the same 85 -> 86 edit); and a SILENT keep-both auto-merge (a stale baseline-stages.json data_footer, and five rounds of keep-both duplicating a row in tests/stages/README.md). - Rules written down: derive every shared counter from a fresh capture and a green run on the rebased tree, never by arithmetic; diff every keep-both resolution against main asserting you removed nothing and added nothing twice; DIV numbers are claimed on merge; re-run the gates AFTER the rebase. - New standing requirement 9: re-measure after every rebase, never carry a number forward. #257's placeholder count moved 2,143 -> 2,142 because #254 landed underneath it, caught only by re-measuring. docs/decbench/features.md - Round-1 menu replaced by round-2 outcomes, keeping the file's shape and its rank-by-correctness thesis. NINE merged PRs: #248 cortexmvectors, #249 funcptralign, #250 paramcopyhoist, #251 subright, #252 returncopysplit, #253 itecondlist, #254 peimportcall (DIV-57), #255 ptrentry and #257 undefname (DIV-58) -- seven of the eight round-2 candidates plus steps 1 and 2 of the ARM entry-recall sequence (#239). Only three of the nine move GED on a mined case; four are correctness fixes the metric cannot see and two are recall. - The dead-pass finding is now three DISTINCT shapes to grep for, not one anecdote: stub body (RuleSubRight), live body with a permanently-zero input (RuleFuncPtrEncoding's hard-coded funcptr_align() = 0), and live body with a gate bit that has no writer anywhere (ActionDeindirect / externref). The third had a second gap in the same chain -- GlobalEntry::func_no_return never copied the callee's no-return flag into the snapshot -- so one dead gate can hide another. - The ARM sequence is cross-referenced to the live table on PR #239 rather than duplicated here, so it cannot go stale in-repo. - Carried forward as the one still-open candidate: catalog-upstream-options (38 upstream-inherited ArchOptions invisible to `kuna catalog`). Re-mined pool tables regenerated against the refreshed tree (snapshot 2026-08-03): backlog.md, backlog-ida.md, novel.md, triage-queue*.json. Gates on the rebased base: make check-spec OK (lenient and strict); make test 675/675 PARITY OK; make test-stages 394/394 PARITY OK. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL
mahaloz
added a commit
that referenced
this pull request
Aug 3, 2026
…cost this round (#256) Docs-only. No .rs, no phases.toml, no baselines, no tests. Rebased onto origin/main 4c2b59b (after #254, #255 and #257). Round 2 shipped, and the benchmark signal was refreshed on 2026-08-03 (all three opt levels re-decompiled from pinned kuna 9623dc2). Several documented claims were provably stale and several hard-won operational facts existed only in agent transcripts. Both fixed, every number re-verified against the live tree. docs/decbench-loop.md - Standings replaced and widened: GED ida 36.06 / kuna 35.93 / angr 34.20, overall ida 38.01 / kuna 37.91 / angr 36.98, byte_match kuna 3.41 (first). Stated plainly that kuna's column is current while the rivals' are from their own last runs, so the tree is a MINING INSTRUMENT, not a leaderboard. - Recall pool: 6,540 (7.3%) -> 1,420 vs angr / 1,552 vs ida, 0 whole-binary failures, now almost entirely embedded ARM Cortex-M. All three named causes corrected: "u-boot 100% / freertos 100%" was a decbench .text-filter artifact and never a kuna discovery failure (angr and ida score nothing there); "betaflight 22%" is 6.0%; the coreutils `main` empty-body/panic is fixed (comm/join/timeout/uniq all produce full bodies today). - The `--mode auto` degrades-to-fast warning is moot for this corpus: the largest stripped binary is O0 bash at 1,513,904 B (1.44 MiB), so all 803 binaries resolve 768 aggressive / 35 reliable / 0 fast. The aggressive-vs- reliable distinction is kept and sharpened; the stale 21-of-24 default-off count is now 20 of 25, with the five exclusions named. - Two operational traps recorded for the first time: (a) byte_match RECOMPILES with an arch-matched toolchain and this box has neither arm-none-eabi-gcc nor MinGW, so deleting kuna's (never auto-invalidated) checkpoints destroys kuna's ARM/PE scores while every rival keeps theirs. The coverage guard caught 34 slices; O2 and O2-noinline are still damaged from an earlier DECBENCH_ALLOW_DROPS=1 run with no surviving copy. Rule: never pass DECBENCH_ALLOW_DROPS=1 without reading every [guard] line. (b) The pools store a PE address as an RVA where kuna uses the VA, so scripts.decbench.rescore fails on every PE case (119 across the three pools). Recorded with a fix direction. - Pointed at the durable refresh recipe at ~/decbench-campaign-state/ and its two pinning rules, plus the non-obvious one: the GED baseline must drop kuna's published scores for EVERY re-decompiled opt level, not just the one being refreshed (an O0-only baseline died with "cannot reproduce published fallback 58.0" on an O2 slice). Method corrections (decbench-loop.md + improvement-pipeline.md standing rules) - "Not a no-op" is not "correct". On paramcopyhoist a refuter proved the proposed hook reached the printer and it was still the wrong site: it deleted an assignment, lost an early return, and made another function return the wrong parameter. The refute brief now carries an explicit "would this produce WRONG output?" axis. - Diff every changed function, not the witness. Those designs all passed on their witness. Round 2's PRs swept 3,031 / 12,241 / 14,720 / 15,386 functions; two caught real problems that way. - The tally, honestly: round 1's filed mechanisms were 2-for-5, round 2's refuters overturned the filed diagnosis on 3 of 8, and the symptom stood in every case. Shared counters in a busy queue (decbench-loop.md + improvement-pipeline.md) - Round 2 ran up to four output-changing PRs over the same hard-coded counters and produced three failure shapes, only one of which announced itself: a conflict (#257's DIV number raced 55 -> 56 -> 57 -> 58); a SILENT identical-edit auto-merge (catalog_bytecompat.rs kept 86 because both sides made the same 85 -> 86 edit); and a SILENT keep-both auto-merge (a stale baseline-stages.json data_footer, and five rounds of keep-both duplicating a row in tests/stages/README.md). - Rules written down: derive every shared counter from a fresh capture and a green run on the rebased tree, never by arithmetic; diff every keep-both resolution against main asserting you removed nothing and added nothing twice; DIV numbers are claimed on merge; re-run the gates AFTER the rebase. - New standing requirement 9: re-measure after every rebase, never carry a number forward. #257's placeholder count moved 2,143 -> 2,142 because #254 landed underneath it, caught only by re-measuring. docs/decbench/features.md - Round-1 menu replaced by round-2 outcomes, keeping the file's shape and its rank-by-correctness thesis. NINE merged PRs: #248 cortexmvectors, #249 funcptralign, #250 paramcopyhoist, #251 subright, #252 returncopysplit, #253 itecondlist, #254 peimportcall (DIV-57), #255 ptrentry and #257 undefname (DIV-58) -- seven of the eight round-2 candidates plus steps 1 and 2 of the ARM entry-recall sequence (#239). Only three of the nine move GED on a mined case; four are correctness fixes the metric cannot see and two are recall. - The dead-pass finding is now three DISTINCT shapes to grep for, not one anecdote: stub body (RuleSubRight), live body with a permanently-zero input (RuleFuncPtrEncoding's hard-coded funcptr_align() = 0), and live body with a gate bit that has no writer anywhere (ActionDeindirect / externref). The third had a second gap in the same chain -- GlobalEntry::func_no_return never copied the callee's no-return flag into the snapshot -- so one dead gate can hide another. - The ARM sequence is cross-referenced to the live table on PR #239 rather than duplicated here, so it cannot go stale in-repo. - Carried forward as the one still-open candidate: catalog-upstream-options (38 upstream-inherited ArchOptions invisible to `kuna catalog`). Re-mined pool tables regenerated against the refreshed tree (snapshot 2026-08-03): backlog.md, backlog-ida.md, novel.md, triage-queue*.json. Gates on the rebased base: make check-spec OK (lenient and strict); make test 675/675 PARITY OK; make test-stages 394/394 PARITY OK. Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
mahaloz
added a commit
that referenced
this pull request
Sep 8, 2026
…es a UINT, so its peimportcall assertion does too `ghdec-peimportcall` PEIMPORTCALL #5 pinned `ExitProcess\(\); // no-return` on the `bail` function of `pe_noreturn_import.exe`. That empty-parens spelling was frozen in by DIV-57 (#254), when kuna carried no Windows API prototype at all and the call's one argument was simply lost. `win32sigs` (DIV-141) supplies the import's `void __stdcall ExitProcess(UINT)`, and the fixture's source is `void bail(int code) { ExitProcess(code); }`, so the site now renders `ExitProcess(a0)` and `bail` recovers its parameter. The assertion is the stale side of that; what the test exists to protect -- the `FF 25`/IAT-slot call binding to its import name and both `// no-return` flow effects surviving -- is asserted by the other four stringmatches and unchanged. The assertion name is untouched, so `docs/baseline-stages.json` needs no re-record; `docs/baseline.json` is byte-identical to origin/main. make test 675/675 PARITY OK, make test-stages 704/704 PARITY OK, make test-cli 99/99, make check-spec OK, kuna catalog --check OK. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
mahaloz
added a commit
that referenced
this pull request
Sep 8, 2026
…in32 imports their signatures (win32sigs, DIV-141) (#520) * [AUTOMATED] feat(analysis): resource-loader-c-retains — give a PE's Win32 imports their signatures (win32sigs, DIV-141) kuna's whole prototype knowledge base was libc, so on a PE every LoadLibraryExW / WriteFile / VirtualQuery call reached ActionDefaultParams with an empty prototype and call-site trial scoring was the only thing between the pushes and the call. Where that scoring loses, the arguments are dropped and the outgoing slots `callsitestackargs` already mapped survive as stack-local debris. `win32sigs` supplies the Windows half of the `.gdt` stand-in `libproto` already is: ~130 WINAPI exports ranked by an import histogram over the 54 PE images of the RE arena corpus, plus the resource/loader family the need was filed against. Signatures are reduced to the same width-stable vocabulary the libc tables use, and a slot with no honest spelling is rejected rather than approximated. The prototypes are parked by ENTRY ADDRESS. A PE import is two FunctionSymbols -- the size-0 IAT slot and the `FF 25` thunk veneer a direct `call` targets -- the global by-name query answers with the slot, and ActionDefaultParams asks about the thunk, so the by-name park is a silent no-op on exactly the calls that need it. A new AnalysisOutput::prototypes_at stream carries the address. Sweep over 22 PE images / 3,029 functions: 168 changed, 0 added, 0 removed, every changed function containing a call to a table name; 35 call sites gain arguments to the documented arity and 16 shed invented ones. Speed -16.9%. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * [AUTOMATED] test(p0): resource-loader-c-retains — list win32sigs among the analysis-tier gates with no codegen live reader `option_values_live_value_present_for_58_suppressed_for_101` enumerates the options whose live state is read console-side rather than through the codegen `live_value`. Like `libproto`/`libcsigs`/`declaredlibcproto`, `win32sigs` is an analysis-pass gate and belongs in that list. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * [AUTOMATED] test(stages): resource-loader-c-retains — ExitProcess takes a UINT, so its peimportcall assertion does too `ghdec-peimportcall` PEIMPORTCALL #5 pinned `ExitProcess\(\); // no-return` on the `bail` function of `pe_noreturn_import.exe`. That empty-parens spelling was frozen in by DIV-57 (#254), when kuna carried no Windows API prototype at all and the call's one argument was simply lost. `win32sigs` (DIV-141) supplies the import's `void __stdcall ExitProcess(UINT)`, and the fixture's source is `void bail(int code) { ExitProcess(code); }`, so the site now renders `ExitProcess(a0)` and `bail` recovers its parameter. The assertion is the stale side of that; what the test exists to protect -- the `FF 25`/IAT-slot call binding to its import name and both `// no-return` flow effects surviving -- is asserted by the other four stringmatches and unchanged. The assertion name is untouched, so `docs/baseline-stages.json` needs no re-record; `docs/baseline.json` is byte-identical to origin/main. make test 675/675 PARITY OK, make test-stages 704/704 PARITY OK, make test-cli 99/99, make check-spec OK, kuna catalog --check OK. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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
A Windows PE reaches its imports through an Import Address Table slot, which is
data.
call dword ptr [slot]therefore lifts to aCALLINDwhose target is thecontents of a global — unlike an ELF PLT stub or a Mach-O
__stubsentry, which arecode and resolve as ordinary direct calls. The only pass that resolves such a target,
ActionDeindirect(coreaction.cc:1235), gates itsqueryExternalRefFunctionarm onisPersist() && isExternalRef(), andVarnode::externrefwas set nowhere in theworkspace: Ghidra sets it from an
ExternRefSymbol(Scope::addExternalRef) thatkuna's port never carried.
So every Windows API call in every PE stayed an unnamed
(*dat_4112c4)(0)— no name,no prototype and, the damaging part, no no-return flow effect, so a function
ending in
ExitThread/ExitProcesskept its fall-through and swallowed the whole ofthe next function.
Closes decbench case
O0-mydoom-mydoom-mmsender_th(IDA, Ghidra and angr all GED 0;kuna 37) and its un-triaged ida-pool sibling
O0-mydoom-mydoom-sync_visual_th.Before / after —
mmsender_th(mydoom.exe @0x4041e2)The stored IDA pane for reference (GED 0):
_InterlockedExchangeAdd(&dword_4102E4, 1u);…if (lpThreadParameter) { … sub_4040EB(…); … }…if (dword_4102E4) _InterlockedExchangeAdd(…);…ExitThread(0);. The full captured side-by-side,including the
sub_40424cbody kuna had been absorbing, isdocs/features/peimportcall/before-after.txt.Mechanism (three parts, one gate)
externrefover the IAT slots.kuna-analysis/src/loader/kuna_peimportcall.rs (PeImportCallPass)reports one[slot, slot+ptr)range per import-descriptor entry (pe_iat::resolve_pe_import_slots,reusing the existing INT/IAT lockstep walk), and the commit ORs
Varnode::externrefover each in the symbol-table property map — the sameDatabase::set_property_rangethe loader's read-only section ranges already use.Scope::queryPropertiesfolds the property map into every global Varnode coveringthe range, so the slot read now carries
persist|externrefandActionDeindirectresolves it against the
FunctionSymbolpe_iatalready registered at that sameslot VA. No second symbol is mapped: kuna's
query_functionkeys on the Varnode'sown address where upstream indirects through
ExternRefSymbol::refaddr, and theimport FunctionSymbol's map entry is 1 byte (
min_funcsymbol_size), so apointer-width slot read never finds it as a container and always takes the property
branch.
externrefis read in exactly one place in the whole workspace(
p9_emit/coreaction_render.rs:1177), so the blast radius is bounded by construction.The callee's no-return flag reaches the deindirect — a separate port gap,
see the section below.
Database::build_global_querynow carriesSymbolKind::Function { no_return }intoGlobalEntry::func_no_return, andArchitecture::query_functionputs it on the prototype it handsActionDeindirect.Upstream's PE-only no-return API list.
Ghidra/Features/Base/data/PEFunctionsThatDoNotReturnis vendored verbatim atdecompiler/crates/kuna-analysis/data/PEFunctionsThatDoNotReturnand matched againsta PE/COFF object only. kuna merges the PE and Mach-O name sets into one shipped
file (
PeMacFunctionsThatDoNotReturn, 8 shared CRT names) where upstream keeps themseparate; rather than widen that merged file with
ExitProcess/ExitThread/KeBugCheck/the MSVC-mangled?_Xbad_alloc@std@@YAXXZfamily — Windows names aMach-O would then be matched against — the Windows list stays its own file on its own
format arm. (kuna's Mach-O list is still missing upstream's
MachOFunctionsThatDoNotReturnnames: a separate, out-of-scope gap, recorded in the bundle.)
Each part alone can change emitted C on some target, so all three sit behind the one
option.
p9_emit/coreaction_render.rs(ActionDeindirect) andp4_calls/fspec.rs(
FuncCallSpecs::deindirect) are unchanged consumers, verified against.The filed mechanism was refuted before any code was written. The triage record
proposed a new P2 pass in
p2_lift/flow.rsmatching a CALLIND through a global; apre-pipeline IR dump (
load addr+print raw, nodecompile) shows the target is afree unique temp and every varnode is
(free)at that seam — raw flow IR carries nodef-use links, so the backward walk it needs is unavailable. Nothing new is added in
p2_lift.Second, separate finding:
query_functionnever reported a callee's no-returnThis one was not in the brief and is worth reading on its own, because it is a
general port gap that happens to be load-bearing here.
Database::build_global_queryflattens the global scope into a read-onlyGlobalQuerysnapshot for the per-function
ArchHandle. It copiedSymbolKind::Function'sinject_idbut not itsno_return, soArchitecture::query_function— the onlycaller of which is
ActionDeindirect— returned a prototype withis_no_return() == falsefor every callee, including one the no-return analysis pass had explicitlyflagged. Upstream never had to carry the bit:
Scope::queryFunctionreturns thecallee's live
Funcdata, whosegetFuncProto().isNoReturn()is simply true.The consequence is not "the call is missing a comment".
FuncCallSpecs::deindirectbranches on it:
With the flag lost, deindirect always took the
lateRestrictionsuccess path, rewrotethe
CALLINDto aCALLin place, and returned without scheduling a restart — sothe flow, which had already walked past the call when the function was first followed,
was never recomputed.
decomp_dbg'srestartsreported "No restart events recordedfor sub_4041e2" even after a successful deindirect.
Proved by A/B rather than inferred: with
externrefforced on and this bit stillmissing, the call renders
ExitThread(0)and the entire absorbed body is stillthere — and so it is even under the explicit
option noreturn ExitThreadoverride(the same counterfactual the triage record reported as evidence that "no name is ever
queried", which turns out to have had a second cause). Naming was necessary but not
sufficient; this is the half that fixes the boundary.
The carry is gated by the same option, because
query_functionis format-neutral: aconstant-folded indirect call on any target (e.g. the MIPS
$gp/GOT const-range path)could now resolve to a known no-return callee. Measured as inert on every ELF tested.
Follow-up filed (campaign-wide, not this PR): decbench cannot rescore PE cases
scripts.decbench.rescoreinvokeskuna decompile-all --addr 0x<address_hex>using theaddress stored in the mined pools. For a PE those pools store an RVA (
0x41e2)while kuna — like IDA and Ghidra — uses the image-based VA (
0x4041e2), so every PEcase fails with
no fresh code: Unable to load 512 bytes at r0x000041e2before anycomparison happens. This silently blocks GED rescoring for the whole PE half of the
corpus (mydoom and dexter), which is exactly the half this PR moves.
Still present after the results-tree refresh and pool re-mine — I re-checked on the
current pools and
address_hexis still the RVA0x41e2, so this is not something therefresh fixed. The two mydoom entries were corrected in a throwaway local edit to take
the numbers above and then reverted —
docs/decbench/triage-queue*.jsonare unmodifiedby this PR (
git statusondocs/decbench/is clean). The real fix (normalise thepool address to the loader's base, or teach
rescoreto add the PEImageBase) belongsin the decbench tooling, not here.
The option
--option peimportcall on|off, P1 / external-refinement, default-ON (DIV-57),tier = transform,change_kind = correctness-fix. PE/COFF only — the pass isregistered only for those formats and self-gates in
run, so every other objectformat's pass set is byte-identical (pinned by
passes::tests::peimportcall_pass_is_pe_coff_gated).Ablation and the default decision
make testis PARITY OK 675/675 with the flip and no re-pin and no per-testopt-out.
make test-stagesis PARITY OK 386/386 (the delta is purely the 5 newkeys).
Regression sweep — both PE binaries, whole-binary
kuna decompile-all, option OFF vs ON:(*dat_…)()calls// no-returnmarkswhileloopsgoto927 unnamed Windows API call sites → 8. No function is gained or lost in either
binary and gotos never increase. Beyond the five mydoom functions the triage named,
three dexter functions also stop overrunning: the largest single win is dexter
Uninstall152 → 19 lines, now 16 statements endingExitProcess(0); // no-return.Others: mydoom
sub_402a62169 → 64,sub_402eda96 → 28,sub_40710787 → 50,sub_40451c40 → 7,sub_4024c553 → 30; dexterHttpMain118 → 91,TrackSearch299 → 284,
ScanMemory88 → 72 (and it loses its onegoto).Exactly two functions grow, both by one line, and both for the same benign reason —
a named import now takes a typed argument through a temporary:
a1 = (*dat_411464)(*(unsigned short *)(a0+a1)); a1 &= 0x3fff;becomesv2 = *(unsigned short *)(a0+a1); a1 = ntohs(v2) & 0x3fff;.Shipped PE fixtures:
pe_imports_stripped.exe79 → 3 unnamed slot calls,pe_dwarf.exe50 → 0;msvc_rtti_x64/x86.exe,pdb_min.exe,pdb_prog.exeunchanged.Controls. Option-ON output is byte-identical to option-OFF on every non-PE target
measured (coreutils
b2sum,mirai,tar-O2 — same md5), and option-OFF isbyte-identical to the pre-change binary on both PEs (mydoom
49a1873b…, dexter8dc4bd5b…).All four PE md5s were re-measured on the final base
65543461and are bit-for-bitthe numbers above: neither #252 (which does change emitted C — it drops phantom
.rodatastores) nor #253 (ternary rendering) touches these witnesses, and the ELFcontrol (
b2sum, ON == OFF,06df920f…) is likewise unchanged. Confirmed byre-measurement, not from memory.
Benchmark (GED)
O0-mydoom-mydoom-mmsender_thO0-mydoom-mydoom-sync_visual_thBoth re-measured on the refreshed decbench results tree and the re-mined pools, at
the final rebase (
ged_kuna_commit 6d160156), not quoted from the pre-refresh run --the numbers are unchanged. See the follow-up section above: the RVA/VA bug is still
present after the pool re-mine (
address_hexis still0x41e2), so the measurementstill needs a local address fix-up first.
Speed
scripts.pipeline.timeit, target function, 15 repeats: 387.96 → 380.58 ms (-1.9%),within the +5% budget. An earlier 7-repeat run on this (shared, loaded) box reported
+49% and did not reproduce — three re-runs at repeat=11 gave +0.67%, -0.99%,
-3.74% — so the interleaved form DIV-54 uses on this box is quoted alongside:
decompile-allmydoom, 7 pairsdecompile-alldexter, 7 pairsb2sum, 5 pairsWhole-binary is negative because the truncated functions are less work.
Test
tests/stages/ghdec-peimportcall.xml— a two-passdecompilertestover the realload file → read symbols → decompilepath on a new 6 KB PE fixture(
pe_noreturn_import.exe, built with MinGW-w64 in thekuna-devcontainer; source andrecipe committed beside it and documented in the fixtures README). It is purpose-built
for the one call shape
pe_imports.exelacks: a__declspec(dllimport)call [__imp_ExitProcess](the direct IAT-slot shape MSVC emits for every Win32 call),with the next
.textfunction deliberately containing a loop. Pass 1(
option peimportcall off) asserts the bug —(*dat_140005038)(0xc)and(*dat_140005038)(), no// no-return. Pass 2 (option peimportcall on) asserts thefix —
ExitProcess(0xc); // no-return,ExitProcess(); // no-return, and exactly two// no-returnmarks. 2 of the 5 assertions fail with the option off; 5/5 with it on.Plus
passes::tests::peimportcall_pass_is_pe_coff_gated(format gating) and the twovendored-list guards in
kuna_peimportcall.rs(the Win32 exits are present; thereturning APIs —
CreateThread,GetTickCount,TerminateProcess, … — are not).Gates
All five re-run on the final base
65543461(after #252/DIV-55 and #253/DIV-56).Shared counters this PR moves:
kuna-base/src/xml.rscorpus count 189 -> 190,settables 86 -> 87, transform tier 40 -> 41, live-value 28 -> 29 (
itecondlistdeclares no
live_field, so only this PR moves that last one).tests/fixtures/phase_catalog.jsonwas re-captured on the rebased tree rather thancarried forward, and
docs/baseline-stages.jsonre-recorded, never hand-merged(386 keys,
data_footer [386, 386]).Two counters git resolved without a conflict were nevertheless wrong and were fixed by
hand — worth flagging for the next PR in this queue:
catalog_bytecompat.rssilentlykept
86because both sides had made the identical85 -> 86edit, and my ownpre-emptive
with_livebump to30was one too many. Both were caught only by runningthe suite, not by the merge.
Docs
docs/spec/01-program-prep.md— new prose in §import resolution: why naming apointer slot is not enough to bind a call through it, the property-map carrier, and
the
query_functionno-return carry.docs/history.md— DIV-57.docs/options.mdregenerated;tests/stages/README.mdand the fixtures README gaintheir rows;
docs/features/peimportcall/bundle (analysis.md,plan.md,before-after.txt,record.json,pr_body.md).🤖 Generated with Claude Code