Skip to content

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

Closed
steppergg wants to merge 1 commit into
Marvisak:mainfrom
steppergg:win10-loader-iat
Closed

steppergg wants to merge 1 commit into
Marvisak:mainfrom
steppergg:win10-loader-iat

Conversation

@steppergg

Copy link
Copy Markdown

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.

Windows 10's loader (19045) still reads the IAT directory of the
prepared image after the import directory is cleared, and faults
reading a descriptor's Name at 0xC inside LoadLibraryExW. Windows 11
skips it. Clear the IAT directory with the other two: we unprotect and
fill every slot ourselves from the original's imports, so nothing
needs it.

Also skip WinHttpGetProxySettingsEx in net.rs's "every override names
a real export" test: the export is Windows 11 only, and our override
serves the title either way.
@Proudnoob4

Copy link
Copy Markdown

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 Loader: preserve an empty import table for Windows 10 static TLS #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 Loader: preserve an empty import table for Windows 10 static TLS #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

Copy link
Copy Markdown

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

@Sunkiller-qc

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

@Marvisak Marvisak closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants