pe: pin the delay-load import pairing with a synthetic image #573

Open
qnjk wants to merge 1 commit from qnjk/Darner:pe-delay-import-test into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: nothing. This is a tests-only change (no production line is edited), so it needs no A/B result and no gameplay run.

  • What it pins: parse_delay_imports hands the descriptor's ImportNameTableRva to entries as the thunk list and its ImportAddressTableRva as the IAT base (crates/darner-pe/src/image.rs:316-321), and entries takes the symbol from the first and the slot RVA from the second (:337-340). Nothing in the workspace built an image whose delay-load directory was parsed: parses_own_test_binary reads the rustc-linked test exe, which has no delay-load table (apps/darner/build.rs links with /DELAYLOAD:d3d12.dll, but that is a different binary), and the synthetic helper was only used for exports, sections and TLS. The two fields are two u32s of one 32-byte descriptor read symmetrically, so swapping them, naming entries from the address table, or dropping the SizeOfImage bound would not have been caught: a swapped binding names every delay-loaded import wrongly and calls through the wrong slot, which only shows up as a wrong function in a run.

  • This change adds synthetic_image_with_delay_import(iat_rva), which wraps the existing synthetic_image helper with a one-descriptor delay-load directory (data directory 13), and two tests. Production code is untouched.

How it was tested

  • Tested revision: 0b7a1bb (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-pe --lib — 41 passed, 0 failed.
    • New image::tests::delay_imports_pair_the_name_table_with_the_address_table: the image has DLL delay.dll, a name table at 0x1040 naming Foo (hint 7) and an address table at 0x10C0 whose thunk points at a different hint/name entry, Bar (hint 9), so a crossed pairing cannot agree by accident. It asserts one module, one entry, symbol == ImportSymbol::Name { hint: 7, name: "Foo" } and iat_slot_rva == 0x10C0 (the address table's RVA, not the name table's 0x1040).
    • New image::tests::rejects_a_delay_import_iat_outside_the_image: the same image with the address table at 0x3000, past SizeOfImage (0x2000), must be Err(PeError::Malformed(_)), mirroring the existing rejects_iat_outside_image for the normal import table.
    • Fail-before, with three temporary mutations of the parser (each reverted with git checkout --, never git stash), e.g. the crossed pair:
      delay_imports_pair_the_name_table_with_the_address_table ... FAILED
      panicked at crates\darner-pe\src\image.rs:650:
      assertion `left == right` failed
        left:  Name { hint: 9, name: "Bar" }
        right: Name { hint: 7, name: "Foo" }
      
    • cargo clippy --locked -p darner-pe --all-targets -- -D warnings passes.
  • Changes a default: no. Tests only.
  • A/B result: not applicable — tests-only change.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not run to completion here; the pre-existing darner-gpu test deadlock (#224) and the darner-shader waterfall fixture failure (#227) make the whole-workspace run non-green on this machine, and neither crate is touched. darner-pe's suite is green (41 passed).
  • Gameplay, when relevant: not applicable — tests-only change.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none.
  • Coverage gaps: only one descriptor with one entry is built; a multi-entry name/address table, a delay-load descriptor with Attributes not RVA-based, and an ordinal entry are not exercised.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not applicable: tests-only change, stated at the top.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md. (cargo xtask policy: 576 files ok.)
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found. No open pull request changes crates/darner-pe/src/image.rs (checked against the file list of all 189 open pull requests), and no open or closed issue mentions the delay-load import table.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: nothing. This is a **tests-only** change (no production line is edited), so it needs no A/B result and no gameplay run. - What it pins: `parse_delay_imports` hands the descriptor's `ImportNameTableRva` to `entries` as the thunk list and its `ImportAddressTableRva` as the IAT base (`crates/darner-pe/src/image.rs:316-321`), and `entries` takes the symbol from the first and the slot RVA from the second (`:337-340`). Nothing in the workspace built an image whose delay-load directory was parsed: `parses_own_test_binary` reads the rustc-linked test exe, which has no delay-load table (`apps/darner/build.rs` links with `/DELAYLOAD:d3d12.dll`, but that is a different binary), and the synthetic helper was only used for exports, sections and TLS. The two fields are two `u32`s of one 32-byte descriptor read symmetrically, so swapping them, naming entries from the address table, or dropping the `SizeOfImage` bound would not have been caught: a swapped binding names every delay-loaded import wrongly and calls through the wrong slot, which only shows up as a wrong function in a run. - This change adds `synthetic_image_with_delay_import(iat_rva)`, which wraps the existing `synthetic_image` helper with a one-descriptor delay-load directory (data directory 13), and two tests. Production code is untouched. ## How it was tested - Tested revision: `0b7a1bb` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-pe --lib` — 41 passed, 0 failed. - New `image::tests::delay_imports_pair_the_name_table_with_the_address_table`: the image has DLL `delay.dll`, a name table at 0x1040 naming `Foo` (hint 7) and an address table at 0x10C0 whose thunk points at a **different** hint/name entry, `Bar` (hint 9), so a crossed pairing cannot agree by accident. It asserts one module, one entry, `symbol == ImportSymbol::Name { hint: 7, name: "Foo" }` and `iat_slot_rva == 0x10C0` (the address table's RVA, not the name table's 0x1040). - New `image::tests::rejects_a_delay_import_iat_outside_the_image`: the same image with the address table at 0x3000, past `SizeOfImage` (0x2000), must be `Err(PeError::Malformed(_))`, mirroring the existing `rejects_iat_outside_image` for the normal import table. - Fail-before, with three temporary mutations of the parser (each reverted with `git checkout --`, never `git stash`), e.g. the crossed pair: ``` delay_imports_pair_the_name_table_with_the_address_table ... FAILED panicked at crates\darner-pe\src\image.rs:650: assertion `left == right` failed left: Name { hint: 9, name: "Bar" } right: Name { hint: 7, name: "Foo" } ``` - `cargo clippy --locked -p darner-pe --all-targets -- -D warnings` passes. - Changes a default: no. Tests only. - A/B result: not applicable — tests-only change. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: not run to completion here; the pre-existing `darner-gpu` test deadlock (#224) and the `darner-shader` waterfall fixture failure (#227) make the whole-workspace run non-green on this machine, and neither crate is touched. `darner-pe`'s suite is green (41 passed). - Gameplay, when relevant: not applicable — tests-only change. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: only one descriptor with one entry is built; a multi-entry name/address table, a delay-load descriptor with `Attributes` not RVA-based, and an ordinal entry are not exercised. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not applicable: tests-only change, stated at the top. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. (`cargo xtask policy`: 576 files ok.) - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. No open pull request changes `crates/darner-pe/src/image.rs` (checked against the file list of all 189 open pull requests), and no open or closed issue mentions the delay-load import table. - Replaces or overlaps: none found
`parse_delay_imports` pairs the descriptor's ImportNameTableRva with its
ImportAddressTableRva, and `entries` takes the symbol from the first and the
slot RVA from the second, but no test built an image whose delay-load
directory was parsed at all: `parses_own_test_binary` reads a rustc-linked exe
with no delay-load table, and the synthetic images covered exports and TLS
only. The two fields read symmetrically (two u32s of one 32-byte descriptor),
so swapping them bound every delay-loaded import to the wrong IAT slot while
naming it from the slot's contents — the census then reports everything
resolved and the first call lands elsewhere — and the SizeOfImage bound on the
slot was equally untested. `apps/darner/build.rs` links the binary with
`/DELAYLOAD:d3d12.dll`, so the table is not a dead path.

`synthetic_image_with_delay_import` adds a one-descriptor delay-load directory:
the name table at 0x1040 names `Foo`, and the address table at 0x10C0 points
at a different hint/name entry (`Bar`), so a parser that swaps the pair or that
names the entry from the address table cannot pass by accident. The test
`delay_imports_pair_the_name_table_with_the_address_table` pins the DLL name,
the symbol and the slot RVA, and
`rejects_a_delay_import_iat_outside_the_image` gives the descriptor an address
table at 0x3000 in an image whose SizeOfImage is 0x2000 and expects
`PeError::Malformed`, mirroring `rejects_iat_outside_image` for the import
table. Swapping the descriptor's two RVAs, taking the slot from the name
table, or dropping the size filter each make one of them fail.
TrustNo1 changed title from [pr-tests] pe: pin the delay-load import pairing with a synthetic image to pe: pin the delay-load import pairing with a synthetic image 2026-12-06 03:26:59 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pe-delay-import-test:qnjk-pe-delay-import-test'
git switch 'qnjk-pe-delay-import-test'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'qnjk-pe-delay-import-test'
git switch 'qnjk-pe-delay-import-test'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-pe-delay-import-test'
git switch 'qnjk-pe-delay-import-test'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-pe-delay-import-test'
git switch 'Main'
git merge --squash 'qnjk-pe-delay-import-test'
git switch 'Main'
git merge --ff-only 'qnjk-pe-delay-import-test'
git switch 'Main'
git merge 'qnjk-pe-delay-import-test'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
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.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!573
No description provided.