pe_map cannot resolve a forwarded export #206

Closed
opened 2026-11-26 21:34:28 +00:00 by github-bot · 1 comment
Owner

@⁠raulmoracode on GitHub · 2026-11-21 18:23 UTC · original

Problem

pe_map_export returns null for a forwarded export. The export address table entry points back into the export directory, where the string Module.Symbol lives, and the lookup treats that as "not code here".

Windows returns the target module's address from GetProcAddress in the same situation: it parses the forwarder string, loads the module and looks the symbol up. Forwarded exports are common in system DLLs (kernel32 forwards to kernelbase, for example), so a mapped image that only forwards an export is currently unusable through the mapper's own lookup.

The Python inventory already follows forwarders (tools/pe_inventory.py, bundled_export_forwarders). The C++ mapper does not.

Proposed change

Add pe_map_export_resolved(mapped, name, resolve), which behaves like pe_map_export except that a forwarder is resolved through the same host resolver that pe_map_image already takes:

  • Module.Symbol → resolve("Module", "Symbol", 0);
  • Module.#ordinal → resolve("Module", nullptr, ordinal).

pe_map_export keeps its current contract and still returns null for a forwarder, so existing callers see no change.

Verification path

A source-built DLL (cpu_forwarder) exports local_value and forwards mix_args to cpu_import_provider.mix_args. The test compares both loaders:

  • the forwarded address must equal GetProcAddress on a LoadLibraryExW copy;
  • local_value must resolve to the same RVA under pe_map and Windows;
  • an absent name and a resolver that returns null must give null;
  • pe_map_export must still return null for the forwarder.

The Module.#ordinal form is implemented but has no fixture yet.

Required environment

x64 Windows, MSVC with MASM, CMake/Ninja, Python 3.11 or newer with pefile. No game files.

AI-assisted.

**@⁠raulmoracode** on GitHub · 2026-11-21 18:23 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/206) ## Problem `pe_map_export` returns null for a forwarded export. The export address table entry points back into the export directory, where the string `Module.Symbol` lives, and the lookup treats that as "not code here". Windows returns the target module's address from `GetProcAddress` in the same situation: it parses the forwarder string, loads the module and looks the symbol up. Forwarded exports are common in system DLLs (`kernel32` forwards to `kernelbase`, for example), so a mapped image that only forwards an export is currently unusable through the mapper's own lookup. The Python inventory already follows forwarders (`tools/pe_inventory.py`, `bundled_export_forwarders`). The C++ mapper does not. ## Proposed change Add `pe_map_export_resolved(mapped, name, resolve)`, which behaves like `pe_map_export` except that a forwarder is resolved through the same host resolver that `pe_map_image` already takes: - `Module.Symbol` → `resolve("Module", "Symbol", 0)`; - `Module.#ordinal` → `resolve("Module", nullptr, ordinal)`. `pe_map_export` keeps its current contract and still returns null for a forwarder, so existing callers see no change. ## Verification path A source-built DLL (`cpu_forwarder`) exports `local_value` and forwards `mix_args` to `cpu_import_provider.mix_args`. The test compares both loaders: - the forwarded address must equal `GetProcAddress` on a `LoadLibraryExW` copy; - `local_value` must resolve to the same RVA under `pe_map` and Windows; - an absent name and a resolver that returns null must give null; - `pe_map_export` must still return null for the forwarder. The `Module.#ordinal` form is implemented but has no fixture yet. ## Required environment x64 Windows, MSVC with MASM, CMake/Ninja, Python 3.11 or newer with `pefile`. No game files. _AI-assisted._
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:34:28 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 19:05 UTC · original

The per-call host resolver is approved. #208 carries the implementation; the remaining Windows checks cover ordinal callback arguments, a null resolver and malformed or out-of-directory forwarders. This issue tracks the fix through merge. Contract and review feedback

**@⁠R0Y00** on GitHub · 2026-11-21 19:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/206#issuecomment-7067749612) The per-call host resolver is approved. #208 carries the implementation; the remaining Windows checks cover ordinal callback arguments, a null resolver and malformed or out-of-directory forwarders. This issue tracks the fix through merge. [Contract and review feedback](https://git.gtahub.st/github/R0Y00--Xbox2Windows/pulls/208)
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/R0Y00--Xbox2Windows#206
No description provided.