* 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
5.2 KiB
PE import and delay-load tables
inspect_pe_imports / inspect-pe-imports answers whether one selected local
PE32/PE32+ image declares an IMAGE_DIRECTORY_ENTRY_IMPORT table, which DLLs
and functions that table names, which delay-load descriptors are present, and
the pefile-compatible import hash of the standard import table. It reads the
file without executing it and does not require a Windows SDK or disassembler.
rea inspect-pe-imports /absolute/path/to/application.exe --json
The CLI resolves relative paths against the caller's working directory. MCP and the advertised input schema require an absolute filesystem path and preserve that exact selection:
{
"name": "inspect_pe_imports",
"arguments": { "path": "/artifacts/application.exe" }
}
Observations
The inline Evidence result contains the artifact path, SHA-256, byte length and
the optional-header image_base. Each function row gives its import address
table slot as iat_rva and as iat_va (image_base plus iat_rva). iat_va
is relative to the ImageBase the file declares, which is where a provider
loads the image unless its database was rebased. Pass iat_va to xrefs and
other provider tools for a database at the file's base. For a rebased database,
such as an IDA database moved before REA attached, add iat_rva to the base
that provider reports for the image instead; REA does not observe that base
from the file.
import_directory and delay_import_directory report the data directory RVA
and size, or null when a directory is absent or zero. Their locations are
the file spans actually read for the descriptor array and its terminator. When
consecutive descriptors map to discontiguous file bytes (for example across a
section boundary), each span is reported separately, and each becomes its own
Evidence file-offset range.
If the first descriptor cannot be examined, the directory declaration remains
present with no consumed locations, and coverage is partial. Descriptors,
thunks and NUL-terminated names stay within PE's 32-bit RVA space, including
PE32+ images. Like the Windows loader, descriptor walks continue to the null
descriptor past a short declared directory Size; that Size is reported in
header_anomalies. See
PE header admission.
machine retains the original unsigned COFF value. architecture decodes
known machines, including ReadyToRun OS overrides when a CLI directory is
declared; that declaration does not establish valid CLR metadata or runtime
compatibility. Unrecognized machines retain pe-machine-<decimal> while their
import tables remain inspectable. A recognized machine whose width contradicts
the optional header is malformed.
Each imports[] item reports the DLL name, descriptor RVAs, and named or
ordinal functions with ILT/IAT RVAs. delay_imports[] reports RVA-based
delay-load descriptors separately. imphash is pefile's get_imphash() over
the standard import table only; delay-load rows do not participate. Ordinal
imports use pefile's ordinal name tables and otherwise its ord<decimal>
fallback.
imphash.md5 is null with a reason whenever the value would not be
pefile's hash of this image: the standard import table is partial, or pefile
would read a different row sequence (names it treats as invalid or truncates,
ordinal 0, descriptors without functions, or tables its bounds and import
symbol cap truncate). Delay-load issues do not withhold the hash.
Import inspection uses a forensic file-backed RVA mapping that can include raw
alignment bytes beyond a section's VirtualSize. The hash compatibility check
compares the consumed spans with pefile's section selection and raw read bounds.
A matching hash describes that on-disk import stream.
pefile 2024.8.26 section mapping
A missing import directory is observed absence of that table. It is not proof the image never imported APIs through another table or overlay.
Limits and failures
The reader reads at most 64 MiB by default (max_file_bytes, 512 MiB maximum;
see read allowance), whatever the file size. At most
256 import and delay-load descriptors are examined by default (4096 maximum),
and at most 8192 functions across every table (262144 maximum). Malformed PE
headers and exhausted DLL or function budgets fail without partial success.
Decoded DLL and function names are limited to a fixed 16 MiB of retained text
with no runtime override; max_file_bytes, max_dlls and max_functions do
not raise it. Resource failures report the exhausted allowance as limit
(dlls, functions or retained_text) with matching recovery.
Unreadable DLL names, hint/name entries, thunks, or descriptors are reported as
partial coverage with issues. A
descriptor whose required table RVA is zero (a
standard FirstThunk, or a delay-load import address or name table) is
reported as malformed_entry with no functions, never as a complete empty
inventory. Delay-load descriptors that store virtual addresses rather than RVAs
are recorded as unsupported_form and are not decoded.
This workflow does not resolve bound imports, loaded IAT contents, or export-forward names in another DLL.