mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 22:11:12 +00:00
* 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
65 lines
3.9 KiB
Markdown
65 lines
3.9 KiB
Markdown
# PE TLS callbacks and load configuration
|
|
|
|
Use `inspect_pe_load_config` to locate declared TLS callbacks and inspect the load
|
|
configuration of an explicit local PE32 or PE32+ image. No disassembler, Windows
|
|
host, or target execution is required.
|
|
|
|
```sh
|
|
rea inspect-pe-load-config /absolute/path/to/application.exe --json
|
|
rea inspect-pe-load-config /absolute/path/to/application.exe --max-callbacks 256 --json
|
|
```
|
|
|
|
MCP accepts `{ "path": "/absolute/path/to/application.exe" }`. CLI paths may be
|
|
relative to the current directory; MCP paths must be absolute.
|
|
|
|
The complete Evidence includes the artifact path, SHA-256, directory file ranges,
|
|
and callback-array file ranges. `tls` reports the raw data range, index address,
|
|
zero-fill size, characteristics and null-terminated callback array. Callback VAs
|
|
are hexadecimal strings to preserve 64-bit precision. RVA, mapped file offset,
|
|
and section are derived locations; unknown mappings are `null`.
|
|
TLS template file offsets require file-backed bytes within the declared image;
|
|
file-alignment padding outside a section's virtual extent leaves the offset
|
|
unknown while retaining the stored address range.
|
|
|
|
`load_config` reports fields only when its declared `Size` covers the entire
|
|
field. MSVC x86 images often declare a 64-byte load-config data directory while
|
|
the structure's own `Size` is larger; like the Windows loader, REA reads `Size`
|
|
bytes when they are file-backed in one run, and reports both
|
|
`directory.size` and `size`. `structure_location` is the file range of the
|
|
`Size` bytes REA checked; Evidence locations include it beside the declared
|
|
directory range when the two differ. Unavailable fields are `null`; a covered zero pointer remains `"0x0"`.
|
|
The report includes the security cookie, PE32 SafeSEH table/count, CFG pointers
|
|
and table/count, address-taken IAT and long-jump tables/counts, EH continuation
|
|
table/count, and XFG check pointer. CHPE and dynamic relocation pointers are raw
|
|
values. The dynamic relocation table offset (DWORD) and section (WORD) are
|
|
reported separately when `Size` covers them, including zero values; REA does
|
|
not infer a VA from that pair or decode the target and mitigation-table entries.
|
|
|
|
Guard flags retain the raw DWORD, recognized names, unknown bits, and the CFG
|
|
entry stride. Mitigation claims derived from those flags carry
|
|
`evidence_kind: "inferred"`; they do not prove runtime enforcement. The image is
|
|
never executed. Missing directories are observed absence of those declarations,
|
|
not proof that no callback or mitigation exists by another mechanism.
|
|
|
|
The default [read allowance](reference/limits-and-recovery.md#static-reader-read-allowance) is 64 MiB of reads (`max_file_bytes`, ceiling 512 MiB),
|
|
whatever the file size. The default
|
|
callback budget is 64 (`max_callbacks`, ceiling 4096). An exact-budget array is
|
|
accepted if its next slot is null. A TLS directory `Size` below its structure is
|
|
read at its RVA, cited as `tls.structure_location`, and reported in
|
|
`header_anomalies`, and a zero directory RVA is
|
|
absent, as the loader treats them; see
|
|
[PE header admission](guides/native/binary-diagnostics.md#pe-header-admission).
|
|
Truncated, ambiguous or unmapped directory and
|
|
callback-array storage fails closed, as does budget exhaustion; no partial
|
|
success is returned. An unmapped callback **target** retains its VA/RVA with an
|
|
unknown file offset. Load-config versions beyond the supported fields remain
|
|
undecoded.
|
|
|
|
Layout references: [Microsoft PE format](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format),
|
|
[IMAGE_LOAD_CONFIG_DIRECTORY32](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_load_config_directory32),
|
|
and [IMAGE_LOAD_CONFIG_DIRECTORY64](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_load_config_directory64).
|
|
|
|
For a real cross-compiled fixture, run `npm run verify:pe:load-config` with Zig
|
|
on PATH (or `REA_ZIG` set to its path). The script builds PE32 and PE32+ samples
|
|
and inspects them through the public CLI without running them.
|