pe: validate forwarded export ordinals in pe_inventory #561

Merged
Neoplayer merged 1 commit from upstream-pr/567 into main 2026-11-22 14:29:34 +00:00
Neoplayer commented 2026-11-22 12:47:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Neoplayer on 2026-11-22T12:47:32Z.


Change

Validate forwarded export ordinals in tools/pe_inventory.py (resolve_desktop) via _parse_forwarded_ordinal(), matching the mapper contract in tools/pe_map.cpp:

  • Preserve the existing dot-splitting rule (target.partition(".") + dll. stripping) and keep the original step["forwarder"] text in the chain before validation so unresolved inputs stay visible in the report.
  • Parse #... forwarder targets as ASCII decimal integers in 1..65535 by accumulating digits with a 65535 upper bound (avoiding Python's int string-length limit exception on arbitrarily long digit strings) and report out-of-range (#0, #65536), empty (#), negative (#-1), non-decimal/non-ASCII, or oversized digit strings as invalid_forwarder.
  • Add boundary (#1, #65535) and negative (#0, #, #65536, #12abc, #-1, non-ASCII \u0661, and 10,000-digit decimal/0 strings) test cases in tests/intake/paths_check.py, asserting that chain[-1]["forwarder"] keeps the original unresolved forwarder string.

Verification

Commit under test: 06e148b on macOS arm64 (Python 3.12.13, pefile==2024.8.26):

  • python3 -B tests/intake/paths_check.py: exit 0.
  • python3 -B tests/dependency_paths_check.py: dependency_paths: the pinned hash reaches the conditional target; a different hash reports unverified_loader_hash and no conditional edge, exit 0.
  • python3 -B tests/form_coverage_check.py: form coverage checks passed.
  • python3 -B tests/docs_links_check.py: Self-test passed. Checked 10 Markdown files and 119 links.
  • python3 -B tests/bidi_controls_check.py: Self-test passed. Checked 549 tracked source, script and build/CI files: no bidirectional controls.
  • git diff --check: exit 0.

Windows MSVC builds and native Windows GetProcAddress comparisons were not run on this macOS host; Windows builds run in GitHub Actions CI.

Evidence and follow-up

All fixtures are source-built in-memory synthetic export tables in tests/intake/paths_check.py. Any future change to dot splitting in pe_inventory.py should follow a source-built Windows GetProcAddress comparison covering explicit .dll, multi-dot module/namespace candidates, and #0.

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. (No docs or build requirements changed.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6542563076 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/567). Originally posted by [Neoplayer](https://github.com/Neoplayer) on 2026-11-22T12:47:32Z. --- ## Change Validate forwarded export ordinals in `tools/pe_inventory.py` (`resolve_desktop`) via `_parse_forwarded_ordinal()`, matching the mapper contract in `tools/pe_map.cpp`: - Preserve the existing dot-splitting rule (`target.partition(".")` + `dll.` stripping) and keep the original `step["forwarder"]` text in the chain before validation so unresolved inputs stay visible in the report. - Parse `#...` forwarder targets as ASCII decimal integers in `1..65535` by accumulating digits with a `65535` upper bound (avoiding Python's `int` string-length limit exception on arbitrarily long digit strings) and report out-of-range (`#0`, `#65536`), empty (`#`), negative (`#-1`), non-decimal/non-ASCII, or oversized digit strings as `invalid_forwarder`. - Add boundary (`#1`, `#65535`) and negative (`#0`, `#`, `#65536`, `#12abc`, `#-1`, non-ASCII `\u0661`, and 10,000-digit decimal/`0` strings) test cases in `tests/intake/paths_check.py`, asserting that `chain[-1]["forwarder"]` keeps the original unresolved forwarder string. ## Verification Commit under test: `06e148b` on macOS arm64 (Python 3.12.13, `pefile==2024.8.26`): - `python3 -B tests/intake/paths_check.py`: exit 0. - `python3 -B tests/dependency_paths_check.py`: `dependency_paths: the pinned hash reaches the conditional target; a different hash reports unverified_loader_hash and no conditional edge`, exit 0. - `python3 -B tests/form_coverage_check.py`: `form coverage checks passed`. - `python3 -B tests/docs_links_check.py`: `Self-test passed. Checked 10 Markdown files and 119 links.` - `python3 -B tests/bidi_controls_check.py`: `Self-test passed. Checked 549 tracked source, script and build/CI files: no bidirectional controls.` - `git diff --check`: exit 0. Windows MSVC builds and native Windows `GetProcAddress` comparisons were not run on this macOS host; Windows builds run in GitHub Actions CI. ## Evidence and follow-up All fixtures are source-built in-memory synthetic export tables in `tests/intake/paths_check.py`. Any future change to dot splitting in `pe_inventory.py` should follow a source-built Windows `GetProcAddress` comparison covering explicit `.dll`, multi-dot module/namespace candidates, and `#0`. ## 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. - [ ] I updated README/docs when a capability or build requirement changed. (No docs or build requirements 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:43:43 +00:00
R0Y00 commented 2026-11-24 06:48:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T13:42:38Z.


The offline inventory can keep the original forwarder text. Please keep the existing dot-splitting rule for this change and validate forwarded ordinals as ASCII decimal 1–65535, matching the mapper contract. Keep unresolved input visible in the report. Please cover #0, overflow, a nondecimal suffix and a very long decimal string. Accumulating with a 65535 limit avoids Python's input-length exception and keeps the rest of the inventory running.

Before changing the separator, please add a source-built Windows GetProcAddress comparison. Use different return markers to distinguish candidates for an explicit .dll, front.Ns.Value, and my.lib.Value; record the marker or error with both candidates present, only one present, and neither present. Please also record what native Windows returns for a #0 forwarder. The ordinal validation can land independently of that investigation.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7080005606 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/567#issuecomment-7080005606). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T13:42:38Z. --- The offline inventory can keep the original forwarder text. Please keep the existing dot-splitting rule for this change and validate forwarded ordinals as ASCII decimal 1–65535, matching the mapper contract. Keep unresolved input visible in the report. Please cover `#0`, overflow, a nondecimal suffix and a very long decimal string. Accumulating with a 65535 limit avoids Python's input-length exception and keeps the rest of the inventory running. Before changing the separator, please add a source-built Windows `GetProcAddress` comparison. Use different return markers to distinguish candidates for an explicit `.dll`, `front.Ns.Value`, and `my.lib.Value`; record the marker or error with both candidates present, only one present, and neither present. Please also record what native Windows returns for a `#0` forwarder. The ordinal validation can land independently of that investigation.
Neoplayer commented 2026-11-24 06:48:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Neoplayer on 2026-11-22T14:11:28Z.


Updated in 06e148b per your feedback:

  • Kept the existing partition(".") + dll. dot-splitting rule unchanged in tools/pe_inventory.py.
  • Added _parse_forwarded_ordinal() to validate #... forwarders strictly as ASCII decimal 1..65535 (matching tools/pe_map.cpp), accumulating digit-by-digit with an early > 0xFFFF stop so 10,000-digit strings do not trigger Python's int string-length limit.
  • Kept step["forwarder"] = target before validation so unresolved forwarders stay visible in chain[-1]["forwarder"] alongside status == "invalid_forwarder".
  • Updated tests/intake/paths_check.py to cover #1, #65535, #0, #65536, #, #12abc, #-1, non-ASCII digits, and 10,000-digit decimal/zero strings (asserting chain[-1]["forwarder"] is preserved), and deferred separator exploration to a future Windows GetProcAddress comparison.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7080358968 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/567#issuecomment-7080358968). Originally posted by [Neoplayer](https://github.com/Neoplayer) on 2026-11-22T14:11:28Z. --- Updated in `06e148b` per your feedback: - Kept the existing `partition(".")` + `dll.` dot-splitting rule unchanged in `tools/pe_inventory.py`. - Added `_parse_forwarded_ordinal()` to validate `#...` forwarders strictly as ASCII decimal `1..65535` (matching `tools/pe_map.cpp`), accumulating digit-by-digit with an early `> 0xFFFF` stop so 10,000-digit strings do not trigger Python's `int` string-length limit. - Kept `step["forwarder"] = target` before validation so unresolved forwarders stay visible in `chain[-1]["forwarder"]` alongside `status == "invalid_forwarder"`. - Updated `tests/intake/paths_check.py` to cover `#1`, `#65535`, `#0`, `#65536`, `#`, `#12abc`, `#-1`, non-ASCII digits, and 10,000-digit decimal/zero strings (asserting `chain[-1]["forwarder"]` is preserved), and deferred separator exploration to a future Windows `GetProcAddress` comparison.
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!561
No description provided.