HLE: a null or empty subkey opens the emulated OEM key itself (#765) #2390

Open
KainanP wants to merge 2 commits from upstream-pr/2392 into main
KainanP commented 2026-11-25 12:39:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-25T12:39:33Z.


Fixes #765.

This carries Peppacodes' fix from the issue (branch fix/oem-key-empty-subkey, 8e9f9b3), cherry-picked unchanged onto current main with their name kept on the commit, plus one commit of mine that settles the open point from the thread (a null phkResult with a non-empty subkey). The earlier PRs for this (#1431 and the bundle #1603) were closed without being merged, and no open PR covers it.

Problem. open in crates/victory-hle/src/modules/xsystem.rs returned ERROR_FILE_NOT_FOUND for any open whose root is our emulated OEM key, including a null or empty subkey. Microsoft documents that case as opening the key itself: for RegOpenKeyW, "If this parameter is NULL or a pointer to an empty string, the function returns the same handle that was passed in"; for RegOpenKeyExW, phkResult "receives a new handle to the opened key" (the same handle for a predefined key).

Change

  • c76edcc (Peppacodes): a null or empty subkey under the OEM key gives back the OEM key; any other subkey is still not found (the key has none).
  • 7955705 (mine): the null phkResult check now comes before the path check, so a non-empty subkey with nowhere to put the key returns ERROR_INVALID_PARAMETER, not ERROR_FILE_NOT_FOUND. Microsoft's pages do not name the error for a null phkResult, so the test asks the host's advapi32 the same calls on a host key and holds ours to the host's answers. On Windows 11 (build 26200) the host returns ERROR_INVALID_PARAMETER (87) for a null phkResult whether the subkey is missing, empty or null.

Tests (both in device_type::tests, Windows only, like the module)

  • a_null_or_empty_path_opens_the_key_itself (Peppacodes): RegOpenKeyW and RegOpenKeyExW with a null and an empty subkey, on our key and on a host key for comparison.
  • nowhere_to_put_the_key_is_an_invalid_parameter (new): a null phkResult with a missing, an empty and a null subkey, on our key and the host's, then a missing subkey with a real phkResult is still ERROR_FILE_NOT_FOUND.

With open as on main, both fail: left: 2, right: 0 and left: 2, right: 87. With only Peppacodes' commit, the new test fails on the missing subkey (2, not 87). With both commits, both pass.

Checked on Windows 11 x64, main 940d32f + these two commits:

  • cargo test -p victory-hle --locked: 145 passed, 0 failed (plus the 3 integration tests)
  • cargo clippy --workspace --all-targets --locked -- -D warnings and the --all-features variant: clean
  • cargo xtask policy: asset policy, 182 files ok
  • rustfmt --edition 2024 --check on the changed file: clean

Not covered: in-game behavior (the title opens the full path, as the issue says, so this does not change what it reads); a caller reopening an already-open OEM key with a null or empty subkey is exercised only by the unit test. #2285 (open) touches the same module's DLL list, not open; the two do not overlap.

No game data used. AI use: Claude Code (Claude Opus 5.5).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6604676971 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2392). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-25T12:39:33Z. --- Fixes #765. This carries Peppacodes' fix from the issue (branch `fix/oem-key-empty-subkey`, `8e9f9b3`), cherry-picked unchanged onto current `main` with their name kept on the commit, plus one commit of mine that settles the open point from the thread (a null `phkResult` with a non-empty subkey). The earlier PRs for this (#1431 and the bundle #1603) were closed without being merged, and no open PR covers it. **Problem.** `open` in `crates/victory-hle/src/modules/xsystem.rs` returned `ERROR_FILE_NOT_FOUND` for any open whose root is our emulated OEM key, including a null or empty subkey. Microsoft documents that case as opening the key itself: for [`RegOpenKeyW`](https://learn.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyw), "If this parameter is NULL or a pointer to an empty string, the function returns the same handle that was passed in"; for [`RegOpenKeyExW`](https://learn.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw), `phkResult` "receives a new handle to the opened key" (the same handle for a predefined key). **Change** - `c76edcc` (Peppacodes): a null or empty subkey under the OEM key gives back the OEM key; any other subkey is still not found (the key has none). - `7955705` (mine): the null `phkResult` check now comes before the path check, so a non-empty subkey with nowhere to put the key returns `ERROR_INVALID_PARAMETER`, not `ERROR_FILE_NOT_FOUND`. Microsoft's pages do not name the error for a null `phkResult`, so the test asks the host's `advapi32` the same calls on a host key and holds ours to the host's answers. On Windows 11 (build 26200) the host returns `ERROR_INVALID_PARAMETER` (87) for a null `phkResult` whether the subkey is missing, empty or null. **Tests** (both in `device_type::tests`, Windows only, like the module) - `a_null_or_empty_path_opens_the_key_itself` (Peppacodes): `RegOpenKeyW` and `RegOpenKeyExW` with a null and an empty subkey, on our key and on a host key for comparison. - `nowhere_to_put_the_key_is_an_invalid_parameter` (new): a null `phkResult` with a missing, an empty and a null subkey, on our key and the host's, then a missing subkey with a real `phkResult` is still `ERROR_FILE_NOT_FOUND`. With `open` as on `main`, both fail: `left: 2, right: 0` and `left: 2, right: 87`. With only Peppacodes' commit, the new test fails on the missing subkey (2, not 87). With both commits, both pass. Checked on Windows 11 x64, `main` `940d32f` + these two commits: - `cargo test -p victory-hle --locked`: 145 passed, 0 failed (plus the 3 integration tests) - `cargo clippy --workspace --all-targets --locked -- -D warnings` and the `--all-features` variant: clean - `cargo xtask policy`: asset policy, 182 files ok - `rustfmt --edition 2024 --check` on the changed file: clean **Not covered:** in-game behavior (the title opens the full path, as the issue says, so this does not change what it reads); a caller reopening an already-open OEM key with a null or empty subkey is exercised only by the unit test. #2285 (open) touches the same module's DLL list, not `open`; the two do not overlap. No game data used. AI use: Claude Code (Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
cloph-dsp commented 2026-11-25 13:03:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T13:00:43Z.


Independent local verification (Windows, Rust 1.100.0/MSVC, head 7955705, no game data): cargo test --locked -p victory-hle --lib modules::xsystem::device_type::tests -> 4 tests passed on this PR (a_null_or_empty_path_opens_the_key_itself, nowhere_to_put_the_key_is_an_invalid_parameter, other_keys_reach_the_host, titles_read_the_chosen_model), exit 0; the same command on main 940d32f runs 2 tests (titles_read_the_chosen_model, other_keys_reach_the_host), confirming this PR adds the two null/empty-path and invalid-parameter cases. Only a pre-existing fetch_update deprecation warning. I did not exercise a real title registry path. AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only unit tests). No game data used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163165461 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2392#issuecomment-7163165461). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T13:00:43Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, head 7955705, no game data): `cargo test --locked -p victory-hle --lib modules::xsystem::device_type::tests` -> 4 tests passed on this PR (`a_null_or_empty_path_opens_the_key_itself`, `nowhere_to_put_the_key_is_an_invalid_parameter`, `other_keys_reach_the_host`, `titles_read_the_chosen_model`), exit 0; the same command on main 940d32f runs 2 tests (`titles_read_the_chosen_model`, `other_keys_reach_the_host`), confirming this PR adds the two null/empty-path and invalid-parameter cases. Only a pre-existing `fetch_update` deprecation warning. I did not exercise a real title registry path. AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only unit tests). No game data used.
Xvania7 commented 2026-11-25 14:06:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T13:02:34Z.

Review: APPROVED


Windows verification on real hardware: Windows 10 x64, Rust 1.98.1.

Checked out 7955705 into an isolated tree:

  • cargo test -p victory-hle device_type::tests: 4/4 passed:
    • titles_read_the_chosen_model: ok
    • other_keys_reach_the_host: ok
    • nowhere_to_put_the_key_is_an_invalid_parameter: ok
    • a_null_or_empty_path_opens_the_key_itself: ok
  • cargo clippy -p victory-hle --target-dir ... -- -D warnings: 0 warnings, clean.
  • cargo run -p xtask -- policy: clean (asset policy: 182 files ok).

Ordering the null phkResult check before the path validation accurately aligns with Win32 advapi32 behavior returning ERROR_INVALID_PARAMETER (87) across missing/null/empty subkeys. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6058097252 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2392#pullrequestreview-6058097252). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T13:02:34Z. **Review:** APPROVED --- Windows verification on real hardware: Windows 10 x64, Rust 1.98.1. Checked out `7955705` into an isolated tree: - `cargo test -p victory-hle device_type::tests`: 4/4 passed: - `titles_read_the_chosen_model`: ok - `other_keys_reach_the_host`: ok - `nowhere_to_put_the_key_is_an_invalid_parameter`: ok - `a_null_or_empty_path_opens_the_key_itself`: ok - `cargo clippy -p victory-hle --target-dir ... -- -D warnings`: 0 warnings, clean. - `cargo run -p xtask -- policy`: clean (`asset policy: 182 files ok`). Ordering the null `phkResult` check before the path validation accurately aligns with Win32 `advapi32` behavior returning `ERROR_INVALID_PARAMETER` (87) across missing/null/empty subkeys. LGTM.
catminou4 commented 2026-11-25 14:06:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T13:19:21Z.

Review: COMMENTED


HLE: null/empty subkey opens the emulated OEM key itself; null out-param checked first (host order). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.

<!-- greyfinch-sync:Marvisak/VIctory:review:6058344332 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2392#pullrequestreview-6058344332). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T13:19:21Z. **Review:** COMMENTED --- HLE: null/empty subkey opens the emulated OEM key itself; null out-param checked first (host order). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
Marvisak commented 2026-11-25 15:04:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:00:14Z.


Automated triage for the maintainers.

Merge candidate. device_type::open (crates/victory-hle/src/modules/xsystem.rs) now opens the emulated OEM key itself for a null or empty subkey, as Microsoft documents for RegOpenKeyW/RegOpenKeyExW. It also returns ERROR_INVALID_PARAMETER for a null phkResult before looking at the path. Other subkeys still give ERROR_FILE_NOT_FOUND. I checked that RegCloseKey in the same module already treats the OEM pseudo-key as ours, so closing the returned handle is safe. The tests hold our answers to the host advapi32's for the same calls on a real key, which is the evidence for the error code the documentation does not name. It carries the issue author's commit with their name kept.

As the description says, the title opens the full path, so this is API correctness rather than a visible fix.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166149564 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2392#issuecomment-7166149564). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:00:14Z. --- <!-- victory-triage v1 head=795570572cebd0c9548d7d79ee36f380b93420c9 verdict=merge-candidate at=2026-11-25T15:00:03Z --> Automated triage for the maintainers. **Merge candidate.** `device_type::open` (`crates/victory-hle/src/modules/xsystem.rs`) now opens the emulated OEM key itself for a null or empty subkey, as Microsoft documents for `RegOpenKeyW`/`RegOpenKeyExW`. It also returns `ERROR_INVALID_PARAMETER` for a null `phkResult` before looking at the path. Other subkeys still give `ERROR_FILE_NOT_FOUND`. I checked that `RegCloseKey` in the same module already treats the OEM pseudo-key as ours, so closing the returned handle is safe. The tests hold our answers to the host `advapi32`'s for the same calls on a real key, which is the evidence for the error code the documentation does not name. It carries the issue author's commit with their name kept. As the description says, the title opens the full path, so this is API correctness rather than a visible fix. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-26 03:03:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:20:42Z.

Review: COMMENTED


Reviewed and verified against main (63bcca43) on Windows 11 — clean Win32 parity fix and ready to merge:

  • Checking out.is_null() (INVALID_PARAMETER) before path handling and returning oem() on null/empty subkey matches real Windows RegOpenKeyExW behavior, directly cross-checked against Software\Microsoft\Windows NT\CurrentVersion in the new unit tests.

Local verification:

  • cargo test --locked -p victory-hle: 154/154 unit (xsystem 6/6) + 2/2 integration tests passed
  • cargo clippy --all-targets -p victory-hle -- -D warnings + cargo xtask policy (191 files ok): 0 warnings
<!-- greyfinch-sync:Marvisak/VIctory:review:6067704974 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2392#pullrequestreview-6067704974). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T02:20:42Z. **Review:** COMMENTED --- Reviewed and verified against `main` (`63bcca43`) on Windows 11 — clean Win32 parity fix and ready to merge: - Checking `out.is_null()` (`INVALID_PARAMETER`) before path handling and returning `oem()` on null/empty subkey matches real Windows `RegOpenKeyExW` behavior, directly cross-checked against `Software\Microsoft\Windows NT\CurrentVersion` in the new unit tests. **Local verification**: - `cargo test --locked -p victory-hle`: **154/154 unit** (`xsystem` **6/6**) + **2/2 integration tests passed** - `cargo clippy --all-targets -p victory-hle -- -D warnings` + `cargo xtask policy` (`191 files ok`): 0 warnings
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/2392:upstream-pr/2392'
git switch 'upstream-pr/2392'

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/2392'
git switch 'upstream-pr/2392'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2392'
git switch 'upstream-pr/2392'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2392'
git switch 'main'
git merge --squash 'upstream-pr/2392'
git switch 'main'
git merge --ff-only 'upstream-pr/2392'
git switch 'main'
git merge 'upstream-pr/2392'
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
Marvisak/VIctory!2390
No description provided.