Commit Graph

26 Commits

Author SHA1 Message Date
8d942ae214 tests: an export RVA at the end of the export directory is not a forwarder
The directory is [begin, end), as in runtime/src/pe_loader.cpp. A mutation that made
the end inclusive survived. Reported by enlighted-agent on the carry PR.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-12-02 08:30:47 +01:00
c681cd9261 Merge main into #693: keep resources, unverified imports and system-DLL notes next to forwarders and pdata
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-12-02 08:12:56 +01:00
76b5d19354 pe_inspect: ask report_paths for the report-path guard (PE-INSPECT-SHARED-REPORT-PATH)
tools/pe_inspect.py carried a private same_output_path (realpath + normcase +
samefile). CONTRIBUTING asks report writers to use
tools/report_paths.same_report_path, which also folds case on a
case-insensitive macOS volume where normcase does not, and samefile cannot see
a report that is not written yet. same_output_path stays as its alias.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014sDZDAAcsauTL6d8ie67Qo
2026-11-26 22:22:26 +01:00
b8c44ce8ec Merge pull request #649 from aslan2142/pe-inspect-rt-version
OLD-7282: restore old upstream PR 7282 - pe_inspect: read the resource directory and the RT_VERSION block without its strings
2026-11-25 23:20:51 +01:00
865e2d7912 Merge commit 'refs/fix2/main' into fix2-653 2026-11-25 16:51:53 -05:00
3a7b8b2190 pe_inspect: resolve legacy VA delay-import thunks and skip ImageBase DLL name 2026-11-24 23:03:42 +01:00
0d666fcf4f pe_inspect: classify system DLLs on Linux through the Wine prefix, bundled names without case
On a host that isn't Windows, classify_dll marked the C runtime and every
system DLL `shim`: the bundled check was case-sensitive (an import of
MSVCP140.dll missed the package's msvcp140.dll), System32 doesn't exist and
the API-set query only works on Windows. The first look's to-do list was
wrong there.

- bundled: the game folder is listed once and compared lower-cased.
- elsewhere than Windows, `system` is checked in the Wine prefix's system32
  ($WINEPREFIX, else ~/.wine), without case, and API sets through the
  prefix's apisetschema.dll (version-6 schema; Wine installs no file for
  most of them).
- with no prefix, a DLL that is neither bundled nor owned by the runtime's
  shims (SHIM_TABLEs in runtime/shims, less owns_dll's host list) is
  "unverified", shown as `system (unverified)`; first_look.ps1 lists those
  after the to-do and warns.
- the report's new `system_dlls` field and the Markdown/stdout summary say
  where system DLLs were checked. Windows classification is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 06:00:38 -05:00
b8951357f1 pe_inspect: read the resource directory and the RT_VERSION block without its strings
Data directory 2 was never read, so the report said nothing about the version block, the one part of a PE that
names its build. The block's values are free UTF-16 text that can name the title, so the report holds no value:

- resources: the types present with entry and byte counts; named types are counted, not named.
- version: the fixed file info's numbers (file and product version, flags with their names, OS, type, subtype,
  date), the translations, and per string table each standard key with its value's length and SHA-256. A key
  outside the standard names is listed by its hash.
- problems: a resource tree or version block that is cut short, loops, points outside the file or has a bad
  signature is listed (offsets and counts only); the rest of the report is still written.

The Markdown report gets a Resources section and stdout one line per image with a version block. The tests build
a resource tree and a version block by hand, check that the made-up values reach no output, and cover a missing
directory, a cut file, malformed blocks and a loop in the tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 05:55:40 -05:00
5f1d88ef29 tools/pe_inspect: bound strings and directory reads to one section
Clamp PeImage.string_at() and multi-byte table/directory lookups to the
containing header or mapped section span so entries or unterminated
strings cannot read across into an unmapped raw tail or the next section.

- Add PeImage._range() and check full item width in thunk_names(),
  _exports(), _export_module_name(), and _tls_callbacks(), while still
  raising PeFormatError when a truncated file ends mid-export or mid-TLS
  directory.
- Clamp PeImage.string_at() to the mapped byte range of its header or
  section.
- Stop masking non-ordinal PE32+ thunk RVAs with 0x7FFFFFFF so invalid
  high bits resolve to "?" instead of aliasing low hint/name entries.
- Add synthetic two-section and PE32+ regression tests in
  tests/test_pe_inspect.py.

Claim: https://github.com/ItsNotRexed/Leonida/issues/4084#issuecomment-7088230651
AI-assisted: yes (Antigravity)
2026-11-22 21:20:30 -03:00
5be0d993a1 Merge pull request #2660 from veloraxxx 2026-11-22 13:16:53 -05:00
09a3ff39f7 Merge pull request #2557 from jvinpe 2026-11-22 13:16:09 -05:00
b9abeefc25 Merge pull request #2456 from Dominik 2026-11-22 13:15:27 -05:00
12bc25eab9 pe_inspect: bound import descriptor reads (BUILD-732) 2026-11-22 17:43:23 +00:00
e739047d4d pe_inspect: name the header a short file stops before, not a missing signature
A 4-byte truncated copy that starts with MZ was rejected as "no MZ header",
but the signature is there: the file is just shorter than the 64-byte MS-DOS
header that carries e_lfanew at 0x3c. The same class of wrong cause sat one
check later, where a cut before or inside the PE header said "no PE signature"
even when PE\0\0 was present and only the bytes after it were missing. The
signature and the length are now checked apart, each reporting its real cause.
Tested with the new ShortHeaderTest (hand-built bytes, parser and CLI paths):
4 of its 6 cases fail without the parser change; the suite runs 50 tests, all
passing, 1 Windows-only skip.

AI-assisted: written by Qwen (model qwen3.8-gx10-claude-compatible).
Co-Authored-By: Qwen qwen3.8-gx10-claude-compatible <noreply@qwen.ai>
2026-11-22 14:27:56 -03:00
396ebb0693 pe_inspect: report run-time load candidates (DLL names held as strings, not imported)
A module can reach another one only through LoadLibrary* at run time:
XCurl.dll and libHttpClient.GDK.dll reach xgameruntime.dll that way, and
XCurl also gameplatformservices.dll (docs/runtime_imports.md, #1384, #2372).
The import table doesn't show those, so pe_inspect's report didn't either.

It now lists DLL names the image holds as ASCII or UTF-16LE strings without
importing them, each with its encoding and the same bundled/system/shim
classification as the imports, in the JSON (runtime_load_candidates) and a
markdown section. The image's own names (file name and export-directory
name) are left out. A UTF-16 name must follow a NUL, so the tail of an ASCII
string followed by a wide one isn't read as a name (the test caught
"a.dll\0" + L"b.dll" reading as "lb.dll").

On the package's DLLs (local run, nothing committed) it lists exactly the
loads found by hand: XCurl gameplatformservices.dll and xgameruntime.dll
(utf-16), libHttpClient xgameruntime.dll and ntdll.dll, the FidelityFX loader
its upscaler and frame-generation DLLs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 17:06:32 +00:00
069d7c888b fix(pe): require populated slots for named exports
A name pointer identifies an export only through its address table index. Check the same slot for named and ordinal-only exports so an empty or out-of-range slot cannot appear in the report.
2026-11-22 17:21:09 +01:00
d84f78ecec fix: validate PE optional header bounds (BUILD-496) 2026-11-22 11:03:18 -03:00
6e4c9632be pe_inspect: refuse reports that overwrite input images and check output directory 2026-11-22 17:12:20 +05:30
32c2a23299 pe_inspect: honour NumberOfRvaAndSizes, map RVAs by virtual span, read long import names
Three places where the report on an image could be wrong, each reproduced with a synthetic image:

- Data directories: all 16 slots were read whatever NumberOfRvaAndSizes said, so stale bytes past the count showed
  up as .pdata functions, TLS callbacks or a relocation directory (has_relocs decides whether the image can load
  away from its preferred base). A slot past the count is now empty, as in runtime/src/pe_loader.cpp.
- RVA to file offset: a section's span was max(VirtualSize, SizeOfRawData), so a section whose raw data is longer
  than the span to the next one answered the next section's RVAs from its own raw tail. The span is VirtualSize
  (SizeOfRawData when that is 0), as the loader maps it.
- Names stopped at 512 characters: a longer decorated import name became "?", and a DLL with a longer name lost
  its entry. The bound is 4,096 characters.

tests/test_pe_inspect.py: nine new tests, seven of which fail on the old code. No game files; synthetic images only.
2026-11-22 10:00:48 +00:00
ae1daa66d7 Merge pull request #1190 from Tayar 2026-11-22 03:14:25 -05:00
be562fc277 pe_inspect: report an unusable output directory 2026-11-22 05:06:02 -03:00
a7543bc555 pe_inspect: an unused export-table slot is not an export
_exports() listed every index below NumberOfFunctions that had no name as
#<ordinal>, without reading AddressOfFunctions. A zero RVA there marks an
unused ordinal, so an image with gaps in its ordinals got exports that do
not exist and a count that was too high. Each unnamed slot's RVA is read
now; a zero one, or one the file does not hold, is left out. A forwarder
stays.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 14:12:07 +07:00
1ff9e22e7c pe_inspect.py: treat the same image under a different search folder as a separate input
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 00:59:31 +01:00
41cb7c541c pe_inspect.py: one report per input image (same-stem inputs overwrote each other)
Reports were named after the image's stem, so game.exe + game.dll, or a/x.exe +
b/x.exe, in one call wrote the same <out>/<stem>.json/.md and the last one won,
with exit 0. Reports are now named after the full file name (game.exe.json,
game.dll.md); a second image with the same file name from another directory
gets a numbered suffix (x.exe-2.json), compared case-insensitively, and the
name used is printed to stderr. The same path given twice is inspected once.

scripts/first_look.ps1, the only consumer of the report name, reads
<exe file name>.json. Tests cover the exe/dll pair and the two-directory case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 00:49:13 +01:00
b33cfa9e8c pe_inspect.py: report a truncated image instead of stopping the run with struct.error
A file cut off inside the optional header, the export directory, the TLS directory or an import lookup table
raised struct.error. main() catches only PeFormatError and OSError, so a run over several images ended in a
traceback at that file and the rest were never inspected. The optional header's fixed fields are now
length-checked, and inspect() turns any remaining struct.error into PeFormatError, which main() reports as
"not a PE image (...)" before moving on.

The two export loops also ran to NumberOfFunctions / NumberOfNames as read from the file, so a corrupt count
near 2^32 kept a run busy indefinitely. They are now capped at MAX_ENTRIES like the import, thunk and TLS
loops, whose comment already says that is what the cap is for.

Tests: TruncatedImageTest in tests/test_pe_inspect.py (each table cut short, a sweep over cut lengths for
PE32 and PE32+, a CLI run that keeps going after a truncated file, and a 0xFFFFFFFF export count).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 01:31:03 +03:00
67735ca1d4 Tools: parse PE images with struct instead of pefile
tools/pe_inspect.py imported pefile at module level, which the contributing rules do not allow, and which kept
the tool out of the standard-library check job: no test imported it, so CI only syntax-checked it while
scripts/first_look.ps1 still ran it on the executable people bring. It now reads the DOS and NT headers, the
section table and the import, delay-import, export, TLS and relocation directories with struct, and writes the
same JSON and Markdown with the same keys.

Delay-import descriptors without dlattrRva store 32-bit virtual addresses, so they are converted with the image
base instead of being read as RVAs. The Markdown shim list no longer tests for a classifier result that is never
produced.

tests/test_pe_inspect.py builds a 64-bit and a 32-bit image byte by byte and covers both descriptor forms,
imports by name and ordinal, an ordinal-only export, .pdata and TLS callback counts, DLL classification, the
CLI's output files and its rejection path.
2026-11-21 20:11:55 +00:00