Import scanners read resolved addresses as names when the import name table is missing

Open
#76 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
62/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp

Research direction

Start with the import walk in clean/rr_f/proxy/src/hook_dll.cpp around lines 849-861, where names come from OriginalFirstThunk with a FirstThunk fallback, then check the same pattern in clean/rr_f/proxy/src/setupapi_identity.cpp near line 390. The proposed fix is to skip a descriptor whose OriginalFirstThunk is zero and log once. Done means a synthetic PE64 test with a zero OriginalFirstThunk asserts nothing is patched and nothing faults, and the scanner must first be exported or compiled into the test.

Written by the indexing model from the issue text.

Description

area: ray-reconstruction bug

This was found by reading the code. It has not been reproduced.

What happens

The import scanner in clean/rr_f/proxy/src/hook_dll.cpp:853-861 reads names from OriginalFirstThunk, and falls back to FirstThunk when it is zero. It then dereferences base + names->u1.AddressOfData as an IMAGE_IMPORT_BY_NAME. At run time FirstThunk holds resolved absolute addresses. The ordinal check passes (the top bit is clear for user-mode addresses). The result is base + address, which is unmapped, so the read faults.

The scanner runs on every loaded module (hook_dll.cpp:1105-1115). Only descriptors whose DLL name equals the interface file name reach the walk (hook_dll.cpp:849). There is no __try around do_hook.

The same fallback and interpretation is in clean/rr_f/proxy/src/setupapi_identity.cpp:390. That scanner only runs for Spider-Man2.exe.

When it can happen

Only for a module that imports the game interface (or, for the SetupAPI scanner, a Spider-Man2.exe that imports SetupAPI) and was linked or packed without an import name table. Current MSVC and LLVM x64 linkers always emit one. This is old-Borland or packer territory. No known RR game qualifies. Low severity: a crash at load if it ever occurs.

To do

  • In both scanners: if (!OriginalFirstThunk) { log once; continue; }.
  • Optionally bounds-check each name RVA against SizeOfImage.
  • Caution: none in practice. A module without an import name table is simply not patched, and that is logged.

Test

CPU-only. Build a synthetic in-memory PE64 image: DOS and NT headers, one import descriptor naming the interface, OriginalFirstThunk = 0, FirstThunk filled with a real function address. Call the scanner (it needs to be exported to the test or compiled into it). Assert nothing is patched and nothing crashes.

Dominant language
C++
Stars
12
Forks
2
Avg merge
3h 10m
Merged PRs (30d)
171

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phantoslayer21/wronggpu

All issues in phantoslayer21/wronggpu

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.