Loader: run on Windows 10 (clear the IAT directory) #44

Closed
steppergg wants to merge 1 commit from upstream-pr/44 into main
steppergg commented 2026-11-23 23:42:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steppergg on 2026-11-23T23:42:59Z.


What

On Windows 10 (19045), LoadLibraryExW of the prepared image faults with 0xC0000005 in ntdll, reading 0xC (an import descriptor's Name). prepare clears the import directory but leaves the IAT directory, and Windows 10's loader still walks it; Windows 11 skips it.

This clears the IAT directory together with the import and bound-import directories (dir::IAT = 12 added to victory-pe layout). Nothing needs it afterwards: bind_imports unprotects and fills each slot itself (windows.rs, VirtualProtect per slot) from info.imports parsed from the original.

It also skips WinHttpGetProxySettingsEx in net.rs's "every override names a real export" test. That export only exists in Windows 11's winhttp.dll; our override serves the title either way.

Relation to #28

#28 fixes the same crash by pointing the import directory at the table's all-zero terminator. This is an alternative: it removes what Windows 10 trips on instead of feeding it an empty table, so there is no fallback path when an image has no readable terminator (#28 falls back to zeroing, which is the crashing case). Either is fine by me; happy to close this if #28 is preferred. The net.rs test fix is independent of either.

How the cause was found

I took the prepared image the crashing load_probe test left behind and loaded copies with one data directory zeroed at a time, each in its own process. Only zeroing the IAT directory loaded; zeroing load config, TLS, relocations, exceptions, debug, exports or delay imports did not.

Tested

  • Windows 10 Pro 22H2 (19045), Rust 1.98.1, RTX 4060 Ti.
  • Before: cargo test --workspace failed victory-loader --test load_probe (STATUS_ACCESS_VIOLATION inside victory_loader::load) and only_loopback_is_reachable.
  • After: cargo test --workspace --locked passes everything, including loads_binds_and_calls_probe end to end (bind, calls into the image, TLS callbacks and DllMain on new threads, detach).
  • prepare's test now also asserts the IAT directory is cleared.
  • cargo xtask policy passes. Not tested with game data.

AI assistance: Claude Code traced the crash, prepared the patch and ran the checks above.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6571196722 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/44). Originally posted by [steppergg](https://github.com/steppergg) on 2026-11-23T23:42:59Z. --- ## What On Windows 10 (19045), `LoadLibraryExW` of the prepared image faults with `0xC0000005` in `ntdll`, reading `0xC` (an import descriptor's `Name`). `prepare` clears the import directory but leaves the **IAT directory**, and Windows 10's loader still walks it; Windows 11 skips it. This clears the IAT directory together with the import and bound-import directories (`dir::IAT = 12` added to `victory-pe` layout). Nothing needs it afterwards: `bind_imports` unprotects and fills each slot itself (`windows.rs`, `VirtualProtect` per slot) from `info.imports` parsed from the original. It also skips `WinHttpGetProxySettingsEx` in `net.rs`'s "every override names a real export" test. That export only exists in Windows 11's `winhttp.dll`; our override serves the title either way. ## Relation to #28 #28 fixes the same crash by pointing the import directory at the table's all-zero terminator. This is an alternative: it removes what Windows 10 trips on instead of feeding it an empty table, so there is no fallback path when an image has no readable terminator (#28 falls back to zeroing, which is the crashing case). Either is fine by me; happy to close this if #28 is preferred. The `net.rs` test fix is independent of either. ## How the cause was found I took the prepared image the crashing `load_probe` test left behind and loaded copies with one data directory zeroed at a time, each in its own process. Only zeroing the IAT directory loaded; zeroing load config, TLS, relocations, exceptions, debug, exports or delay imports did not. ## Tested - Windows 10 Pro 22H2 (19045), Rust 1.98.1, RTX 4060 Ti. - Before: `cargo test --workspace` failed `victory-loader --test load_probe` (`STATUS_ACCESS_VIOLATION` inside `victory_loader::load`) and `only_loopback_is_reachable`. - After: `cargo test --workspace --locked` passes everything, including `loads_binds_and_calls_probe` end to end (bind, calls into the image, TLS callbacks and `DllMain` on new threads, detach). - `prepare`'s test now also asserts the IAT directory is cleared. - `cargo xtask policy` passes. Not tested with game data. AI assistance: Claude Code traced the crash, prepared the patch and ran the checks above.
Proudnoob4 commented 2026-11-24 06:54:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Proudnoob4 on 2026-11-24T00:21:32Z.


Tested 6ca3bef on Windows 10 22H2 (19045.6456), i5-13600K, RTX 4080 (driver 621.01). AI-assisted (Claude); I ran all of this myself.

  • cargo test --workspace: all pass (224, 3 ignored). On main 97c78d1 the same machine fails load_probe (0xC0000005 in ntdll) and net::only_loopback_is_reachable, so both fixes work as described.
  • With the real title, map-only victory run (no --execute) maps and binds with 0 missing imports, but never logs static TLS redirected. Windows 10 left the exe's TLS index at 0.
  • With #28's empty import descriptor (25a3e95, and its earlier d85097a), the same run logs static TLS redirected index=12 patched=53246, and the title then boots (details in #28).
  • load_probe can't catch this, because the probe has no static TLS.

So what passed everything here on Windows 10 was #28's layout together with this PR's net.rs change.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7117984493 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/44#issuecomment-7117984493). Originally posted by [Proudnoob4](https://github.com/Proudnoob4) on 2026-11-24T00:21:32Z. --- Tested `6ca3bef` on Windows 10 22H2 (19045.6456), i5-13600K, RTX 4080 (driver 621.01). AI-assisted (Claude); I ran all of this myself. - **`cargo test --workspace`**: all pass (224, 3 ignored). On main `97c78d1` the same machine fails `load_probe` (0xC0000005 in ntdll) and `net::only_loopback_is_reachable`, so both fixes work as described. - **With the real title**, map-only `victory run` (no `--execute`) maps and binds with 0 missing imports, but never logs `static TLS redirected`. Windows 10 left the exe's TLS index at 0. - **With #28's empty import descriptor** (`25a3e95`, and its earlier `d85097a`), the same run logs `static TLS redirected index=12 patched=53246`, and the title then boots (details in #28). - `load_probe` can't catch this, because the probe has no static TLS. So what passed everything here on Windows 10 was #28's layout together with this PR's `net.rs` change.
noviw-rblx commented 2026-11-24 06:54:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by noviw-rblx on 2026-11-24T00:44:00Z.


checked: #44 | with: cargo test -p victory-loader | on: Windows 10, Rust 1.98.1, head 6ca3befa, CPU only | result: load_probe 2 passed. IAT directory is cleared alongside import/bound-import. No game data required.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118374367 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/44#issuecomment-7118374367). Originally posted by [noviw-rblx](https://github.com/noviw-rblx) on 2026-11-24T00:44:00Z. --- checked: #44 | with: cargo test -p victory-loader | on: Windows 10, Rust 1.98.1, head 6ca3befa, CPU only | result: load_probe 2 passed. IAT directory is cleared alongside import/bound-import. No game data required.
Sunkiller-qc commented 2026-11-24 06:54:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sunkiller-qc on 2026-11-24T01:05:47Z.


Now that #28 is merged, the prepare.rs part here conflicts with main, and per Proudnoob4's Windows 10 run above it is also the layout that leaves the static TLS index at 0. (I suggested clearing the IAT on #28, but that turned out to be wrong for the same reason.) I think it's best to drop it.

The net.rs change is still useful, though: main's only_loopback_is_reachable test still checks WinHttpGetProxySettingsEx (crates/victory-hle/src/modules/net.rs:1052-1056 here), which fails on Windows 10. Could this PR be cut down to just that test change, rebased on main?

Static review, not built or run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118750161 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/44#issuecomment-7118750161). Originally posted by [Sunkiller-qc](https://github.com/Sunkiller-qc) on 2026-11-24T01:05:47Z. --- Now that #28 is merged, the `prepare.rs` part here conflicts with main, and per Proudnoob4's Windows 10 run above it is also the layout that leaves the static TLS index at 0. (I suggested clearing the IAT on #28, but that turned out to be wrong for the same reason.) I think it's best to drop it. The `net.rs` change is still useful, though: main's `only_loopback_is_reachable` test still checks `WinHttpGetProxySettingsEx` (`crates/victory-hle/src/modules/net.rs:1052-1056` here), which fails on Windows 10. Could this PR be cut down to just that test change, rebased on main? Static review, not built or run.
Sunkiller-qc commented 2026-11-24 06:54:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sunkiller-qc on 2026-11-24T01:29:42Z.


Follow-up: #152 now makes just the net.rs test change (and only skips WinHttpGetProxySettingsEx when the host really lacks it). With #28 merged, I think this PR can be closed in favour of #152.

Static review, not built or run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119154264 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/44#issuecomment-7119154264). Originally posted by [Sunkiller-qc](https://github.com/Sunkiller-qc) on 2026-11-24T01:29:42Z. --- Follow-up: #152 now makes just the `net.rs` test change (and only skips `WinHttpGetProxySettingsEx` when the host really lacks it). With #28 merged, I think this PR can be closed in favour of #152. Static review, not built or run.
upstream-sync closed this pull request 2026-11-24 09:04:55 +00:00

Pull request closed

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!44
No description provided.