Repository navigation
feat(pe): report the overlay appended after a PE image's last section - #13245
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The reviewed code appears safe to merge; no new blocking issue was found. SummaryAdds
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["CLI or MCP request"] --> B["PeOverlayService"]
B --> C["PeOverlayProvider"]
C --> D["Bounded, stable file snapshot"]
D --> E["Shared PE header reader"]
E --> F["computePeOverlay"]
F --> G["Shared security-directory checks"]
G --> H["Certificate and other ranges"]
H --> I["Hashes, entropy and format probes"]
I --> J["Validated derived Evidence"]
Reviews (15) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
Keep impossible security directory spans in measured overlay bytes and share bounded format recognition with inventory. Validate structured overlay facts in the domain while preserving provider diagnostics.
|
@mvanhorn thanks for the PR — this branch has merge conflicts with |
Resolve conflicts against upstream main (42bbf33) and carry the PE overlay feature onto upstream's new structure: - composition: binaryDiagnostics.ts was split into per-service modules; add composition/binaryDiagnostics/peOverlay.ts and import it lazily from the CLI as the other services do. - server: bind inspect_pe_overlay in offlineInspectionToolBindings.ts. - PE headers: peImageHeaders.ts no longer reads headers; the overlay parser now admits headers through readPeImage(bytes, "headers"). - certificates: keep upstream's parser and failure kinds; apply the shared security-directory admission for absent, in-header, unaligned and out-of-file tables, and leave short or off-grid sizes to the entry walk, which reports the truncated header or padding. - recognition: recognizeBoundedArtifactFormat takes the caller's XML plist probe result, as inventory now probes plists incrementally; overlay ranges run the same bounded probe. Leading formats include upstream's new recognizers. - register the overlay structural allowance in the fixed-ceiling registry; restore computeBlockEntropy for single-sample entropy. - tests follow upstream's malformed-target and certificate failure shapes; regenerate the nushell completion golden.
Resolve conflicts against upstream main (26cb5b5), which added the ISO 9660 disc image reader: - recognition: keep recognizeBoundedArtifactFormat beside upstream's new recognizesArtifactPrefix. - inventory: classifyArtifactHeader keeps the shared bounded recognizer and now passes upstream's ISO 9660 descriptor through to it.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Conflicts with main are resolved in a4b6e6f, which brings in the ISO 9660 reader and keeps it working next to the PE overlay recognition. CI is running on the new head now. |
parsePeOverlay dropped pe_header_anomalies from readPeImage, so a SizeOfHeaders that ends before the section table reached the overlay report without its warning. Carry header_anomalies through the output contract and Evidence result, as the certificate, import and load config reports already do.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
… caller parameters in inspect_pe_overlay
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
# Conflicts: # src/native/pe/PeCertificateParser.ts
…tifactInspection in PeOverlayService
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
# Conflicts: # docs/index.md
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Preserve both origin/main (morluto#12469 VSIX, morluto#13245 PE overlay, morluto#14649 Qualcomm MBN) and YARA entries across conflicted skill docs and test-projects, and include qualcomm-mbn in PE_OVERLAY_LEADING_FORMATS to resolve the typecheck regression between morluto#13245 and morluto#14649.
Summary
Installers, self-extracting archives and tampered executables often carry data appended after the last section of a PE file. REA can parse PE headers, resources and certificates, but it has no direct way to answer "is there anything after the image, where does it start, and what is it". Today an analyst works that out by hand from section tables or with a separate tool, with no Evidence tying the answer to the file.
This adds
inspect_pe_overlay(CLIrea inspect-pe-overlay <path> --json), an offline report of the bytes after the end of a PE32 or PE32+ image. No issue exists for this; it is a static format-inspection addition within the supported contribution scope.Problem and expected behavior
Use case: given
setup.exe, find whether it carries an overlay, separate a trailing Authenticode certificate table from other appended bytes, and get each remaining range's offset, size, hash and leading format.Observable outcome:
SizeOfHeadersand every contributing section's declaredPointerToRawData + SizeOfRawData, so section padding is never reported as overlay. Zero-size and uninitialized-only sections are listed but do not move the image end.presentis false when the file ends at the image end.security_directoryreports the declaredIMAGE_DIRECTORY_ENTRY_SECURITYasabsent,table, ormalformedwith the defect. A valid table that lies entirely inside the overlay becomes its owncertificate_tablerange; a malformed or straddling table stays in ordinary ranges with a limitation naming why.otherrange carries offset, size, SHA-256, a Shannon entropy sample over at most the first 4096 bytes, the first 16 bytes as hex, and aleading_formatfrom REA's existing recognizers (otherwiseunrecognized).section_coverage.statusispartialand every declared section still counts toward the image end.Change and scope
src/domain/native/peOverlay.tscomputes the image end, section rows, raw pointer rounding, overlay span and range split from parsed headers.src/native/pe/PeOverlayParser.tsreads headers and the overlay through bounded reads;PeOverlayProvider.tsandsrc/application/binaryDiagnostics/PeOverlayService.tswire it as a binary diagnostics provider. The service re-validates certificate ranges against the declared security directory before splitting.src/domain/pe/peSecurityDirectory.tsholds the security directory checks shared withinspect_pe_certificates(zero size, offset inside headers, 8-byte alignment, range outside the file), so both tools classify the same directory the same way.PeCertificateParser.tsnow uses it.docs/guides/native/pe-overlay.md, sidebar entry, CLI reference, docs index and skill references.Not included: packer identification, Authenticode verification, decoding certificate entries, and detecting data hidden in section slack inside the mapped image (stated as a limitation in every report).
Contract and boundary impact
peOverlay.tsowns overlay facts; parser, provider and service consume them.inspect_pe_overlay(path, optionalmax_file_bytes, default 64 MiB, ceiling 512 MiB), and the CLI commandinspect-pe-overlay. Existing tools unchanged.rea-pe-overlay; PE32 and PE32+ only.inspect_pe_overlaynormalized result; existing Evidence shapes unchanged.docs/public/product-catalog.json), package, or installation impact: none committed; authored skill references updated under.agents/skills/reverse-engineer-anything/.Expected effects:
Evidence and regression coverage
src/native/pe/PeOverlayParser.test.ts(image end from headers and sections, padding, uninitialized and zero-size sections, raw pointer rounding, 96-section cap, certificate table inside, straddling and malformed, out-of-file section failures),src/application/binaryDiagnostics/PeOverlayService.test.ts(directory layout re-validation, derived Evidence),PeCertificateParser.test.ts(shared security directory checks),tests/acceptance/peOverlayCli.test.ts,tests/boundary/filesystem/peOverlay.test.ts,tests/boundary/mcp/peOverlayMcp.test.ts, plus the local tool contract test. Fixtures are generated inPeOverlay.fixture.ts.rea inspect-pe-overlay setup.exe --json, excerpt ofnormalized_result, generated PE32 with a certificate table and an appended ZIP):{ "format": "pe32", "size_of_headers": 512, "image_end": 512, "file_size": 1366, "present": true, "section_coverage": { "status": "complete", "declared": 1, "reported": 1 }, "security_directory": { "status": "table", "offset": 512, "size": 384 }, "ranges": [ { "role": "certificate_table", "offset": 512, "size": 384 }, { "role": "other", "offset": 896, "size": 470, "sha256": "87cadb30e946d88313ea98c46ba82907aca205e89c7d2047cdff7c61c621e944", "entropy": { "window_bytes": 4096, "sampled_bytes": 470, "shannon_bits": 3.4771 }, "prefix_hex": "504b0304140000000000000000000000", "leading_format": "zip" } ] }On a second fixture whose security directory points past the end of the file, the report shows
"security_directory": { "status": "malformed", "offset": 1056, "size": 256, "defect": "outside-artifact" }, keeps the 64 trailing bytes as oneotherrange, and adds the limitation "IMAGE_DIRECTORY_ENTRY_SECURITY is malformed: PE certificate table range leaves the artifact. No certificate table is separated; its bytes are reported as ordinary ranges."For evidence-bearing changes:
Demo
Rendered walkthrough of the CLI output above (simulated terminal, values taken from a real run on the generated fixtures).
Validation performed
npx --no-install vitest runover the changed test files (overlay service, certificate parser, overlay parser, CLI acceptance, local tool contracts, filesystem boundary, MCP boundary): passednpm run format:check: all matched files use the correct formatCompatibility, safety, and release
inspect_pe_certificateskeeps its behavior; its directory checks moved into a shared helper.AI was used for assistance.
Author readiness
Human owner: @mvanhorn
Before merge
type(scope): outcome.