Skip to content

feat(pe): inspect TLS callbacks and load configuration - #7008

Merged
morluto merged 2 commits into
morluto:mainfrom
mvanhorn:fix/pe-tls-load-config
Oct 24, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
mvanhorn:fix/pe-tls-load-config

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

TLS callbacks run before a PE image's entry point, and the load configuration declares the security cookie, SafeSEH table and Control Flow Guard metadata. REA can inspect PE imports, resources and certificates, but had no static view of either directory. This adds inspect-pe-load-config (CLI) and inspect_pe_load_config (MCP) for PE32 and PE32+ images, read without executing the image or opening a disassembler. No related issue; this is a new static inspection within existing native authority.

Problem and expected behavior

An analyst asking "what runs before main?" or "which mitigations does this image declare?" today needs llvm-readobj, dumpbin or a disassembler. Expected: REA returns the TLS directory and its null-terminated callback array (each callback VA with RVA, file offset and section), and the load configuration fields its declared Size covers, with flag-derived mitigation claims labeled inferred.

Change and scope

src/native/pe/PeLoadConfigParser.ts reuses the shared PE image reader and file-mapping index. Callback VAs are hexadecimal strings to keep 64-bit precision; unmapped targets keep their VA with an unknown file offset. Load-config fields are reported only when Size covers the whole field.

MSVC x86 images commonly declare a 64-byte load-config data directory while the structure's Size is larger (188 bytes on the sample below). Like the Windows loader, the parser reads Size bytes when they are file-backed in one run and reports both values; otherwise it fails as malformed.

Budgets: 64 MiB file read (ceiling 512 MiB), 64 callbacks (ceiling 4096). Truncated, ambiguous or unmapped directory storage fails closed with no partial success. Not included: decoding CHPE or dynamic relocation tables, or verifying that CFG instructions are present. AI was used for assistance.

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: native PE inspection (src/native/pe/) and the binary diagnostics service.
  • Contribution scope fit and linked maintainer decision: static format inspection of a local file within existing native authority; separate scope decision not applicable.
  • CLI and MCP/tool-catalog contract: new inspect-pe-load-config command and inspect_pe_load_config tool with path, max_file_bytes and max_callbacks inputs.
  • Provider, bridge, target-format, or platform compatibility: portable TypeScript, no provider or Windows host.
  • Evidence, artifact, provenance, or reconstruction contract: Evidence carries artifact SHA-256, directory and callback-array file ranges; guard-flag mitigations carry evidence_kind: "inferred".
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): unchanged; reads a stable regular file.
  • 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): catalog builder entry, authored skill guidance in .agents/skills/reverse-engineer-anything/, and a verify:pe:load-config package script. No committed build outputs.

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: src/native/pe/PeLoadConfigParser.test.ts (PE32 and PE32+ synthetic images: callbacks, Size-covered fields, the legacy 64-byte PE32 directory, budgets, malformed and ambiguous storage), PeLoadConfigService.test.ts, tests/acceptance/peLoadConfigCli.test.ts, tests/boundary/mcp/peLoadConfigMcp.test.ts, tests/boundary/filesystem/peLoadConfig.test.ts, and the shared tool-contract and stable-artifact lists. Fixtures are synthetic; no binaries are committed.
  • Base reproduction or other evidence: the released CLI has no TLS or load-config inspection. Cross-checked against llvm-readobj --coff-tls-directory and --coff-load-config on local, uncommitted binaries: a MinGW-linked PE32+ TLS sample, and Sysinternals strings64.exe and strings.exe (MSVC). Details are in docs/verification/pe-load-config-2026-10-24.md.
  • User-visible CLI/MCP output (if applicable): see below.
  • Remaining proof gaps: no real image with XFG or EH-continuation tables was exercised (synthetic coverage only). Runtime enforcement of any declared mitigation is not verified.
$ rea inspect-pe-load-config tls64.exe --json | jq ...
format: pe32-plus   tls.alignment: 8
callbacks: 0x140001000 .text  0x140001020 .text  0x140001470 .text  0x140001500 .text

$ rea inspect-pe-load-config strings.exe --json | jq ...
format: pe32   directory.size: 64   size: 188
security_cookie: 0x4560dc (.data)   se_handler_table: 0x453b28  count: 7
guard_flags: 0x100 IMAGE_GUARD_CF_INSTRUMENTED (inferred)

llvm-readobj --coff-load-config strings.exe reports Size: 0xBC, SecurityCookie: 0x4560DC, SEHandlerTable: 0x453B28, SEHandlerCount: 7, GuardFlags: 0x100.

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

Head f2346e4d5 on main d361c53c5; macOS arm64, Node 26.5.0, npm 12.2.0:

  • npx --no-install vitest run src/application/binaryDiagnostics/PeLoadConfigService.test.ts src/contracts/toolEffects.test.ts src/native/pe/PeLoadConfigParser.test.ts tests/acceptance/peLoadConfigCli.test.ts tests/acceptance/tools/localToolContracts.test.ts tests/boundary/filesystem/peLoadConfig.test.ts tests/boundary/mcp/peLoadConfigMcp.test.ts tests/process-global/stableArtifactConsumers.test.ts - passed.
  • npm run verify:pe:load-config with Zig 0.16.0 - PE32 and PE32+ samples inspected; neither image was started.
  • Sysinternals strings.exe (PE32, MSVC) matches the llvm-readobj fields shown above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; new command and tool only.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS arm64; no provider involved.
  • Package or release metadata impact: one new package script (verify:pe:load-config).
  • Security, privacy, process, or containment review: the image is never executed; reads are bounded by named budgets and malformed storage fails closed.

Author readiness

Human owner: @mvanhorn

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

Before merge

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

Demo

demo

Adds inspect-pe-load-config and inspect_pe_load_config for PE32 and
PE32+ images, with artifact hashes and file ranges in the returned
evidence. Reports callback addresses and mappings, plus size-covered
security-cookie, SafeSEH, CFG, EH-continuation and XFG fields;
flag-derived mitigation claims are explicitly labeled inferred. Missing
directories remain null, and malformed storage or exhausted read budgets
return errors without partial success. Adds documentation and tests for
service validation, CLI/MCP access, malformed inputs and stable-file
handling.

x86 images that declare the legacy 64-byte load-config directory are
read to the structure's own Size when those bytes are file-backed, as
the Windows loader does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016y53PdpyMAp9RSW65fatHe
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

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-10-24T13:14:12.265366Z
We couldn’t complete this review. Comment @codex review to try again.
f2346e4 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.

@greptile-apps

greptile-apps Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge, with all four previous findings addressed.

Summary

Adds static PE32/PE32+ TLS callback and load-configuration inspection through CLI and MCP.

  • REA reports TLS callbacks and load-configuration fields from PE files.

Reviews (2) · Last reviewed commit: "fix(pe): retain snapshot facts and bound..." · Reviewed by Greptile

Comment thread src/native/pe/PeLoadConfigProvider.ts Resolved
Comment thread src/native/pe/PeLoadConfig.fixture.ts Resolved
Comment thread src/native/pe/PeLoadConfigParser.ts Resolved
Keep the completed stable-read path, SHA-256 and byte count as a
file-snapshot-hash partial observation when descriptor close fails or is
cancelled. Report the checked Size span as structure_location and add it
to Evidence locations beside the declared directory range. Resolve
callback sections through a sorted segment index built once per image,
keeping the ambiguity failure. Pin every load-config field to offsets
transcribed from the PE/COFF spec and llvm COFF.h at its exact Size
boundary for PE32 and PE32+.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016y53PdpyMAp9RSW65fatHe
@morluto
morluto merged commit 3d84215 into morluto:main Oct 24, 2026
45 checks passed
@morluto morluto mentioned this pull request Oct 25, 2026
3 tasks done
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request labels Nov 23, 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.

2 participants