HLE: implement the RPC runtime's GUID calls #636

Merged
Nixitov merged 1 commit from upstream-pr/636 into main 2026-11-25 00:09:01 +00:00
Nixitov commented 2026-11-24 06:00:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Nixitov on 2026-11-24T06:00:30Z.


Fixes #510 (the null GUID). Following @mercuryVM's review, this no longer passes rpcrt4.dll through: it implements the calls titles use and leaves everything else refused.

Implemented (crates/victory-hle/src/modules/rpcrt4.rs, served as rpcrt4.dll):

  • UuidCreate, UuidCreateSequential: 16 bytes from BCryptGenRandom, version 4 and variant bits set. Sequential does not report a MAC address or a clock of this machine; it is the same generator in the same shape.
  • UuidFromStringA/W: braces and upper case taken, 32 hex digits required, dashes optional, and nothing after the last digit but a closing brace. Anything else answers RPC_S_INVALID_STRING_UUID and leaves the out GUID alone.
  • UuidToStringA/W: the canonical lower-case form. The allocation keeps its length in a word before the text, so RpcStringFreeA and RpcStringFreeW both give the whole thing back, and both take null.
  • RpcStringFreeA/W.

LoadLibrary("rpcrt4.dll") returns our pseudo module: the kernel module already does that for a DLL a module serves that the host policy refuses, so the title resolves these imports without the host DLL.

Why not pass-through: as the review says, RpcBindingFromStringBinding with ncacn_ip_tcp or ncacn_http opens sockets through rpcrt4's own ws2_32 imports, which modules::net never sees.

Verified here (Windows 11 26200.9974, RTX 5070, driver 617.14, release build):

  • loaded as a pseudo module dll="rpcrt4.dll", and no a host DLL outside the host policy: refused line for it (it was the only one).
  • The title runs through its first screens and into the world, same as before.
  • cargo test -p victory-hle --lib: 92 passed. The new tests cover the format/parse round trip in both string widths, version and variant bits over 64 creates, invalid text refused, and both frees including null.
  • cargo xtask policy: 152 files ok. Clippy clean on the new module; fmt clean on the touched files.

The host policy is unchanged: HostPolicy::default() still refuses rpcrt4.dll, and the_rpc_runtime_is_implemented_here checks that every call above resolves to HLE even with HostPolicy::none().

No game files; only log lines and identifiers.

AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6575684178 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/636). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-11-24T06:00:30Z. --- Fixes #510 (the null GUID). Following @mercuryVM's review, this no longer passes `rpcrt4.dll` through: it implements the calls titles use and leaves everything else refused. **Implemented (`crates/victory-hle/src/modules/rpcrt4.rs`, served as `rpcrt4.dll`):** - `UuidCreate`, `UuidCreateSequential`: 16 bytes from `BCryptGenRandom`, version 4 and variant bits set. Sequential does not report a MAC address or a clock of this machine; it is the same generator in the same shape. - `UuidFromStringA/W`: braces and upper case taken, 32 hex digits required, dashes optional, and nothing after the last digit but a closing brace. Anything else answers `RPC_S_INVALID_STRING_UUID` and leaves the out GUID alone. - `UuidToStringA/W`: the canonical lower-case form. The allocation keeps its length in a word before the text, so `RpcStringFreeA` and `RpcStringFreeW` both give the whole thing back, and both take null. - `RpcStringFreeA/W`. `LoadLibrary("rpcrt4.dll")` returns our pseudo module: the kernel module already does that for a DLL a module serves that the host policy refuses, so the title resolves these imports without the host DLL. **Why not pass-through:** as the review says, `RpcBindingFromStringBinding` with `ncacn_ip_tcp` or `ncacn_http` opens sockets through rpcrt4's own `ws2_32` imports, which `modules::net` never sees. **Verified here** (Windows 11 26200.9974, RTX 5070, driver 617.14, release build): - `loaded as a pseudo module dll="rpcrt4.dll"`, and no `a host DLL outside the host policy: refused` line for it (it was the only one). - The title runs through its first screens and into the world, same as before. - `cargo test -p victory-hle --lib`: 92 passed. The new tests cover the format/parse round trip in both string widths, version and variant bits over 64 creates, invalid text refused, and both frees including null. - `cargo xtask policy`: 152 files ok. Clippy clean on the new module; fmt clean on the touched files. The host policy is unchanged: `HostPolicy::default()` still refuses `rpcrt4.dll`, and `the_rpc_runtime_is_implemented_here` checks that every call above resolves to HLE even with `HostPolicy::none()`. No game files; only log lines and identifiers. AI-assisted (DeepSeek V4.1 Flash coding agent).
mercuryVM commented 2026-11-24 08:02:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T07:42:39Z.

Review: CHANGES_REQUESTED


Tested f35849c on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed).

This is the same change as #510, and my concern there applies here too.

  • ws2_32 and winhttp are only safe to pass through because modules::net overrides the title's imports of them and refuses off-machine traffic.
  • rpcrt4.dll is the RPC client runtime. RpcBindingFromStringBinding with ncacn_ip_tcp or ncacn_http opens sockets through rpcrt4's own ws2_32 imports, which modules::net never sees.
  • Allowing the whole DLL therefore gives a title a network path that skips the loopback-only rule.

The null-GUID symptom is real and worth fixing. The narrow fix is to implement the calls titles use as HLE in modules:

  • UuidCreate: 16 bytes from BCryptGenRandom, version 4 and variant bits set.
  • UuidCreateSequential, if imported: same.
  • UuidFromStringA/W, UuidToStringA/W, RpcStringFreeA/W.

Everything else stays refused as today. Happy to re-review that version.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6035406571 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/636#pullrequestreview-6035406571). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T07:42:39Z. **Review:** CHANGES_REQUESTED --- Tested f35849c on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (265 passed, 0 failed). This is the same change as #510, and my concern there applies here too. - `ws2_32` and `winhttp` are only safe to pass through because `modules::net` overrides the *title's* imports of them and refuses off-machine traffic. - `rpcrt4.dll` is the RPC client runtime. `RpcBindingFromStringBinding` with `ncacn_ip_tcp` or `ncacn_http` opens sockets through rpcrt4's own `ws2_32` imports, which `modules::net` never sees. - Allowing the whole DLL therefore gives a title a network path that skips the loopback-only rule. The null-GUID symptom is real and worth fixing. The narrow fix is to implement the calls titles use as HLE in `modules`: - `UuidCreate`: 16 bytes from `BCryptGenRandom`, version 4 and variant bits set. - `UuidCreateSequential`, if imported: same. - `UuidFromStringA/W`, `UuidToStringA/W`, `RpcStringFreeA/W`. Everything else stays refused as today. Happy to re-review that version. AI-assisted (Claude Code).
upstream-sync changed title from [PR #636] HLE: allow rpcrt4.dll in the default host policy to [PR #636] HLE: implement the RPC runtime's GUID calls 2026-11-24 09:05:50 +00:00
Nixitov commented 2026-11-24 09:06:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Nixitov on 2026-11-24T08:34:51Z.


Reworked along the lines you suggested, @mercuryVM — thank you, the point about rpcrt4's own ws2_32 imports is right and it is not worth that hole for a GUID.

The policy change is gone. crates/victory-hle/src/modules/rpcrt4.rs now implements exactly the calls you listed and serves the DLL name from the modules registry, so the resolution order makes them HLE with any policy (a test asserts that with HostPolicy::none()), and LoadLibrary("rpcrt4.dll") takes the pseudo-module path the kernel module already uses for console DLLs the host policy refuses. Every other rpcrt4 import stays Missing.

  • UuidCreate and UuidCreateSequential: BCryptGenRandom, version 4, variant bits; sequential deliberately does not report this machine's MAC or clock.
  • UuidFromStringA/W and UuidToStringA/W: the canonical text, braces and upper case accepted on input, RPC_S_INVALID_STRING_UUID and the out GUID untouched otherwise.
  • RpcStringFreeA/W: the allocation carries its length, so both frees take it (and null).

On this machine (Windows 11, RTX 5070, release build) the title logs loaded as a pseudo module dll="rpcrt4.dll", the outside the host policy: refused line for it is gone, and it still reaches the world. cargo test -p victory-hle --lib 92 passed, cargo xtask policy 152 files ok, clippy clean on the new module.

One thing I could not check: whether the title's identifiers now differ from the null GUID in its own logs beyond the creation call — the UUID calls no longer answer zero, but I have no other observable of the value it uses. If you have a check for that in mind, I will add it.

AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7126307641 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/636#issuecomment-7126307641). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-11-24T08:34:51Z. --- Reworked along the lines you suggested, @mercuryVM — thank you, the point about rpcrt4's own `ws2_32` imports is right and it is not worth that hole for a GUID. The policy change is gone. `crates/victory-hle/src/modules/rpcrt4.rs` now implements exactly the calls you listed and serves the DLL name from the modules registry, so the resolution order makes them HLE with any policy (a test asserts that with `HostPolicy::none()`), and `LoadLibrary("rpcrt4.dll")` takes the pseudo-module path the kernel module already uses for console DLLs the host policy refuses. Every other rpcrt4 import stays Missing. - `UuidCreate` and `UuidCreateSequential`: `BCryptGenRandom`, version 4, variant bits; sequential deliberately does not report this machine's MAC or clock. - `UuidFromStringA/W` and `UuidToStringA/W`: the canonical text, braces and upper case accepted on input, `RPC_S_INVALID_STRING_UUID` and the out GUID untouched otherwise. - `RpcStringFreeA/W`: the allocation carries its length, so both frees take it (and null). On this machine (Windows 11, RTX 5070, release build) the title logs `loaded as a pseudo module dll="rpcrt4.dll"`, the `outside the host policy: refused` line for it is gone, and it still reaches the world. `cargo test -p victory-hle --lib` 92 passed, `cargo xtask policy` 152 files ok, clippy clean on the new module. One thing I could not check: whether the title's identifiers now differ from the null GUID in its own logs beyond the creation call — the UUID calls no longer answer zero, but I have no other observable of the value it uses. If you have a check for that in mind, I will add it. AI-assisted (DeepSeek V4.1 Flash coding agent).
mercuryVM commented 2026-11-24 12:04:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T11:09:56Z.

Review: APPROVED


Tested 7216ab7 on Windows 11, RTX 5070, MSVC: cargo test -p victory-hle 93 passed, including the_rpc_runtime_is_implemented_here and the rpcrt4 module tests. Clippy's 1 warning is the existing field_reassign_with_default at xmem.rs:747.

This addresses my earlier review: rpcrt4.dll stays out of HostPolicy, and only the eight GUID/string calls are served. RpcServerRegisterIf and the rest still classify as None, so the RPC transports (and their own ws2_32 imports) never load.

  • UuidCreate: the version and variant bits are set on the right bytes (bytes[7] high nibble is data3's version under little-endian, bytes[8] is data4[0]). BCryptGenRandom with BCRYPT_USE_SYSTEM_PREFERRED_RNG is the right source.
  • RpcStringFree*: the length prefix in allocate lets free rebuild the exact Layout, and nulling the caller's pointer matches the documented contract.
  • Nit: parse is more lenient than UuidFromString. It skips - anywhere and accepts a leading {, so {0123…} and dash-less 32-digit strings succeed, where rpcrt4 returns RPC_S_INVALID_STRING_UUID. Harmless for well-formed input; mention it in the doc comment if you keep it.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038129020 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/636#pullrequestreview-6038129020). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T11:09:56Z. **Review:** APPROVED --- Tested 7216ab7 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-hle` 93 passed, including `the_rpc_runtime_is_implemented_here` and the rpcrt4 module tests. Clippy's 1 warning is the existing `field_reassign_with_default` at xmem.rs:747. This addresses my earlier review: `rpcrt4.dll` stays out of `HostPolicy`, and only the eight GUID/string calls are served. `RpcServerRegisterIf` and the rest still classify as `None`, so the RPC transports (and their own `ws2_32` imports) never load. - `UuidCreate`: the version and variant bits are set on the right bytes (`bytes[7]` high nibble is `data3`'s version under little-endian, `bytes[8]` is `data4[0]`). `BCryptGenRandom` with `BCRYPT_USE_SYSTEM_PREFERRED_RNG` is the right source. - `RpcStringFree*`: the length prefix in `allocate` lets `free` rebuild the exact `Layout`, and nulling the caller's pointer matches the documented contract. - Nit: `parse` is more lenient than `UuidFromString`. It skips `-` anywhere and accepts a leading `{`, so `{0123…}` and dash-less 32-digit strings succeed, where rpcrt4 returns `RPC_S_INVALID_STRING_UUID`. Harmless for well-formed input; mention it in the doc comment if you keep it. AI-assisted (Claude Code).
molodayamama commented 2026-11-24 15:03:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by molodayamama on 2026-11-24T14:07:47Z.


Independent Windows check of 7216ab7113115ea1accfabc6e3a00ee700c7c846 (Windows 10 22H2 19045, Rust 1.98.1, MSVC x64).

  • cargo test -p victory-hle --locked --lib rpcrt4 -- --test-threads=1 --nocapture: 5 passed.

The focused RPC UUID fixtures ran on Windows. They cover format/parse round trips, malformed text, version-4 creation, and releasing strings using the two entry points. No RPC connection was opened.

Only source-built synthetic fixtures were used. AI-assisted verification.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133885514 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/636#issuecomment-7133885514). Originally posted by [molodayamama](https://github.com/molodayamama) on 2026-11-24T14:07:47Z. --- Independent Windows check of `7216ab7113115ea1accfabc6e3a00ee700c7c846` (Windows 10 22H2 19045, Rust 1.98.1, MSVC x64). - `cargo test -p victory-hle --locked --lib rpcrt4 -- --test-threads=1 --nocapture`: 5 passed. The focused RPC UUID fixtures ran on Windows. They cover format/parse round trips, malformed text, version-4 creation, and releasing strings using the two entry points. No RPC connection was opened. Only source-built synthetic fixtures were used. AI-assisted verification.
upstream-sync closed this pull request 2026-11-25 01:04:34 +00:00
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!636
No description provided.