Read export names as stored in the PE inventory #123

Merged
Vonsek merged 3 commits from upstream-pr/124 into main 2026-11-22 03:49:46 +00:00
Vonsek commented 2026-11-21 16:39:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T16:39:27Z.


Change

Follow-up to #81. pefile's export parser stops reading names at the first one outside its character set (a space, ;, =, a control byte or any non-ASCII byte), and lists every later named export as a bare ordinal. It also cuts names at 512 bytes and gives up after 8,192 entries. Because the name table is sorted, one such name hides every named export after it. pe_inventory.exports() feeds bundle_exports_in, the System32 tables used by desktop_resolution, and the export names dependency_paths checks, so a correct named import could be reported as bundled_export_missing or export_not_found.

exports() now reads the export directory from data directory 0, and its address, name and name-ordinal tables, itself, and keeps names and forwarders as stored. Output order and fields are unchanged for readable tables.

Every read goes through the existing read_rva / read_name helpers that the import reader already uses, so exports follow the same rule as imports: data must lie in a section's file data. These now raise ValueError instead of producing a partial table:

  • an export directory, address table, name pointer table or name-ordinal table that does not fit in section file data: Export name pointer table at RVA 0x2048 is outside the file's sections (likewise Export directory, Export address table, Export name ordinal table);
  • a name or forwarder RVA outside section file data: Export name at RVA 0x3100 is outside the file's sections, Export forwarder at RVA 0x3100 is outside the file's sections;
  • a name or forwarder with no NUL before the end of its section's file data: Unterminated export name at RVA 0x21ff;
  • a name ordinal outside the address table: Export name ordinal is outside the export address table.

Before this, an out-of-section name made that export ordinal-only (pefile) or gave it an empty name, an unterminated name was cut at the end of the section, a forwarder outside the file became an empty forwarder string, and a truncated name table made pefile drop the export directory, so the image had no exports at all. All of these were silent. read_name now also says "outside the file's sections" rather than "Unterminated" for an import name RVA outside every section; the import messages are otherwise unchanged.

A System32 DLL with such a table now stops the scan as well, as a package DLL does. The rule is section file data: header-resident tables and the zero-filled tail beyond SizeOfRawData are not accepted, matching the import reader.

Verification

  • tests/intake/provider.def adds named_alias = named_value. static_exe_intake patches a copy of the provider so that name becomes named alias (same length), scans it with the fixture, and requires both names and ordinal 77 in images, and named_value in bundle_exports_in.
  • static_exe_intake also patches four more copies of intake_provider.dll and requires scan() to raise the exact message with the patched RVA: the first name pointer set past SizeOfImage; the last name pointer set to the last byte of its section's file data, made nonzero; NumberOfNames raised so the name pointer table runs one entry past the section's file data; and the export directory size widened so ordinal 77's address, set past SizeOfImage, counts as a forwarder.
  • Linux with clang/lld-link stand-in fixtures and pefile 2024.8.26: with main's exports() the four cases give ordinal-only 78, name x, an empty export list and an empty forwarder; with the first commit of this PR, name '', name x, an empty list and an empty forwarder. All four raise the expected message with this change. The renamed-alias check fails on main and passes here. bundled_export_forwarders and conditional_import_paths pass.
  • Old and new exports() gave identical results on 73 unrelated PE images (44 with exports).
  • Rebased on main after #208, #230 and #238.
  • Windows: ctest --preset dev --no-tests=error -R '^(static_exe_intake|bundled_export_forwarders|conditional_import_paths)$' -V at 654ee9b on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12: 3/3 passed, with the fixtures built by MSVC and the host's System32 as the desktop provider set. The full ctest --preset dev --no-tests=error passed 121/121, with bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp skipped.
  • System32 scan on the same machine: exports() on every C:\Windows\System32\*.dll (3,702 images, 3,491 with exports) raised no error.

Evidence and follow-up

The fixture is the existing source-built intake_provider.dll with one extra alias export, patched in temporary copies by the test. It is never loaded. Real System32 and package DLLs are not known to contain such names or malformed tables; this removes a silent dependency on pefile's heuristics, not a measured miss. Names longer than 64 KiB are reported as unterminated, the same limit the import reader uses.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6531539131 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/124). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T16:39:27Z. --- ## Change Follow-up to #81. pefile's export parser stops reading names at the first one outside its character set (a space, `;`, `=`, a control byte or any non-ASCII byte), and lists every later named export as a bare ordinal. It also cuts names at 512 bytes and gives up after 8,192 entries. Because the name table is sorted, one such name hides every named export after it. `pe_inventory.exports()` feeds `bundle_exports_in`, the System32 tables used by `desktop_resolution`, and the export names `dependency_paths` checks, so a correct named import could be reported as `bundled_export_missing` or `export_not_found`. `exports()` now reads the export directory from data directory 0, and its address, name and name-ordinal tables, itself, and keeps names and forwarders as stored. Output order and fields are unchanged for readable tables. Every read goes through the existing `read_rva` / `read_name` helpers that the import reader already uses, so exports follow the same rule as imports: data must lie in a section's file data. These now raise `ValueError` instead of producing a partial table: - an export directory, address table, name pointer table or name-ordinal table that does not fit in section file data: `Export name pointer table at RVA 0x2048 is outside the file's sections` (likewise `Export directory`, `Export address table`, `Export name ordinal table`); - a name or forwarder RVA outside section file data: `Export name at RVA 0x3100 is outside the file's sections`, `Export forwarder at RVA 0x3100 is outside the file's sections`; - a name or forwarder with no NUL before the end of its section's file data: `Unterminated export name at RVA 0x21ff`; - a name ordinal outside the address table: `Export name ordinal is outside the export address table`. Before this, an out-of-section name made that export ordinal-only (pefile) or gave it an empty name, an unterminated name was cut at the end of the section, a forwarder outside the file became an empty forwarder string, and a truncated name table made pefile drop the export directory, so the image had no exports at all. All of these were silent. `read_name` now also says "outside the file's sections" rather than "Unterminated" for an import name RVA outside every section; the import messages are otherwise unchanged. A System32 DLL with such a table now stops the scan as well, as a package DLL does. The rule is section file data: header-resident tables and the zero-filled tail beyond `SizeOfRawData` are not accepted, matching the import reader. ## Verification - `tests/intake/provider.def` adds `named_alias = named_value`. `static_exe_intake` patches a copy of the provider so that name becomes `named alias` (same length), scans it with the fixture, and requires both names and ordinal 77 in `images`, and `named_value` in `bundle_exports_in`. - `static_exe_intake` also patches four more copies of `intake_provider.dll` and requires `scan()` to raise the exact message with the patched RVA: the first name pointer set past `SizeOfImage`; the last name pointer set to the last byte of its section's file data, made nonzero; `NumberOfNames` raised so the name pointer table runs one entry past the section's file data; and the export directory size widened so ordinal 77's address, set past `SizeOfImage`, counts as a forwarder. - Linux with clang/lld-link stand-in fixtures and pefile 2024.8.26: with main's `exports()` the four cases give ordinal-only 78, name `x`, an empty export list and an empty forwarder; with the first commit of this PR, name `''`, name `x`, an empty list and an empty forwarder. All four raise the expected message with this change. The renamed-alias check fails on main and passes here. `bundled_export_forwarders` and `conditional_import_paths` pass. - Old and new `exports()` gave identical results on 73 unrelated PE images (44 with exports). - Rebased on main after #208, #230 and #238. - Windows: `ctest --preset dev --no-tests=error -R '^(static_exe_intake|bundled_export_forwarders|conditional_import_paths)$' -V` at 654ee9b on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12: 3/3 passed, with the fixtures built by MSVC and the host's System32 as the desktop provider set. The full `ctest --preset dev --no-tests=error` passed 121/121, with `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp` skipped. - System32 scan on the same machine: `exports()` on every `C:\Windows\System32\*.dll` (3,702 images, 3,491 with exports) raised no error. ## Evidence and follow-up The fixture is the existing source-built `intake_provider.dll` with one extra alias export, patched in temporary copies by the test. It is never loaded. Real System32 and package DLLs are not known to contain such names or malformed tables; this removes a silent dependency on pefile's heuristics, not a measured miss. Names longer than 64 KiB are reported as unterminated, the same limit the import reader uses.
upstream-sync closed this pull request 2026-11-24 06:41:25 +00:00
R0Y00 commented 2026-11-24 06:47:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T17:16:26Z.


Please validate the export name/forwarder reads as well as the array indices. A nonzero name RVA that yields no bytes must not silently become an ordinal-only entry. Please cover an out-of-section name RVA and a truncated table with deterministic diagnostics.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066348949 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/124#issuecomment-7066348949). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T17:16:26Z. --- Please validate the export name/forwarder reads as well as the array indices. A nonzero name RVA that yields no bytes must not silently become an ordinal-only entry. Please cover an out-of-section name RVA and a truncated table with deterministic diagnostics.
Vonsek commented 2026-11-24 06:47:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:47:55Z.


Thanks, done. exports() now reads the export directory, its three tables, and every name and forwarder through the same read_rva / read_name helpers as the import reader, so a table that runs past section file data, or a name or forwarder RVA outside it or without a NUL before its end, raises a ValueError naming the table or string and its RVA instead of yielding an ordinal-only export, an empty name or an empty table. static_exe_intake now patches four copies of intake_provider.dll (out-of-section name RVA, unterminated name at the end of .rdata, truncated name pointer table, forwarder RVA past the image) and checks the exact message for each; all four were silently accepted before. The branch is rebased on current main, and the System32 scan on Windows 11 26200 raised nothing (3,702 DLLs, 3,491 with exports).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068285527 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/124#issuecomment-7068285527). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:47:55Z. --- Thanks, done. `exports()` now reads the export directory, its three tables, and every name and forwarder through the same `read_rva` / `read_name` helpers as the import reader, so a table that runs past section file data, or a name or forwarder RVA outside it or without a NUL before its end, raises a `ValueError` naming the table or string and its RVA instead of yielding an ordinal-only export, an empty name or an empty table. `static_exe_intake` now patches four copies of `intake_provider.dll` (out-of-section name RVA, unterminated name at the end of `.rdata`, truncated name pointer table, forwarder RVA past the image) and checks the exact message for each; all four were silently accepted before. The branch is rebased on current main, and the System32 scan on Windows 11 26200 raised nothing (3,702 DLLs, 3,491 with exports).
R0Y00 commented 2026-11-24 06:47:57 +00:00 (Migrated from github.com)

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


The new export reader limits the forwarder start to [start, start + size), but read_name(pe, functions[i], "export forwarder") can still find its terminator later in the enclosing section. That reports a valid forwarder even when part of its name is outside the export directory. Please cap this particular read at the directory end and exercise terminators at the last allowed byte and one byte beyond. Ordinary exported symbol names can keep their existing section bound.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068402559 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/124#issuecomment-7068402559). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T19:57:41Z. --- The new export reader limits the forwarder start to `[start, start + size)`, but `read_name(pe, functions[i], "export forwarder")` can still find its terminator later in the enclosing section. That reports a valid forwarder even when part of its name is outside the export directory. Please cap this particular read at the directory end and exercise terminators at the last allowed byte and one byte beyond. Ordinary exported symbol names can keep their existing section bound.
R0Y00 commented 2026-11-24 06:48:24 +00:00 (Migrated from github.com)

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


Merged after the bounded forwarder read and two source-built boundary controls. The NUL in the last byte of the directory passes, and moving the directory end back one byte fails with the expected diagnostic. Local static_exe_intake and bundled_export_forwarders both passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7073887034 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/124#issuecomment-7073887034). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T03:57:12Z. --- Merged after the bounded forwarder read and two source-built boundary controls. The NUL in the last byte of the directory passes, and moving the directory end back one byte fails with the expected diagnostic. Local static_exe_intake and bundled_export_forwarders both passed.
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!123
No description provided.