PE: read long-format import descriptors #963

Closed
enzoduarte1 wants to merge 1 commit from upstream-pr/963 into main
enzoduarte1 commented 2026-11-24 14:33:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by enzoduarte1 on 2026-11-24T14:33:08Z.


What

ImportLibrary::parse only understood short-format import objects. Long-format import libraries (the ones whose archive members start with a 20-byte descriptor and no inline strings) were counted in other_members but yielded no imports at all.

This patch recognizes that descriptor form, walks the following COFF members, and recovers the DLL from __IMPORT_DESCRIPTOR_<dll> plus exports from __imp_<name> symbols. Type, ordinal/hint and name-decoration bits are read from the descriptor header, matching the short-format rules already used by the object crate. Short imports and unrecognized members keep their previous behaviour.

Tested

  • Windows 11, Rust 1.98.1, x86_64-pc-windows-gnu (no MSVC linker on this machine).
  • cargo test -p victory-pe --lib -- --test-threads=1: 11 passed, 0 failed.
  • New tests cover a short import, a long import with named exports, a long import by ordinal, and accounting for an unknown member.
  • cargo check --workspace: clean, no new warnings.
  • rustfmt --edition 2024 --check crates/victory-pe/src/implib.rs and git diff --check: clean.
  • cargo xtask policy: 154 files ok. No game files or data taken from them were added.

Checklist

  • cargo fmt --all --check and cargo test --workspace pass — the workspace has pre-existing formatting diffs and the loader fixture needs MSVC /DELAYLOAD, which MinGW rejects here; the changed crate and a full cargo check --workspace are clean.
  • cargo xtask policy passes. The change adds no game files or data taken from them (docs/asset-policy.md).
  • If an AI tool wrote part of this change, the description says so: an AI tool assisted with the parser and tests; I reviewed and ran them.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6584159414 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/963). Originally posted by [enzoduarte1](https://github.com/enzoduarte1) on 2026-11-24T14:33:08Z. --- ## What `ImportLibrary::parse` only understood short-format import objects. Long-format import libraries (the ones whose archive members start with a 20-byte descriptor and no inline strings) were counted in `other_members` but yielded no imports at all. This patch recognizes that descriptor form, walks the following COFF members, and recovers the DLL from `__IMPORT_DESCRIPTOR_<dll>` plus exports from `__imp_<name>` symbols. Type, ordinal/hint and name-decoration bits are read from the descriptor header, matching the short-format rules already used by the `object` crate. Short imports and unrecognized members keep their previous behaviour. ## Tested - Windows 11, Rust 1.98.1, `x86_64-pc-windows-gnu` (no MSVC linker on this machine). - `cargo test -p victory-pe --lib -- --test-threads=1`: 11 passed, 0 failed. - New tests cover a short import, a long import with named exports, a long import by ordinal, and accounting for an unknown member. - `cargo check --workspace`: clean, no new warnings. - `rustfmt --edition 2024 --check crates/victory-pe/src/implib.rs` and `git diff --check`: clean. - `cargo xtask policy`: 154 files ok. No game files or data taken from them were added. ## Checklist - [ ] `cargo fmt --all --check` and `cargo test --workspace` pass — the workspace has pre-existing formatting diffs and the loader fixture needs MSVC `/DELAYLOAD`, which MinGW rejects here; the changed crate and a full `cargo check --workspace` are clean. - [x] `cargo xtask policy` passes. The change adds no game files or data taken from them (`docs/asset-policy.md`). - [x] If an AI tool wrote part of this change, the description says so: an AI tool assisted with the parser and tests; I reviewed and ran them.
mercuryVM commented 2026-11-24 15:03:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T14:46:09Z.

Review: APPROVED


Tested adeb9ff4 on Windows 11, RTX 5070, MSVC: cargo test -p victory-pe 11 passed, including the long-format import library tests.

  • Recognising the 20-byte descriptor member, then recovering the DLL from __IMPORT_DESCRIPTOR_<dll> and names from __imp_<name>, matches how link.exe lays out long-format import libraries. Short-format parsing is unchanged.
  • Nit, new clippy warning: implib.rs:125, "this if statement can be collapsed".

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6041408926 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/963#pullrequestreview-6041408926). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T14:46:09Z. **Review:** APPROVED --- Tested adeb9ff4 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-pe` 11 passed, including the long-format import library tests. - Recognising the 20-byte descriptor member, then recovering the DLL from `__IMPORT_DESCRIPTOR_<dll>` and names from `__imp_<name>`, matches how link.exe lays out long-format import libraries. Short-format parsing is unchanged. - Nit, new clippy warning: `implib.rs:125`, "this `if` statement can be collapsed". AI-assisted (Claude Code).
Zipettte commented 2026-11-24 16:05:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T15:13:14Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at adeb9ff: cargo test -p victory-pe passes, 11 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7135655851 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/963#issuecomment-7135655851). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T15:13:14Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at adeb9ff: `cargo test -p victory-pe` passes, 11 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
upstream-sync closed this pull request 2026-11-25 01:05:04 +00:00
Marvisak commented 2026-11-25 01:07:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:28:49Z.


Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148552286 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/963#issuecomment-7148552286). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:28:49Z. --- Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

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