HLE: GetModuleHandleEx finds the title's modules, not the host's #2506

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

@⁠cryst4lpepsi on GitHub · 2026-11-25 14:59 UTC · original
cryst4lpepsi:hle/get-module-handle-ex → main · +154 −1 · 2 files · 1 commits · open

What

GetModuleHandleA/W, LoadLibrary* and GetProcAddress give a title its own modules, but GetModuleHandleExA/W had no override, so imports of them (and GetProcAddress lookups) were bound to the host:

  • With no name they returned victory.exe, not the title's image.
  • Title DLLs and console modules (xgameruntime.dll) were looked up under host names, not ours.
  • A host DLL outside HostPolicy was found if anything in our process had loaded it.

Both now use the same lookup as GetModuleHandle. Lookups by address (FROM_ADDRESS), allowed host DLLs and invalid arguments still go to the host. No reference is taken on title images or pseudo modules, matching FreeLibrary, which never drops one.

I have no copy of the title, so I haven't checked whether it calls these.

An AI tool (Claude Code) wrote this change.

Tested

Windows 11, Rust 1.98.1, rebased on 940d32f:

  • cargo test -p victory-hle --locked: all pass, three runs (144 unit tests, plus the integration tests). With the two exports removed, the new unit test fails. The no-name case has its own test process, because the main image is process-wide.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean.
  • cargo test --workspace --locked: passes except in victory-gpu (aborts) and victory-shader (6 hardware tests), neither of which depends on victory-hle. Without this change, 940d32f fails the same way on this machine (AMD Radeon iGPU + RTX 3050 Ti Laptop): the same 6 shader tests and the same victory-gpu abort. One victory-gpu test, null_3d_uav_is_accepted_by_the_device, was reported failed only in the run with the change.
  • cargo xtask policy: asset policy: 183 files ok. Nothing from the game was used.
**@⁠cryst4lpepsi** on GitHub · 2026-11-25 14:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2506) `cryst4lpepsi:hle/get-module-handle-ex` → `main` · +154 −1 · 2 files · 1 commits · open ## What `GetModuleHandleA/W`, `LoadLibrary*` and `GetProcAddress` give a title its own modules, but `GetModuleHandleExA/W` had no override, so imports of them (and `GetProcAddress` lookups) were bound to the host: - With no name they returned `victory.exe`, not the title's image. - Title DLLs and console modules (`xgameruntime.dll`) were looked up under host names, not ours. - A host DLL outside `HostPolicy` was found if anything in our process had loaded it. Both now use the same lookup as `GetModuleHandle`. Lookups by address (`FROM_ADDRESS`), allowed host DLLs and invalid arguments still go to the host. No reference is taken on title images or pseudo modules, matching `FreeLibrary`, which never drops one. I have no copy of the title, so I haven't checked whether it calls these. An AI tool (Claude Code) wrote this change. ## Tested Windows 11, Rust 1.98.1, rebased on `940d32f`: - `cargo test -p victory-hle --locked`: all pass, three runs (144 unit tests, plus the integration tests). With the two exports removed, the new unit test fails. The no-name case has its own test process, because the main image is process-wide. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. - `cargo test --workspace --locked`: passes except in `victory-gpu` (aborts) and `victory-shader` (6 hardware tests), neither of which depends on `victory-hle`. Without this change, `940d32f` fails the same way on this machine (AMD Radeon iGPU + RTX 3050 Ti Laptop): the same 6 shader tests and the same `victory-gpu` abort. One `victory-gpu` test, `null_3d_uav_is_accepted_by_the_device`, was reported failed only in the run with the change. - `cargo xtask policy`: asset policy: 183 files ok. Nothing from the game was used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:07:43 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:56 UTC · original

Automated triage for the maintainers. Recommended for a look (not an approval).

Adds GetModuleHandleExA/W overrides in crates/victory-hle/src/modules/kernel.rs that reuse find_module (and runtime::main_image for a null name), as GetModuleHandleA/W already do; previously these went straight to the host, so a null name gave our exe and a DLL outside HostPolicy (e.g. wininet) could be found if loaded. Address lookups and unsupported flags still go to the host; the unit test and the separate-process integration test cover title images, console modules, the refused-DLL case and the host fallbacks. CI (check) is passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2506#issuecomment-7167452470) <!-- victory-triage v1 head=748efa86bf2ef7f2ff2e69a75a02d9777e6d0e7a verdict=merge-candidate at=2026-11-25T15:56:35Z --> Automated triage for the maintainers. Recommended for a look (not an approval). Adds `GetModuleHandleExA/W` overrides in `crates/victory-hle/src/modules/kernel.rs` that reuse `find_module` (and `runtime::main_image` for a null name), as `GetModuleHandleA/W` already do; previously these went straight to the host, so a null name gave our exe and a DLL outside `HostPolicy` (e.g. wininet) could be found if loaded. Address lookups and unsupported flags still go to the host; the unit test and the separate-process integration test cover title images, console modules, the refused-DLL case and the host fallbacks. CI (`check`) is passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 00:52 UTC · original

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

  • Code review (crates/victory-hle/src/modules/kernel.rs:34-73):
    • named_handle cleanly handles name-based GetModuleHandleExA/W calls (flags in 0 | PIN | UNCHANGED_REFCOUNT, !out.is_null()): returns runtime::main_image() for NULL, resolves title/console modules through find_module(&name, false) (rejecting disallowed host DLLs with ERROR_MOD_NOT_FOUND and writing null to *out), and forwards allowed host DLLs, FROM_ADDRESS, invalid flag combinations (PIN | UNCHANGED_REFCOUNT), and null out straight to the host.
    • Verified clean merge compatibility with #2902 (does not modify find_module, so it inherits the trailing-dot fix automatically). Non-blocking note: GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS against a manually mapped title DLL still delegates to host Ldr (matching existing crash::module_of scope).
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 192 files ok; cargo clippy -p victory-hle --all-targets --locked -- -D warnings (default + --all-features): 0 warnings
    • cargo test -p victory-hle --locked (default + --all-features): 153/153 lib + 1 subprocess (module_handle_ex_finds_what_module_handle_does) + fidelityfx + main_module_handle + no_dll_planting all passed.

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2506#issuecomment-7179205382) Code review and Windows 11 verification at head `748efa86bf2e` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review (`crates/victory-hle/src/modules/kernel.rs:34-73`)**: - `named_handle` cleanly handles name-based `GetModuleHandleExA`/`W` calls (`flags` in `0 | PIN | UNCHANGED_REFCOUNT`, `!out.is_null()`): returns `runtime::main_image()` for `NULL`, resolves title/console modules through `find_module(&name, false)` (rejecting disallowed host DLLs with `ERROR_MOD_NOT_FOUND` and writing null to `*out`), and forwards allowed host DLLs, `FROM_ADDRESS`, invalid flag combinations (`PIN | UNCHANGED_REFCOUNT`), and null `out` straight to the host. - Verified clean merge compatibility with `#2902` (does not modify `find_module`, so it inherits the trailing-dot fix automatically). Non-blocking note: `GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS` against a manually mapped title DLL still delegates to host Ldr (matching existing `crash::module_of` scope). - **Verified (Windows 11, Rust 1.98.1)**: - `cargo xtask policy`: `192 files ok`; `cargo clippy -p victory-hle --all-targets --locked -- -D warnings` (default + `--all-features`): 0 warnings - `cargo test -p victory-hle --locked` (default + `--all-features`): **153/153 lib + 1 subprocess (`module_handle_ex_finds_what_module_handle_does`) + `fidelityfx` + `main_module_handle` + `no_dll_planting`** all passed. LGTM.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 01:44 UTC · original

NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head 748efa8 (on its base 940d32f).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 698 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: module_handle_ex_finds_what_module_handle_does, no_name_is_the_titles_exe.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-26 01:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2506#issuecomment-7180075669) NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head `748efa8` (on its base `940d32f`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **698 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `module_handle_ex_finds_what_module_handle_does`, `no_name_is_the_titles_exe`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-26 08:50 UTC · original

Independent local verification of head 748efa8 on Windows 11, Rust 1.100.0/MSVC:

  • cargo test --locked -p victory-hle --lib module_handle_ex_finds_what_module_handle_does — 1 passed, 0 failed.
  • cargo test --locked -p victory-hle --test main_module_handle — 1 passed, 0 failed.

One housekeeping issue: git diff --check origin/main HEAD fails because the branch is behind current main — it reports crates/victory-formats/src/xma/tables.rs:410: new blank line at EOF. A rebase onto current main should clear it; the module-handle changes themselves pass.

Synthetic tests only; no game assets or DRM material used. AI-assisted (Hy4 flash).

**@⁠cloph-dsp** on GitHub · 2026-11-26 08:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2506#issuecomment-7187085069) Independent local verification of head `748efa8` on Windows 11, Rust 1.100.0/MSVC: - `cargo test --locked -p victory-hle --lib module_handle_ex_finds_what_module_handle_does` — 1 passed, 0 failed. - `cargo test --locked -p victory-hle --test main_module_handle` — 1 passed, 0 failed. One housekeeping issue: `git diff --check origin/main HEAD` fails because the branch is behind current `main` — it reports `crates/victory-formats/src/xma/tables.rs:410: new blank line at EOF`. A rebase onto current `main` should clear it; the module-handle changes themselves pass. Synthetic tests only; no game assets or DRM material used. AI-assisted (Hy4 flash).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 09:05 UTC · original · approved these changes

Checked all GetModuleHandleExA/W boundary cases in crates/victory-hle/src/modules/kernel.rs (748efa86):

  • Null out, invalid flag combinations (e.g. PIN | UNCHANGED_REFCOUNT), FROM_ADDRESS, and HostPolicy-allowed host DLLs cleanly fall through to host GetModuleHandleExA/W, preserving host LastError and refcount semantics.
  • Null name with 0 | PIN | UNCHANGED_REFCOUNT returns runtime::main_image(), and named lookups share find_module(&name, false) with GetModuleHandleA/W (covering title DLLs, console pseudo-modules, empty-string / disallowed host DLL rejection with ERROR_MOD_NOT_FOUND + null *out), while matching FreeLibrary's no-decrement handling for title images and pseudo-modules.
  • Clean, conflict-free merge check against current origin/main (63bcca43) via git merge-tree. (Optional housekeeping: rebasing onto current main would drop the stale base diff warning, and supporting FROM_ADDRESS for title-mapped virtual ranges can be a separate follow-up if a title needs it.)

Verified locally on Windows 11:

  • cargo clippy -p victory-hle --all-targets -- -D warnings (default and --all-features): clean
  • cargo test -p victory-hle --lib -- modules::kernel::tests::: 6/6 passed
  • cargo test -p victory-hle --test main_module_handle: 1/1 passed
  • cargo xtask policy: clean

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 09:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2506#pullrequestreview-6071175138) · **approved these changes** Checked all `GetModuleHandleExA/W` boundary cases in `crates/victory-hle/src/modules/kernel.rs` (`748efa86`): - Null `out`, invalid flag combinations (e.g. `PIN | UNCHANGED_REFCOUNT`), `FROM_ADDRESS`, and `HostPolicy`-allowed host DLLs cleanly fall through to host `GetModuleHandleExA/W`, preserving host `LastError` and refcount semantics. - Null `name` with `0 | PIN | UNCHANGED_REFCOUNT` returns `runtime::main_image()`, and named lookups share `find_module(&name, false)` with `GetModuleHandleA/W` (covering title DLLs, console pseudo-modules, empty-string / disallowed host DLL rejection with `ERROR_MOD_NOT_FOUND` + null `*out`), while matching `FreeLibrary`'s no-decrement handling for title images and pseudo-modules. - Clean, conflict-free merge check against current `origin/main` (`63bcca43`) via `git merge-tree`. *(Optional housekeeping: rebasing onto current `main` would drop the stale base diff warning, and supporting `FROM_ADDRESS` for title-mapped virtual ranges can be a separate follow-up if a title needs it.)* Verified locally on Windows 11: - `cargo clippy -p victory-hle --all-targets -- -D warnings` (default and `--all-features`): clean - `cargo test -p victory-hle --lib -- modules::kernel::tests::`: 6/6 passed - `cargo test -p victory-hle --test main_module_handle`: 1/1 passed - `cargo xtask policy`: clean 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/2506/head:github-bot/gh-2506'
git switch 'github-bot/gh-2506'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2506'
git switch 'github-bot/gh-2506'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2506'
git switch 'github-bot/gh-2506'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2506'
git switch 'main'
git merge --squash 'github-bot/gh-2506'
git switch 'main'
git merge --ff-only 'github-bot/gh-2506'
git switch 'main'
git merge 'github-bot/gh-2506'
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!2506
No description provided.