Skip to content

[AUTOMATED] Expand a by-value block for a callee whose stack effect the walk cannot settle - #1598

Open
borancar wants to merge 3 commits into
Noelo-Lab:mainfrom
borancar:byval-reuse
Open

borancar wants to merge 3 commits into
Noelo-Lab:mainfrom
borancar:byval-reuse

Conversation

@borancar

Copy link
Copy Markdown
Contributor

A by-value struct that MSVC copies with rep movsd over an earlier call's deferred pushes is dropped from the __thiscall call it feeds:

$ kuna decompile decompiler/crates/kuna-analysis/tests/fixtures/byvalreuse_pe_i386.exe 0x401000
  v5[4] = 0x401015;
  sub_401070(v4,a1,0x20);
  ...
  while (v3) {
  ...
  sub_401040();

With this change:

  sub_401070(&v1,a1,0x20);
  sub_401040(v1,v2,v3,v4,v5,v6,v7,v8);

Fix

  • repframecopy's argument_block falls back to the call's calleeargs window as the pop that releases the block when there is no stated pop and the purge walk cannot settle the callee. The window is what the callee's reached returns pop (ret 0x20) or what the caller removes right after the call.
  • An expansion that relies on that window states the pop on the call. It also states that the earlier call whose pushes the block reuses pops only its return address. That call is found by walking the copy's stack pointer back to its INDIRECT, and is only stated when its prototype gives no pop and any purge its returns prove agrees.
    • Without that, the solver, which applies proven purges only when every call in the function has one, guessed that the earlier call popped its 12 bytes. The block's reads then landed in the caller's parameters, and four functions in the game below gained bogus parameters.

Tests

tests/stages/kuna-repframecopy.xml gains REPFRAMECOPY #14 on the new clean-room fixture byvalreuse_pe_i386.exe. byval copies a 32-byte struct into a block that reuses a __cdecl call's 12 bytes of pushes, then calls a __thiscall method ending in ret 0x20 that hands its argument's address to a helper called through a pointer. REPFRAMECOPY #14 fails on main.

python -m scripts.prepr.aritydiff against main:

  • The five public MSVC binaries and a 2,198-function MSVC game are unchanged.
  • A 23,101-function VC8 game changes 16 functions, gains arguments at 34 calls, and loses none. No function's own signature changes.
  • decompile-all time is unchanged.

Fixes #1597

🤖 Generated with Claude Code

borancar and others added 3 commits November 15, 2026 11:56
…he walk cannot settle

repframecopy's argument_block takes the call's calleeargs window (what the
callee's reached returns pop, or the caller removes after the call) as the
pop releasing the block when neither a stated extrapop nor the purge walk
gives one. A __thiscall method ending in ret 0x20 that calls a helper the
walk cannot read kept the copy as a loop and printed with no arguments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When repframecopy expands a block on the call's calleeargs window alone, it
states that pop on the call, and states that the earlier call whose pushes
the block reuses pops only its return address. The solver otherwise guessed
that call popped its pushes and placed the block's reads 12 bytes too high,
in the caller's parameters.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
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.

[AUTOMATED] x86-32: a by-value struct copied with rep movsd over an earlier call's pushes is dropped from a __thiscall call

1 participant