Keep import names that pefile rejects in the PE inventory #81

Manually merged
github merged 2 commits from gh-pr/81/head into gh-pr/81/base 2026-11-26 21:25:50 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-21 15:41 UTC · original
Vonsek:pe-inventory-imports → main · +80 −16 · 3 files · 2 commits · merged 2026-11-21 16:42 UTC

Change

pefile 2024.8.26 skips import lookup entries whose names contain characters outside letters, digits and ._?@$()<>, skips ordinal 0, and drops any descriptor those skips leave empty, without a parse warning. pe_inventory therefore lost such edges silently: a provider could appear unlinked in dependency_paths, and an image whose only delay descriptor was affected failed with "Could not parse delay imports". pefile also substitutes names from its built-in table for some ordinal imports (ws2_32, oleaut32, wsock32), so those edges and by_ordinal did not reflect the image.

pe_inventory now reads normal and delay import descriptors and lookup tables itself, with the same descriptor rules as pe_map.cpp (stop at Name 0, OriginalFirstThunk or else FirstThunk; delay descriptors as RVAs, or as virtual addresses when attributes bit 0 is clear). It reports every entry as stored (#N for ordinals) and raises ValueError for data outside the file's sections or an unterminated name. pefile still parses exports.

Behavior change: ordinal imports from ws2_32/oleaut32/wsock32 now appear as #N, which shows up as changed edges against an older baseline. Desktop resolution is unaffected because System32 export tables are keyed by #ordinal as well.

Verification

ctest --preset dev --no-tests=error -R '^(static_exe_intake|conditional_import_paths)$' -V

Windows result at 5f912f5 on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12, RTX 5080 (driver 32.0.16.1692): both tests passed (conditional_import_paths 0.13 s, static_exe_intake 2.98 s). The Windows CI job also passed: https://github.com/R0Y00/Xbox2Windows/actions/runs/44920493329.

Pre-Windows evidence: on Linux, with lld-link builds of the intake fixtures from the repository's .def files and a stub for the Windows host queries, tests/intake/check.py passes with this change and exits with "Could not parse delay imports" without it. parse_image output is unchanged on 27 third-party PE32/PE32+ images (4,900 edges). conditional_import_paths passes.

Evidence and follow-up

static_exe_intake patches the source-built candidate (as the existing bad-tls case does), renaming named_value and delayed_value to same-length named-value/delayed-value, and checks that both edges reach the inventory and entry_import_gaps, and that dependency_paths reports bundled_export_missing against intake_provider.dll. No new binary fixtures.

Follow-ups not in this PR: call_evidence.py, cpu_call_aot.py and cpu_chained_aot.py still take imports from pefile; pefile's export parsing has a similar (warned) name filter.

**@⁠Vonsek** on GitHub · 2026-11-21 15:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/81) `Vonsek:pe-inventory-imports` → `main` · +80 −16 · 3 files · 2 commits · merged 2026-11-21 16:42 UTC ## Change pefile 2024.8.26 skips import lookup entries whose names contain characters outside letters, digits and `._?@$()<>`, skips ordinal 0, and drops any descriptor those skips leave empty, without a parse warning. `pe_inventory` therefore lost such edges silently: a provider could appear unlinked in `dependency_paths`, and an image whose only delay descriptor was affected failed with "Could not parse delay imports". pefile also substitutes names from its built-in table for some ordinal imports (`ws2_32`, `oleaut32`, `wsock32`), so those edges and `by_ordinal` did not reflect the image. `pe_inventory` now reads normal and delay import descriptors and lookup tables itself, with the same descriptor rules as `pe_map.cpp` (stop at Name 0, OriginalFirstThunk or else FirstThunk; delay descriptors as RVAs, or as virtual addresses when attributes bit 0 is clear). It reports every entry as stored (`#N` for ordinals) and raises `ValueError` for data outside the file's sections or an unterminated name. pefile still parses exports. Behavior change: ordinal imports from `ws2_32`/`oleaut32`/`wsock32` now appear as `#N`, which shows up as changed edges against an older baseline. Desktop resolution is unaffected because System32 export tables are keyed by `#ordinal` as well. ## Verification ``` ctest --preset dev --no-tests=error -R '^(static_exe_intake|conditional_import_paths)$' -V ``` Windows result at 5f912f5 on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12, RTX 5080 (driver 32.0.16.1692): both tests passed (`conditional_import_paths` 0.13 s, `static_exe_intake` 2.98 s). The Windows CI job also passed: https://github.com/R0Y00/Xbox2Windows/actions/runs/44920493329. Pre-Windows evidence: on Linux, with lld-link builds of the intake fixtures from the repository's `.def` files and a stub for the Windows host queries, `tests/intake/check.py` passes with this change and exits with "Could not parse delay imports" without it. `parse_image` output is unchanged on 27 third-party PE32/PE32+ images (4,900 edges). `conditional_import_paths` passes. ## Evidence and follow-up `static_exe_intake` patches the source-built candidate (as the existing `bad-tls` case does), renaming `named_value` and `delayed_value` to same-length `named-value`/`delayed-value`, and checks that both edges reach the inventory and `entry_import_gaps`, and that `dependency_paths` reports `bundled_export_missing` against `intake_provider.dll`. No new binary fixtures. Follow-ups not in this PR: `call_evidence.py`, `cpu_call_aot.py` and `cpu_chained_aot.py` still take imports from pefile; pefile's export parsing has a similar (warned) name filter.
pefile skips lookup entries whose names contain characters outside
letters, digits and ._?@$()<>, skips ordinal 0, and drops a descriptor
those skips leave empty. pe_inventory therefore lost such edges without
a warning: a provider could appear unlinked, and a lone delay descriptor
failed the whole scan as unparseable. pefile also replaced some ordinal
imports with names from its built-in table.

pe_inventory now reads normal and delay import descriptors and lookup
tables itself, reports every entry as stored (#N for ordinals) and
rejects data outside the file's sections or an unterminated name.
static_exe_intake renames the fixture's named and delayed imports to
same-length names with a hyphen and checks that both edges, their
entry gaps and the bundled-export mismatch reach the intake report.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:25:50 +00:00
github manually merged commit 3f1cd41d13 into gh-pr/81/base 2026-11-26 21:25:50 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 15:46 UTC · original

Thanks for the inventory work. When the draft is ready, please request review. I'll focus on descriptor and file bounds for normal and delay imports.

**@⁠R0Y00** on GitHub · 2026-11-21 15:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/81#issuecomment-7065131772) Thanks for the inventory work. When the draft is ready, please request review. I'll focus on descriptor and file bounds for normal and delay imports.
This discussion has been locked. Commenting is limited to contributors.
No description provided.