pe: harden call_evidence CLI and import guards and add unit suite #1914

Merged
Ammmae0x merged 1 commit from upstream-pr/1921 into main 2026-11-24 21:25:55 +00:00
Ammmae0x commented 2026-11-24 21:17:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T21:17:31Z.


Change

Harden tools/call_evidence.py against missing import directories, malformed or non-ASCII import names, and invalid CLI inputs, and add a synthetic PE32+ unit and refusal test suite in tests/call_evidence_check.py registered in CMakeLists.txt:

  • Guard DIRECTORY_ENTRY_IMPORT, desc.imports, desc.dll, and imp.name in inspect() using getattr(..., None) or () and decode("ascii", "replace").
  • Update main(argv=None) to accept an explicit argument list, validate directory resolution (OSError, is_dir()), verify all three expected DLL names exist before inspection, exit cleanly via parser.exit(1, ...) on OSError, ValueError, pefile.PEFormatError, or subprocess.SubprocessError, and return 0.
  • Add tests/call_evidence_check.py with synthetic PE32+ builders and mocked dumpbin /nologo /disasm:nobytes output covering instruction reference parsing, IAT call/jmp sites with upstream callers, mapped DXBC/RTS0/DXIL containers and overlay exclusion, missing import directory and non-ASCII import names, _mapped_rva() bounds/slack rejection, end-to-end main() JSON output, and clean CLI error exit codes without tracebacks.
  • Register call_evidence_check in CMakeLists.txt.

Verification

Verified on rebased branch pe/call-evidence-validation (on top of upstream/main 67a240ba):

  • cmake --preset dev -> Configuring done (0.2s), Total Tests: 1200 (#1181: call_evidence_check)
  • cmake --preset release -> Configuring done (0.2s), Total Tests: 1200 (#1181: call_evidence_check)
  • ctest --preset dev --no-tests=error -R "^call_evidence_check$" -V -> 1/1 passed (Ran 6 tests in 0.583s)
  • ctest --preset release --no-tests=error -R "^call_evidence_check$" -V -> 1/1 passed (Ran 6 tests in 0.575s)
  • python -B tests/call_evidence_check.py -v -> Ran 6 tests in 0.578s, OK
  • python -B tests/form_coverage_check.py -> form coverage checks passed
  • python -B tests/docs_links_check.py -> Checked 18 Markdown files and 385 links.
  • python -B tests/bidi_controls_check.py -> Checked 1346 tracked source, script and build/CI files: no bidirectional controls.

Evidence and follow-up

All fixtures in tests/call_evidence_check.py are constructed synthetically in memory using standard Python struct and mocked dumpbin disassembly strings; no game binaries, dumps, or secrets are included.

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.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6591598739 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1921). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T21:17:31Z. --- ## Change Harden [`tools/call_evidence.py`](tools/call_evidence.py) against missing import directories, malformed or non-ASCII import names, and invalid CLI inputs, and add a synthetic PE32+ unit and refusal test suite in [`tests/call_evidence_check.py`](tests/call_evidence_check.py) registered in [`CMakeLists.txt`](CMakeLists.txt): - Guard `DIRECTORY_ENTRY_IMPORT`, `desc.imports`, `desc.dll`, and `imp.name` in `inspect()` using `getattr(..., None) or ()` and `decode("ascii", "replace")`. - Update `main(argv=None)` to accept an explicit argument list, validate directory resolution (`OSError`, `is_dir()`), verify all three expected DLL names exist before inspection, exit cleanly via `parser.exit(1, ...)` on `OSError`, `ValueError`, `pefile.PEFormatError`, or `subprocess.SubprocessError`, and return `0`. - Add `tests/call_evidence_check.py` with synthetic PE32+ builders and mocked `dumpbin /nologo /disasm:nobytes` output covering instruction reference parsing, IAT call/jmp sites with upstream callers, mapped DXBC/RTS0/DXIL containers and overlay exclusion, missing import directory and non-ASCII import names, `_mapped_rva()` bounds/slack rejection, end-to-end `main()` JSON output, and clean CLI error exit codes without tracebacks. - Register `call_evidence_check` in `CMakeLists.txt`. ## Verification Verified on rebased branch `pe/call-evidence-validation` (on top of `upstream/main` `67a240ba`): - `cmake --preset dev` -> `Configuring done (0.2s)`, `Total Tests: 1200` (`#1181: call_evidence_check`) - `cmake --preset release` -> `Configuring done (0.2s)`, `Total Tests: 1200` (`#1181: call_evidence_check`) - `ctest --preset dev --no-tests=error -R "^call_evidence_check$" -V` -> `1/1` passed (`Ran 6 tests in 0.583s`) - `ctest --preset release --no-tests=error -R "^call_evidence_check$" -V` -> `1/1` passed (`Ran 6 tests in 0.575s`) - `python -B tests/call_evidence_check.py -v` -> `Ran 6 tests in 0.578s`, `OK` - `python -B tests/form_coverage_check.py` -> `form coverage checks passed` - `python -B tests/docs_links_check.py` -> `Checked 18 Markdown files and 385 links.` - `python -B tests/bidi_controls_check.py` -> `Checked 1346 tracked source, script and build/CI files: no bidirectional controls.` ## Evidence and follow-up All fixtures in `tests/call_evidence_check.py` are constructed synthetically in memory using standard Python `struct` and mocked `dumpbin` disassembly strings; no game binaries, dumps, or secrets are included. ## 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. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
upstream-sync closed this pull request 2026-11-24 21:27:36 +00:00
tedin7 commented 2026-11-24 21:27:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:22:16Z.

Review: COMMENTED


Review of 435a15f20f4f064375eadecd0b47704c9e736260 (comment only, no approval). No earlier review on this PR.

Verdict: no P1/P2 found. Three P3 test gaps below.

Read: the full diff vs origin/main (tools/call_evidence.py, the new tests/call_evidence_check.py, one CMake line). The CLI changes are bounded: a missing path, a non-directory, a missing image and an overlapping report directory each end in parser.error (exit 2, no traceback); read and parse errors end in exit 1 with a one-line message. Non-ASCII import names are decoded with replace, so they never match the experiment table and cannot crash the run. The synthetic PE32+ builder and the DXBC fixtures are built in the test, not taken from a title.

Commands run locally (Linux, pefile==2024.8.26 in a temporary venv; dumpbin is mocked in the test):

  • git diff --check origin/main...HEAD: clean
  • python -B tests/call_evidence_check.py: 6 tests OK
  • python3 tests/docs_links_check.py: 385 links OK; python3 tests/bidi_controls_check.py: no bidirectional controls

Mutations on tools/call_evidence.py (each reverted with git checkout -- ., tree clean afterwards):

  1. import directory read unguarded (pe.DIRECTORY_ENTRY_IMPORT): killed (4 errors)
  2. no-missing-image check disabled: killed
  3. overlapping-output check disabled: killed
  4. strict ASCII decode of the symbol name: survived
  5. if not root.is_dir() disabled: survived
  6. except (OSError, ValueError, pefile.PEFormatError, subprocess.SubprocessError) narrowed to ValueError: survived

P3 (test gaps, not defects):

  • tools/call_evidence.py (symbol-name decode): the non-ASCII test does not fail when the decode is strict, so it does not yet prove the fixture reaches that line.
  • tools/call_evidence.py (root.is_dir()): the "path is a file" case still exits 2 through the missing-image check, so the dedicated guard has no test of its own.
  • tools/call_evidence.py (the except around inspect): no test makes inspect raise, so the exit-1 path and its message are untested.

Not run: the real dumpbin /disasm output (Windows only). The tests feed a hand-written disassembly format, so a change in the dumpbin text format would not be caught here.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047621973 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1921#pullrequestreview-6047621973). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T21:22:16Z. **Review:** COMMENTED --- Review of `435a15f20f4f064375eadecd0b47704c9e736260` (comment only, no approval). No earlier review on this PR. **Verdict: no P1/P2 found. Three P3 test gaps below.** Read: the full diff vs `origin/main` (`tools/call_evidence.py`, the new `tests/call_evidence_check.py`, one CMake line). The CLI changes are bounded: a missing path, a non-directory, a missing image and an overlapping report directory each end in `parser.error` (exit 2, no traceback); read and parse errors end in exit 1 with a one-line message. Non-ASCII import names are decoded with `replace`, so they never match the experiment table and cannot crash the run. The synthetic PE32+ builder and the DXBC fixtures are built in the test, not taken from a title. Commands run locally (Linux, `pefile==2024.8.26` in a temporary venv; `dumpbin` is mocked in the test): - `git diff --check origin/main...HEAD`: clean - `python -B tests/call_evidence_check.py`: 6 tests OK - `python3 tests/docs_links_check.py`: 385 links OK; `python3 tests/bidi_controls_check.py`: no bidirectional controls Mutations on `tools/call_evidence.py` (each reverted with `git checkout -- .`, tree clean afterwards): 1. import directory read unguarded (`pe.DIRECTORY_ENTRY_IMPORT`): killed (4 errors) 2. no-missing-image check disabled: killed 3. overlapping-output check disabled: killed 4. strict ASCII decode of the symbol name: **survived** 5. `if not root.is_dir()` disabled: **survived** 6. `except (OSError, ValueError, pefile.PEFormatError, subprocess.SubprocessError)` narrowed to `ValueError`: **survived** P3 (test gaps, not defects): - `tools/call_evidence.py` (symbol-name decode): the non-ASCII test does not fail when the decode is strict, so it does not yet prove the fixture reaches that line. - `tools/call_evidence.py` (`root.is_dir()`): the "path is a file" case still exits 2 through the missing-image check, so the dedicated guard has no test of its own. - `tools/call_evidence.py` (the `except` around `inspect`): no test makes `inspect` raise, so the exit-1 path and its message are untested. Not run: the real `dumpbin /disasm` output (Windows only). The tests feed a hand-written disassembly format, so a change in the `dumpbin` text format would not be caught here. AI-assisted; commands listed were executed locally.
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!1914
No description provided.