Skip to content

[AUTOMATED] Give a virtual call its receiver when MSVC sets ECX after the vtable load - #1591

Open
borancar wants to merge 4 commits into
Noelo-Lab:mainfrom
borancar:vcall-typed
Open

borancar wants to merge 4 commits into
Noelo-Lab:mainfrom
borancar:vcall-typed

Conversation

@borancar

@borancar borancar commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

On x86-32 Windows, an MSVC virtual call still prints without this when ECX is set after the vtable load, or when a later call follows it before the epilogue:

$ kuna decompile decompiler/crates/kuna-analysis/tests/fixtures/vcall_pe_i386.exe 0x4011f0
  (**(void (**)(unsigned int))(*a0 + 0x30))(6);
$ kuna decompile decompiler/crates/kuna-analysis/tests/fixtures/vcall_pe_i386.exe 0x401230
  (**(void (**)(unsigned int))(*a0 + 0x34))(7);

With this change:

  (**(void (**)(int *,unsigned int))(*a0 + 0x30))(a0,6);
  (**(void (**)(int *,unsigned int))(*a0 + 0x34))(a0,7);

Fix

  • MSVC usually sets ECX last: mov eax,[ebx]; mov eax,[eax+0x24]; push 6; mov ecx,ebx; call eax. An ECX write between the vtable load and the call is now accepted when it copies the object back. One that loads another object still keeps the default.
  • The caller-cleanup scan (shared with calleeargs) now ends at a store through FS. mov fs:[0],ecx unlinks an MSVC SEH frame, and the pop ecx after it frees the frame's own slot. It is not a cleanup of the call before it.
  • The check that rejects a C __cdecl table call (the caller cleans up after it) now counts only a cleanup made before the next call. The calleeargs scan it used takes the virtual call to pop only its return address. Past a later call, that scan read frame teardown (pop ecx before pop edi) as a cleanup of the virtual call. It also read a later callee popping pushes made before the virtual call (o->child()->take(1, 2)) as one.

Apart from the FS stop, the calleeargs scan is unchanged. The docs/spec/04 section on virtual calls drops the "not recognized" note for this shape.

Tests

vcall_pe_i386.exe gains five functions after the existing ones, so no address moves. tests/stages/kuna-calleereginputs.xml gains assertions CALLEEREGINPUTS #31–#39:

  • latecopy sets ECX after the vtable load;
  • lateother loads another object into ECX and gets no receiver;
  • vepilog has a later call and a pop ecx epilogue;
  • vouter is o->child()->take(1, 2);
  • vseh is a call right before an SEH epilogue.

On main, CALLEEREGINPUTS #32, #35, #37 and #39 fail.

python -m scripts.prepr.aritydiff against main:

  • The five public MSVC binaries are unchanged.
  • A 2,198-function MSVC game gains a receiver on 30 indirect calls and loses no argument. Every sampled one is mov edx,[edi]; push ...; mov ecx,edi; call [edx+k].
  • On a 23,101-function VC8 game, the SEH stop:
    • gives 246 more virtual calls their receiver;
    • drops 29 stray arguments, each the /GS cookie slot after a call such as push esi; call f; add esp,4;
    • moves that cookie slot onto 7 direct calls that the virtual call used to take it from. That is the existing cookie-as-argument bug, not new behaviour.
  • decompile-all time is unchanged.

Not fixed: in o->child()->take(1, 2), take's pushes are still offered to child().

Fixes #1590

🤖 Generated with Claude Code

borancar and others added 4 commits November 14, 2026 21:00
… the vtable load

calleereginputs' virtual-call rule now accepts an ECX write between the
vtable load and the call when it copies the object back (mov eax,[ebx];
push 6; mov ecx,ebx; call eax), and judges a caller cleanup only up to the
next call: past a later call the calleeargs scan reads frame teardown, or a
later callee's pops of earlier pushes, as cleanup of the virtual call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A store through FS (mov fs:[0],ecx) unlinks an MSVC SEH frame; the pop ecx
after it frees the frame's own slot and is no cleanup of an earlier call.
An MSVC virtual call right before such an epilogue kept the default model
and lost its receiver.

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: an MSVC virtual call still loses its receiver when ECX is set after the vtable load, or when the epilogue follows it

1 participant