Skip to content

feat(pe): inspect Rich header linker records - #8923

Open
Plastic-time wants to merge 57 commits into
morluto:mainfrom
Plastic-time:rrfz/inspect-pe-rich-header
Open

Plastic-time wants to merge 57 commits into
morluto:mainfrom
Plastic-time:rrfz/inspect-pe-rich-header

Conversation

@Plastic-time

@Plastic-time Plastic-time commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This adds inspect_pe_rich_header and rea inspect-pe-rich-header. They read the Rich header of a local PE32 or PE32+ image with no provider, and never run the target.

The Rich header is the record Microsoft's linker writes between the DOS stub and the PE signature. It lists which compiler, assembler, linker and import-library builds produced the image, and how many objects each contributed. Today REA has no reader for it.

This is a proposed new read-only tool, and whether REA wants it is for maintainers to decide. An earlier revision exceeded the Grok client verifier's former 255-tool assertion. Main's verifier now discovers the catalog through bounded keyword queries (e9c72dbd1). #10776 still tracks the catalog-size question.

Problem and expected behavior

Use case: an analyst wants to know which Microsoft toolchain built a Windows binary, or whether its Rich header was copied or edited after linking. The binary has no DWARF to ask, so #8523 does not cover it.

Observable outcome:

  • rich_header.state is present, malformed or absent.
  • A present record reports its file range, key, decoded padding, and each entry's product_id, build and count.
  • checksum.computed is the linker checksum recomputed from the DOS header, stub and entries. checksum.matches says whether it reproduces the stored key.
  • A footer without its DanS marker, or a record that ends inside an entry, is malformed with a reason. A missing record is absent and carries a limitation saying absence does not show how the image was built.
  • A PE header whose e_lfanew overlaps the 64-byte DOS header is rejected as unsupported_target by the shared readPeImageFromReader admission check.
  • A DOS MZ executable with no PE header is unsupported_target, not absent.

Change and scope

  • src/native/pe/PeRichHeaderParser.ts reads the record. It takes the last DWORD-aligned Rich footer before the PE signature and walks back to the nearest DanS encoded with that key. Only zero bytes may follow the key up to the PE signature, as the linker writes it. Otherwise the report is absent.
  • src/domain/native/peRichHeader.ts owns the report schema, PE_RICH_HEADER_ENTRY_BUDGET, and peRichHeaderEntryLimit. The provider, service (executeArtifactInspection), and MCP tool (admission: "application" in src/server/offlineInspectionToolBindings.ts) follow inspect_pe_certificates. The CLI command is registered from the contract, like inspect-pe-imports. Failures go through the shared projectPeBinaryFailure, reporting structured details.limit with required_value and adapter-aware recovery when max_entries is exceeded.
  • PE header admission reuses readPeImageFromReader. No existing reader changes.
  • The CLI's --max-file-bytes and --max-entries accept decimal integers only.
  • The guide is docs/guides/native/pe-rich-header.md, at route /pe-rich-header, and docs/reference/limits-and-recovery.md lists inspect_pe_rich_header max_entries.

Two choices differ from pefile, on purpose:

  • pefile assumes DanS sits at 0x80. On this host it is at 0x58 in two third-party drivers and at 0x200 in a third.
  • pefile takes the first Rich marker. tcblaunch.exe has a custom DOS stub that is itself a PE image, with its own record at 0xC0. The image's record is the last one, at 0x2D20.

Not included: names for product IDs or Visual Studio releases, the "rich hash", or any edit of the record.

Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.

Contract and boundary impact

  • Semantic owner and earliest changed stage: new src/native/pe/PeRichHeaderParser.ts. It consumes the existing readPeImageFromReader.
  • Contribution scope fit and linked maintainer decision: format inspection of a local file, with no execution, injection, mutation or protection recovery. A required decision is not applicable. I have not assumed the tool is wanted.
  • CLI and MCP/tool-catalog contract: additive. One new tool, inspect_pe_rich_header, and one new command, inspect-pe-rich-header.
  • Provider, bridge, target-format, or platform compatibility: no provider or bridge. PE32 and PE32+ on any supported host.
  • Evidence, artifact, provenance, or reconstruction contract: new Evidence with artifact SHA-256, the record's file range (or only the footer when malformed), and observed confidence. Existing Evidence is unchanged.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): the caller selects one local path, read through readStableArtifact. No resources are retained.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): one new verify:pe:rich-header script in package.json. No runtime dependency and no build output.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • PeRichHeaderParser.test.ts: 20 cases on synthetic PE32 and PE32+ images. The expected key comes from a separate BigInt checksum. Cases include an image embedded in the stub, unaligned markers, a 4 MiB stub that must yield, malformed records, and the entry budget (including required entry count reporting).
    • PeRichHeaderService.test.ts: input validation, cancellation (a late cancellation keeps the abort reason and the completed Evidence), Evidence locations, omitted vs explicit parameters, and 5 kinds of malformed provider output.
    • PeRichHeaderProvider.test.ts: after the read, an exhausted budget (preserving required count), a malformed header and a cancellation during decoding all keep the file's path, SHA-256 and size.
    • PeUnsupportedTargets, unit and acceptance: DOS, NE, LE, LX and truncated images get the same codes as the other PE tools.
    • tupleSchemaParity for padding, CLI acceptance (peRichHeaderCli.test.ts, including --max-entries recovery below and above the 65,536 hard ceiling), MCP boundary (peRichHeaderMcp.test.ts, verifying omitted optional parameters are not stamped as caller-selected), filesystem boundary tests, and the shared localToolContracts, stableArtifactConsumers and toolEffects lists.
  • Base reproduction: on main, rea inspect-pe-rich-header is COMMAND_NOT_FOUND.
  • Real files:
    • scripts/verify-pe-rich-header.mjs compares key and entries with pefile 2024.8.26. Over 17,896 PE files in C:\Windows\System32, C:\Program Files and C:\Program Files (x86), 17,890 agree, 0 differ, and 5 fall outside pefile's 0x80 assumption. One 0-byte file is rejected by both. docs/verification/pe-rich-header-2026-11-04.md holds the record. Third-party files on the test host are not named.
    • The recomputed checksum reproduces the key for 10,901 of 10,915 records. The other 14 are 13 files from three third-party packages, and tcblaunch.exe.
  • User-visible CLI/MCP output, reduced from rea inspect-pe-rich-header ... --json:
C:\Windows\System32\notepad.exe (10.0.26100.8457, pe32-plus)
pe_header_offset 248
state present  location 128+112  key 2756908916
checksum computed 2756908916  matches true  padding 0,0,0
entries 11: (147, 30729, 94) (0, 0, 1) (260, 33145, 11) ...

A third-party kernel driver (not named)
pe_header_offset 600  DanS at 512  entries 5  matches true
entries: (1, 0, 15) (93, 4035, 5) (131, 30729, 2) (148, 30729, 1) (145, 30729, 1)
pefile on the same file: 53 pairs, each (0x184a, 61001, 407563849),
  warning "Rich Header is not in Microsoft format, possibly malformed"
  • Remaining proof gaps:
    • Windows host only. The parser has no host-specific code, but Linux and macOS were not run locally.
    • The checksum algorithm is confirmed on 10,901 real records, not against a Microsoft document. Microsoft does not document the Rich header.
    • I did not find why the 14 mismatching images differ.

For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Windows 11 x64, Node 24.22.1, head b9520bc25, merged with main b3e769d97 (verified zero conflicts against latest origin/main via git merge-tree).

  • 28fcde234 resolves the merge conflicts in src/native/pe/PeBinaryFailure.ts (adopting main's projectPeBinaryFailure options and required limit propagation) and scripts/verify/fixed-ceiling-registry.json.
  • ec0873c21 fixes two issues found after the merge:
    • src/server/offlineInspectionToolBindings.ts switches inspect_pe_rich_header to admission: "application" so MCP omits unselected default budgets from Evidence.parameters (matching CLI and inspect_dwarf_units).
    • src/domain/native/peRichHeader.ts, PeRichHeaderParser.ts, and PeRichHeaderProvider.ts now define PE_RICH_HEADER_ENTRY_BUDGET / peRichHeaderEntryLimit, forward unit: "entries" and required: count, and drop the hand-written remediationAction so projectPeBinaryFailure formats adapter-aware recovery (--max-entries on CLI, max_entries on MCP) and stops suggesting raising max_entries when required exceeds the 65,536 ceiling. docs/reference/limits-and-recovery.md is updated to match.
  • b9520bc25 removes the three unused legacy constant aliases (MIN_INSPECT_PE_RICH_HEADER_ENTRIES, DEFAULT_INSPECT_PE_RICH_HEADER_ENTRIES, MAX_INSPECT_PE_RICH_HEADER_ENTRIES) superseded by PE_RICH_HEADER_ENTRY_BUDGET.
  • Checks run on b9520bc25:
    • npm run test:focused -- src/native/pe/PeRichHeaderParser.test.ts src/native/pe/PeRichHeaderProvider.test.ts src/application/binaryDiagnostics/PeRichHeaderService.test.ts tests/acceptance/peRichHeaderCli.test.ts tests/boundary/mcp/peRichHeaderMcp.test.ts: 5/5 files, 41/41 tests passed.
    • npm run check:fast (typecheck, lint, verify:architecture-guards across 3,171 source files): passed.
  • Additional checks run on ec0873c21 (before removing the unused aliases in b9520bc25):
    • npm run docs:check (6/6 + 8/8), npm run format:check, and node scripts/verify/fixed-ceilings.mjs: passed.
    • npm run test:focused across 13 files (Rich header unit/acceptance/boundary + localToolContracts, advertisedCatalogSummary, advertisedDialect, advertisedMcpTool, providerCapabilityConformance, providerLifecycleCoverage, typedResourceRefusalRule): 13/13 files, 193 passed / 4 skipped.
    • tests/boundary/filesystem/peRichHeader.test.ts was not rerun in this merge update because Windows symlink EPERM persists on this host; CI runs it on Linux/macOS.

Earlier validation (5070cbd6f, merged with main 0a145c842):

  • Greptile asked the service to use the shared runner. 849157483 runs PeRichHeaderService through executeArtifactInspection, like inspect_pe_imports. validReport and the Evidence locations are its callbacks.
  • Greptile noted that Evidence parameters recorded the default limits as if the caller chose them. 5070cbd6f builds them with callerAnalysisParameters(rawInput), as DwarfUnitsService does. A new service test covers omitted and explicit limits on the completed result and on the late-cancellation partial observation. Without the fix the omitted case fails; with it the service file passes 13 of 13.
  • Main removed the binaryDiagnostics.ts re-export file (refactor(composition): prune binaryDiagnostics re-export barrel and migrate callers #13839) and moved the offline tool bindings to src/server/offlineInspectionToolBindings.ts. The service, the filesystem boundary test and the verifier import binaryDiagnostics/peRichHeader.js directly. The binding sits next to inspect_pe_imports.
  • Main now reports malformed target bytes as unsupported_target (fix(errors): refuse malformed target bytes as a target, not invalid input #14195) and checks that once per byte reader in stableArtifactParserFailureCli.test.ts. inspect-pe-rich-header is in that table. Its own non-PE CLI case and the malformed row of its boundary test are removed, as main did for the other PE readers.
  • The CI failure on 548b1c30d was directoryArtifactReaderOpen.test.ts. It failed the same way on main 57f4e3c4b and was fixed by fix(tests): expect the path reason for a FIFO root and a symlinked ZIP #14242, which this merge brings in.
  • typecheck, check:fast and docs:check pass. The zsh, fish and nushell completion goldens pass.
  • npm run test:focused on the Rich header tests, stableArtifactParserFailureCli, peUnsupportedTargets, localToolContracts, tupleSchemaParity and the capability conformance tests: 237 passed, 4 skipped. On 5070cbd6f, the service, provider, CLI, MCP, stableArtifactParserFailureCli, peUnsupportedTargets and capability conformance tests: 161 passed; stableArtifactConsumers filtered to the Rich header: 9 passed; tsc passes.
  • tests/boundary/filesystem/peRichHeader.test.ts fails on this host with a symlink EPERM, as peImports.test.ts does on main.
  • This host's Windows native addon is the 6.9.0 package build, with its manifest relabelled to 6.10.1 so the build loads it. The Rich header tool does not call it.

Earlier merges:

  • On ee449a5bd, merged with main 69a691e05:
    • Main split the binary-diagnostics composition into one file per service, and the CLI now loads each service lazily. The merge's two conflicts came from that. src/composition/binaryDiagnostics/peRichHeader.ts builds the service like peImports.ts, and inspect-pe-rich-header imports it the same way inspect-pe-imports does.
    • Main now has 263 tools, so the advertised catalog lists 264 with this one, plus discover_tools. I recomputed the advertised schema summaries while only the listing server reported a POSIX platform. All 265 match the committed files, this tool's included.
    • typecheck, lint (with module boundaries), format:check, verify:architecture-guards, docs:check and verify:test-discovery pass.
    • vitest on this PR's test files plus src/contracts, src/native/pe, src/server, tests/conformance, tests/evaluation, the CLI parity and coverage tests and stableArtifactConsumers: 3,442 passed, 17 skipped, 4 failed. All four fail on this Windows host for reasons outside this PR:
      • A symlink EPERM in peRichHeader.test.ts and in the Hopper fixture test. The Rich header test's four other selections pass when run without the symlink.
      • moduleBoundaries.test.ts expects a forward-slash path in an error message.
      • managedNativeVerification for an empty PE module filename fails the same way on clean main.
    • cliParityGoldens.test.ts: 29 cases fail on this host, the count recorded on clean main f7849cad3. None names the Rich header. The three completion goldens that list inspect-pe-rich-header pass. Clean main 69a691e05 was not rerun.
    • This host's Windows native addon is the 6.9.0 package build, with its manifest relabelled to 6.10.1 so the build loads it. The Rich header tool does not call it.
  • On 5aa1ccbf5, merged with main 9c3ab4a0d:
    • Both Python and the CLI run through one verifier command owner. The fixture releases its root after command cleanup confirms. On notepad.exe and cmd.exe, pefile 2024.8.26 agreed on both records and both checksums matched. The CLI result matched the service result for the first present record. Command: node scripts/verify-pe-rich-header.mjs C:\Windows\System32\notepad.exe C:\Windows\System32\cmd.exe.
    • Upstream removed tracked planning files in docs: remove tracked planning and architecture records #12856. The merge removes this feature's three planning files and their guide links. The maintained guide and dated verification record remain linked.
    • In a separate temporary directory, the verifier exited 0 on a valid PE and 1 when the Python executable was missing. Neither run left a verifier fixture.
    • npm run check:fast and npm run docs:check pass. npm run verify:docs:routes checked 178 HTML pages and 1,569 distinct internal targets and anchors.
    • npm run test:focused on the 11 test files this PR changes: 376 passed, 4 skipped, 1 failed. The failure is the symlink EPERM in tests/boundary/filesystem/peRichHeader.test.ts on this host.
  • Main replaced the docs/index.md guide table with a link to the documentation directory and regrouped docs/README.md. This merge takes main's version of both. The Rich header guide is listed under "Native binaries", next to the other PE guides.
  • Main removed readPeHeaders from src/domain/pe/peResourceLayout.ts. 9a0e6b2d7 reads the PE header offset, machine and format through readPeImageHeaders in src/domain/pe/peImageHeaders.ts, the shared reader that replaced it.
  • cliParityGoldens.test.ts: 29 cases fail on this head, the same count as on clean main f7849cad3 on this host. None of them names the Rich header. Clean main 8c7977f17 was not rerun.
  • The Grok client verifier was not run locally in this update.
  • 472f6c0ce registers tests/acceptance/peRichHeaderCli.test.ts as the capability's public-workflow case. providerCapabilityConformance.test.ts failed 2 of 75 cases before and passes 75 of 75 after. All of tests/conformance: 527 passed, 14 skipped, 2 failed. One failure is a symlink EPERM in the Hopper fixture test. The other, managedNativeVerification for an empty PE module filename, fails the same way on clean main 552d1c710 on this host.
  • 8efcfdd0e fixes the two CI failures on 472f6c0ce:
    • providerLifecycleCoverage.test.ts lacked rea-pe-rich-header. It now lists the provider as in-process, covered like the other PE providers. Before: 1 of 3 failed. After: 3 of 3 pass.
    • The zsh, fish and nushell completion goldens in cliParityGoldens.test.ts lacked inspect-pe-rich-header. Only those three cases were re-recorded. Each file differs from the old one by that single entry, with LF endings.
  • stableArtifactConsumers covers the provider's read-cleanup, nested-owner and cancellation paths through the shared PE projection.
  • Each fix against the commit before it:
Case Before After
Image embedded in the stub, no outer record present with the inner entries on 6f3b15c84 absent on cc3b002ce
DOS MZ image with no PE header execution_failure on 2e1f23bf0 unsupported_target on 5a912aea9
PE header inside the DOS header unreadable_output on 4af9a5243 absent on c03be56c4
Unaligned Rich marker parser case fails on the first commit passes on 4af9a5243
--max-entries 0x10 and 1e3 cliDecimalArguments fails on ec62523bf passes on 0f412071d
File identity after the read provider cases fail with the c1db5e5ec provider pass on 155b2c700
  • node scripts/verify-pe-rich-header.mjs C:\Windows\System32\drivers with pefile 2024.8.26 passed on 1dd2dbe93.
  • On cc3b002ce, the zero-padding rule on real files, read-only: 18,451 PE files under the same folders, with some third-party folders skipped. All 11,427 records are followed only by zeros, so the rule changes no result there. The built parser on the files up to 64 MiB: 11,398 present, 7,004 absent, 0 malformed.
  • On eae1409f3, through scripts/rea.mjs: --help lists both options. --max-entries 2 on notepad.exe fails with resource_constraint (11 entries). A relative path keeps caller_input_path.
  • On 582fe9f80: typecheck, lint (with module boundaries), format:check, docs:check, verify:architecture-guards, verify:test-discovery and verify:docs:routes (437 pages) passed.
  • knip and lint:typed fail only on files this PR does not change: unused exports, an unused src/cli/domainInput.ts, the duplicate export in src/hopper/HopperReplyContracts.ts, and four switch-exhaustiveness-check errors.
  • An earlier CI run failed the former 255-tool assertion in the Grok verifier. Main replaced it with bounded catalog queries in e9c72dbd1.
  • CI on eae1409f3 also failed Native package baseline (darwin arm64). Hopper's list_segments output misses its contract. Main 2e1e6593f fails the same job with the same error.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The tool is additive.
  • Real Hopper/Ghidra, browser, or OS coverage: none needed. Real images on Windows 11 only.
  • Package or release metadata impact: one new package.json script. No new dependency.
  • Security, privacy, process, or containment review: the image is parsed and never run. The read is bounded by max_file_bytes (default 64 MiB), decoding by max_entries (default 1024), and long scans yield and check cancellation every 1 MiB. Exhausted budgets fail without partial success.

Author readiness

Human owner: @Plastic-time

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

Author checklist (completed by the PR author before requesting review)

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.
  • I ran every test, build, or measurement needed to validate this change, reported a browser, GPU, or environment gap only when that runtime or hardware is unavailable, and reported the checks I ran and their results without presenting inferred correctness or speedups as measured.
  • Comments explain constraints or non-obvious decisions; task history and conversations stay out of code and docs.
  • Documentation is concise and factual, without punchy slogans or promotional language.
  • This change fixes the root cause and follows the engineering rules in AGENTS.md.
  • Formatted input is interpreted once at the owning boundary, and consumers use the owner's parsed facts. See Interpret boundary facts once.
  • Combined failures preserve partial observations, remaining resources, and cleanup facts. See Own the lifecycle.
  • A hardcoded limit is an REA_ runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.

Left unchecked:

  • Scope: no maintainer scope decision on this new tool yet.
  • Limits: max_file_bytes and max_entries are caller arguments with fixed ceilings, not REA_ runtime settings. The file budget (default 64 MiB, ceiling 512 MiB) is the one inspect_pe_imports, inspect_pe_load_config and inspect_pe_certificates use. The entry ceiling (65,536) matches inspect_pe_resources directory entries.

AI was used for assistance.

Add inspect_pe_rich_header and the inspect-pe-rich-header command. They
read the Rich header between the DOS stub and the PE signature without a
provider.

- Take the last DWORD-aligned Rich footer before the PE signature and
  walk back to its DanS marker.
- Report each product ID, build and use count, the decoded padding and
  the record's file range.
- Recompute the linker checksum and report whether it reproduces the
  stored key.
- Report an absent record, and a footer without DanS or with a partial
  entry as malformed.

The verifier compares key and entries with pefile 2024.8.26.
@chatgpt-codex-connector

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 ⚠️ Failed 2026-11-04T16:33:29.424749Z
We couldn’t complete this review. Comment @codex review to try again.
82d3f76 PR opened
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The reviewed code appears safe to merge, subject to the maintainer scope decision Plastic-time has left pending.RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed code appears safe to merge, subject to the maintainer scope decision Plastic-time has left pending.

Summary

Adds inspect_pe_rich_header and inspect-pe-rich-header for local PE inspection without running the target. The latest change replaces the large stub copy with one buffer read while preserving the short-read check.

  • PE files now report their Rich header entries and linker checksum.
  • The Rich-header reader is available from the CLI and MCP.
  • Operators can compare Rich-header results with pefile on selected files.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["CLI / MCP"] --> B["PeRichHeaderService"]
  B --> C["PeRichHeaderProvider"]
  C --> D["Hash file and retain prefix"]
  D --> E["Read shared PE headers"]
  E --> F["Fill one stub buffer and decode"]
  F --> G{"File still matches?"}
  G -->|Yes| H["Observed Evidence"]
  G -->|No| I["Typed failure"]
Loading

Reviews (40) · Last reviewed commit: "fix(pe): read large DOS stub into one bu..." · Reviewed by Greptile

Comment thread src/domain/native/peRichHeader.ts Resolved
Comment thread src/native/pe/PeRichHeaderParser.ts Resolved
Comment thread scripts/verify-pe-rich-header.mjs Resolved
Comment thread scripts/verify-pe-rich-header.mjs Resolved
- Scan aligned DWORDs for the Rich footer and DanS marker in one loop
  that yields and checks cancellation every MiB. A stub full of
  unaligned Rich strings no longer holds the event loop.
- Declare the padding words with fixedTupleSchema and cover them in the
  tuple parity tests.
- Import the binary diagnostics contract family in the focused CLI and
  MCP tests.
- In the pefile verifier, exclude files only by pefile's own layout
  result, fail any other state difference, refuse a run that compares
  nothing, and give the CLI check the same read budget.
A PE whose e_lfanew points inside the 64-byte DOS header passes
readPeHeaders, and the parser reports no Rich record for it. The
service then refused the report as malformed provider output, because
it required pe_header_offset to be at least 64.

Drop that lower bound. The footer checks still reject any record
reported before 0x40.
@morluto

morluto commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Very interesting!

Comment thread src/native/pe/PeRichHeaderProvider.ts Resolved
Comment thread scripts/verify-pe-rich-header.mjs Resolved
- Once the stable read completes, a later decoding failure or
  cancellation keeps the file's path, SHA-256 and byte count as a
  partial observation.
- The pefile verifier now fails on a file that pefile reads but REA
  rejects. An input both reject, such as an empty file, is listed
  apart.
…ct-pe-rich-header

# Conflicts:
#	.agents/skills/reverse-engineer-anything/SKILL.md
#	.agents/skills/reverse-engineer-anything/references/native-and-artifacts.md
#	docs/cli.md
#	docs/index.md
#	package.json
#	src/domain/investigationProviders.ts
#	tests/process-global/stableArtifactConsumers.test.ts
Comment thread src/native/pe/PeRichHeaderProvider.ts Resolved
- Since main's 21ad5b1, readPeHeaders reports a valid DOS MZ image
  with no PE header as unsupported. The Rich header provider now maps
  that to unsupported_target instead of execution_failure.
- PeUnsupportedTargets.test.ts and the CLI and MCP acceptance test now
  cover inspect_pe_rich_header.
…pect-pe-rich-header

# Conflicts:
#	src/contracts/toolEffects.test.ts
…pect-pe-rich-header

# Conflicts:
#	docs/.vitepress/config.ts
#	docs/index.md
Comment thread src/cli/binaryDiagnosticsCommands.ts Resolved
Comment thread docs/guides/native/pe-rich-header.md Resolved
`--max-file-bytes` and `--max-entries` on `inspect-pe-rich-header` now use
`cliDecimalField`, like the other numeric CLI options since main's
99db80a. `0x10` and `1e3` are rejected instead of parsed.
- Add spec.md, plan.md and tasks.md under docs/specs/native/pe-rich-header/,
  as docs/development/documentation.md now requires for a new feature.
- tasks.md says the specification was written after the first
  implementation.
- The guide links to the three documents.
Comment thread docs/guides/native/pe-rich-header.md Resolved
- docs/development/documentation.md puts analyst guides under
  docs/guides/<domain>/.
- The public route stays /pe-rich-header. documentation.ts now lists the
  guide under Native binaries.
- Links from the docs index, the docs README, the CLI guide, the spec plan
  and the skill follow the move.
@CassieFox23

CassieFox23 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: I ran the PR's 11 changed test files on Node 22.23.4, 24.22.1 and 26.12.1. Every run passed all 256 tests. The head is 25 commits behind main c78c8ae, and I did not test a merge.

Edit (20 Nov): I ran the new head, 9a0e6b2, in a VM, and the results are here.

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Test Files (11 changed) 11 passed (11) 11 passed (11) 11 passed (11)
Tests 256 passed (256) 256 passed (256) 256 passed (256)

The PR changes 41 files against the merge base 559083b. Eleven are test files and 30 are others, such as docs and .agents/skills files. I ran only the 11 test files, not the full suite.

CI on head 01fb8cb, read live with gh:

  • Mergeable is true, the state is blocked, and the PR is not a draft.
  • Workflow runs: CI completed/success, CodeQL production completed/skipped.
  • PR readiness has two runs, one completed/cancelled and one completed/success. PR title also has two runs, one completed/cancelled and one completed/success.
  • Check runs: 33 success, including CI required, Source tests, Static checks, Documentation and Test shard (1/8) through Test shard (8/8).
  • Check runs: 15 skipped, including Deep static checks and Windows capability and package lane.
  • Check runs: 2 cancelled, Conventional PR title and Validate author declaration. Both names also appear once in the success list.
  • Commit status: PR readiness is success.

Not run

  • A fixture with block: false and a stub holding an embedded richFixtureBlock(...), expecting absent
  • A test that covers the Cancellation during decoding takes the same path claim in PeRichHeaderProvider.test.ts
  • 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: 01fb8cb / 559083b (merge base with main)
  • 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/application/binaryDiagnostics/PeRichHeaderService.test.ts src/contracts/tupleSchemaParity.test.ts src/native/pe/PeRichHeaderParser.test.ts src/native/pe/PeRichHeaderProvider.test.ts src/native/pe/PeUnsupportedTargets.test.ts tests/acceptance/applications/peUnsupportedTargets.test.ts tests/acceptance/peRichHeaderCli.test.ts tests/acceptance/tools/localToolContracts.test.ts tests/boundary/filesystem/peRichHeader.test.ts tests/boundary/mcp/peRichHeaderMcp.test.ts tests/process-global/stableArtifactConsumers.test.ts

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

@CassieFox23

CassieFox23 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: On head 9a0e6b2, the PR's 11 changed test files pass on Node 22.23.4, 24.22.1 and 26.12.1. CI run 44663165115 failed 3 tests outside those files. Main's own CI failed the same 3 tests that night, and main is green again now.

Edit (20 Nov): I ran the new head, 5aa1ccb, in a VM, and the results are here.

My last comment tested head 01fb8cb. This run is on head 9a0e6b2.

Thanks, Plastic-time, for the tests on the two gaps I listed. does not take the record of an image embedded in the stub covers block: false with an embedded record. keeps the file identity when cancellation arrives during decoding covers the cancellation path. Both pass in my run.

Results

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Test files pass, 11 of 11 pass, 11 of 11 pass, 11 of 11
Tests pass, 381 of 381 pass, 381 of 381 pass, 381 of 381

The PR changes 46 files against the merge base 8c7977f. Of those, 11 are test files and 35 are other files. I ran only the 11 test files.

The CI workflow run 44663165115 ended completed/failure. The log of the CI run says Error: CI lanes did not pass: test, test-shard, test-source. The log shows three failing tests:

  • supports architectures, signatures, plists, and ordered demangling in tests/boundary/providers/native/nativeProvider.test.ts
  • names an existing test file and literal test title for every covered stage in tests/evaluation/providerLifecycleCoverage.test.ts
  • keeps the decision record in docs/providers/ghidra-riscv.md in step with the tables in src/ghidra/GhidraRiscvProfile.test.ts

The run tested this head merged into main 88f885a. The PR doesn't change any of those 3 test files.

Main's own CI failed the same 3 tests that night:

Main's CI on c0d3f2e passed today. So these failures look like main's, not this PR's.

Check runs on the head:

  • Failure (4): CI required, Portable tests, Source tests, Test shard (3/12).
  • Cancelled (7): Test shard (1/12), Test shard (6/12), Test shard (8/12), Test shard (9/12), Test shard (10/12), Test shard (11/12) and Test shard (12/12).
  • Success (26): Static checks, Documentation, Build package and Conventional PR title are among them.
  • Skipped (18): Deep static checks and Source-built conformance fixtures are among them.
  • Other runs: PR title ran twice, both completed/success. CodeQL production was completed/skipped.

GitHub shows the PR as mergeable true with state blocked. The head is 156 commits behind main c0d3f2e.

Not run

  • A run of this head merged into current main, c0d3f2e.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB, Linux 7.2.11) on my Nobara 44 PC
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 9a0e6b2 / 8c7977f (merge base with main)
  • 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/application/binaryDiagnostics/PeRichHeaderService.test.ts src/contracts/tupleSchemaParity.test.ts src/native/pe/PeRichHeaderParser.test.ts src/native/pe/PeRichHeaderProvider.test.ts src/native/pe/PeUnsupportedTargets.test.ts tests/acceptance/applications/peUnsupportedTargets.test.ts tests/acceptance/peRichHeaderCli.test.ts tests/acceptance/tools/localToolContracts.test.ts tests/boundary/filesystem/peRichHeader.test.ts tests/boundary/mcp/peRichHeaderMcp.test.ts tests/process-global/stableArtifactConsumers.test.ts

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

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: On head 5aa1ccb, the PR's 11 changed test files pass on Node 22.23.4, 24.22.1 and 26.12.1, 381 of 381 on each. Since my last run, the only code change is in scripts/verify-pe-rich-header.mjs, which I did not run.

Results

My last comment tested 9a0e6b2. Two commits came after it. The merge 1e834e9 also edits scripts/verify-pe-rich-header.mjs and drops the three docs/specs/native/pe-rich-header/ files. Then 5aa1ccb removes the links to them from docs/guides/native/pe-rich-header.md. I compared the PR's diff at both heads, and those are the only changes. This run covers 5aa1ccb in a VM, with the PR's 11 changed test files.

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Test Files pass, 11 passed (11) pass, 11 passed (11) pass, 11 passed (11)
Tests pass, 381 passed (381) pass, 381 passed (381) pass, 381 passed (381)
  • The verifier now runs pefile and the CLI through createVerifierCommands instead of execFileSync. I read the helper at this head. exec returns stdout as a string and throws VerifierCommandExitError on a non-zero exit (scripts/lib/verifier-command-owner.mts, lines 45 and 223), so the old encoding: "utf8" isn't needed. maxBuffer and the CLI's 60 s timeout are still passed.
  • No file at this head still links to docs/specs/native/pe-rich-header/ (git grep).
  • The PR changes 43 files against the merge base: 11 test files and 32 others. The head is 23 commits behind main 329510a.
  • I read CI on the head live with gh. It shows mergeable, state clean, not a draft. CI is completed/success, with 37 check runs success (all 12 Test shard runs among them) and 18 skipped.

Not run

  • node scripts/verify-pe-rich-header.mjs against pefile 2024.8.26. It needs REA_PEFILE_PYTHON and real PE files, and it's the one file the new commits change in code.
  • A merge with current main, 329510a.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB, Linux 7.2.11) on my Nobara 44 PC
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 5aa1ccb / 9c3ab4a (merge base with main)
  • 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/application/binaryDiagnostics/PeRichHeaderService.test.ts src/contracts/tupleSchemaParity.test.ts src/native/pe/PeRichHeaderParser.test.ts src/native/pe/PeRichHeaderProvider.test.ts src/native/pe/PeUnsupportedTargets.test.ts tests/acceptance/applications/peUnsupportedTargets.test.ts tests/acceptance/peRichHeaderCli.test.ts tests/acceptance/tools/localToolContracts.test.ts tests/boundary/filesystem/peRichHeader.test.ts tests/boundary/mcp/peRichHeaderMcp.test.ts tests/process-global/stableArtifactConsumers.test.ts

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

Conflicts:
- src/composition/binaryDiagnostics.ts: main split each service factory
  into src/composition/binaryDiagnostics/<service>.ts and re-exports
  them. Take main's file, add the createPeRichHeaderService re-export
  and its own peRichHeader.ts, like peImports.ts.
- src/cli/binaryDiagnosticsCommands.ts: main loads each service's
  composition lazily. Take main's file and register
  inspect-pe-rich-header the same way as inspect-pe-imports.
@Plastic-time Plastic-time reopened this Nov 22, 2026
@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
Conflicts:
- src/composition/binaryDiagnostics.ts: main removed the re-export
  barrel (morluto#13839). Drop it and import createPeRichHeaderService from
  binaryDiagnostics/peRichHeader.js in capabilityServices, the
  filesystem boundary test and the verify script.
- src/server/serviceToolBindings.ts: main moved the offline inspection
  bindings into offlineInspectionToolBindings.ts. Register
  inspect_pe_rich_header there next to inspect_pe_imports.
- reverse-engineer-anything SKILL.md: main compacted the tool list.
  Add inspect_pe_rich_header and its guide to the PE tables entry.

Follow main's malformed-target classification (morluto#14195):
- Add inspect-pe-rich-header to the stable-artifact parser-failure CLI
  table and drop the command's own non-PE refusal case.
- Drop the malformed-file row from the filesystem boundary test.
- Expect a truncated MZ image to refuse as unsupported_target with
  format_failure malformed.
…ection

Input parsing, the provider call, output validation and late-cancellation checks now come from the shared artifact inspection runner, like inspect_pe_imports. validReport and the Evidence locations stay as the runner's callbacks.
No conflicts. Brings in the main fix for the DirectoryArtifactReader non-file test (morluto#14242) that failed CI on the previous merge base.
Comment thread src/native/pe/PeRichHeaderProvider.ts Resolved
Comment thread scripts/verify-pe-rich-header.mjs Resolved
…header

# Conflicts:
#	docs/getting-started/cli.md
#	src/domain/investigationProviders.ts
#	tests/fixtures/cli-parity/complete-nushell-described-commands.txt
#	tests/process-global/stableArtifactConsumers.test.ts
Comment thread src/native/pe/PeRichHeaderParser.ts Resolved

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