Bind delay imports through the resolver in pe_map #126
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/127"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by dcastell1 on 2026-11-21T16:40:29Z.
Change
pe_map_imagerejected every image with a delay-import directory. It now resolves eachIMAGE_DELAYLOAD_DESCRIPTORentry through the same host resolver as ordinary imports and writes the bound address into the descriptor's IAT.The PE loader does not resolve delay imports; the image's own helper does, with
LoadLibraryandGetProcAddress.pe_maphas neither and must bind through the host resolver, so it binds at map time. This is a deliberate difference from Windows: an absent provider fails the map withMAP_UNRESOLVED_IMPORT, where Windows maps and fails on the first call. The test documents it. Descriptors must setdlattrRva(bit 0); old-style virtual-address descriptors are rejected as unsupported.The delay directory is validated before use: address and size in the image, at least one descriptor, DLL name inside the image, name table and IAT present, each thunk and IAT slot inside the image. A normal import IAT write may not overlap the delay directory, because the delay walk happens after the normal bindings.
Test
New
cpu_native_delaywithdelay_route, which importsdelayed_valueby name anddelayed_ordinalby ordinal 2 fromcpu_delay_provider.dllusing/DELAYLOAD. It compares the mapped calls with the Windows delay helper, checks both IAT slots before the calls, binds an altered provider to change both results, and maps without the provider to check the rejection. Damaged copies cleardlattrRva, move the DLL name outside the image, zero the name table, move the IAT outside the image, or shrink the directory to zero or below one descriptor; all are rejected before the provider is requested.On Windows 11 build 26300.9974, VS 2022 17.14 (MSVC 14.44), Python 3.13:
ctest --preset dev --no-tests=error -R '^(cpu_native_map|cpu_native_seh|cpu_native_tls|cpu_native_delay)$' -V4/4 pass.
Refs #46.
Note for #103: this removes the
delay importsrejection line that #103 also edits. A zero-size delay directory is rejected here asMAP_FORMATwith "delay import directory smaller than one descriptor", which is more specific than the unsupported status. The TLS zero-size rule in #103 is independent.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T17:16:40Z.
Please sync with main and reconcile the delay-directory handling from #103. Preserve its empty-directory and malformed-directory controls and add the new binding cases alongside them.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T17:23:22Z.
Thanks for incorporating the #103 path in 56184a1. GitHub still reports a merge conflict against current main. Please reconcile with the merged ordinary import walk from #85 and preserve its walked-descriptor IAT overlap protection, then run the normal and delay-import tests on the same head.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T17:26:55Z.
The latest 2dc4694 does preserve both walked descriptor ranges. One remaining validation issue in the new delay path: a named thunk is masked with
0x7fffffffbefore the RVA bounds check, so an out-of-range value can alias a valid low RVA. Please reject invalid high bits before narrowing and cover the rejection with a source-built control.Imported from R0Y00/Xbox2Windows. Originally posted by dcastell1 on 2026-11-21T17:32:15Z.
Handled in ee269b8:
name_rvakeeps all 64 bits untilname_rva >> 31rejects bits 31..62, thenimage.at<WORD>bounds-checks the low RVA. The new control sets bit 40 in the named thunk of the source-built delay fixture and expectsMAP_FORMAT"delay import name for cpu_delay_provider.dll outside image".cpu_native_map,cpu_native_seh,cpu_native_tlsandcpu_native_delaypass on the same head (Windows 11 build 26300.9974, MSVC 14.44).