Skip to content

[AUTOMATED] option extrapop <n> <name>: set a named function's extrapop - #1709

Merged
mahaloz merged 15 commits into
Noelo-Lab:mainfrom
coleleavitt:fork/extrapop-name
Nov 20, 2026
Merged

mahaloz merged 15 commits into
Noelo-Lab:mainfrom
coleleavitt:fork/extrapop-name

Conversation

@coleleavitt

@coleleavitt coleleavitt commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

[AUTOMATED]

The problem

option extrapop <n> <name> sets the stack bytes one function pops when it returns. It answers "Unknown function name" for every name, including functions that exist.

$ cat > ep.s <<'EOF'
.intel_syntax noprefix
.globl f, g
.type f, @function
.type g, @function
f:  push 2
    push 1
    call g
    mov eax, [esp+4]
    ret
g:  mov eax, [esp+4]
    ret 8
EOF
$ as --32 ep.s -o ep.o && ld -m elf_i386 -e f ep.o -o ep
$ kuna decompile ep f --option extrapop '12 g'
error: option extrapop: Unknown function name: g

g returns with ret 8, so it pops 12 bytes. Without the option the model's extrapop (4) leaves both pushes on the stack and f prints g(1); return 2;. With this change the command prints:

unsigned int f(unsigned int a0)
{
  g(1,2);
  return a0;
}

The fix

  • Architecture::set_function_extra_pop was a stub. It now looks the name up in the global scope and stores the value on the function symbol, the way option inline and option noreturn store theirs.
  • A call takes its callee's stored extrapop when its prototype is set up, and the function's own prototype takes it when the function is decompiled. This matches upstream Ghidra, where the caller copies the callee's prototype.
  • A name with no function symbol still reports "Unknown function name".
  • No new option: the syntax already existed and could not succeed.

The tests

  • tests/stages/kuna-extrapop-function.xml: the two functions above as bytes; pass 1 is the model extrapop, pass 2 option extrapop 12 g. The pass-2 assertions fail without the change.
  • Datatest corpus 675/675; no existing stage expectation moved.

Model: anthropic/claude-fable-5-2

coleleavitt and others added 9 commits November 18, 2026 21:10
Architecture::set_function_extra_pop was a stub that returned "Unknown
function name" for every name. Port OptionExtraPop's per-function arm
(decompiler/cpp/options.cc OptionExtraPop::apply): look the function up in
the global scope and park the value on its FunctionSymbol, as the inline
and noreturn options do. The decompile driver applies it to the
function's own prototype, and ActionDefaultParams copies it into every
call spec that targets the function, as the C++ copies the callee's
prototype.

0/675 datatest assertions move. New stage test
kuna-extrapop-function.xml: a `ret 8` callee whose extrapop 12 makes the
caller see both pushed arguments popped.
…t is undefined

`validate_pointer_targets` built the function-start fingerprint histogram,
decoding two instructions of every discovered function, before checking
whether any candidate pointer target is still undefined. It now filters
the candidates to undefined addresses first and returns before decoding
anything when none remain. The listing is not modified during the loop,
so the filter is the one the loop already applied and the result is the
same.

User-mode instructions of `kuna functions --json`, pinned to one core:
libQt6Core.so.6 30.16e9 -> 29.23e9 (-3.1%), libcrypto.so.3 24.79e9 ->
24.15e9 (-2.6%), a 314k-function AArch64 Mach-O 499.7e9 -> 472.5e9
(-5.4%). The JSON is byte-identical on all three.
A filtered run with one --addr naming an IAT slot (an import with no
body) refused the whole run, so one such address in a batch decompiled
nothing. Among several --addr/--functions selectors the slot is now
reported as `warning: <diagnostic>; skipped` and the others still
decompile. A lone slot, or a run whose every selector is one, still
fails with exit 1.
[AUTOMATED]

A call whose prototype is forced late (ActionDeindirect, from a typed function
pointer) re-maps its existing inputs onto the locked parameters by their
trials. A trial keeps the width it was recorded with, but subvariable flow can
narrow the Varnode an unlocked call reads. transfer_locked_input then handed a
2-byte Varnode to build_param for an 8-byte parameter, which emitted
SUBPIECE(vn:2, 0):8; RuleSubNormal folded a shift below it into a SUBPIECE
with a negative offset, and get_nz_mask_local shifted by it: a build with
overflow checks panicked with "attempt to shift right with overflow".

transfer_locked_input now refuses an input narrower than its parameter, so the
site takes the existing restart path and is rebuilt with its inputs locked.
get_nz_mask_local compares the SUBPIECE offset with the word size as unsigned,
as the C++ does, so it is total for an offset that is negative as an int4.

Stage test kuna-narrowed-call-input, unit test
nz_mask_of_a_subpiece_past_the_word.
…is re-followed

Upstream ActionRestartGroup calls Architecture::clearAnalysis, which is
Funcdata::clear plus commentdb->clearType(fd, warning|warningheader).
refollow_flow only ran Funcdata::clear, so a warning the discarded pass
raised survived into the output: a `// return-dupe` on a function whose
kept pass has a single return, or a `// branch-flip` on a guard the re-run
did not flip.

refollow_flow now drops the function's published warning and warningheader
comments and the ones still buffered on the Funcdata.
tests/stages/kuna-restart-warnings.xml pins it. Datatests unchanged
(675/675).
[AUTOMATED]

nzmask_subpiece_negative_offset_diverges documented that get_nz_mask_local
panicked in debug on a SUBPIECE truncation offset that is negative as an int4,
where the C++ compares the offset with sizeof(uintb) as unsigned and returns 0.
The previous commit made the port compare the same way, so the should_panic
test no longer panicked. The test now asserts the C++ result, 0 for an input
at or below the word and an untouched mask for extended precision.
…ect to it

option extrapop <n> <name> reached only direct calls, through
ActionDefaultParams. A call through a register or an import slot takes
its prototype from ArchContext::query_function, which ignored the parked
value, so the same callee popped the model's bytes there. query_function
now hands back the prototype with the parked extrapop; it is unchanged
when no extrapop is parked. The stage test gains a caller that reaches g
through ecx.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
…ing to decompile

A run of an import slot plus a --functions name that matches nothing failed
with "every selector names an import slot", which is false for the missing
name. Count the skipped slots: the all-slots message is kept when every
selector was a slot, and the mixed case says no selector names a function
body. The CLI test covers the mixed case; docs/cli.md and the spec state the
rule as "fails when the skips leave nothing to decompile".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
@mahaloz

mahaloz commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Merged current main into this branch. The conflicts were the corpus count, decompile_drive.rs (kept both blocks) and docs/baseline-stages.json. Added one commit (3104258) so a call that reaches the named function through a register or an import slot also takes its extrapop. Deindirect and the MSVC import-call path take the callee prototype from ArchContext::query_function, which ignored the parked value: mov ecx, offset g; call ecx still printed g(1); return 2; under extrapop 12 g. query_function now returns the prototype with the parked extrapop, and the stage test gains a caller k that calls g through ecx (EXTRAPOP #4). Without the option, decompile-all output is byte-identical to main.

mahaloz and others added 6 commits November 20, 2026 21:24
@mahaloz
mahaloz merged commit 310a42b into Noelo-Lab:main Nov 20, 2026
@coleleavitt
coleleavitt deleted the fork/extrapop-name branch November 21, 2026 06:26
coleleavitt added a commit to coleleavitt/kuna that referenced this pull request Nov 22, 2026
Merging upstream/main brought tests/stages/kuna-extrapop-function.xml
(Noelo-Lab#1709), whose first pass prints f under the model extrapop of 4. spsolve
read g's `ret 8` and applied 12 there, and it also replaced an extrapop
that `option extrapop <n> <name>` stated: `option extrapop 4 g` still
printed `g(1,2); return a0;`. The merge pinned `option spsolve off` in the
upstream test; this drops the pin.

- A call whose callee has a stated extrapop keeps it: the solve takes it as
  a fixed delta and settle never changes it (kuna_spsolve.rs `stated`).
- spsolve applies only to a loaded ELF image (new load-time fact
  `Architecture::image_elf`). Under the XML <binaryimage> bootstrap the
  stated model is the whole contract, as for Ghidra's decompiler before
  any analysis records a callee's RET n.
- kuna-spsolve.xml gains a third pass, `option extrapop 4 mk`, that keeps
  the stated value over mk's `ret 4`.

[AUTOMATED]
Model: anthropic/claude-opus-5-5:low
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.

2 participants