Skip to content

feat(pe)!: decode legacy PE32 delay import addresses - #8758

Draft
ArjenS-LA wants to merge 3 commits into
morluto:mainfrom
ArjenS-LA:feat/pe-legacy-delay-imports
Draft

ArjenS-LA wants to merge 3 commits into
morluto:mainfrom
ArjenS-LA:feat/pe-legacy-delay-imports

Conversation

@ArjenS-LA

@ArjenS-LA ArjenS-LA commented Nov 3, 2026 •

Copy link
Copy Markdown

Summary

Adds legacy PE32 delay-import decoding to inspect-pe-imports / inspect_pe_imports. Previously every descriptor using virtual addresses was skipped as unsupported. Descriptor address fields and named thunks now normalize against the preferred image base; ordinal thunks retain their original interpretation.

The partial-facts review finding is addressed in 0d0bb2da: each descriptor address is normalized independently. A bad optional module-handle, bound, or unload pointer no longer hides readable DLL/functions. Invalid addresses become null with field-specific issues containing the original VA and source location. An invalid name pointer leaves the name unknown while preserving functions; an invalid required table pointer preserves descriptor facts with functions undecoded.

The format follows the Microsoft PE specification and historical VC6 description. No related issue was found.

Contract and boundary impact

  • PeImportParser owns normalization once. Consumers use its parsed fields; no adapter-specific reinterpretation.
  • Breaking output change: six delay-descriptor RVA fields now allow null when normalization fails: name_rva, import_address_table_rva, import_name_table_rva, module_handle_rva, bound_import_rva, and unload_information_table_rva. Consumers must handle unknown addresses instead of assuming numbers. Encoded zero still means absent; historical numeric reports remain accepted. Returning zero for an invalid pointer would falsely report absence.
  • Raw thunk values, descriptor locations/attributes, artifact identity, ordinary imports, and their imphash are preserved. PE32+ legacy descriptors remain unsupported; existing resource/cancellation boundaries remain shared.
  • Existing static inspection; no new provider or execution authority. A maintainer scope decision is not applicable. No dependency, installer, release metadata, or tracked generated-output changes.

Expected effects:

  • Read existing files or captured data.

Current branch validation (2026-11-05)

Merged upstream main a7574d4274728fcb0a13414d6ae43f1597864d94 into the existing branch in dd4ee510. The local merge was conflict-free and retains the original focused PR diff.

Windows x64, Node 24.22.1, npm 11.16.0:

  • npm run test:focused -- src/native/pe/PeImportParser.test.ts tests/acceptance/peImportsCli.test.ts tests/boundary/mcp/peImportsMcp.test.ts: 72 passed, covering parser, CLI and MCP behavior after rebuilding runtime/skill artifacts.
  • npm run docs:check: passed, including generated metadata checks and 9 consistency tests.
  • npm run check:fast: typecheck and lint passed; normal pre-push validation passed.
  • git diff --check: passed. Commit hooks ran; their unrelated JavaScript import rewrite was removed from the unpublished merge, restoring the exact validated tree.
  • The prior head passed upstream CI. New CI is pending; no full-CI pass on this updated head is claimed.

Prior implementation validation

Prior head 0d0bb2da, Windows x64, Node 24.22.1, npm 11.16.0:

  • Review regressions before the fix: 7 failed, 53 passed.
  • npm run test:focused -- src/native/pe/PeImportParser.test.ts tests/acceptance/peImportsCli.test.ts tests/boundary/mcp/peImportsMcp.test.ts: 72 passed. Covers each invalid descriptor pointer, simultaneous optional failures, named/ordinal retention, zero-versus-null semantics, required-table failures, budgets, and standard imphash isolation.
  • CLI and stdio MCP return equal reports and preserve input bytes. MCP output with null optional addresses validates against the advertised SDK-converted JSON Schema.
  • npm run check: passed, including type-aware lint (0 errors).
  • npm run docs:check: passed, including generated metadata and 9 consistency tests.
  • Pre-commit checks, pre-push check:fast, and git diff --check: passed; hooks preserved the validated file contents.

Coverage limits: legacy cases use synthetic PE32 fixtures; no historical VC6-built binary or independent pefile runtime comparison was executed. The earlier unchanged filesystem test was blocked at Windows symlink creation (EPERM); that lane was not rerun for this update. No performance claim.

Author readiness

Human owner: @ArjenS-LA

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Prepared with Codex assistance; opened as a draft for human review.

@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The code changes appear safe to merge, with no blocking issue found.

Summary

Adds legacy PE32 delay-import decoding and makes six delay-descriptor address fields nullable.

  • PE32 delay imports now decode into readable import rows.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  D["Delay descriptor"] --> F{"Legacy VA form?"}
  F -- No --> R["Use stored RVAs"]
  F -- Yes --> P{"PE32?"}
  P -- No --> U["Report unsupported_form"]
  P -- Yes --> N["Normalize each address independently"]
  N --> K["Keep readable facts; failed addresses become null"]
  K --> S["Shared schema and Evidence"]
  R --> S
  S --> C["CLI and MCP"]
Loading

Reviews (3) · Last reviewed commit: "chore(pe): merge current main for PR val..." · Reviewed by Greptile

Comment thread src/native/pe/PeImportParser.ts Resolved
BREAKING CHANGE: delay-descriptor RVA fields may be null when a legacy address cannot be normalized. Numeric zero still denotes an absent pointer.
@ArjenS-LA ArjenS-LA changed the title feat(pe): decode legacy PE32 delay import addresses feat(pe)!: decode legacy PE32 delay import addresses Nov 4, 2026
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: All 72 tests in the 3 changed test files passed on each Node version. With the two source files swapped back to the merge base, 14 tests failed on each. I did not merge with current main or run the PE32 probe.

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Head dd4ee51 pass: 3 of 3 files, 72 of 72 tests pass: 3 of 3 files, 72 of 72 tests pass: 3 of 3 files, 72 of 72 tests
Red run (old source) fail: 3 of 3 files, 14 failed, 58 passed fail: 3 of 3 files, 14 failed, 58 passed fail: 3 of 3 files, 14 failed, 58 passed

The 3 test files are src/native/pe/PeImportParser.test.ts, tests/acceptance/peImportsCli.test.ts and tests/boundary/mcp/peImportsMcp.test.ts. The red run puts src/domain/native/peImports.ts and src/native/pe/PeImportParser.ts back to merge base a7574d4. Those 14 tests fail on the old source and pass on the PR source.

The log for Node 24.22.1 names all 14 failing tests. Twelve are in src/native/pe/PeImportParser.test.ts. One is in tests/acceptance/peImportsCli.test.ts and one is in tests/boundary/mcp/peImportsMcp.test.ts. Two examples are decodes PE32 delay VAs into RVAs while preserving raw thunks and standard imports and preserves missing legacy table fields at offset 12. Node 22.23.4 and Node 26.12.1 fail the same tests as Node 24.22.1.

The PR changes 7 files against the merge base: 3 test files and 4 others. The head is 187 commits behind main c78c8ae.

CI on head dd4ee51, read live with gh. The PR is a draft, with mergeable true and state unstable.

  • Workflow runs: CI is completed/success and CodeQL production is completed/skipped. PR readiness and PR title each have one completed/success run and one completed/cancelled run.
  • Check runs, 20 success: CI required, Source tests, Portable tests, Static checks, Documentation, Build package and Test shard (1/8) through Test shard (8/8), among others.
  • Check runs, 2 cancelled: Conventional PR title and Validate author declaration. Both names also appear in the success list.
  • Check runs, 24 skipped.
  • The commit status PR readiness is pending.

Not run

  • A probe of a PE32 fixture with a named legacy thunk. The image base and delayBase are both at or above 0x80000000. The probe would check whether RegOpenKeyExW comes back named.
  • A merge with current main, c78c8ae.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: dd4ee51 / a7574d4 (merge base with main)
  • Red run: dd4ee51 with the changed source files from a7574d4
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/native/pe/PeImportParser.test.ts tests/acceptance/peImportsCli.test.ts tests/boundary/mcp/peImportsMcp.test.ts

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request labels Nov 22, 2026
@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@ArjenS-LA thanks for the PR — this branch has merge conflicts with main. Could you merge or rebase onto the latest main and resolve them? Once it's clean and CI is green we can take another look.
cc @gensokyo-dev @dandgabr

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants