Repository navigation
switchmultipred: recover multi-predecessor jump tables - #102
Merged
Merged
Conversation
angr's test_decompiling_abnormal_switch_case_case3 (memmove @ 0x18003c330, msvcr120.dll) recovers a clean 17-case switch where kuna truncated the image-base-relative dispatch to a computed (code *)() call. The BRANCHIND's parent block has multiple predecessors, each ending in its own bound guard (entry `count <= 16`; back-copy `count & 7 != 0`); the single-predecessor guard walk in analyzeGuards short-circuited to the empty checkUnrolledGuard SEAM, so no dominating guard bounded the table. This ports the upstream multi-predecessor unrolled-guard machinery (JumpBasic::checkCommonCbranch + BlockBasic::findMultiequal + liftVerifyUnroll) into checkUnrolledGuard (the faithful lockstep path for true-unrolled copies), and adds a kuna_try_multipred_guard_table fallback in recoverModel for the x86 abnormal-switch shape where the per-path guards are semantically different: it finds the dispatch MULTIEQUAL, evaluates each predecessor guard as a function of its MULTIEQUAL input, and re-bounds the table to [0, max-over-paths) so the existing readonly-LOAD image-base table model recovers the switch. Gated behind `option switchmultipred` (default OFF, upstream byte-identical when off). Fully registered (options.rs, architecture.rs field/ctor/reset/ set_kuna_option + build_arch_handle seam copy, seams.rs, stages.toml surface + settable, kuna_stages counts 96->97 / 60->61, assertions.md). Stage testcase tests/stages/ghangr-switchmultipred-memmove.xml: off = computed call, on = recovered switch (17 cases 0..16, no default — matches angr). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
…ettable Bump the kuna_stages count tests (surface 96->97, settable 60->61, trailing-comma 60, field-backed live readers 26->27 for switch_multi_pred), the kuna-catalog.xml stage testcase bounds (use_when/change_kind counts, angr-provenance + opt-in-tool lists), and regenerate docs/baseline-stages.json (227 keys) for the 5 new switchmultipred assertions. Add the default-off assertion in architecture/tests. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
…age testcase Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
…post-rebase After rebasing onto main (FID PR4 #101 brought settables to 61), the combined tree has 62 settables; the console 'stage catalog' + 'stage catalog returnpair' emits 63 use_when / change_kind entries (62 + returnpair double-count), so bump the KUNA-CATALOG #5/#9 max from 62 to 63. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
…ount (61->62) The catalog_bytecompat gate compares the live emitter against the captured tests/fixtures/stage_catalog.json byte-for-byte; recapture it (no program loaded, no `current` field) so it includes the new switchmultipred settable row, and bump fixture_has_all_*_settables 61->62. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
mahaloz
added a commit
that referenced
this pull request
Jun 26, 2026
Reconcile the taildup feature with main after the FID PRs (#97-#101) and switchmultipred (#102) landed: - ElementId: taildup collided with switchsharedcase (both 4106 on the merged tree). Renumbered taildup -> 4108 (next free above ifelseflatten's 4107). - Count unions (taildup +1 settable, switchmultipred +1, fid +1 vs merge-base): settable 60 -> 63, surface stays 97 (taildup adds no surface row), corpus files 151 -> 153, universalaction leaves -> 264 (252 C++ + 5 kuna), bytecompat fixture 63, stages.toml header counts. - kuna-catalog.xml provenance: source_decompiler angr 22, structure-recovery 12 (+taildup), opt-in-tool 11 (+switchmultipred), use_when/change_kind max 64 (settables + returnpair double-count in `stage catalog`). - Regenerated docs/assertions.md (no change) and docs/baseline-stages.json (230 passing keys). Gates: catalog --check OK; make test PARITY OK 675/675 (baseline.json untouched); make test-stages PARITY OK 230/230; make rust-test green.
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
Implements proposal #36 (
abnormal-switch-case-case3-0a21b8): recover a multi-predecessor jump-tableswitchthat kuna currently truncates to a computed call.angr's
test_decompiling_abnormal_switch_case_case3(memmove@0x18003c330,msvcr120.dll) recovers a clean 17-caseswitch. kuna lost the switch entirely and rendered the image-base-relative dispatch as an indirect call:The dispatch is an image-base-relative jump table (
target = 0x180000000 + table[index*4], a 17-entry RVA table at0x18003c410) whoseBRANCHINDparent block has multiple predecessors with different bound guards (cmp $0x10 ; jbeat function entry;and $0x7 ; test ; jneon the backward-copy path that re-enters the dispatch). The single-predecessor guard walk inJumpBasic::analyzeGuardsshort-circuits tocheckUnrolledGuard— which kuna left as an empty SEAM stub — so no dominating guard bounded the table, the normalized range stayed> maxtablesize, the basic model declined, andflow.rstruncated the indirect jump to a call.How
New S2 jump-table recovery behind a default-OFF
option switchmultipred:JumpBasic::checkUnrolledGuardported from upstream (checkCommonCbranch+BlockBasic::findMultiequal+liftVerifyUnroll, extended to peel single-in/single-out trampoline blocks x86 compilers interpose between the bound guard and the multi-entry dispatch). The faithful lockstep path that fires when the SAME guard is duplicated.kuna_try_multipred_guard_tablefallback inrecoverModelfor the x86 abnormal-switch shape, where the per-path guards are semantically different so the lockstep cannot collapse them: it locates the dispatch-index MULTIEQUAL, evaluates each predecessor guard as a function of its MULTIEQUAL input (the contiguous[0, N_K)toward-switch prefix), unions the per-path prefixes (N = max_K N_K), and re-bounds the table to[0, N). The existing image-base-relative readonly-LOAD table model then reads theNRVAs and the structurer emits theswitch.Before / after (on the target)
A bytechunk stage testcase (
tests/stages/ghangr-switchmultipred-memmove.xml) loads the realmemmovebytes at their VA (kuna's loader is ELF-only and cannot load the PE, per the proposal's go/no-go note):option switchmultipred on(*(code *)(...))(a0,a1)computed call +Treating indirect jump as callwarningswitch(...)case 0:...case 0x10:), nodefault:— matches angrRecovery log (only with the option on):
[kuna switchmultipred] recovered multi-predecessor unrolled-guard jump table at 0x18003c40e: 3 predecessor guards, union bound [0,17)Default + speed
Default OFF (upstream byte-identical): the gate short-circuits
checkUnrolledGuardand therecoverModelfallback, so a binary with no multi-predecessor switch does zero extra work. On the target the on-cost is ~3% (0.32s -> 0.33s) — the difference is recovering the larger live function vs the truncated call, not analysis overhead.Registration
Fully wired:
options.rsKUNA_OPTION_NAMES,architecture.rsfield + ctor +reset_defaults+set_kuna_optionarm +build_arch_handleseam copy,seams.rsfield + ctor,stages.tomlsurface + settable,kuna_stagescount tests (surface 96->97, settable 61->62, field-backed live readers 26->27, trailing-comma 60->61),kuna-catalog.xmlstage bounds, XML corpus file count (151->152),docs/assertions.mdregenerated,docs/baseline-stages.jsonregenerated (227 keys).kuna catalog --checkOK.Gates
make test: PARITY OK 675/675 (default-off byte-identical)make test-stages: PARITY OK (227/227, the 5 new switchmultipred asserts)make rust-test: greenkuna catalog --check: OK(Rebased onto current
mainover FID PR4 #101; combined counts reconciled.)🤖 Generated with Claude Code
https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac