pe: resolve forwarded exports through the host resolver #205

Merged
raulmoracode merged 2 commits from upstream-pr/208 into main 2026-11-22 07:34:39 +00:00
raulmoracode commented 2026-11-21 18:23:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by raulmoracode on 2026-11-21T18:23:45Z.


Change

pe_map_export returned null for every forwarded export: the address table entry points back into the export directory, and the lookup stopped there. Windows resolves the same entry through GetProcAddress by loading the target module.

This adds pe_map_export_resolved(mapped, name, resolve). It shares the export walk with pe_map_export and, when the entry is a forwarder, parses Module.Symbol or Module.#ordinal and calls the host resolver that pe_map_image already receives. pe_map_export is unchanged and still returns null for a forwarder.

The export walk moved into one find_export helper, so both entry points apply the same live page-protection checks added in #167.

Fixes #206

Verification

Commit 0250ec3 on Windows 10 22H2 build 19045.6466, VS Build Tools 2022 17.14, MSVC 14.44.35207, Windows SDK 10.0.26100, CMake 4.4.4, Python 3.12.10.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^cpu_native_forwarder$' -V

Result:

cpu_forwarder.dll: forwarded mix_args matches GetProcAddress at 0x7ffca0d611e5; local_value RVA matches; an absent name and a refusing resolver return null
1/1 Test #79: cpu_native_forwarder .............   Passed    0.13 sec

Full build: 228/228 targets. The CPU group passes 28/28.

Evidence and follow-up

The fixture is tests/cpu/forwarder.asm with forwarder.def:

EXPORTS
    mix_args=cpu_import_provider.mix_args
    local_value

The linker only accepts that forwarder when the target module's import library is linked as well, even though the resulting DLL has no import descriptor (dumpbin /imports is empty), so pe_map_image still maps it without a resolver.

Controls in the test: pe_map_export must return null for the forwarder, an absent name must return null, and a resolver that returns null must return null. The local export is the positive control that the shared walk still returns ordinary addresses.

Not covered: the Module.#ordinal form is parsed but has no fixture, and a forwarder whose target module fails to load returns null without a diagnostic. Both are candidates for a follow-up.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532700568 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/208). Originally posted by [raulmoracode](https://github.com/raulmoracode) on 2026-11-21T18:23:45Z. --- ## Change `pe_map_export` returned null for every forwarded export: the address table entry points back into the export directory, and the lookup stopped there. Windows resolves the same entry through `GetProcAddress` by loading the target module. This adds `pe_map_export_resolved(mapped, name, resolve)`. It shares the export walk with `pe_map_export` and, when the entry is a forwarder, parses `Module.Symbol` or `Module.#ordinal` and calls the host resolver that `pe_map_image` already receives. `pe_map_export` is unchanged and still returns null for a forwarder. The export walk moved into one `find_export` helper, so both entry points apply the same live page-protection checks added in #167. Fixes #206 ## Verification Commit `0250ec3` on Windows 10 22H2 build 19045.6466, VS Build Tools 2022 17.14, MSVC 14.44.35207, Windows SDK 10.0.26100, CMake 4.4.4, Python 3.12.10. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R '^cpu_native_forwarder$' -V ``` Result: ```text cpu_forwarder.dll: forwarded mix_args matches GetProcAddress at 0x7ffca0d611e5; local_value RVA matches; an absent name and a refusing resolver return null 1/1 Test #79: cpu_native_forwarder ............. Passed 0.13 sec ``` Full build: 228/228 targets. The CPU group passes 28/28. ## Evidence and follow-up The fixture is `tests/cpu/forwarder.asm` with `forwarder.def`: ```text EXPORTS mix_args=cpu_import_provider.mix_args local_value ``` The linker only accepts that forwarder when the target module's import library is linked as well, even though the resulting DLL has no import descriptor (`dumpbin /imports` is empty), so `pe_map_image` still maps it without a resolver. Controls in the test: `pe_map_export` must return null for the forwarder, an absent name must return null, and a resolver that returns null must return null. The local export is the positive control that the shared walk still returns ordinary addresses. Not covered: the `Module.#ordinal` form is parsed but has no fixture, and a forwarder whose target module fails to load returns null without a diagnostic. Both are candidates for a follow-up. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. _AI-assisted._
upstream-sync closed this pull request 2026-11-24 06:41:49 +00:00
R0Y00 commented 2026-11-24 06:47:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:04:48Z.


The per-call resolver API is approved for #206. The caller keeps the mapping live throughout lookup. Both entry points return the same local address without invoking the resolver. The existing entry point continues to return null on forwarders. The new entry point synchronously uses the pe_map_image callback ABI, preserves the module spelling, passes (module, symbol, 0) or (module, nullptr, ordinal), and returns the callback result unchanged. Loading the target and following further forwarders belong to the host. The mapper does not cache the callback.

At 0250ec35, the Windows named-forwarder comparison, local RVA, absent name and refusing-resolver checks are already present. Please extend cpu_native_forwarder to check the exact ordinal callback arguments and a null resolver. In the parser, require ASCII decimal digits in the range 1–65535 after #. strtoul accepts a leading plus or whitespace, so cover malformed input such as #+1 and verify it returns null without calling the resolver. Bound the readable forwarder string, including its terminator, to the export directory. Include a case whose terminator falls just outside that directory. Please post the focused Windows result on the updated SHA.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067744597 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/208#issuecomment-7067744597). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T19:04:48Z. --- The per-call resolver API is approved for #206. The caller keeps the mapping live throughout lookup. Both entry points return the same local address without invoking the resolver. The existing entry point continues to return null on forwarders. The new entry point synchronously uses the pe_map_image callback ABI, preserves the module spelling, passes (module, symbol, 0) or (module, nullptr, ordinal), and returns the callback result unchanged. Loading the target and following further forwarders belong to the host. The mapper does not cache the callback. At `0250ec35`, the Windows named-forwarder comparison, local RVA, absent name and refusing-resolver checks are already present. Please extend cpu_native_forwarder to check the exact ordinal callback arguments and a null resolver. In the parser, require ASCII decimal digits in the range 1–65535 after #. strtoul accepts a leading plus or whitespace, so cover malformed input such as #+1 and verify it returns null without calling the resolver. Bound the readable forwarder string, including its terminator, to the export directory. Include a case whose terminator falls just outside that directory. Please post the focused Windows result on the updated SHA.
RonLogic commented 2026-11-24 06:47:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-21T19:05:52Z.


I tested the ordinal-only forwarding path on Windows x64 at 0250ec3. Both pe_map_export_resolved and Windows GetProcAddress resolved the forwarder to cpu_ordinal_provider.#77 at the same address. The callback received a null name and ordinal 77. The named forwarder and local export also matched Windows, and the refusing resolver returned null.

MSVC LINK rejected the direct ordinal definition in my fixture. I shortened an existing forwarder string in a private copy of the source-built DLL and used that same copy for both lookups.

cpu_native_forwarder, cpu_aot_ordinal_import and cpu_aot_import_call all passed. I have a source-only test patch ready if you'd like to include this case.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067758328 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/208#issuecomment-7067758328). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-21T19:05:52Z. --- I tested the ordinal-only forwarding path on Windows x64 at `0250ec3`. Both `pe_map_export_resolved` and Windows `GetProcAddress` resolved the forwarder to `cpu_ordinal_provider.#77` at the same address. The callback received a null name and ordinal 77. The named forwarder and local export also matched Windows, and the refusing resolver returned null. MSVC LINK rejected the direct ordinal definition in my fixture. I shortened an existing forwarder string in a private copy of the source-built DLL and used that same copy for both lookups. `cpu_native_forwarder`, `cpu_aot_ordinal_import` and `cpu_aot_import_call` all passed. I have a source-only test patch ready if you'd like to include this case.
R0Y00 commented 2026-11-24 06:48:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T03:44:20Z.


@RonLogic, please share the source-only ordinal control you tested here, or link its commit, so the PR author can reuse it. @raulmoracode, that independent Windows run covers the valid ordinal callback. Please integrate it if suitable and keep the malformed ordinal and export-directory terminator controls from the existing review separate; those exercise different rejection paths.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7073744577 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/208#issuecomment-7073744577). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T03:44:20Z. --- @RonLogic, please share the source-only ordinal control you tested here, or link its commit, so the PR author can reuse it. @raulmoracode, that independent Windows run covers the valid ordinal callback. Please integrate it if suitable and keep the malformed ordinal and export-directory terminator controls from the existing review separate; those exercise different rejection paths.
RonLogic commented 2026-11-24 06:48:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-22T11:19:15Z.


Thanks for asking for the source. I checked the merged cpu_native_forwarder test. It already covers the exact ordinal callback arguments, a null resolver, malformed ordinal strings, and a terminator outside the export directory. The remaining distinction is comparison with Windows for a real ordinal-only export. I adapted my earlier source-only control to current main and kept the existing cases intact.

On Windows x64, cpu_native_forwarder passed with the added comparison. Windows GetProcAddress and pe_map_export_resolved returned the same address for cpu_ordinal_provider.#77, and the resolver received (module, nullptr, 77). The optional test-only change is RonLogic/Xbox2Windows@768be85.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7078364355 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/208#issuecomment-7078364355). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-22T11:19:15Z. --- Thanks for asking for the source. I checked the merged `cpu_native_forwarder` test. It already covers the exact ordinal callback arguments, a null resolver, malformed ordinal strings, and a terminator outside the export directory. The remaining distinction is comparison with Windows for a real ordinal-only export. I adapted my earlier source-only control to current main and kept the existing cases intact. On Windows x64, `cpu_native_forwarder` passed with the added comparison. Windows `GetProcAddress` and `pe_map_export_resolved` returned the same address for `cpu_ordinal_provider.#77`, and the resolver received `(module, nullptr, 77)`. The optional test-only change is [RonLogic/Xbox2Windows@768be85](https://github.com/RonLogic/Xbox2Windows/commit/768be8548eebb5505f5ef4d493c3b5f2a997eaa4).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!205
No description provided.