pe_map cannot resolve a forwarded export #203

Closed
opened 2026-11-21 18:23:36 +00:00 by raulmoracode · 1 comment
raulmoracode commented 2026-11-21 18:23:36 +00:00 (Migrated from github.com)
Contributor

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


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532699029 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/206). Originally posted by [raulmoracode](https://github.com/raulmoracode) on 2026-11-21T18:23:36Z. --- ## 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._
R0Y00 commented 2026-11-24 06:47:52 +00:00 (Migrated from github.com)
Author
Contributor

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


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067749612 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/206#issuecomment-7067749612). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T19:05:12Z. --- 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://github.com/R0Y00/Xbox2Windows/pull/208#issuecomment-7067744597)
Sign in to join this conversation.
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#203
No description provided.