leonida_mods checks the executable and DLLs by SHA-256 before starting gta6rt (carry of #358) #3084

Merged
MoonEyes merged 6 commits from upstream-pr/3084 into main 2026-12-02 12:32:38 +00:00
MoonEyes commented 2026-12-02 10:29:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T10:29:08Z.


Claimed in the coordination issue as: OLD-8041, OLD-8404 (the original author's claim: https://github.com/ProjectLeonida/mandy/issues/14#issuecomment-7121328982)

What and why

Carry of #358 (ItsMrDubey), unchanged since 2026-11-24. Branch = main + the author's head (commit kept) + conflict resolution + my commits.

The change makes tools/leonida_mods.py check the executable and the package DLLs by SHA-256 before it starts gta6rt (CLI run and the GUI launch buttons; not --print). A new manifest_verifier.check_files checks size first, then the streamed SHA-256, with the same cache rules as --cache. game/xbox-1.0.2.1.json gains expected_exe_size and expected_exe_sha256, the values already published in docs/runtime_imports.md. --image still names a stand-in executable that is not checked (the DLLs still are). See #358 for the full description.

What I did on top of the author's commit:

  • Resolved the conflict in tools/leonida_mods.py (imports): kept main's TOOLS path setup and report_paths import, and the PR's manifest_verifier import.
  • Moved the PR's check_files test back into TestVerifyCache. main added TestSaveVerifyCache right after it, so the merge had placed the test in the wrong class, where it failed with TypeError: 'dict' object is not callable.
  • Fixed the two points the review on #358 raised:
    1. check_launch_files skipped a manifest DLL that the package does not contain, so a partially copied package passed. Every DLL in the manifest is now checked, and a missing one fails with <file>: cannot read it (...).
    2. The check took the executable name from the manifest while runtime_command starts EXPECTED_EXE. The check now uses EXPECTED_EXE, so the file checked is the file started.
      Two tests cover these.

The other review comments on #358 (the needs rebase label and the request to rebase for CI) are addressed by this branch being based on current main.

Tested

Windows 11, no GPU, no game files, on main a917c54d6 plus this branch (head 7539b86cb).

  • python -I tests/test_leonida_mods.py: Ran 23 tests, OK (includes the 5 launch-check tests of the PR and my 2).
  • python -I tests/test_manifest_verifier.py: Ran 81 tests, OK (skipped=5).
  • python -m pytest tests/test_manifest_verifier.py -k check_files (venv): 1 passed.
  • Red: with tools/leonida_mods.py, tools/manifest_verifier.py and game/xbox-1.0.2.1.json restored to main's version, python -I tests/test_leonida_mods.py fails with 7 errors (all in LaunchCheckTests) and the check_files test fails (no check_files on main). With only the PR's original check_launch_files (before my fix commit), test_declared_dll_missing_from_the_package_refuses_to_start and test_checks_the_executable_that_is_started_not_the_manifest_name fail; everything passes with the fix. The files were restored afterwards and git status was clean.
  • python -I scripts/check_no_game_data.py on the 6 changed files: clean (exit 0).
  • python -m compileall -q tools tests: ok.
  • git merge-tree against origin/main 80910637f (newer than the base above): no conflict.

Not run: the full suite, CI.

GPUs tested: n/a (unit tests only)

AI-assisted: yes. Models: Claude Opus 5.5 in Claude Code (carry, conflict resolution, fixes, tests); separate read-only reviewer agent: Claude Opus 5.5.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator rule here, so nothing to add.)

Supersedes #358 once merged; the original stays open until a maintainer decides.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5604587655 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3084). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T10:29:08Z. --- Claimed in the coordination issue as: OLD-8041, OLD-8404 (the original author's claim: https://github.com/ProjectLeonida/mandy/issues/14#issuecomment-7121328982) ### What and why Carry of #358 (ItsMrDubey), unchanged since 2026-11-24. Branch = main + the author's head (commit kept) + conflict resolution + my commits. The change makes `tools/leonida_mods.py` check the executable and the package DLLs by SHA-256 before it starts `gta6rt` (CLI `run` and the GUI launch buttons; not `--print`). A new `manifest_verifier.check_files` checks size first, then the streamed SHA-256, with the same cache rules as `--cache`. `game/xbox-1.0.2.1.json` gains `expected_exe_size` and `expected_exe_sha256`, the values already published in `docs/runtime_imports.md`. `--image` still names a stand-in executable that is not checked (the DLLs still are). See #358 for the full description. What I did on top of the author's commit: - Resolved the conflict in `tools/leonida_mods.py` (imports): kept main's `TOOLS` path setup and `report_paths` import, and the PR's `manifest_verifier` import. - Moved the PR's `check_files` test back into `TestVerifyCache`. main added `TestSaveVerifyCache` right after it, so the merge had placed the test in the wrong class, where it failed with `TypeError: 'dict' object is not callable`. - Fixed the two points the review on #358 raised: 1. `check_launch_files` skipped a manifest DLL that the package does not contain, so a partially copied package passed. Every DLL in the manifest is now checked, and a missing one fails with `<file>: cannot read it (...)`. 2. The check took the executable name from the manifest while `runtime_command` starts `EXPECTED_EXE`. The check now uses `EXPECTED_EXE`, so the file checked is the file started. Two tests cover these. The other review comments on #358 (the `needs rebase` label and the request to rebase for CI) are addressed by this branch being based on current main. ### Tested Windows 11, no GPU, no game files, on main a917c54d6 plus this branch (head 7539b86cb). - `python -I tests/test_leonida_mods.py`: Ran 23 tests, OK (includes the 5 launch-check tests of the PR and my 2). - `python -I tests/test_manifest_verifier.py`: Ran 81 tests, OK (skipped=5). - `python -m pytest tests/test_manifest_verifier.py -k check_files` (venv): 1 passed. - Red: with `tools/leonida_mods.py`, `tools/manifest_verifier.py` and `game/xbox-1.0.2.1.json` restored to main's version, `python -I tests/test_leonida_mods.py` fails with 7 errors (all in `LaunchCheckTests`) and the `check_files` test fails (no `check_files` on main). With only the PR's original `check_launch_files` (before my fix commit), `test_declared_dll_missing_from_the_package_refuses_to_start` and `test_checks_the_executable_that_is_started_not_the_manifest_name` fail; everything passes with the fix. The files were restored afterwards and `git status` was clean. - `python -I scripts/check_no_game_data.py` on the 6 changed files: clean (exit 0). - `python -m compileall -q tools tests`: ok. - `git merge-tree` against origin/main 80910637f (newer than the base above): no conflict. Not run: the full suite, CI. GPUs tested: n/a (unit tests only) AI-assisted: yes. Models: Claude Opus 5.5 in Claude Code (carry, conflict resolution, fixes, tests); separate read-only reviewer agent: Claude Opus 5.5. ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (No translator rule here, so nothing to add.) Supersedes #358 once merged; the original stays open until a maintainer decides. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Kal0s-design commented 2026-12-02 11:02:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T11:02:03Z.


Ran this natively on Windows 11 (NTFS), Python 3.13, no game files. Head 7539b86cb merged with current main (43e5769d8), no conflicts.

Unit tests (py -I):

  • tests/test_leonida_mods.py: 23 tests, OK
  • tests/test_manifest_verifier.py: 81 tests, OK (5 skipped)
  • tests/test_exe_sha.py: 16 tests, OK

check_files with its cache on NTFS. I also drove manifest_verifier.check_files directly on a temp folder with one DLL and one exe and a verified_files.json cache. I wrapped sha256_file to count reads and set RACY_WINDOW_NS = 0 so the cache fills at once.

Step Result Files hashed
first run pass, 2 cache entries both
second run pass none (cache hit)
1 byte rewritten in the DLL, same size, old mtime put back with os.utime fails: a.dll: SHA-256 is …, expected … DLL only
DLL restored, then run twice pass, then pass DLL, then none
exe swapped through os.replace for a file with the same bytes and times pass exe only (new file id, so no stale hit)
same files passed with upper-case paths pass none (normcase key matches)
DLL deleted fails: cannot read it (The system cannot find the file specified) none

So the rewrite with the old mtime restored is caught on Windows. That works through the NTFS ChangeTime in _cache_stamp, not st_ctime. An expected hash in upper case is also accepted, because of the .lower().

Not checked: the GUI launch buttons, a real game package, and the time to hash the 120 MB exe the first time.

GPUs tested: n/a (CPU-only tests).

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7343328653 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3084#issuecomment-7343328653). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-12-02T11:02:03Z. --- Ran this natively on Windows 11 (NTFS), Python 3.13, no game files. Head `7539b86cb` merged with current `main` (`43e5769d8`), no conflicts. **Unit tests** (`py -I`): - `tests/test_leonida_mods.py`: 23 tests, OK - `tests/test_manifest_verifier.py`: 81 tests, OK (5 skipped) - `tests/test_exe_sha.py`: 16 tests, OK **`check_files` with its cache on NTFS.** I also drove `manifest_verifier.check_files` directly on a temp folder with one DLL and one exe and a `verified_files.json` cache. I wrapped `sha256_file` to count reads and set `RACY_WINDOW_NS = 0` so the cache fills at once. | Step | Result | Files hashed | |---|---|---| | first run | pass, 2 cache entries | both | | second run | pass | none (cache hit) | | 1 byte rewritten in the DLL, same size, old mtime put back with `os.utime` | fails: `a.dll: SHA-256 is …, expected …` | DLL only | | DLL restored, then run twice | pass, then pass | DLL, then none | | exe swapped through `os.replace` for a file with the same bytes and times | pass | exe only (new file id, so no stale hit) | | same files passed with upper-case paths | pass | none (`normcase` key matches) | | DLL deleted | fails: `cannot read it (The system cannot find the file specified)` | none | So the rewrite with the old mtime restored is caught on Windows. That works through the NTFS ChangeTime in `_cache_stamp`, not `st_ctime`. An expected hash in upper case is also accepted, because of the `.lower()`. Not checked: the GUI launch buttons, a real game package, and the time to hash the 120 MB exe the first time. GPUs tested: n/a (CPU-only tests). AI-assisted: yes (Claude Code).
enlight3d commented 2026-12-02 12:14:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-02T12:14:03Z.


RUN (independent run on Windows, #3084 head 43e5769d8, merged locally into main 9b4d71899 with git merge --no-ff, no conflicts. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.)

  • History: #358's head f35a1c4e2 (ItsMrDubey) is an ancestor of the head through the merge d0266321a, under its author's name.
  • The executable size and SHA-256 added to game/xbox-1.0.2.1.json are the values docs/runtime_imports.md on main already publishes (both found there).
  • python -I on the three changed test files:
    • tests/test_leonida_mods.py: main 16 tests OK; merge 23 tests OK.
    • tests/test_manifest_verifier.py: main 80 tests OK (3 skipped); merge 81 tests OK (3 skipped).
    • tests/test_exe_sha.py: main 16 tests OK; merge 16 tests OK.
  • python -m pytest on the 12 test files that name leonida_mods, manifest_verifier or exe_sha: main 218 passed / 11 skipped; merge 226 passed / 11 skipped.
  • Red: main's tools and manifest with this pull request's three test files.
    • test_leonida_mods.py: 23 tests, 7 errors, all in LaunchCheckTests (main has no VERSIONS or check_launch_files).
    • test_manifest_verifier.py: 81 tests, 1 error (main has no check_files).
    • test_exe_sha.py: 16 OK, since its change only points the --print-keys test at its own empty manifest. These match the body.
  • Mutations of the merge, each run with test_leonida_mods.py and test_manifest_verifier.py, and restored afterwards (git status clean). 6 of 8 are killed:
    • #358's original DLL list, which skips a declared DLL the package lacks (and os.path.isfile(...)): killed by test_declared_dll_missing_from_the_package_refuses_to_start. This is the first review point.
    • #358's original executable name from the manifest (version.get("expected_exe", EXPECTED_EXE)): killed by test_checks_the_executable_that_is_started_not_the_manifest_name. This is the second review point.
    • check_launch_files no longer called before subprocess.call in run: killed (6 failures).
    • Size check removed from check_files: killed in both files.
    • A stand-in --image still has the executable checked: killed.
    • Expected digests no longer lowercased: killed by test_check_files_size_then_hash_then_cache, which passes uppercase digests.
    • Survives: the racy-window condition dropped from the new _stable_stamp. It survives test_leonida_mods.py but is killed in test_manifest_verifier.py (test_what_never_gets_cached), which covers the shared helper.
    • Survives both files: a cache hit that no longer compares the cached digest with the expected one (hit["sha256"] == expected dropped). A file cached as passing would then pass a manifest that expects another digest. No test changes the expected digest of an unchanged, cached file.

Not covered here: Linux and macOS, the GUI launch buttons (they call check_launch_files too, but tkinter is not driven here), and a real game package (synthetic manifests and files only).

Verdict: PASS. The launch check works as described, both review points of #358 are pinned by a test that fails on the original code, red on main and green on the merge match the body, and the author's commit is kept. One gap remains: no test changes the expected digest of a file that is already cached.

Machine: Windows 11 Pro 26300 (NTFS), i9-13900K, 64 GB, CPython 3.13.12 (CI uses 3.12); unit tests only, no GPU or game files used.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7345034560 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3084#issuecomment-7345034560). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-12-02T12:14:03Z. --- RUN (independent run on Windows, #3084 head 43e5769d8, merged locally into `main` 9b4d71899 with `git merge --no-ff`, no conflicts. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.) - History: #358's head f35a1c4e2 (ItsMrDubey) is an ancestor of the head through the merge d0266321a, under its author's name. - The executable size and SHA-256 added to `game/xbox-1.0.2.1.json` are the values `docs/runtime_imports.md` on `main` already publishes (both found there). - `python -I` on the three changed test files: - `tests/test_leonida_mods.py`: main 16 tests OK; merge 23 tests OK. - `tests/test_manifest_verifier.py`: main 80 tests OK (3 skipped); merge 81 tests OK (3 skipped). - `tests/test_exe_sha.py`: main 16 tests OK; merge 16 tests OK. - `python -m pytest` on the 12 test files that name `leonida_mods`, `manifest_verifier` or `exe_sha`: main 218 passed / 11 skipped; merge 226 passed / 11 skipped. - Red: `main`'s tools and manifest with this pull request's three test files. - `test_leonida_mods.py`: 23 tests, 7 errors, all in `LaunchCheckTests` (`main` has no `VERSIONS` or `check_launch_files`). - `test_manifest_verifier.py`: 81 tests, 1 error (`main` has no `check_files`). - `test_exe_sha.py`: 16 OK, since its change only points the `--print-keys` test at its own empty manifest. These match the body. - Mutations of the merge, each run with `test_leonida_mods.py` and `test_manifest_verifier.py`, and restored afterwards (`git status` clean). 6 of 8 are killed: - #358's original DLL list, which skips a declared DLL the package lacks (`and os.path.isfile(...)`): killed by `test_declared_dll_missing_from_the_package_refuses_to_start`. This is the first review point. - #358's original executable name from the manifest (`version.get("expected_exe", EXPECTED_EXE)`): killed by `test_checks_the_executable_that_is_started_not_the_manifest_name`. This is the second review point. - `check_launch_files` no longer called before `subprocess.call` in `run`: killed (6 failures). - Size check removed from `check_files`: killed in both files. - A stand-in `--image` still has the executable checked: killed. - Expected digests no longer lowercased: killed by `test_check_files_size_then_hash_then_cache`, which passes uppercase digests. - Survives: the racy-window condition dropped from the new `_stable_stamp`. It survives `test_leonida_mods.py` but is killed in `test_manifest_verifier.py` (`test_what_never_gets_cached`), which covers the shared helper. - Survives both files: a cache hit that no longer compares the cached digest with the expected one (`hit["sha256"] == expected` dropped). A file cached as passing would then pass a manifest that expects another digest. No test changes the expected digest of an unchanged, cached file. Not covered here: Linux and macOS, the GUI launch buttons (they call `check_launch_files` too, but tkinter is not driven here), and a real game package (synthetic manifests and files only). Verdict: PASS. The launch check works as described, both review points of #358 are pinned by a test that fails on the original code, red on `main` and green on the merge match the body, and the author's commit is kept. One gap remains: no test changes the expected digest of a file that is already cached. Machine: Windows 11 Pro 26300 (NTFS), i9-13900K, 64 GB, CPython 3.13.12 (CI uses 3.12); unit tests only, no GPU or game files used.
MoonEyes commented 2026-12-02 12:17:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T12:17:56Z.


Merging. Head 43e5769d8 merges cleanly with main f6dd2242e and does not force a rebase of #2566. Independent check on head 43e5769d8: enlight3d's red/green on main + this head (7 failures + 1 error with main's tools, related suite 218 -> 226, 6 of 8 mutations killed incl. both original bugs of #358; one survivor: a cache that no longer compares the expected SHA, no test changes a cached file's expected SHA, noted as a gap), comment 7345034560; ItsMrDubey's commit from #358 is kept; CI green incl. no-game-data; no open review or question. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7345131972 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3084#issuecomment-7345131972). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T12:17:56Z. --- Merging. Head `43e5769d8` merges cleanly with `main` `f6dd2242e` and does not force a rebase of #2566. Independent check on head 43e5769d8: enlight3d's red/green on main + this head (7 failures + 1 error with main's tools, related suite 218 -> 226, 6 of 8 mutations killed incl. both original bugs of #358; one survivor: a cache that no longer compares the expected SHA, no test changes a cached file's expected SHA, noted as a gap), comment 7345034560; ItsMrDubey's commit from #358 is kept; CI green incl. no-game-data; no open review or question. Merged by MoonEyes. AI-assisted (Claude Code).
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
ProjectLeonida/mandy!3084
No description provided.