Read export names as stored in the PE inventory #123
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/124"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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()feedsbundle_exports_in, the System32 tables used bydesktop_resolution, and the export namesdependency_pathschecks, so a correct named import could be reported asbundled_export_missingorexport_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_namehelpers 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 raiseValueErrorinstead of producing a partial table:Export name pointer table at RVA 0x2048 is outside the file's sections(likewiseExport directory,Export address table,Export name ordinal table);Export name at RVA 0x3100 is outside the file's sections,Export forwarder at RVA 0x3100 is outside the file's sections;Unterminated export name at RVA 0x21ff;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_namenow 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
SizeOfRawDataare not accepted, matching the import reader.Verification
tests/intake/provider.defaddsnamed_alias = named_value.static_exe_intakepatches a copy of the provider so that name becomesnamed alias(same length), scans it with the fixture, and requires both names and ordinal 77 inimages, andnamed_valueinbundle_exports_in.static_exe_intakealso patches four more copies ofintake_provider.dlland requiresscan()to raise the exact message with the patched RVA: the first name pointer set pastSizeOfImage; the last name pointer set to the last byte of its section's file data, made nonzero;NumberOfNamesraised 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 pastSizeOfImage, counts as a forwarder.exports()the four cases give ordinal-only 78, namex, an empty export list and an empty forwarder; with the first commit of this PR, name'', namex, 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_forwardersandconditional_import_pathspass.exports()gave identical results on 73 unrelated PE images (44 with exports).ctest --preset dev --no-tests=error -R '^(static_exe_intake|bundled_export_forwarders|conditional_import_paths)$' -Vat654ee9bon 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 fullctest --preset dev --no-tests=errorpassed 121/121, withbvh_wave64_hardware,bvh_wave64_warpandwave_shuffle_warpskipped.exports()on everyC:\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.dllwith 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.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.
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 sameread_rva/read_namehelpers 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 aValueErrornaming the table or string and its RVA instead of yielding an ordinal-only export, an empty name or an empty table.static_exe_intakenow patches four copies ofintake_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).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), butread_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.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.