Repository navigation
[AUTOMATED] Keep calls after a declared __stdcall import from losing their arguments - #1663
Conversation
…tion, not an early INT_ADD [AUTOMATED] An x86-32 `call [slot]` that kuna_slotargs declares states its __stdcall pop. ActionExtraPopSetup wrote that pop into the IR as `INT_ADD(sp_call, #pop)` before the stack solve. In a function whose other pops the solver guesses, that joined the stack pointer after the call to the one before it, and two passes read the joined form wrongly: the next call's push-run guess walked the slots the declared call had popped as its own pushes (VariantClear's argument credited to lstrlenA), and term collection rewrote a pointer difference after GetModuleFileNameA as minus the stack pointer at its last push, which the local-alias boundary took as an escaped address, refusing every later outgoing argument. Such a pop now takes the INDIRECT the other calls take while the prototype keeps it, so StackSolver::build gives the call its exact equation and the solve writes it into the IR. A pop the solve cannot place is written as the INT_ADD afterwards. The cleanup and fold checks of the push-run guess read past a later call by its stated pop. Direct calls and functions with nothing to guess keep the INT_ADD. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…tion-form # Conflicts: # decompiler/crates/kuna-base/src/xml.rs # docs/baseline-stages.json
…tion-form # Conflicts: # decompiler/crates/kuna-base/src/xml.rs # docs/baseline-stages.json
…tion-form # Conflicts: # decompiler/crates/kuna-base/src/xml.rs # docs/baseline-stages.json
…rough its popped slots With a declared pop as an exact INT_ADD, the push-run guess of the next call read whichever stack reference sat at a slot's offset, often the declared call's own popped argument slots. With the pop deferred to the solver, three readings take the place of that coincidence, all inside the frame a call with a stated pop left: - a join of stack pointers whose inputs read back (through constant adjustments and stated pops) to one place is that place, and a joined slot stored on every path with one argument push is a push (FormatMessageW after `call [GetLastError]; push eax` / `push edx`); the folded test reads through such joins too (two `__cdecl` frees cleaned by one `pop ecx; pop ecx`); - a pushed entry value of EAX/ECX/EDX in that frame is an argument, not a saved register (`mov edi,edx; call [CreateFileW]; ... push edi`); - the slot at the stack pointer the declared call left, written before anything is pushed below it, is a local and ends the run (`call [GetModuleFileNameA]; mov [esp],0x44; push` x10). The fixture gains frame_local, keep_edx and join_push; the stage test checks each. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Records the five declaredpop stage assertions added for frame_local, keep_edx and join_push (#7-#11) in docs/baseline-stages.json; every other entry is the merge of main's and this branch's baselines. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
|
[AUTOMATED] Pushed 767f3ce (+ a merge of main and a stage-baseline commit). With the declared pop deferred, nine functions on the 258-PE i386 set printed worse than main, e.g. Spongebob.exe
All nine print main's text again; on the same set call sites stay +15/-0, and 24 functions now guess the callee's real pop. The fixture gains |
Two of the push-run readings for the frame a declared call leaves misread GCC/MinGW code, found on held-out builds: - The `mov [esp],x` local test took a push for a mov when the push landed on the stack pointer the declared call left after a raise (GCC's `call [Sleep]; add esp,12; push; push; push; push; call [f]` around a padded call): the run stopped at the third push and f was guessed to pop 12 bytes too few. The simplifier has already removed such a push's stack-pointer write, so the store's instruction bytes say whether it is a push; only a mov ends the run. - The entry-value test counted ECX's entry value written with MinGW's fixed frame `mov [esp],ebx` as an argument push, so a __cdecl callee was guessed to pop it and the function gained a phantom parameter. Only a pushed entry value counts now. The fixture gains land_push and acc_entry; stage asserts #12 and #13 fail without this change. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
|
[AUTOMATED] Pushed 15b916e: two of the push-run readings for a declared call's frame misread GCC/MinGW code.
The fixture gains |
[AUTOMATED] Preserve the exact decoded call site and executable-section exclusion without adding a discovered procedure.
…ead the form A declared import pop goes to the stack solver as an equation only in a function whose other guessed pops are all direct calls into the image's own code, and whose direct calls' stated pops are the ones their callees' RETs prove. Elsewhere it stays the INT_ADD it was before. The push-run guess of an import or of a call through a pointer reads the slots in front of the call. With the INT_ADD folded in it read whichever reference sat at a slot's offset; with the INDIRECT it reads the call's own slots. On code nobody tuned this on, each reading is right where the other is wrong (GCC alignment pushes, a __cdecl import's cleanup merged into the next call's reservation, arguments stored in the block before the call, a pushed copy of EDX's entry value). A direct call's stated pop under the unknown-pop model is computed as if the callee popped its declared arguments, which a GCC __cdecl or regparm callee does not; that false equation leaves a merge whose paths disagree, and the form changes which path the solve takes. Neither is a change of form only, so both keep the INT_ADD. With no guessed import left in a deferring function, the push-run readings added for the declared call's frame have nothing to read and are removed (kuna_calleepop.rs and kuna_calleepopslot.rs are main's again). The fixed-frame guess measures a call's slots from the stack pointer a stated call left when nothing else is in between, as the INT_ADD form measured them from the one before that call. The fixture keeps only the launcher shape; the stage test keeps its three assertions. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
|
[AUTOMATED] Pushed 941dd6f (narrowing commit d6269db plus merges of main). On 1,274 i386 PEs outside the original corpus the deferral cost about 52 real arguments, from two mechanisms: the push-run guess of an import reads different slots in the two forms (each reading right where the other is wrong), and wine's DWARF-declared direct calls carry false stated pops whose error the solve places by an order the form changes. The deferral now happens only where neither applies: every pop the function guesses is a direct call into its own code, and every stated direct-call pop matches the callee's RET. The push-run readings added for the declared call's frame are unreachable there and are removed. Against main: 258 PEs +10/−0 call sites (cli-32/gui), 1,274 other PEs no call site changes (one function moves an assignment past an early return), 200 PEs built from C no guessed pop changes (957 scored), off-target byte-identical. lstrlenA ×3 and StrStrA ×2 are no longer recovered. The description above predates this narrowing. |
…traps The datatest harness built every test file's architecture from scratch: it re-decoded the same .sla and re-parsed every .ldefs for each file, which was ~60% of `make test` / `make test-stages` CPU. engine::reuse_specs() (opt-in, called by decomp_test_dbg) makes a process scan each set of on-disk spec roots once, and keep a decoded template of each .sla a thread decodes twice (kuna_slacache, keyed by file contents). Later translators are SleighBase::clone_decoded copies: a fresh space set rebuilt from the .sla space records, every space reference remapped by index, xrefs and context variables rebuilt as a decode does. Single-binary CLI runs never enable it and take the unchanged decode path. Harness output is byte-identical on both corpora. decomp_test_dbg, A/B: datatests 3.3 s -> 1.25 s CPU, stages ~50-58 s -> ~23-28 s CPU; peak RSS 96 -> 232 MB and ~400 -> ~620 MB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… PowerPC PLT entry
…her Annex K bounds-checked calls
…stated return register
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
On x86-32 Windows, a call made after a declared
__stdcallimport can lose its stack arguments. This happens in functions where the stack solver still has to guess other calls' pops. setuptools 59.6.0 shipssetuptools/cli-32.exe(sha25675f12ea2…c346):The function calls
GetModuleFileNameA(NULL, path, 0x100), measurespath, then doespush 0; push edx; call sub_40c991. With this change:Fix
INT_ADD(sp, #pop)before the stack solve. That joined the stack pointer after the call to the one before it, and the solved pops came out the same either way. But the simplifier then rewroteend - (path + 1)in terms of the stack pointer at the import's last push. The local-alias boundary took that slot as an escaped address and refused every later outgoing argument. The next call's push-run guess also read the import's popped slot as its own push (push edi; call [VariantClear]; push esi; call [lstrlenA]gave lstrlenA no argument).kuna_declaredpop) now takes an INDIRECT like the other calls and keeps the pop on its prototype.StackSolver::buildreads it as an exact equation, and the solve writes it into the IR. If the solve cannot place the stack pointer (a runtime-sized frame, or a stack pointer an SEH handler loads), the pop is written as the INT_ADD afterwards.Tests
tests/stages/kuna-declaredpop.xmldecompiles a new nasm fixture,declaredpop_pe_i386.exe(recipe in the fixtures README). It pinssub_401080(Filename,0),xlen(a1)andxfill(v1,&Stackfffffff0). Without the change these printsub_401080()andxfill(xlen(),&Stackffffffec).🤖 Generated with Claude Code
https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h