Skip to content

feat(pe): report image_base and IAT slot VAs in static PE results - #14263

Merged
morluto merged 5 commits into
fix/pe-bytes-read-admissionfrom
fix/pe-address-vocabulary
Nov 24, 2026
Merged

morluto merged 5 commits into
fix/pe-bytes-read-admissionfrom
fix/pe-address-vocabulary

Conversation

@morluto

@morluto morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Depends on #14262, which depends on #14253. The base is #14262's branch, so this diff shows only the address vocabulary.

Root cause

The PE reader owner (PeImage) parses ImageBase, but only exports and load config used it, to project VAs. No static PE result exposed the base itself. Imports gave IAT slots only as RVAs, so an agent going from a static import row to a provider (xrefs, decompile) had to compute the VA by hand. Passing the RVA failed with an "outside every segment" error.

Fix

  • src/domain/native/peAddressSpace.ts owns the vocabulary: peVaSchema, an optional peImageBaseSchema, and the peVa / peImageBaseHex helpers. Fields name their space as rva (relative to the base), va or a _va suffix (base plus RVA, what providers accept), and file_offset or a location range (file bytes).
  • image_base (a hex VA) is reported once by imports, exports (PE), load config, resources, certificates and each PE hardening image. All values come from the same PeImage.image_base.
  • Import function rows add iat_va beside iat_rva. PeImportsService rejects a report whose iat_va disagrees with image_base plus iat_rva.
  • Existing fields are unchanged. All new fields are optional, so saved Evidence still parses. Export rows keep their existing VA field address. Renaming it to va would break saved Evidence for a spelling-only gain, so it is documented instead.
  • Docs: the binary diagnostics guide's PE section describes the address spaces, and pe-imports.md describes image_base and iat_va.

Validation

  • New contract test tests/boundary/filesystem/peAddressSpace.test.ts. It runs all six services on one PE32+ fixture and checks that each reports image_base 0x180000000, and that a load-config callback VA equals the base plus its RVA. For PE32 and PE32+ import fixtures, every iat_va equals image_base plus iat_rva.
  • Mutation checks: computing iat_va without the base fails 2 tests, and dropping image_base from resources fails 1.
  • npx vitest run passed on src/native, src/application/binaryDiagnostics, src/domain/native, src/domain/pe and the PE filesystem and MCP boundary suites (3030 tests). Also clean: scoped tsc, the push hook's full typecheck, oxlint, oxfmt and the architecture guards.
  • corkami counts are unchanged from fix(pe)!: share one loader-equivalent PE header owner across static readers #14253/fix(pe)!: bound static readers by the bytes they read, not file size #14262, because this PR adds fields only.

Not in this PR

#14164 also asks for a provider-side hint when an out-of-segment address looks like an RVA (Hopper invalid_request). That error has a different owner (the Hopper and provider error projection), and #14239 is reworking failure details. This PR covers the static half: image_base and VAs. The issue's architecture-spelling difference (amd64 vs x86_64) is also out of scope.

Refs #14164

Every static PE result reports the optional-header image_base once as a hex
VA, and import rows add iat_va beside iat_rva so a slot goes straight to
xrefs. Fields name their space as rva, va or file_offset; the new fields are
optional so saved Evidence still parses, and the imports service rejects an
iat_va that disagrees with image_base plus iat_rva.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T02:45:40.227381Z
We couldn’t complete this review. Comment @codex review to try again.
c545a39 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

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge.

Summary

Adds image_base across six static PE reports and iat_va beside each import slot’s iat_rva.

  • Static PE reports show the image base declared by each file.
  • Import rows include a virtual address for each IAT slot.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["PE optional header"] --> B["PeImage.image_base"]
  B --> C["Six static PE reports: image_base"]
  B --> D["Import slot: base + iat_rva"]
  D --> E["iat_va"]
  C --> F["PeImportsService checks agreement"]
  E --> F
  F --> G["Evidence"]
Loading

Reviews (3) · Last reviewed commit: "Merge branch 'fix/pe-bytes-read-admissio..." · Reviewed by Greptile

Comment thread docs/pe-imports.md Resolved
iat_va is relative to the file's ImageBase; a rebased provider database
needs its own base plus iat_rva. Cover the service rejection of a slot VA
that disagrees with image_base plus iat_rva.
@morluto
morluto merged commit 3f8375b into fix/pe-bytes-read-admission Nov 24, 2026
41 checks passed
@morluto
morluto deleted the fix/pe-address-vocabulary branch November 24, 2026 04:30
morluto added a commit that referenced this pull request Nov 24, 2026
…14262)

* fix(pe)!: share one loader-equivalent PE header owner across static readers

Resources and certificates now admit headers through readPeImage, and
resources map RVAs through the shared file-backed mapping. The owner reads
the optional header at fixed offsets, caps data directories at 16, and lets
a PE signature at e_lfanew override a DOS relocation table. Export, import,
TLS and resource directories are read at their RVA whatever Size declares.
Disregarded declarations are reported in header_anomalies.

BREAKING CHANGE: import and delay-import walks continue to the null
descriptor past a short directory Size instead of stopping with a
malformed_entry issue, and inspect-pe-resources reports an unsupported
optional-header magic as unsupported_target.

* fix(pe): keep valid DOS relocation tables owning e_lfanew

Only a relocation table that describes no DOS load module yields e_lfanew
to a PE signature; update MZ/PE conformance to the shared owner.

* fix(pe)!: bound static readers by the bytes they read, not file size

max_file_bytes now counts the header prefix and every positional read of
headers, directory tables and their referenced ranges. The identity pass
that hashes the whole file is bounded only by a fixed whole-file ceiling:
4 GiB minus one byte for the PE-only readers, whose file offsets are 32-bit,
and 512 MiB for hardening and exports. An exhausted allowance is a capacity
refusal with a typed parameter details.limit.

BREAKING CHANGE: max_file_bytes no longer refuses a large file whose reads
fit; an exhausted read allowance reports resource capacity instead of
file-size, and only a file above the fixed ceiling reports file-size.

* fix(pe): walk resource trees within file-backed bytes and cite TLS reads

The resource walk is bounded by the file-backed run from the directory RVA
rather than its Size, and a Size that ends before the bytes walked is a
directory_size_below_structure anomaly. The TLS result carries
structure_location for the structure read past a short Size, and Evidence
cites it.

* test(pe): assert a refused read never reaches the descriptor

* test(pe): use a resource cycle as damage now that a short Size is read

* fix(pe): read resource trees past an oversized Size and keep damaged MZ headers malformed

An oversized resource Size is reported without requiring its unused bytes
to map. A Windows-header candidate is malformed when the DOS module is also
invalid, and the guide states that a valid DOS relocation table owns
e_lfanew.

* feat(pe): report image_base and IAT slot VAs in static PE results (#14263)

* feat(pe): report image_base and IAT slot VAs in static PE results

Every static PE result reports the optional-header image_base once as a hex
VA, and import rows add iat_va beside iat_rva so a slot goes straight to
xrefs. Fields name their space as rva, va or file_offset; the new fields are
optional so saved Evidence still parses, and the imports service rejects an
iat_va that disagrees with image_base plus iat_rva.

* fix(pe): document iat_va for rebased databases and test VA rejection

iat_va is relative to the file's ImageBase; a rebased provider database
needs its own base plus iat_rva. Cover the service rejection of a slot VA
that disagrees with image_base plus iat_rva.

* chore(pe): register the forwarded whole-file ceiling and shrink refusal baselines
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request labels Nov 26, 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.

1 participant