[PR #1278] [CLOSED] pe_shader_containers: find console programs stored compressed (TOOLS-PE-SHADER-CONTAINERS) #1312

Closed
opened 2026-11-26 20:20:49 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1278
Author: @Moriz82
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: split/tools-pe-shader-containers


📝 Commits (1)

  • 6e0743a pe_shader_containers: find console programs stored compressed (TOOLS-PE-SHADER-CONTAINERS)

📊 Changes

3 files changed (+121 additions, -1 deletions)

View changed files

📝 docs/embedded_shaders.md (+10 -0)
📝 tests/test_pe_shader_containers.py (+106 -0)
📝 tools/pe_shader_containers.py (+5 -1)

📄 Description

Rebased onto bfef489c at 6e0743af. Main already recognizes the compressed envelope. This diff deduplicates a container discovered both as a plain hit and as a stored deflate block, with synthetic coverage. All 25 container tests passed.

Claimed in the coordination issue as: TOOLS-PE-SHADER-CONTAINERS (claim).

Part of the split of #984 into small pull requests.

Depends on: none
Overlaps: #984 is the parent integration. #694 (open, OLD-9775; #53 is its draft twin) numbers the stems of a multi-image --extract in sequence and stages the --json write. Merged three-way with it (its diff applied to the base, then merged into this branch) there are two one-line conflicts, both where each side adds an import at the same place (import zlib here; import tempfile in the tool and from unittest import mock in the test there). Everything else merges, the two changes to extract() included. #387 (open; #303 is closed) adds the make_game.py step that runs this tool on the executable; it does not change the tool, and this pull request does not add a build step. Its diff does not apply to this base, so no merge was tried.

What and why

tools/pe_shader_containers.py lists the DXBC containers that lie in an image as they are. A console program can also be stored compressed, and the scan did not see those: the image has no DXBC magic for a compressed one.

The record is: a u32 stored size, the u32 constant 0x000DDCE7, the stored size again, the u32 size of the container, then a raw deflate stream of the whole DXBC container. Both stored sizes count from the constant, so they include those 12 bytes. The stream is plain deflate; nothing is decrypted.

inspect() now also looks for the constant and takes a record only when all of this holds:

  • both stored sizes are equal, larger than the 12 header bytes, inside the image and at most 64 MiB, and the container size is over 32 bytes and at most 64 MiB;
  • the stream ends exactly at the end of the record, with nothing after it;
  • it inflates to exactly the named size, never more (the inflater is stopped one byte past it);
  • the result is one DXBC container whose own total size is that size and which the existing chunk-table validation accepts;
  • that container holds a console program (has_xbch). The same record form also stores containers with nothing for the RDNA2 pipeline to translate; those are not listed.

Such a record is listed after the plain containers, so those keep their order and therefore the file names --extract gives them. Its offset is that of the constant, stored_size is the stored size, and size, sha256, the chunk list and the name describe the inflated container, which is what --extract writes. A stream made of stored blocks holds the container as it is, where the plain scan finds it already; that container is listed once.

The layout is the one the five-star-recomp project describes for the shader records of the game's effect tables (its note on shader containers); no code is taken from it. One point differs from that description and comes from the integration branch instead: there the stored size counts the 12 header bytes, and the tool requires the stream to end exactly at that size. That was not re-measured for this pull request. The integration reports reading two such pixel programs in the retail executable with this rule; here the rule is exercised on hand-built records only. If the size did not include the header, every real record would be rejected (the stream would be cut 12 bytes short), and the tool would behave as it does today.

The same scan also runs where the tool is used today, on XboxBvhBuilder.dll in the BVH step. Whether that DLL holds such a record was not checked; a record that passes all the tests above would add a program to that step's output.

Tested

Linux (CachyOS, kernel 7.3.5), Python 3.14. One commit on 6293c1c4f.

  • python3 -I tests/test_pe_shader_containers.py: 24 tests pass (19 before, 5 new, in PackedContainerTests):
    • a compressed console program is listed after the plain container, with the offset of the constant, stored_size, and the size, SHA-256, chunk list and name of the inflated container;
    • 13 records that must not be listed, each a subtest: a compressed container without a console program, bytes after the stream, a record cut short, each stored size off by one, an inflated size one too small and one too large, a stored size of the header alone, a stream that is no deflate, inflated bytes that are no container, two containers in one stream, a container followed by padding, and the constant at the very start of the file; then the unchanged record as the control;
    • a stream of stored blocks (deflate level 0) leaves the container listed once, as the plain container it also is;
    • --extract --json --verbose through main(): the inflated container is written, the plain container keeps the first place in index.json, and the JSON rows carry the fields above;
    • 2,000 random buffers with a damaged real record or a random header raise nothing.
  • The same file with the base commit's tool (an export of 6293c1c4f with only the test file replaced): 3 tests fail, the first, the control of the second and the fourth; the compressed program is not found (['PlainCS'] != ['PlainCS', 'PackedPS'], 1 container(s)). The other two new tests pass there too.
  • python3 -I tests/test_bvh_shaders_stage.py (13 tests; it runs the tool on synthetic DLLs) and tests/test_bvh_gpu_smoke.py (13 tests): pass.
  • The CI loop as ci.yml runs it (compileall, every tests/test_*.py outside tests/semantic, the semantic suite, the tracked-file guard), on the committed tree: one failing file, tests/test_imhex_patterns.py, which fails on the base commit too and is the only one there. Semantic suite: 470 files, 6,168 tests, 0 files failed, the same counts as the base.
  • python3 -I scripts/check_no_game_data.py: passes.

Not run: any game file (the executable, the DLLs), so no count of real records; the make_game.py BVH step on a real DLL; native Windows or macOS; the runtime build (no C++ or build file changes).

GPUs tested: none (a file scanner).

AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named.

Checklist

  • Based on upstream main 6293c1c4f, one commit.
  • One topic: the scan and the extraction of one more record form, with its tests and its paragraph in docs/embedded_shaders.md.
  • No game data, keys or decryption; the records in the tests are built by hand, and the stream is plain deflate.
  • No translator rule changed, so no row in docs/design.md.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1278 **Author:** [@Moriz82](https://github.com/Moriz82) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `split/tools-pe-shader-containers` --- ### 📝 Commits (1) - [`6e0743a`](https://github.com/ubiquitarianism/leonida/commit/6e0743af16f1217a89af8e4f90e41e1f096fcbea) pe_shader_containers: find console programs stored compressed (TOOLS-PE-SHADER-CONTAINERS) ### 📊 Changes **3 files changed** (+121 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/embedded_shaders.md` (+10 -0) 📝 `tests/test_pe_shader_containers.py` (+106 -0) 📝 `tools/pe_shader_containers.py` (+5 -1) </details> ### 📄 Description **Rebased onto `bfef489c` at `6e0743af`.** Main already recognizes the compressed envelope. This diff deduplicates a container discovered both as a plain hit and as a stored deflate block, with synthetic coverage. All 25 container tests passed. Claimed in the coordination issue as: TOOLS-PE-SHADER-CONTAINERS ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7144646343)). Part of the split of #984 into small pull requests. Depends on: none Overlaps: #984 is the parent integration. #694 (open, OLD-9775; #53 is its draft twin) numbers the stems of a multi-image `--extract` in sequence and stages the `--json` write. Merged three-way with it (its diff applied to the base, then merged into this branch) there are two one-line conflicts, both where each side adds an import at the same place (`import zlib` here; `import tempfile` in the tool and `from unittest import mock` in the test there). Everything else merges, the two changes to `extract()` included. #387 (open; #303 is closed) adds the `make_game.py` step that runs this tool on the executable; it does not change the tool, and this pull request does not add a build step. Its diff does not apply to this base, so no merge was tried. ### What and why `tools/pe_shader_containers.py` lists the DXBC containers that lie in an image as they are. A console program can also be stored compressed, and the scan did not see those: the image has no `DXBC` magic for a compressed one. The record is: a u32 stored size, the u32 constant `0x000DDCE7`, the stored size again, the u32 size of the container, then a raw deflate stream of the whole DXBC container. Both stored sizes count from the constant, so they include those 12 bytes. The stream is plain deflate; nothing is decrypted. `inspect()` now also looks for the constant and takes a record only when all of this holds: - both stored sizes are equal, larger than the 12 header bytes, inside the image and at most 64 MiB, and the container size is over 32 bytes and at most 64 MiB; - the stream ends exactly at the end of the record, with nothing after it; - it inflates to exactly the named size, never more (the inflater is stopped one byte past it); - the result is one DXBC container whose own total size is that size and which the existing chunk-table validation accepts; - that container holds a console program (`has_xbch`). The same record form also stores containers with nothing for the RDNA2 pipeline to translate; those are not listed. Such a record is listed **after** the plain containers, so those keep their order and therefore the file names `--extract` gives them. Its `offset` is that of the constant, `stored_size` is the stored size, and `size`, `sha256`, the chunk list and the name describe the inflated container, which is what `--extract` writes. A stream made of stored blocks holds the container as it is, where the plain scan finds it already; that container is listed once. The layout is the one the five-star-recomp project describes for the shader records of the game's effect tables (its note on shader containers); no code is taken from it. One point differs from that description and comes from the integration branch instead: there the stored size counts the 12 header bytes, and the tool requires the stream to end exactly at that size. **That was not re-measured for this pull request.** The integration reports reading two such pixel programs in the retail executable with this rule; here the rule is exercised on hand-built records only. If the size did not include the header, every real record would be rejected (the stream would be cut 12 bytes short), and the tool would behave as it does today. The same scan also runs where the tool is used today, on `XboxBvhBuilder.dll` in the BVH step. Whether that DLL holds such a record was not checked; a record that passes all the tests above would add a program to that step's output. ### Tested Linux (CachyOS, kernel 7.3.5), Python 3.14. One commit on `6293c1c4f`. - `python3 -I tests/test_pe_shader_containers.py`: 24 tests pass (19 before, 5 new, in `PackedContainerTests`): - a compressed console program is listed after the plain container, with the offset of the constant, `stored_size`, and the size, SHA-256, chunk list and name of the inflated container; - 13 records that must not be listed, each a subtest: a compressed container without a console program, bytes after the stream, a record cut short, each stored size off by one, an inflated size one too small and one too large, a stored size of the header alone, a stream that is no deflate, inflated bytes that are no container, two containers in one stream, a container followed by padding, and the constant at the very start of the file; then the unchanged record as the control; - a stream of stored blocks (deflate level 0) leaves the container listed once, as the plain container it also is; - `--extract --json --verbose` through `main()`: the inflated container is written, the plain container keeps the first place in `index.json`, and the JSON rows carry the fields above; - 2,000 random buffers with a damaged real record or a random header raise nothing. - The same file with the base commit's tool (an export of `6293c1c4f` with only the test file replaced): **3 tests fail**, the first, the control of the second and the fourth; the compressed program is not found (`['PlainCS'] != ['PlainCS', 'PackedPS']`, `1 container(s)`). The other two new tests pass there too. - `python3 -I tests/test_bvh_shaders_stage.py` (13 tests; it runs the tool on synthetic DLLs) and `tests/test_bvh_gpu_smoke.py` (13 tests): pass. - The CI loop as `ci.yml` runs it (compileall, every `tests/test_*.py` outside `tests/semantic`, the semantic suite, the tracked-file guard), on the committed tree: one failing file, `tests/test_imhex_patterns.py`, which fails on the base commit too and is the only one there. Semantic suite: 470 files, 6,168 tests, 0 files failed, the same counts as the base. - `python3 -I scripts/check_no_game_data.py`: passes. Not run: any game file (the executable, the DLLs), so no count of real records; the `make_game.py` BVH step on a real DLL; native Windows or macOS; the runtime build (no C++ or build file changes). GPUs tested: none (a file scanner). AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named. ### Checklist - [x] Based on upstream main `6293c1c4f`, one commit. - [x] One topic: the scan and the extraction of one more record form, with its tests and its paragraph in `docs/embedded_shaders.md`. - [x] No game data, keys or decryption; the records in the tests are built by hand, and the stream is plain deflate. - [x] No translator rule changed, so no row in `docs/design.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:20:49 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1312
No description provided.