Skip to content

feat(pe): inspect import and delay-load tables - #6509

Merged
gensokyo-dev merged 17 commits into
morluto:mainfrom
mvanhorn:feat/pe-imports
Oct 24, 2026
Merged

gensokyo-dev merged 17 commits into
morluto:mainfrom
mvanhorn:feat/pe-imports

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Related to #4539.

Adds inspect_pe_imports / inspect-pe-imports for one selected local PE: standard/delay DLLs, names or ordinals, hints, IAT RVAs, consumed ranges and a pefile-compatible imphash when the complete standard table supports it. CLI/MCP share bounded stable-file reading, validation and Evidence; the target is never executed.

The integration consumes parsed PE facts and canonical indexed mappings. Descriptor/thunk RVA overflow and descriptor mapping gaps preserve preceding rows and explicit partial coverage. An unexamined directory retains its declaration with zero consumed spans. Coverage is reconciled with actual rows, standard-table issues withhold the hash, and delay-only issues preserve an independently complete standard hash. Cancellation, typed resource recovery and failed-cleanup ownership remain intact.

Validation:

  • 277 checks pass on main 7f70797b integration, covering parser/mapping/image/service/filesystem/CLI/MCP/lifecycle behavior and the upstream plist-fixture correction. Full npm run check, npm run docs:check and test discovery pass. Negative controls reproduce the corrected overflow, mapping-gap, coverage and cancellation failures before correction. Actual SDK output is checked against the advertised JSON schema.
  • Independent pefile 2024.8.26 agrees with every ordered DLL/name/ordinal/hint/IAT RVA, machine, bitness and imphash from shipped pip PE32/PE32+ launchers (85 / 86 imports), and all 696 ordinal-map entries. Full MIT attribution is included. The proposed 63-bit ordinal mask was rejected after byte-level controls proved it disagrees with pinned pefile. No Windows execution or deep-engine behavior is newly qualified.
  • Two 24-task CLI comparisons cover empty, shipped and 2,048-section/function fixtures with complete Evidence/oracle equality. In the final measured RVA comparison, large-case estimated tokens remain 70,342; elapsed median 2.825 → 2.221 s has overlapping ranges, CPU 2.423 → 2.428 s and sampled family RSS 382.9 → 389.0 MiB. No speedup is claimed. Later coverage/mapping guards and main changes are outside those pinned timings.

Verification report records artifact digests, revisions, provenance and measurement limits. Final CI run 40057282775 fails on 11 separate plist cases. Exact main cd10ee1f and actual CI merge c3d08d01 reproduce the same 19 passing / 11 failing cases with identical normalized failures and unchanged producing sources. Two other shards are cancelled; their remaining coverage is unexecuted. The maintainer-authorized baseline bypass is supported by these controls; the PR's selected checks pass.

Author readiness

Human owner: @mvanhorn

  • 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.

Add inspect_pe_imports / inspect-pe-imports to read PE32/PE32+ import
and delay-load directories without executing the image. The report keeps
DLL names, named and ordinal functions, ILT/IAT RVAs, and a pefile
import hash of the standard import table. A missing directory is
observed absence, not proof the image never imported APIs.
Allow peImportImage() without an argument so CLI and filesystem tests
can use the KERNEL32 sample without repeating an empty options object.
inspect_pe_imports already rejects relative MCP paths in its own
boundary test. Leave the shared absolute-path matrix to tools whose
handler issue projection matches that suite's expected shape.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T03:19:04.742249Z 0f225fb New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the outstanding ordinal-lookup bug is fixed.

Summary

Adds inspect_pe_imports and inspect-pe-imports to read PE import and delay-load tables without running the image.

  • REA lists imported DLLs and functions from a selected PE file.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[CLI or MCP] --> B[Validate explicit file selection]
  B --> C[Read bounded stable file]
  C --> D[Parse standard and delay-load imports]
  D --> E[Compute or withhold import hash]
  E --> F[Return Evidence and limitations]
Loading

Reviews (3) · Last reviewed commit: "fix(pe): read only own ordinal tables fo..." · Reviewed by Greptile

Comment thread src/native/pe/PeImportParser.ts Resolved
Comment thread src/native/pe/PeImportParser.ts Resolved
Comment thread src/native/pe/PeImportParser.ts Resolved
Comment thread src/native/pe/PeImportsProvider.ts Resolved
Comment thread src/native/pe/PeImportParser.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 130b5babaa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/native/pe/PeImportParser.ts Resolved
Comment thread src/native/pe/PeImportParser.ts Resolved
Comment thread src/native/pe/PeImportParser.ts Resolved
Comment thread src/native/pe/PeImportsProvider.ts Resolved

@baron baron 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.

AI-assisted independent review confirms substantive producer defects despite green CI:

  • PeImportParser.ts:454 computes imphash from retained rows even when a standard-table name is unreadable. The two-import probe retained only GetProcAddress, reported partial coverage, yet emitted a successful MD5 with no unavailable reason. That prefix hash is not an established image import hash.
  • Missing FirstThunk with a populated ILT becomes complete/empty imports and MD5(empty), rather than malformed/partial evidence.
  • Directory Evidence claims one contiguous physical span even when consecutive RVA descriptors map into disjoint file spans. The probe consumed [5100,5120) and [8192,8212), but advertised [5100,5140).

Fix completeness and consumed-span ownership in the parser, and carry exhausted-limit tags instead of parsing diagnostic prose in provider remediation. The review also confirms the existing ordinal compatibility issue. Mapping complexity is multiplicative by source inspection, not an independently measured freeze.

These findings were checked against exact-source isolated parser probes, not a real PE corpus/Windows or full CLI/MCP run. No OOM, latency or peak-memory claim is made. Existing threads cover the findings, so no duplicate inline threads added. Main CI passes; incomplete human readiness and unresolved substantive issues still block approval.

mvanhorn and others added 2 commits October 23, 2026 08:03
mappedFileOffset scans every mapping twice per span, so a parser that
translates one span per table entry costs sections x entries. Add
fileMappingLookup, which builds an O(n log n) interval index once and
answers each span in O(log n) with the same accept, reject and
translation results. A differential test checks it against
mappedFileOffset over randomized overlapping mappings and zero fills.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ra7LM2NyQ7DumdssxbUq5g
- Withhold imphash with an explicit reason whenever the standard import
  table is partial (unreadable names or thunks, missing tables), or when
  pefile 2024.8.26 would hash a different row sequence: invalid or
  truncated names, ordinal 0, descriptors without functions, tables its
  bounds or repeat/spread heuristics discard, and its 8192-thunk import
  symbol cap. Delay-load issues do not withhold it.
- Hash ordinal imports with pefile's complete ordlookup tables and its
  ord<decimal> fallback instead of declining unmapped ordinals.
- Report a nonterminal descriptor whose FirstThunk is zero, and a
  delay-load descriptor whose IAT or INT RVA is zero, as malformed_entry
  partial coverage instead of a complete empty inventory.
- Directory evidence lists the file spans actually consumed for the
  descriptor array and terminator; discontiguous mappings produce
  separate spans and separate Evidence ranges.
- Carry exhausted limits as PeImportLimitFailure.limit and derive
  recovery from it; the fixed 16 MiB retained-text ceiling reports a
  fixed allowance instead of max_file_bytes advice.
- Translate RVAs through the indexed mapping lookup and yield with a
  cancellation check every 1024 table entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ra7LM2NyQ7DumdssxbUq5g
@mvanhorn

Copy link
Copy Markdown
Contributor Author

@baron thanks for the review. e13fee6 fixes these in the parser: imphash is withheld with a reason whenever standard imports are partial (test hashes come from pefile 2024.8.26 on the same bytes), a zero FirstThunk with a populated ILT is malformed and partial, and directory evidence reports each consumed file span instead of one contiguous range. Limit failures carry structured tags, and ordinals fall back to pefile's ord names. 4682a8e indexes section lookups; 65,535 sections with 8,192 imports went from 178.6 s to 0.21 s. Not run against a real PE corpus on Windows.

Comment thread src/native/pe/pefileImphash.ts Resolved
DLL names such as constructor and __proto__ pass pefile's name rule but
resolved inherited object members, throwing before the ord<n> fallback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ra7LM2NyQ7DumdssxbUq5g

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0b65cbcfe2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/native/pe/PeImportParser.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7406eca81

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/native/pe/pefileImphash.ts Resolved
Comment thread src/native/pe/PeImportParser.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adc2a91a37

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/native/pe/PeImportParser.ts Resolved
@gensokyo-dev

Copy link
Copy Markdown
Collaborator

Final-head CI attribution for 0f225fb:

CI run 40057282775 has 25 successful, 11 skipped, 3 failed and 2 cancelled jobs. The functional failures are 11 plist cases in nativePlistTextSource.test.ts / plistSourceFormat.test.ts; Portable tests repeats those 11 and CI required aggregates test/test-shard failures. The two cancelled shards report cancellation without another functional failure; their remaining coverage was not executed.

Reproduced both files on exact main cd10ee1 and the actual CI merge c3d08d0 (parents main + this PR head). Both runs have 30 cases: 19 pass / 11 fail. All 30 statuses and all failure messages match after normalizing checkout roots and temporary directory suffixes only. The failing files, fixture runner and selected XML/plist producing sources are byte-identical. The existing source/optional-conversion expectations disagree on main as well; this PR does not establish a diagnosis of that separate behavior.

The PR's 277 selected PE/mapping/image/service/filesystem/CLI/actual SDK/lifecycle checks and full static/docs/discovery gates pass. Final-head CI also passes build, source/static/documentation and the completed provider lanes. Title and existing human-readiness checks pass. Two superseded metadata runs were cancelled while unassigned (runner 0, zero steps); their newer same-head runs pass.

The maintainer's authorization permits merging when failures are proven unrelated to this PR. This record supports the baseline-failure bypass for the exact reviewed head; cancelled coverage and provider/platform limits remain as reported in the verification document.

@gensokyo-dev

Copy link
Copy Markdown
Collaborator

Latest integration verification before merge: the PR head 0f225fb combined with main ae24b78 produces tree 4e65ee22cf14f3d7a0b4a5de94f329aa83e11f59. Installed its exact lock with the pinned toolchain (Husky disabled to preserve shared Git configuration), built the runtime, and passed 143 selected service/filesystem/public CLI/actual SDK/shared-lifecycle checks. These overlap the earlier 277-check selection. Later main commits through f508a1a change release tooling, unreachable native command routing and Windows native-load diagnostics; the PE implementation and its portable static-reader path are unchanged. The predicted clean merge tree there is f7610c5e2a992708fa62ddd5875848635e4686ee.

All actionable review threads are resolved and the existing human-readiness declaration passes. The baseline attribution above covers the 11 plist failures and the two fail-fast cancellations. Proceeding with the maintainer-authorized bypass for the exact reviewed PR head.

@gensokyo-dev
gensokyo-dev merged commit 4ef916d into morluto:main Oct 24, 2026
41 of 48 checks passed
@morluto morluto mentioned this pull request Oct 25, 2026
3 tasks done
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request labels Nov 23, 2026
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.

4 participants