Skip to content

RT-5: how the retail executable calls xmem.dll: all 23 XMemVirtualAlloc sites pass an attribute word the shim refuses - #6843

Closed
Etoile-Bleu wants to merge 1 commit into
ItsNotRexed:mainfrom
Etoile-Bleu:exe-xmem-physical-pages
Closed

Etoile-Bleu wants to merge 1 commit into
ItsNotRexed:mainfrom
Etoile-Bleu:exe-xmem-physical-pages

Conversation

@Etoile-Bleu

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #6603 (RT-5, claim posted at the time of this PR)

@ItsNotRexed third exe PR, after #6715 and #6751.

Depends on: none. Related, not overlapping in files: #6709, #6814, #6733, #3390, #4531, #3601 (all change runtime/shims/xmem.cpp; this PR does not).

What and why

The executable imports 12 functions from xmem.dll and 7 have no shim. Several open PRs are filling that in, so this measures, from the file alone, how the executable calls them:

  • tools/import_call_sites.py (new, with tests/test_import_call_sites.py): finds an import's thunk and the call/jmp rel32 instructions that reach it, from a PE32+ file, and prints counts or RVAs. It reuses pe_inspect.PeImage. The test builds a PE byte by byte (calls, a tail jump, an unused import, an ordinal import, a 32-bit image, the CLI and its exit code 2).
  • docs/xmem_exe_calls.md (new, one index row in docs/README.md): the counts and the constant arguments, and what is inference and what is unmeasured.

What it shows:

  • All 23 XMemVirtualAlloc call sites pass a nonzero attributes word (0x3, 0x7, 0x21, 0x23, 0x27, 0x181, 0x183, 0x283), and runtime/shims/xmem.cpp returns ERROR_NOT_SUPPORTED for any nonzero value. Past that check, 5 sites use the 2 MiB mode (0x20003000) and 6 carry allocation-type bits the shim does not know (0x4000, 0x40000). Their protect values carry the SDK's PAGE_GRAPHICS_* bits (0x2004 = PAGE_READWRITE + PAGE_GRAPHICS_READWRITE).
  • The physical-page family has 21 call sites and no shim (XMemMapPhysicalPages 12, XMemAllocatePhysicalPages 4, XMemFreePhysicalPages 3, XMemMapPhysicalPagesScatter 2). Their shape is the Win32 AWE family's, with 64 KiB pages; the page lists the inferred signatures and marks XMemFreePhysicalPages as the least certain. It also records that the first function using them needs XMemVirtualAlloc to accept the attribute words first.
  • Constants for XMemAlloc, XMemFree, XMemTransferMemory and XMemGetWorkingSetStatistics, and that the 0x5e50000 attribute xmem.cpp mentions is not among the XMemAlloc sites that pass a constant.

No code of the executable is quoted, only counts and the constants a call passes.

Tested

Own Xbox 1.0.2.1 package plus the executable (SHA-256 e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993), Windows 11 26200, Python 3.13, main 1cc6e3c1. Nothing was run from the executable.

  • python -I tools/import_call_sites.py game_scarlett_master.exe --dll xmem.dll --dll d3d12_xs.dll --dll xg_xs.dll: 17 imports, 67 call sites, 1 s. The counts match an independent scan I made first (XMemVirtualAlloc 23, XMemMapPhysicalPages 12, XMemAllocatePhysicalPages 4, XMemFreePhysicalPages 3, XMemMapPhysicalPagesScatter 2).
  • The argument constants were read by hand from the instructions before each call with radare2; they are in the page as constants, not as code.
  • python -I tests/test_import_call_sites.py: 8 tests OK. tests/test_pe_inspect.py (60), tests/test_ci_registration.py (14) and all 11 tests/test_docs_*.py OK.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. Counts and call constants only; no disassembly, strings or code from the executable.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (not a translator change)

…oc sites pass an attribute word the shim refuses

tools/import_call_sites.py finds an import's thunk and the call/jmp rel32 instructions that reach it, from the file
alone. On game_scarlett_master.exe: XMemVirtualAlloc 23 sites (every attributes value nonzero, protections carrying
PAGE_GRAPHICS bits), the physical-page family 21 sites with an AWE-shaped signature and 64 KiB pages, and the
constants the other xmem imports are called with. docs/xmem_exe_calls.md records them and what is still unmeasured.
@HansBullet

Copy link
Copy Markdown
Contributor

Independent CPU-only check of dfcc046b on Windows 10 build 19045, Python 3.14.5, Capstone 5.0.6 and pefile 2024.8.26. The local EXE matched the SHA-256 in the PR. Coordination claim.

  • The PR CLI reproduced 17 imports and 67 candidate sites across xmem.dll, d3d12_xs.dll and xg_xs.dll. All eight synthetic tests passed.
  • Starting at PE exception-directory function entries and following fall-through and direct branches, Capstone confirmed 60 calls at instruction boundaries. For each, the direct target decoded as a RIP-relative jump to the matching import address-table slot. This covers 19 of 23 XMemVirtualAlloc candidates, all 21 physical-page candidates, and all 10 candidates for the other two DLLs.
  • Four more XMemVirtualAlloc calls and their targets matched a linear decode from the containing function entry. Their reachability remained unverified. All three tail-jump candidates decoded to the expected import when started at the reported address. Those three were outside the exception-directory function ranges, so their instruction boundaries remain unverified.

This checks the byte scanner’s candidate boundaries and import targets. The argument constants were outside the scope of this check. AI-assisted.

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Adds tools/import_call_sites.py and its test suite (thunk discovery via PE32+ import tables, call/jmp rel32 counting, JSON output, 32-bit refusal) plus docs/xmem_exe_calls.md and a README row. The doc reports per-import call-site counts for the retail executable's 12 xmem.dll imports: all 23 XMemVirtualAlloc sites pass a nonzero attributes word that runtime/shims/xmem.cpp rejects, five use the 2 MiB page mode, and six carry unknown allocation bits. It infers the AWE-style physical-page signatures and a 64 KiB page unit, and lists constants for XMemAlloc, XMemFree, XMemTransferMemory and XMemGetWorkingSetStatistics.

Why merge

Core static-recompilation input: explains why the xmem shim rejects every real allocation and what shape a replacement needs. Synthetic tests and docs only, no game data.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

Adds tools/import_call_sites.py and its test suite (thunk discovery via PE32+ import tables, call/jmp rel32 counting, JSON output, 32-bit refusal) plus docs/xmem_exe_calls.md and a README row. The doc reports per-import call-site counts for the retail executable's 12 xmem.dll imports: all 23 XMemVirtualAlloc sites pass a nonzero attributes word that runtime/shims/xmem.cpp rejects, five use the 2 MiB page mode, and six carry unknown allocation bits. It infers the AWE-style physical-page signatures and a 64 KiB page unit, and lists constants for XMemAlloc, XMemFree, XMemTransferMemory and XMemGetWorkingSetStatistics.

Why merge

Core static-recompilation input: explains why the xmem shim rejects every real allocation and what shape a replacement needs. Synthetic tests and docs only, no game data.

Verdict: Approve

@lordnyx0

Copy link
Copy Markdown

Tested dfcc046 on Windows 11 Pro 10.0.26100, Python 3.14.3 (CPU-only change, no GPU involved): pass

Independent check on my own copy of the same executable (SHA-256 e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993), with python -I tools/import_call_sites.py game_scarlett_master.exe --dll xmem.dll --dll d3d12_xs.dll --dll xg_xs.dll: 17 imports, 67 call sites, with the same counts as the PR (XMemVirtualAlloc 23, XMemMapPhysicalPages 12, XMemAllocatePhysicalPages 4, XMemFreePhysicalPages 3, XMemMapPhysicalPagesScatter 2). python -I tests/test_import_call_sites.py: 8/8 OK.

No game code was executed; only counts and constants were read. AI-assisted (opencode).

@Etoile-Bleu

Copy link
Copy Markdown
Contributor Author

Closing: this PR's three files (tools/import_call_sites.py, its test and docs/xmem_exe_calls.md, plus the index row) are on main byte for byte since #6899 was merged at 15:37 UTC (it was stacked on this branch), so there is nothing left to merge here, and the branch now conflicts only because of that. Thanks to everyone who checked it independently.

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.

4 participants