Repository navigation
[AUTOMATED] feat(analysis): resource-loader-c-retains — give a PE's Win32 imports their signatures (win32sigs, DIV-141) - #520
Merged
Conversation
…in32 imports their signatures (win32sigs, DIV-141) kuna's whole prototype knowledge base was libc, so on a PE every LoadLibraryExW / WriteFile / VirtualQuery call reached ActionDefaultParams with an empty prototype and call-site trial scoring was the only thing between the pushes and the call. Where that scoring loses, the arguments are dropped and the outgoing slots `callsitestackargs` already mapped survive as stack-local debris. `win32sigs` supplies the Windows half of the `.gdt` stand-in `libproto` already is: ~130 WINAPI exports ranked by an import histogram over the 54 PE images of the RE arena corpus, plus the resource/loader family the need was filed against. Signatures are reduced to the same width-stable vocabulary the libc tables use, and a slot with no honest spelling is rejected rather than approximated. The prototypes are parked by ENTRY ADDRESS. A PE import is two FunctionSymbols -- the size-0 IAT slot and the `FF 25` thunk veneer a direct `call` targets -- the global by-name query answers with the slot, and ActionDefaultParams asks about the thunk, so the by-name park is a silent no-op on exactly the calls that need it. A new AnalysisOutput::prototypes_at stream carries the address. Sweep over 22 PE images / 3,029 functions: 168 changed, 0 added, 0 removed, every changed function containing a call to a table name; 35 call sites gain arguments to the documented arity and 16 shed invented ones. Speed -16.9%. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…g the analysis-tier gates with no codegen live reader `option_values_live_value_present_for_58_suppressed_for_101` enumerates the options whose live state is read console-side rather than through the codegen `live_value`. Like `libproto`/`libcsigs`/`declaredlibcproto`, `win32sigs` is an analysis-pass gate and belongs in that list. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…es a UINT, so its peimportcall assertion does too `ghdec-peimportcall` PEIMPORTCALL #5 pinned `ExitProcess\(\); // no-return` on the `bail` function of `pe_noreturn_import.exe`. That empty-parens spelling was frozen in by DIV-57 (#254), when kuna carried no Windows API prototype at all and the call's one argument was simply lost. `win32sigs` (DIV-141) supplies the import's `void __stdcall ExitProcess(UINT)`, and the fixture's source is `void bail(int code) { ExitProcess(code); }`, so the site now renders `ExitProcess(a0)` and `bail` recovers its parameter. The assertion is the stale side of that; what the test exists to protect -- the `FF 25`/IAT-slot call binding to its import name and both `// no-return` flow effects surviving -- is asserted by the other four stringmatches and unchanged. The assertion name is untouched, so `docs/baseline-stages.json` needs no re-record; `docs/baseline.json` is byte-identical to origin/main. make test 675/675 PARITY OK, make test-stages 704/704 PARITY OK, make test-cli 99/99, make check-spec OK, kuna catalog --check OK. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
kuna carries libc prototypes and not one Windows API signature, so on a PE every
LoadLibraryExW/WriteFile/VirtualQuerycall has to have its argumentsguessed from the call site — and when that guess loses, the values are left
behind as stack locals.
LoadLibraryExWtakes three arguments. Two of them have been handed to theunrelated
sub_401080above it. On the reported binary the same shape costs 47declarations where 8 would do, and the calls print
LoadLibraryExW(),EnumResourceTypesW()andFreeLibrary()with empty argument lists. Thefixture is generated by
win32sigs_pe_i386.pybeside it.The fix
win32sigs, default on), the Windows half ofthe
.gdtstand-inlibprotoalready is. ~130WINAPIexports, ranked by animport histogram over 54 PE images rather than picked by hand, plus the
resource/loader family the report was about.
FunctionSymbols —the size-0 IAT slot and the
FF 25thunk a directcalltargets — the globalby-name query answers with the slot, and
ActionDefaultParamsasks about thethunk.
--assert 'prototype LoadLibraryExW …'is byte-identical to no assertat all on the fixture; the same prototype at the thunk address repairs the
call. A new
AnalysisOutput::prototypes_atstream carries the address.__stdcallwith an unknownextrapop, so a locked arity is also the callee'sstack pop, and a
__cdeclname here would get the wrong cleanup.approximated, which is why
SetFilePointerExandRtlVirtualUnwindare absent.The tests
tests/cli/resource-loader-c-retains.jsonruns the command above against thevendored fixture and fails without the change. Unit tests pin the resource-family
arities, the CRT exclusion, and that the resolver names both the slot and the
thunk. Sweep over 22 PE images / 3,029 functions: 168 changed, 0 added, 0 removed,
and every changed function contains a call to a table name — 35 call sites gain
arguments to the documented arity, 16 shed invented ones
(
GetCurrentProcess(CONCAT44(dat_c,argc))→GetCurrentProcess()). Parity is675/675 and 704/704, and
sub_401ba0decompiles 16.9% faster.One kuna-owned stage assertion moved with the change.
ghdec-peimportcallpinnedExitProcess(); // no-return, an empty-parens spelling from before kuna had anyWin32 prototype.
ExitProcesstakes oneUINT, and that fixture'sbail(int code)passes it, soExitProcess(a0)is the correct rendering and theold regex was pinning the argument being lost. What the test exists to protect,
the IAT-slot call binding to its import and keeping its no-return flow effect, is
unchanged; the other four assertions in the file are untouched.
🤖 Generated with Claude Code