Repository navigation
runtime: add an opt-in console profile for the OEM ConsoleMode read - #2650
Conversation
X2W_DEVICE_TYPE (with X2W_RUNTIME_PROXY) answers the title's reads of HKLM\Software\Microsoft\Windows NT\CurrentVersion\OEM\ConsoleMode: 6 = 0x60 (Series S), 7 = 0x64 (Series X), 1 = value missing (PC). Unset, every call goes to the real registry. The proxy rewrites five registry imports of the EXE and package helpers (regular IAT and GetProcAddress by name); visit_imports_with takes a classifier for them and visit_imports keeps its own behaviour. Opening the key and reading the value are logged a few times either way. New fixture with a negative control: startup_console_mode, against fake registry functions; the control leaves the switch unset for the answered cases.
tedin7
left a comment
There was a problem hiding this comment.
Review of head bac83cb against main (comment only).
Code read: console_mode.h, registry_console_mode.inl, the runtime_gpa_patch.h classifier change, the runtime_proxy.cpp wiring, and tests/startup_console_mode_check.cpp.
- The switch is opt-in. Unset, or any number other than 1, 6 or 7, passes every call to the real registry.
- The
visit_imports_withrefactor keepsvisit_importsunchanged: it passes the old classifier through. The existingstartup_runtime_gpa_patchtests cover that. - The fixture is source-built, goes through
GetProcAddresslike a title would, and uses fake registry functions. It has a negative control (--control,PASS_REGULAR_EXPRESSION "FAIL: "). So the "source-built regression test plus negative control" requirement is met. - Small note, not a blocker:
oem_keysholds 16 handles. When it is full, a further OEM key is not tracked and its reads go to the real registry. That is a safe fallback, but a log line when it happens would help. - The meaning of 0x60 / 0x64 / missing comes from public notes of another project. The PR says this itself.
Commands run locally on the exact head:
python3 -B tests/docs_links_check.py,python3 -B tests/bidi_controls_check.py,git diff --check origin/main...HEAD: all clean.- The fixture includes
<windows.h>, so it does not build on Linux. I could not run it or a mutation of it here, and I did not run Win2025. The test results in the PR body are the author's.
Merge: the PR says that, with a local console executable, each value changed which start-up path the title took (#2591). This is a start-up claim from running the game, and I cannot check it. I am not merging this. The merge stays with MasterDomino or @R0Y00, who can verify on the game.
AI-assisted; commands listed were executed locally.
R0Y00
left a comment
There was a problem hiding this comment.
The registry hooks currently match function name alone on both routes. patch_registry_imports ignores the imported DLL argument, and hooked_get_proc_address passes only the export name and address into registry_hook_for. Because remember_registry saves the first address globally, a package DLL exporting the same name can change which implementation later calls reach, even with X2W_DEVICE_TYPE unset. Please restrict both routes to the supported Windows registry providers, preserving the existing provider identity checks on the other proxy hooks. Add a source-built decoy DLL or synthetic IAT provider with the same export name and distinct result to verify the decoy is untouched, including with the switch unset.
Both console-mode routes matched the import name alone, so a package DLL exporting RegQueryValueExW or RegOpenKeyExW could be hooked and, because the first address is kept, become the registry later calls reach. The IAT route now needs the import DLL to be advapi32.dll, kernelbase.dll, kernel32.dll or an api-ms-win-core-registry-* API set, and the bound address to lie in the system-directory copy of one of those modules. The GetProcAddress route needs the module to be one of them. Only addresses inside them are remembered as the real function. startup_console_mode loads a source-built decoy DLL with the same export names and a distinct result. With X2W_DEVICE_TYPE unset and set, its GetProcAddress lookups and synthetic IAT entries naming it (or naming advapi32.dll but bound to it) stay untouched, and the hooks still reach the fake registry. startup_console_mode_provider_control matches by name alone and must fail. startup_runtime_proxy_scope checks the same through the real loader against advapi32.dll. A full 16-entry OEM handle table is now logged once.
|
@R0Y00 thanks, addressed in 0ac58f7 (new commit on top of bac83cb, no rebase). Both routes are now limited to the Windows registry providers (
Decoy coverage
tedin7's note: when all 16
Commands and results (commit 0ac58f7; NVIDIA GeForce RTX 5090, driver 32.0.16.1088, Windows 10.0.26200.9974, D3D12 debug layer off; none of the tests below use the GPU) . .\tools\dev.ps1
cmake --preset release
cmake --build --preset release
ctest --preset release --no-tests=error -R 'console_mode|gpa_patch|proxy' -V6/6 passed: ctest --preset release -j 6 --no-tests=error -R '^startup_' -E '_hardware$|^startup_audio_'640/641 passed, plus 6 not run (skip/disabled): python -B tests/docs_links_check.py # 19 Markdown files, 509 links: ok
python -B tests/bidi_controls_check.py # 1869 files: no bidirectional controls
git diff --check origin/main...HEAD # cleanThis change was AI-assisted. |
R0Y00
left a comment
There was a problem hiding this comment.
Re-reviewed the bound-address plus system-module checks for IAT and GetProcAddress at 0ac58f7. Windows Release passed six targeted CTests, including the real loaded runtime-proxy host. The decoy kept its sentinel with the switch unset and with X2W_DEVICE_TYPE=7. The genuine advapi32 lookup reached the system registry, and both the registry name-only mutant and the original provider-scope mutant were detected. This resolves my provider-identity finding. The startup behavior remains an opt-in experiment.
Change
Slice 4 of 4 from #2591: the opt-in profile.
X2W_DEVICE_TYPE(withX2W_RUNTIME_PROXY=1) answers the title's reads ofHKLM\Software\Microsoft\Windows NT\CurrentVersion\OEM\ConsoleMode:671Unset, every call goes to the real registry as before.
console_mode.hholds the value table and recognises the key and value.registry_console_mode.inlholds hooks forRegOpenKeyExW,RegOpenKeyW,RegQueryValueExW,RegGetValueWandRegCloseKey. They answer only a ConsoleMode read under the OEM key while theswitch names a known console. Every other call is passed through. Opening the key and reading the
value are logged a few times either way.
runtime_gpa_patch.h:visit_imports_withtakes a classifier, so the proxy can rewrite theregistry imports of the EXE and package helpers.
visit_importskeeps its old behaviour.runtime_proxy.cpppatches those imports and returns the hooks fromGetProcAddressby name.The switch changes only what the registry reads answer. On the Series S profile, the path a title
then takes meets desktop refusals that the other profiles do not reach. Those are separate slices:
device slot 76 and view dimensions.
R9G9B9E5_SHAREDEXPwith unordered access is already covered onmain. This slice claims nothing about what runs after the profile is chosen.Refs #2591. Independent of the other three slices. Comparing a combined start-up build needs all four.
Verification
Build: this branch, one commit
bac83cb2onmainat02368737. From the worktree in PowerShell:. .\tools\dev.ps1,cmake --preset release,cmake --build --preset release(Python envout/pe-envfromrequirements-dev.txt).Environment: NVIDIA GeForce RTX 5090, driver 32.0.16.1088, Windows 10.0.26200.9974. The fixture
creates no device and replaces the registry functions with fakes, so no machine state is read or
changed.
ctest --preset release --no-tests=error -R '^startup_(console_mode(_control)?|runtime_gpa_patch(_name_only_control)?|runtime_proxy_scope.*)$' -V: 5/5 passed (startup_console_modeand its control, which prints 5FAIL:lines;startup_runtime_gpa_patchand itsname_onlycontrol;startup_runtime_proxy_scope).ctest --preset release -j 6 --no-tests=error -R '^startup_' -E '_hardware$|^startup_audio_': 640 tests, 633 passed, 6 skipped (capability, exit 77), 1 failed:startup_storage_worker_starttimed out at 60 s under-j 6; rerun alone (ctest --preset release --no-tests=error -R '^startup_storage_worker_start$') it passed in 13.9 s, as on the slice-1 build (14.0 s). This change does not touch it.python -B tests/docs_links_check.py: pass (19 Markdown files, 509 links).python -B tests/bidi_controls_check.py: pass.git diff --check origin/main...HEAD: clean.Evidence
startup_console_mode(from #2591, unchanged) reaches the hooks throughGetProcAddress, the way atitle does, against fake registry functions that report the value missing:
6and7: answer 0x60 and 0x64 without calling the fake.1: answers missing.--controlleavesX2W_DEVICE_TYPEunset for the answered cases, so those rows printFAIL:. Thetest is registered with
PASS_REGULAR_EXPRESSION "FAIL: ". The existingstartup_runtime_gpa_patchand its
name_onlycontrol pass unchanged, which shows the classifier refactor keeps the proxy's ownimport walk the same.
Hypothesis: what the
ConsoleModevalues mean on the console comes from public notes, not from ameasurement here. With a local console executable (not included), each value changed which start-up
path the title took (#2591).
Checklist
This change was AI-assisted.