Skip to content

[AUTOMATED] feat: RE-friction loop round 1 — strings, disassemble, triage, and six correctness options - #367

Merged
mahaloz merged 9 commits into
mainfrom
feat/re-round1
Sep 3, 2026
Merged

mahaloz merged 9 commits into
mainfrom
feat/re-round1

Conversation

@mahaloz

@mahaloz mahaloz commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Round 1 of the RE-friction loop, end to end: three codex testers reverse-engineered nine
crackmes with kuna as their primary tool and recorded where it failed them; 26 observations
were filed, 23 passed the two-arm gate, and six builders closed them.

What testers actually asked for

Five testers across four challenges independently asked for a string inventory. Three
wanted disassembly when the decompilation looked wrong. Two could not triage a
whole-binary JSON dump. That convergence is the signal — none of them could see each other's
reports.

kuna strings VMA + section + owning function per string. strings(1) gives a file offset and no owner; this is the whole reason the subcommand exists. UTF-16 included, which is what turned a LoadLibraryW("n") into LoadLibraryW(L"ntdll.dll") on an anti-debug PE.
kuna disassemble by name, bare address, or range; --json carries raw bytes so an agent can check the decompiler against the instructions rather than trusting it
kuna functions triage --summary --filter --reachable-from --min-size --sort --limit. On a 211 KB PE: 174 KB of JSON → 2.8 KB that answers "where do I start" (1150 functions, entry named, 334 reachable, 714 orphaned).

Correctness fixes, each behind a named option with a two-pass stage test

option default
unmappedentry ON A direct CALL target outside every executable range became a DiscoveredFunction — the instruction worklist had already refused to decode it, but the function worklist took the target unconditionally. Sweep over 250 crackmes: 150 phantom entries removed, 0 added; 6,085 shared functions decompiled, exactly 1 changed, and it improves.
entrymainproto ON main typed void(void). kuna recovers parameters from the callee's own body and main never reads its argument registers, so the in-image CRT call site is read instead. PE-only, because on ELF the CRT lives in libc and there is no call site to read.
linuxsyscall OFF 32-bit int 0x80 rendered as an indirect call through swi(0x80), arguments dead-coded away
switchselector OFF loweredswitch detects a cascade on the simplified graph and installs the BRANCHIND on re-lifted raw p-code, where it must re-find the selector — and commits the surgery whether or not either recovery arm succeeded. A Win32 dialog procedure rendered switch(0), every case unreachable.
varargstackargs OFF two ways a call argument was recovered and then discarded
calleearity OFF

Three hypotheses overturned

The symptom held in every case; the tester's diagnosis did not. unmappedentry was filed as
a discovery heuristic misfiring, entrymainproto as failed interprocedural propagation, and
switchselector as a switch-recovery bug. All three root causes above are what the builders
actually found, by reproducing rather than by reading the report.

Closure, measured on this branch

Re-running both arms of all 23 gated observations: 12 genuinely fixed, 2 fixed behind a
default-OFF option (so correctly still reproducing at defaults), 9 still open, and 1
falsely reported fixed
. That last one is the most useful result of the round: a probe
asserted _secret_function(v2); for a void function called with an argument, the build now
emits _secret_function(v3); — the identical defect, one renumbered local — and the probe
stopped matching, so the machine called it fixed. An over-specified acceptance leaves
finished work looking open; an over-specified probe closes work that was never done. Both
prompts now say: assert the property, never a vN, a sub_<addr>, or a whole signature line.

Counters

133 settables (30 core / 54 transform / 49 analysis), stage corpus 228, catalog records 132.
This branch said 131 and callargrecovery said 129 — both had bumped from 127, so picking
either side would have been silently wrong. Every site was re-derived from the live tree;
phase_catalog.json, docs/options.md and docs/baseline-stages.json were regenerated,
never merged. Two guards that were blind to this are fixed in the same PR (a missing
counters.py site, and a smoke.sh that pinned literal counts).

tests/cli grows 5 → 10 promoted acceptance probes, run by make test-cli in CI.

Gates

make test 675/675 PARITY OK (docs/baseline.json untouched) · make test-stages 594/594
PARITY OK · make rust-test 339 targets / 5,203 passed, 0 failed · make check-spec OK ·
kuna catalog --check OK · make test-cli 10/10 · tools/repipe/smoke.sh 72/72.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YcFmfZndNjgfqLQVBZCdkY

claude and others added 4 commits September 3, 2026 03:11
…argument was recovered and then discarded

RE-friction round 1 filed four "call and argument recovery" observations across
three challenges. They are NOT one bug; reproduced and root-caused separately,
they are three causes, two of which are call-site argument loss with different
owners. Both are fixed here, each behind its own option, each default-ON on a
0/675 ablation and a classified whole-corpus sweep.

varargstackargs (DIV-101, P4 active-input-trial-scoring, ElementId 4132)
  68149b8a `_main`: scanf("%d") loses its destination and three printf calls
  lose the buffer their %s consumes, and the local scanf writes ends up read
  but never written. checkInputTrialUse scores the [sp+0] trial ACTIVE;
  ParamListStandard::fillinMap deactivates it again, because on AArch64 x0-x7
  and the outgoing stack area are ONE resource section and its two positional
  rules read the seven registers Apple's arm64 ABI structurally leaves empty
  between the fixed parameter and the first vararg as the end of the argument
  list. The section is now cut in two at its first stack trial, gated on the
  callee being variadic and on the stack area starting at callee-relative
  offset 0. Sweep: 1 changed function of 3857.

calleearity (DIV-102, P4 trial-finalization, ElementId 4133)
  69a54bd7 0x1400024a0: the same allocator wrapper renders sub_140008160(0x28)
  at one site and sub_140008160() thirty bytes later, at the site where the
  size is also the operand of an MSVC operator new[] overflow guard --
  only_op_use rejects the trial on its CPUI_CBRANCH descendant. Relaxing that
  rejection would fabricate an argument at every `test rcx,rcx; jz; call`, so
  buildInputFromTrials instead reconciles a call whose argument list came out
  EMPTY with a sibling call to the same callee whose list is already final.
  The storage is recorded on the call spec, because a CALL op's inputs carry
  argument values (0x28 is a constant) and the trials that knew the location
  are deleted one statement later. Sweep: 25 changed of 3857, no regression;
  the first cut ("same callee, same arity") changed 43 and produced
  Sleep(200,0), which is where the empty-list condition comes from.
  Its acceptance probe flips.

Gates: make test 675/675 PARITY OK (docs/baseline.json untouched) · make
test-stages 578/578 PARITY OK · make rust-test 334 targets / 5018 passed ·
make check-spec OK · kuna catalog --check OK · counters re-derived, no drift.
Speed flat for both, measured on interleaved child CPU time with a null
control because the box carried load average 11-14 throughout.

Bundles: docs/features/varargstackargs/, docs/features/calleearity/.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…, and four correctness options

Round 1 of the RE-friction loop: three codex testers on nine crackmes filed 26
observations; 23 passed the two-arm gate. This lands the fixes for them.

Interface (Track T) -- five testers across four challenges independently asked
for a string inventory, three for disassembly, two for whole-binary triage:
  kuna strings       VMA + section + owning function, which strings(1) cannot give
  kuna disassemble   named function, bare address, or range; --json carries bytes
  kuna functions     --summary --filter --reachable-from --min-size --sort --limit
                     (211 KB PE: 174 KB of JSON -> 2.8 KB that answers "start where")

Correctness (Track D), each behind a named option with a two-pass stage test:
  unmappedentry   ON   a direct CALL target outside every executable range became
                       a DiscoveredFunction; the instruction worklist had already
                       refused to decode it. 250-binary sweep: 150 phantom entries
                       removed, 0 added, 1 function's C changed and it improves.
  entrymainproto  ON   main typed void(void); parameters are recovered from the
                       callee's own body and main never reads its argument
                       registers, so the in-image CRT call site is read instead.
  linuxsyscall    OFF  int 0x80 rendered as an indirect call through swi(0x80)
  switchselector  OFF  loweredswitch detects a cascade on the simplified graph and
                       installs the BRANCHIND on re-lifted raw p-code it cannot
                       re-find the selector in -- and commits regardless, so a
                       Win32 dialog dispatcher rendered switch(0), every case dead

tests/cli grows 5 -> 10 promoted acceptance probes, run by make test-cli in CI.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Conflicts were all in the shared-counter surface. Resolved by taking this
branch's structure and re-deriving every count from the live tree afterwards --
never by picking a side: HEAD said 131 settables and the branch said 129, and
the truth after the merge is 133. Two match arms and one comment block the
branch added were restored by hand; `--ours` had dropped them.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…se two guard gaps

Counters after merging both lanes: 133 settables (30 core / 54 transform /
49 analysis), stage corpus 228, catalog records 132. Neither branch's number:
this branch said 131 and callargrecovery said 129, both having bumped from 127.
Every site was re-derived from the live tree with `counters.py --fix`, and
phase_catalog.json / docs/options.md / docs/baseline-stages.json were
REGENERATED rather than merged.

Two guards were blind and are now not:

- `counters.py` had no site for the catalog-record assert in kuna_phases/tests.rs
  (`json.matches("},\n").count()`), so the merge left it at 130 against a truth of
  132 and only `make rust-test` caught it. Added as its own site with a
  `settables_minus_one` derivation -- a regex pinned to `settables` would have
  written the wrong number. Verified it catches injected drift.

- `smoke.sh` asserted the literal strings `"settables": 127` and
  `"corpus_files": 222`, so every option that lands broke the smoke. That is a
  false alarm that teaches people to ignore the smoke, and it never caught a real
  drift because `counters --check` is what does that. It now asserts the
  mechanism: the derivation is plausible and every hard-coded site agrees with it.

Gates: make test 675/675 PARITY OK (baseline.json untouched) · make test-stages
594/594 PARITY OK · make rust-test 339 targets, 5203 passed, 0 failed ·
make check-spec OK · kuna catalog --check OK · make test-cli 10/10 ·
tools/repipe/smoke.sh 72/72.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@mahaloz mahaloz added the full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default) label Sep 3, 2026
mahaloz and others added 5 commits September 3, 2026 04:24
… round 2

The backlog was empty because round 1's observations were gated straight from
the reports; the records are what round 2's tester brief is rendered from, so
without them the next testers would re-file "kuna has no strings command" against
a kuna that now has one.

Closure is the VERIFIED state, from re-running both arms on the merged build:
8 closed (12 of the 23 gated observations, several of them duplicates of each
other), 6 carried open. `void-callee-spurious-arg` is carried OPEN despite its
probe no longer matching -- the probe pinned `_secret_function(v2);` and the
build now emits `_secret_function(v3);`, which is the same defect with one
renumbered local.

Also fixes the renderer: `_recently_shipped` printed each closed need's TITLE,
which states the problem ("kuna cannot list strings"), under a heading that says
"newly available capabilities" -- telling the tester the exact opposite of the
truth. It now renders the `Shipped:` line the record carries, so the brief names
the flag or subcommand to actually exercise.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The PR was CONFLICTING against main, which is why no `pull_request` workflow run
ever appeared for it: GitHub does not run those when it cannot compute the merge
commit, so the PR presented as "CodeQL green" with not one gate executed -- the
exact failure mode the tests.yml header warns about. `open_pr.sh --merge` would
have refused it (a required suite that is `missing` is treated the same as one
that is `skipped`), which is that guard earning its place against a real case.

Both conflicts were additive-on-both-sides and are unioned, not picked:
- `decompile_all.rs` -- the import block; #350 added EntryLookupError /
  EntrySelector / ObjectLocation, this branch added the xrefs index, Address,
  BTreeSet/VecDeque and Rc for `--reachable-from`.
- `docs/cli.md` -- #350 documented `object_location`, this branch documented
  `--summary` and the `total` field.

#350 touches loader/entry selectors, which is where `unmappedentry` and
`entrymainproto` live, so a clean textual merge proves nothing here. Re-verified
on the merged build: the unmappedentry witness still drops 0x349688c1 by default
and restores it with `--option unmappedentry off`; entrymainproto still types
argc/argv/envp on the PE CRT fixture; and #350's own property -- a loader `main`
symbol surviving discovery -- holds.

Gates re-run after the merge: make test PARITY OK · make test-stages PARITY OK ·
make test-cli 10/10 · make check-spec OK · kuna catalog --check OK · counters no
drift.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ates and looks green

Round 1's own PR hit this: six green CodeQL checks, the Tests workflow with no
run object at all, and `gh pr checks` presenting an all-green list. GitHub does
not dispatch `pull_request` workflows while it cannot compute the merge commit.
The `missing` arm of open_pr.sh --merge -- written for a renamed check -- is what
stands between that and an auto-merge of wholly ungated code.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…l the build

`ElementId`'s `PartialEq` is an id comparison (ported from C++), so two options
sharing an id compare EQUAL and the first code that dispatches on one takes the
wrong branch. Three ids were allocated twice on main:

  4110  iteregion / returndup          (one commit, 2026-07-10)
  4122  funcboundflow / orchain        (a day apart, #280 and #285)
  4132  varargstackargs / linuxsyscall (THIS ROUND -- two concurrent builders)

The later of each pair is renumbered: returndup 4135, orchain 4136,
linuxsyscall 4134. Renumbering is free here because nothing consumes any of
them -- `grep ELEM_ITEREGION` etc. finds only the declaration -- which is also
precisely why three of these landed unnoticed. The hazard is the first consumer,
not today's output; that is a reason to fix it now rather than a reason not to.

Both 4122 sources carried a comment reasoning "the next free id above
itecondlist's 4121 is 4122". Two agents grepped for the high-water mark a day
apart and got the same answer. 4132 is the same race inside a single round of
this pipeline. Reading the high-water mark by hand cannot be made safe, so the
comments now point at the deriving tool instead.

`counters.py --check` already FOUND duplicates and printed them -- while exiting
0. That is what let all three land, and it is fixed here: duplicates are now a
`FAIL` line and a non-zero exit, verified by injecting one. The check is wired
into the parity-gates CI job, which is the cheap job that runs on every event,
so this cannot recur silently.

Gates on the renumbered tree: make test 675/675 PARITY OK · make test-stages
PARITY OK · make test-cli 10/10 · make check-spec OK · kuna catalog --check OK ·
counters --check clean (38 ids, 0 duplicates) · smoke 86/86.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A source survey of what an agent can OVERRIDE (as opposed to query) found that
kuna has a working console vocabulary for exactly the levers an obfuscated
binary needs -- `map function`, `map address`, `parse line`, `override flow`,
`rename`, `retype`, `map param/return`, `comment instruction` -- and the `kuna`
binary can reach none of it. `decompile.rs::build_script` emits a fixed
vocabulary and there is no `kuna console`, no `--script` and no passthrough.

Three further findings, all verified by running the commands:
- `function F spans [start,end)` does not exist anywhere. Extent is derived in
  funcextent.rs with no override, and phases.toml has no subphase for
  function-entry identification at all.
- The structuring overrides phases.toml advertises in its own `exposure` fields
  are mostly stubs: `force goto`, `override jumptable` and `structure blocks`
  all return `engine integration not yet ported`. Only `override flow` works.
- `--kassert` is the interface that was meant to carry this, and only its
  `naming-policy` and `Option` dispatch arms do real work.

Four needs seeded, top of the backlog. They are NOT tester-filed and say so;
round 2 confirms the demand. The hypothesis section records the thing a builder
must not assume: the cheap half is exposure and the expensive half is the stubs,
and a scriptable console is a different product from flags an agent composes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@mahaloz
mahaloz merged commit e5ac9c7 into main Sep 3, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/re-round1 branch September 3, 2026 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants