Repository navigation
loader: follow forwarded exports and validate delay-import descriptors - #122
Conversation
|
The two red jobs are the repo-wide numpy failure, not this change. On |
parse_exports stored base + RVA for every export, but an export whose RVA lands inside the export
directory is a forwarder string ("KERNEL32.Sleep"), not code, so an import of one received a pointer
into the string. Forwarders are now recorded separately and followed when an import asks for one:
bundled modules first, then LoadLibraryEx/GetProcAddress for system DLLs, with a depth cap so two
modules re-exporting each other stop instead of recursing. An unresolvable forwarder records the
import as unimplemented.
The delay-import walk also assumed every descriptor is RVA-based and has a name table. A descriptor
without dlattrRva stores 32-bit virtual addresses, which cannot address an x64 image base, so it is
rejected with a message instead of being misread. A missing address table is rejected, and a missing
name table now reads its entries back through the address table.
d6f6e69 to
ff573ee
Compare
|
Delay-import follow-up from the review, for the record. I scanned the installed x64
So rejecting a descriptor without |
What and why
parse_exportsstoredbase + RVAfor every export. An export whose RVA lands inside the export directory is not code: it is a forwarder string such asKERNEL32.Sleep, and an import of one was given a pointer into that string. The function ended with a comment saying forwarders were not followed yet. This follows them.Resolution order per forwarder: a bundled module in the game folder, named with or without
.dllin the string, thenLoadLibraryExwithLOAD_LIBRARY_SEARCH_SYSTEM32andGetProcAddress, which follows host forwarders itself. A chain deeper than eight hops is treated as a loop and stops. A forwarder that resolves to nothing records the import as unimplemented and binds the usual failure thunk, so--dry-runstill reports it.The delay-import walk assumed two things no image guarantees. A descriptor without
dlattrRvastores 32-bit virtual addresses, which cannot address an x64 image base, so it is now rejected with a message instead of being read as RVAs. A descriptor with a zeroImportAddressTableRVAis rejected instead of writing through the image base. A zeroImportNameTableRVAis legal and now reads its entries back through the address table.This touches
pe_loader.cpp,pe_loader.handloader_test.cpp, which open PR #93 also edits for static TLS and unwind. Expect a conflict there if both land, in regions away from this change. The branch is rebased onto main at 4c75ce5, so the merged #95 TLS and DllMain tests are present and still pass.Tested
cmake --build D:\Leonida-work\cbuild2 --config Release --clean-first, MSVC: builds clean.loader_test: 37 checks, 0 failed. Six of them are from the merged TLS/DllMain work; five are new here: a forwarder that binds through tokernel32!GetCurrentProcessId, a forwarder to a module that isn't there binding as unimplemented, two modules forwarding to each other stopping, a descriptor without the RVA attribute being rejected, and a delay import with no name table binding through its address table.ctest -C Release: 7 of 7 pass.Checklist
docs/design.md.