Skip to content

[AUTOMATED] Give an MSVC virtual call its receiver under calleereginputs - #1582

Merged
mahaloz merged 16 commits into
Noelo-Lab:mainfrom
borancar:vcall-this
Nov 14, 2026
Merged

mahaloz merged 16 commits into
Noelo-Lab:mainfrom
borancar:vcall-this

Conversation

@borancar

@borancar borancar commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

An MSVC virtual call prints without the object it is called on, even now that calleereginputs is on by default:

$ kuna decompile decompiler/crates/kuna-analysis/tests/fixtures/vcall_pe_i386.exe 0x401000
  (**(void (**)(unsigned int))(*a0 + 8))(5);

With this change:

  (**(void **)(*a0 + 8))(a0,5);

Fix

  • Under calleereginputs, an indirect call takes the __thiscall model if it is MSVC's virtual dispatch. That means the target is loaded from a slot of a table that is itself loaded from where ECX points (mov eax,[ecx]; call [eax+k], through copies and a zero offset), and no write to ECX or other call comes between that load and the call. It is chosen in ActionDefaultParams, next to the Swift indirect-call hook.
  • A COM method has the same dispatch but is __stdcall, with the interface as its first stack argument. A call whose last push before it stores ECX keeps the default, so p->SetVolume(7) still prints (a0,7) once. A push ecx that only reserves a slot a later store fills (push ecx; fstp [esp]) is not that push.
  • Part of calleereginputs (on by default on x86-32 Windows since [AUTOMATED] Turn calleereginputs on by default on x86-32 Windows #1575; off restores the old output). The phases.toml row and spec 04 describe the new case.

Tests

tests/stages/kuna-calleereginputs.xml gains two passes (off, on) over a new clean-room fixture, vcall_pe_i386.exe, with assertions #18–#22:

  • a virtual call gets its receiver only with the option on;
  • the COM call keeps its pushed interface in both passes;
  • the slot-reserving push ecx doesn't hide this;
  • no call takes its object twice.

python -m scripts.prepr.aritydiff against main, over setuptools cli-32/gui-32, distlib t32/w32, WinHelloCPP.exe and a 2,198-function MSVC game: no change on the five public binaries. On the game, 72 calls through a pointer gain exactly their receiver and none lose an argument. Before the COM rule, two DirectSound-style calls printed the interface twice; they're unchanged now.

Fixes #1579

🤖 Generated with Claude Code

borancar and others added 16 commits November 14, 2026 10:37
With calleereginputs on, an indirect call takes the __thiscall model
when it is MSVC's virtual dispatch: the target is loaded from a slot of
a table loaded from where ECX points, with no ECX write or call between
that load and the call. A COM method has the same dispatch but is
__stdcall with the interface pushed last, so a call whose last push
stores ECX keeps the default; a push ecx that only reserves a slot a
later store fills is not that push.

New fixture vcall_pe_i386.exe; kuna-calleereginputs Noelo-Lab#6-Noelo-Lab#10.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	decompiler/crates/kuna-decomp/phases.toml
#	decompiler/crates/kuna-decomp/src/p4_calls/kuna_calleereginputs.rs
#	decompiler/crates/kuna-decomp/tests/fixtures/phase_catalog.json
#	docs/baseline-stages.json
#	docs/options.md
#	docs/spec/04-calls-and-prototypes.md
#	tests/stages/kuna-calleereginputs.xml
Keep Noelo-Lab#1575's calleereginputs header, row and spec text, with the
virtual-dispatch paragraph after them; move the vcall passes to the
file's off/default form as Noelo-Lab#18-Noelo-Lab#22; options.md and phase_catalog.json
from main (regenerated after the build); synthesize baseline-stages.json.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…dows x86, and type its target

On main calleereginputs is on by default, so the virtual-dispatch case
now runs on every x86-32 image. Gate it to x86-32 Windows like the
direct case (Borland and other x86-32 specs stay inert). A call the
caller cleans up after (add esp,4: a C table of __cdecl function
pointers reached through ECX) keeps the default, since a __thiscall
callee removes its own arguments; a COM call whose interface is pushed
from the register ECX was copied from keeps it too. Lay out the target
type of a __thiscall-modeled indirect call under that model, so the
call prints through a function pointer instead of an uncallable void *.
Fixture gains ctable/comcopy (rebuilt from its recipe); stage Noelo-Lab#23-Noelo-Lab#25.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…ve Delphi receivers alone

With the virtual-call model on by default, a receiver set in an earlier
block failed the upstream register trial, and the failed ECX ended the
argument list: an ATL IAtlStringMgr::Allocate call lost both of its
stack arguments. The chosen model is now recorded as the call's
read-register model, so Noelo-Lab#1575's rules (trial active, no list cut-off)
cover it. A call that also holds the object in EAX is Delphi's
register convention (mov eax,ecx; mov edx,[eax]; call [edx+8]) and
keeps the default; it had lost its Int64 stack argument.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
The fork branch's merge of origin/main (Noelo-Lab#1575) re-resolved the same
calleereginputs files; this head already contains both of its parents and
supersedes that resolution, so the tree is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…he local head

Conflicts: the calleereginputs row in phases.toml keeps main's row (values
off/on/custom, the custom text) with the virtual-dispatch sentence added
before "Inert on every other target"; docs/options.md and phase_catalog.json
take main's side and are regenerated after the build; baseline-stages.json is
synthesized from both sides (main 4322 + 8 virtual-call assertions).
kuna_calleereginputs.rs, spec 04 and the stage XML merged cleanly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
docs/options.md and phase_catalog.json regenerated from the merged build;
counters --check reports no drift.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
custom extends on: a whole-binary run of vcall_pe_i386.exe prints the same
functions under custom as under on (the virtual member gets the object in
ECX as this; the C table and COM calls keep the default), and off gives no
receiver. Spec 04 says the rule holds under both values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Conflicts: kuna_calleepurge.rs takes Noelo-Lab#1581's caller_cleanup doc and body
with this branch's pub(crate) (the virtual-call cleanup check reuses it);
the fixtures README keeps both new sections, main's first; baseline-stages
is synthesized from both sides (main 4327 + 8 virtual-call assertions).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
# Conflicts:
#	decompiler/crates/kuna-analysis/tests/fixtures/README.md
#	decompiler/crates/kuna-decomp/phases.toml
#	decompiler/crates/kuna-decomp/tests/fixtures/phase_catalog.json
#	docs/baseline-stages.json
#	docs/options.md
…ious call

The vtable's object was followed back through copies past intervening
calls, so `mov esi,ecx; call f; mov eax,[esi]; push esi; call [eax+k]`
(COM calls through ESI, and a C table through ESI) took ECX as the
receiver although the earlier call clobbered it; the COM push check also
compared two scans of different reach and missed the pushed interface.
The object, the last push and EAX are now compared as values over the run
of ops since the previous call, carried forward through copies. The
vcall fixture gains comesi and crosscall (stage Noelo-Lab#26, Noelo-Lab#27, the custom test).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…load

Comparing values lets `mov ecx,esi; mov eax,[esi]; call [eax+k]` pass the
object in ECX, since ECX holds it at the call; the vcall fixture gains
ecxcopy for it (stage Noelo-Lab#28, Noelo-Lab#29, the custom test) and spec 04 says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…t at [esp+4]

GCC before 4.7 (MinGW) passes a member function's `this` on the stack as a
__cdecl argument, second behind the hidden pointer of a returned class
(`mov ecx,[ebp+0xc]; mov eax,[ecx]; mov [esp+4],ecx; mov [esp],edx;
call [eax+k]`), so ECX held the object only on the way and the call printed
it twice (`(a1,a0,a1,a2,a3,0,a6)` for `(a0,a1,a2,a3,0,a6)`, 36 calls in two
MinGW images). A store of the object at [esp+4], the stack pointer unchanged
up to the call, now keeps the default like the COM interface push. The vcall
fixture gains gccsret (stage Noelo-Lab#30, the custom test).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
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 MSVC: a virtual call never passes its receiver, even with calleereginputs on

2 participants