HLE: registry lookups through kernelbase.dll reach the device-type overrides #2141

Open
github-bot wants to merge 1 commit from github-bot/gh-2141 into main AGit
Owner

@⁠BastienRodz on GitHub · 2026-11-25 05:54 UTC · original
BastienRodz:hle/kernelbase-registry → main · +88 −1 · 1 files · 1 commits · open

What's wrong

xsystem::device_type serves the console's OEM\ConsoleMode registry value, but its module only lists advapi32.dll and api-ms-win-core-registry-*. GetProcAddress on a host module resolves our overrides by the module's file name (kernel::host_override), and on Windows both the registry API set and kernelbase.dll itself are kernelbase.dll. So GetProcAddress(LoadLibraryW("api-ms-win-core-registry-l1-1-0.dll"), "RegOpenKeyExW") returns the host's function, and the title reads the host registry instead of the emulated key. Imports straight from kernelbase.dll go to the host too. kernel::module() and files::module() already list kernelbase.dll next to their API sets for this reason.

What the fix does

Adds kernelbase.dll to device_type::module().dlls. Nothing else changes: other keys still reach the host through the existing fallthrough.

Tests

New modules::xsystem::device_type::tests::kernelbase_registry_lookups_get_our_overrides:

  • HleResolver::classify("kernelbase.dll", …) gives Hle for RegOpenKeyExW, RegQueryValueExW and RegCloseKey;
  • GetProcAddress on GetModuleHandleW("kernelbase.dll") and on LoadLibraryW("api-ms-win-core-registry-l1-1-0.dll") returns our functions, and reading ConsoleMode through them gives the chosen model.

On main (940d32f) it fails at the first check (left: Some(Host), right: Some(Hle)); with the classify check removed, the GetProcAddress check fails as well (host address instead of ours). With the fix the test and the rest of modules::xsystem::, modules::kernel:: and registry:: pass (Wine 10, x86_64-pc-windows-msvc).

windows-latest run on the fork: https://github.com/BastienRodz/VIctory/actions/runs/45556724719

Not tested

No title run. Per AgneyaK's check of the title's import table, Grand Theft Auto VI 1.0.2.1 binds RegOpenKeyW / RegQueryValueExW / RegCloseKey from advapi32.dll (already served) and its only run-time registry lookup is advapi32.dll!RegGetValueW for a GDK setting, so this change does not affect that title. It only makes the kernelbase.dll / API-set path agree with the advapi32.dll one.

Fixes #2140

AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used.

🤖 Generated with Claude Code

**@⁠BastienRodz** on GitHub · 2026-11-25 05:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2141) `BastienRodz:hle/kernelbase-registry` → `main` · +88 −1 · 1 files · 1 commits · open ### What's wrong `xsystem::device_type` serves the console's `OEM\ConsoleMode` registry value, but its module only lists `advapi32.dll` and `api-ms-win-core-registry-*`. `GetProcAddress` on a host module resolves our overrides by the module's file name (`kernel::host_override`), and on Windows both the registry API set and `kernelbase.dll` itself are `kernelbase.dll`. So `GetProcAddress(LoadLibraryW("api-ms-win-core-registry-l1-1-0.dll"), "RegOpenKeyExW")` returns the host's function, and the title reads the host registry instead of the emulated key. Imports straight from `kernelbase.dll` go to the host too. `kernel::module()` and `files::module()` already list `kernelbase.dll` next to their API sets for this reason. ### What the fix does Adds `kernelbase.dll` to `device_type::module().dlls`. Nothing else changes: other keys still reach the host through the existing fallthrough. ### Tests New `modules::xsystem::device_type::tests::kernelbase_registry_lookups_get_our_overrides`: - `HleResolver::classify("kernelbase.dll", …)` gives `Hle` for `RegOpenKeyExW`, `RegQueryValueExW` and `RegCloseKey`; - `GetProcAddress` on `GetModuleHandleW("kernelbase.dll")` and on `LoadLibraryW("api-ms-win-core-registry-l1-1-0.dll")` returns our functions, and reading `ConsoleMode` through them gives the chosen model. On `main` (940d32f) it fails at the first check (`left: Some(Host)`, `right: Some(Hle)`); with the classify check removed, the `GetProcAddress` check fails as well (host address instead of ours). With the fix the test and the rest of `modules::xsystem::`, `modules::kernel::` and `registry::` pass (Wine 10, x86_64-pc-windows-msvc). windows-latest run on the fork: https://github.com/BastienRodz/VIctory/actions/runs/45556724719 ### Not tested No title run. Per AgneyaK's check of the title's import table, Grand Theft Auto VI 1.0.2.1 binds `RegOpenKeyW` / `RegQueryValueExW` / `RegCloseKey` from `advapi32.dll` (already served) and its only run-time registry lookup is `advapi32.dll!RegGetValueW` for a GDK setting, so this change does not affect that title. It only makes the `kernelbase.dll` / API-set path agree with the `advapi32.dll` one. Fixes #2140 AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Include kernelbase.dll in xsystem::device_type::module().dlls alongside advapi32.dll and api-ms-win-core-registry-*, matching kernel::module() and files::module(). On Windows, api-ms-win-core-registry-l1-1-0.dll resolves to kernelbase.dll, so dynamic lookups via GetProcAddress (through kernel::host_override) and direct imports from kernelbase.dll bypassed the emulated OEM ConsoleMode registry key and fell through to the host registry.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:55:51 +00:00
Author
Owner

@⁠AgneyaK on GitHub · 2026-11-25 06:13 UTC · original

For scope: Grand Theft Auto VI 1.0.2.1 doesn't take this path, so the PR changes nothing for it. It's still right in principle for other titles. From the title's own import table and code (image b99f876b…):

  • Imported registry functions: ADVAPI32.dll → RegOpenKeyW, RegQueryValueExW, RegCloseKey, and nothing from kernelbase.dll or the registry API sets. The ConsoleMode read goes through those, which device_type already serves (device type read at debug level).
  • The one registry function it resolves at run time is RegGetValueW. At +0x55e27b4 it calls LoadLibraryExA("advapi32.dll", 0, 0x800) and then GetProcAddress(…, "RegGetValueW"). The only caller (+0x55e286c) reads HKLM\Software\Microsoft\GamingServices → ForceUseLocalServices (RRF_RT_REG_DWORD). That's GDK library code, not the console model. It's on advapi32.dll, not kernelbase.dll, and RegGetValueW isn't one of device_type's exports, so it reaches the host with or without this PR. On a PC that value is normally absent, so the check reads false.

So nothing in this title reaches the emulated key through kernelbase.dll or GetProcAddress. The PR is a correct guard for titles that do; it just won't show up in a Grand Theft Auto VI run.

AI use: Claude Code (Claude Opus 5.5) read the title's import table and disassembled the image locally; no game data beyond addresses, import names and two registry names the title's library code uses.

**@⁠AgneyaK** on GitHub · 2026-11-25 06:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2141#issuecomment-7154577813) For scope: **Grand Theft Auto VI 1.0.2.1 doesn't take this path, so the PR changes nothing for it.** It's still right in principle for other titles. From the title's own import table and code (image `b99f876b…`): - **Imported registry functions:** `ADVAPI32.dll` → `RegOpenKeyW`, `RegQueryValueExW`, `RegCloseKey`, and nothing from `kernelbase.dll` or the registry API sets. The `ConsoleMode` read goes through those, which `device_type` already serves (`device type read` at debug level). - **The one registry function it resolves at run time** is `RegGetValueW`. At `+0x55e27b4` it calls `LoadLibraryExA("advapi32.dll", 0, 0x800)` and then `GetProcAddress(…, "RegGetValueW")`. The only caller (`+0x55e286c`) reads `HKLM\Software\Microsoft\GamingServices` → `ForceUseLocalServices` (`RRF_RT_REG_DWORD`). That's GDK library code, not the console model. It's on `advapi32.dll`, not `kernelbase.dll`, and `RegGetValueW` isn't one of `device_type`'s exports, so it reaches the host with or without this PR. On a PC that value is normally absent, so the check reads false. So nothing in this title reaches the emulated key through `kernelbase.dll` or `GetProcAddress`. The PR is a correct guard for titles that do; it just won't show up in a Grand Theft Auto VI run. AI use: Claude Code (Claude Opus 5.5) read the title's import table and disassembled the image locally; no game data beyond addresses, import names and two registry names the title's library code uses.
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-25 06:15 UTC · original

Thanks for checking the import table, that answers the open question in "Not tested". I've updated the description: the title binds RegOpenKeyW / RegQueryValueExW / RegCloseKey from advapi32.dll, which device_type already serves, so this PR doesn't change anything for it. What it does is make kernelbase.dll and the registry API set behave like advapi32.dll for lookups by name, the same way kernel and files already handle it. Whether that's worth carrying is the maintainer's call.

**@⁠BastienRodz** on GitHub · 2026-11-25 06:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2141#issuecomment-7154597997) Thanks for checking the import table, that answers the open question in "Not tested". I've updated the description: the title binds `RegOpenKeyW` / `RegQueryValueExW` / `RegCloseKey` from `advapi32.dll`, which `device_type` already serves, so this PR doesn't change anything for it. What it does is make `kernelbase.dll` and the registry API set behave like `advapi32.dll` for lookups by name, the same way `kernel` and `files` already handle it. Whether that's worth carrying is the maintainer's call.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 07:31 UTC · original

Verified locally on Windows (MSVC, pinned 1.98.1): the new test kernelbase_registry_lookups_get_our_overrides passes, and it covers both lookup paths from the issue — direct kernelbase.dll imports via HleResolver::classify, and GetProcAddress on both kernelbase.dll and the api-ms-win-core-registry-l1-1-0.dll handle (whose file name resolves to kernelbase.dll in host_override).

Checked for export collisions: kernel and files modules also serve kernelbase.dll but export no Reg* names, so registry::lookup's first match is unambiguous.

**@⁠kotekompotek** on GitHub · 2026-11-25 07:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2141#issuecomment-7155954922) Verified locally on Windows (MSVC, pinned 1.98.1): the new test `kernelbase_registry_lookups_get_our_overrides` passes, and it covers both lookup paths from the issue — direct `kernelbase.dll` imports via `HleResolver::classify`, and `GetProcAddress` on both `kernelbase.dll` and the `api-ms-win-core-registry-l1-1-0.dll` handle (whose file name resolves to kernelbase.dll in `host_override`). Checked for export collisions: `kernel` and `files` modules also serve `kernelbase.dll` but export no `Reg*` names, so `registry::lookup`'s first match is unambiguous.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:52 UTC · original

Automated triage for the maintainers.

Merge candidate. This adds kernelbase.dll to xsystem::device_type::module().dlls. With it, GetProcAddress on kernelbase or the registry API set (which kernel::host_override resolves by the module's file name, kernelbase.dll) reaches our Reg* overrides. kernel and files already list kernelbase for the same reason, and no other module exports Reg* names, so registry::lookup is unambiguous. The test covers both classify and GetProcAddress. CI passes.

Note that AgneyaK's import-table check shows Grand Theft Auto VI 1.0.2.1 does not take this path. The change only makes the kernelbase path behave like the advapi32.dll one.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2141#issuecomment-7160279058) <!-- victory-triage v1 head=92d75e4d6db53e2605e2e253e205e101d1cc8b96 verdict=merge-candidate at=2026-11-25T10:51:57Z --> Automated triage for the maintainers. Merge candidate. This adds `kernelbase.dll` to `xsystem::device_type::module().dlls`. With it, `GetProcAddress` on kernelbase or the registry API set (which `kernel::host_override` resolves by the module's file name, `kernelbase.dll`) reaches our `Reg*` overrides. `kernel` and `files` already list kernelbase for the same reason, and no other module exports `Reg*` names, so `registry::lookup` is unambiguous. The test covers both `classify` and `GetProcAddress`. CI passes. Note that AgneyaK's import-table check shows Grand Theft Auto VI 1.0.2.1 does not take this path. The change only makes the kernelbase path behave like the `advapi32.dll` one. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:41 UTC · original

Code review and Windows 11 verification at head 92d75e4d6db5 merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-hle/src/modules/xsystem.rs:270-285, 435-515):
    • Adding "kernelbase.dll" to device_type::module().dlls shares the exact same 4 registry exports (RegOpenKeyW, RegOpenKeyExW, RegQueryValueExW, RegCloseKey) as advapi32.dll and api-ms-win-core-registry-*, while non-overridden keys continue forwarding through host!("advapi32.dll", ...) without re-entering HLE kernelbase.dll.
    • Confirmed registry::tests::export_names_are_unique_per_dll_pattern passes with zero export collisions across kernelbase.dll HLE modules.
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-hle --tests -- -D warnings: 0 warnings
    • cargo test --locked -p victory-hle -- --test-threads=1: 155/155 passed (including kernelbase_registry_lookups_get_our_overrides).

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2141#issuecomment-7180032294) Code review and Windows 11 verification at head `92d75e4d6db5` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review (`crates/victory-hle/src/modules/xsystem.rs:270-285, 435-515`)**: - Adding `"kernelbase.dll"` to `device_type::module().dlls` shares the exact same 4 registry exports (`RegOpenKeyW`, `RegOpenKeyExW`, `RegQueryValueExW`, `RegCloseKey`) as `advapi32.dll` and `api-ms-win-core-registry-*`, while non-overridden keys continue forwarding through `host!("advapi32.dll", ...)` without re-entering HLE `kernelbase.dll`. - Confirmed `registry::tests::export_names_are_unique_per_dll_pattern` passes with zero export collisions across `kernelbase.dll` HLE modules. - **Verified (Windows 11, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-hle --tests -- -D warnings`: 0 warnings - `cargo test --locked -p victory-hle -- --test-threads=1`: **155/155 passed** (including `kernelbase_registry_lookups_get_our_overrides`). LGTM.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2141/head:github-bot/gh-2141'
git switch 'github-bot/gh-2141'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2141'
git switch 'github-bot/gh-2141'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2141'
git switch 'github-bot/gh-2141'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2141'
git switch 'main'
git merge --squash 'github-bot/gh-2141'
git switch 'main'
git merge --ff-only 'github-bot/gh-2141'
git switch 'main'
git merge 'github-bot/gh-2141'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2141
No description provided.