Scripts: harden pe_exports CLI argument handling, validation, and test coverage #1804

Open
heditrigui wants to merge 1 commit from upstream-pr/1814 into main
heditrigui commented 2026-11-24 21:04:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by heditrigui on 2026-11-24T21:04:16Z.


Summary

Hardens CLI argument handling and validation in scripts/re/pe_exports.py and expands unit test coverage in scripts/test_pe_exports.py:

  • Adds -h and --help CLI option support with usage docstrings and clean exit code 0.
  • Rejects missing arguments with usage instructions and exit code 2.
  • Handles missing or unreadable files cleanly (reports error: file not found: '<path>' on stderr and exits code 1) instead of crashing with unhandled Python exceptions.
  • Validates PE signatures and header bounds, reporting descriptive errors on truncated or invalid headers.
  • Modularizes export extraction into reusable parse_exports(bytes) and dump_pe_exports(path) functions.
  • Expands scripts/test_pe_exports.py from 1 to 8 tests covering CLI argument flags, exit codes, missing files, invalid PE binaries, and direct Python API parsing across both 32-bit (PE32) and 64-bit (PE32+) binaries.

Tested

  • python -m unittest scripts/test_pe_exports.py (8 passed in 0.40s).
  • python -m pytest scripts/ (23 passed in 0.78s).
  • Validated with scripts/pr_check.py --local.

Not tested

  • Retail game smoke execution (scripts/ tools are non-runtime code).

AI use

  • Antigravity (Gemini 3.8 Flash (High))
<!-- greyfinch-sync:ivall/xcl:issue:5480305274 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1814). Originally posted by [heditrigui](https://github.com/heditrigui) on 2026-11-24T21:04:16Z. --- ### Summary Hardens CLI argument handling and validation in `scripts/re/pe_exports.py` and expands unit test coverage in `scripts/test_pe_exports.py`: - Adds `-h` and `--help` CLI option support with usage docstrings and clean exit code 0. - Rejects missing arguments with usage instructions and exit code 2. - Handles missing or unreadable files cleanly (reports `error: file not found: '<path>'` on stderr and exits code 1) instead of crashing with unhandled Python exceptions. - Validates PE signatures and header bounds, reporting descriptive errors on truncated or invalid headers. - Modularizes export extraction into reusable `parse_exports(bytes)` and `dump_pe_exports(path)` functions. - Expands `scripts/test_pe_exports.py` from 1 to 8 tests covering CLI argument flags, exit codes, missing files, invalid PE binaries, and direct Python API parsing across both 32-bit (PE32) and 64-bit (PE32+) binaries. **Tested** - `python -m unittest scripts/test_pe_exports.py` (8 passed in 0.40s). - `python -m pytest scripts/` (23 passed in 0.78s). - Validated with `scripts/pr_check.py --local`. **Not tested** - Retail game smoke execution (`scripts/` tools are non-runtime code). **AI use** - Antigravity (Gemini 3.8 Flash (High))
futurepro62 commented 2026-11-24 21:29:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T21:14:43Z.


Tested exact head 0180bf4, script tests only, since this PR has no test report yet.

Tested

  • Windows 11 Home 26300, Python 3.14.3 with pytest 9.0.3, Windows PowerShell 5.1.26100.9818 (no PowerShell 7 here).
  • python -m pytest scripts/test_pe_exports.py at the head: 8 passed, 2 subtests passed.
  • The PR's test file against current main's script (266b845): does not get to run: collection fails with FileNotFoundError: ... '-q', because main's pe_exports.py reads sys.argv[1:] at import time (which this PR changes).

Not tested

  • PowerShell 7, the CI workflow itself, a game (no runtime code changed).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7144671784 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1814#issuecomment-7144671784). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T21:14:43Z. --- Tested exact head `0180bf4`, script tests only, since this PR has no test report yet. **Tested** - Windows 11 Home 26300, Python 3.14.3 with pytest 9.0.3, Windows PowerShell 5.1.26100.9818 (no PowerShell 7 here). - `python -m pytest scripts/test_pe_exports.py` at the head: 8 passed, 2 subtests passed. - The PR's test file against current main's script (`266b845`): does not get to run: collection fails with `FileNotFoundError: ... '-q'`, because main's `pe_exports.py` reads `sys.argv[1:]` at import time (which this PR changes). **Not tested** - PowerShell 7, the CI workflow itself, a game (no runtime code changed). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
DavidM1911 commented 2026-11-25 01:10:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T00:28:11Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7148541746 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1814#issuecomment-7148541746). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T00:28:11Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
github-actions[bot] commented 2026-11-28 08:01:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T08:01:08Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7236308163 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1814#issuecomment-7236308163). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T08:01:08Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 06:52:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:52:23Z.


Triage (#1607) – head 0180bf4

Three open PRs fix specific cases in the same script, and this one does not include any of their fixes: #1494 (NumberOfRvaAndSizes), #1685 (export data in the image headers) and #2662 (map RVAs only to file-backed bytes; this PR still maps through max(VirtualSize, SizeOfRawData)). Its full rewrite of scripts/re/pe_exports.py will conflict with each of them. The quote-style change across the whole file is unrelated churn that makes the diff larger. No functional problems found.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7303379798 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1814#issuecomment-7303379798). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:52:23Z. --- **Triage (#1607)** – head 0180bf4 Three open PRs fix specific cases in the same script, and this one does not include any of their fixes: #1494 (NumberOfRvaAndSizes), #1685 (export data in the image headers) and #2662 (map RVAs only to file-backed bytes; this PR still maps through `max(VirtualSize, SizeOfRawData)`). Its full rewrite of scripts/re/pe_exports.py will conflict with each of them. The quote-style change across the whole file is unrelated churn that makes the diff larger. No functional problems found. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1814:upstream-pr/1814'
git switch 'upstream-pr/1814'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1814'
git switch 'upstream-pr/1814'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1814'
git switch 'upstream-pr/1814'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1814'
git switch 'main'
git merge --squash 'upstream-pr/1814'
git switch 'main'
git merge --ff-only 'upstream-pr/1814'
git switch 'main'
git merge 'upstream-pr/1814'
git push origin 'main'
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
xcl-dev/xcl!1804
No description provided.