Skip to content

feat(windows): inventory Windows Registry hive base blocks offline - #9865

Closed
2SinceJuly wants to merge 42 commits into
morluto:mainfrom
2SinceJuly:feat/9424-registry-hive
Closed

2SinceJuly wants to merge 42 commits into
morluto:mainfrom
2SinceJuly:feat/9424-registry-hive

Conversation

@2SinceJuly

@2SinceJuly 2SinceJuly commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #9424 (first step).

An analyst who receives a SYSTEM, SOFTWARE, SAM, SECURITY or
NTUSER.DAT file outside a Windows host can only inspect its header by hand.
inspect_artifact treated every registry hive as an ordinary file. This change
recognises the REGF format from its bytes and reports what its base block and
hive bins declare, so later steps have an owned, validated parse to build value
decoding on.

Problem and expected behavior

Before: git grep -i "regf\|registry hive" src found nothing, and a hive file
classified as file whatever its name. After: a file beginning with the regf
magic is root format regf-hive, and the reader reports the base block's major
and minor version, the primary and secondary sequence numbers, whether the
checksum matches, and the hive-bin and cell spans the bins declare.

Change and scope

  • src/domain/windows/registryHive.ts owns the bytes: base-block validation, the
    bin walk and the cell walk, each returning a tagged format or limit
    failure. hasRegfHiveSignature provides recognition for classification.
  • RegistryHiveArtifactReader reads the admitted file through
    ArtifactFileSource and exposes the facts through formatMetadata(). A hive
    is its own content, so the root occurrence carries every fact and no members
    are enumerated.
  • regf-hive joins the artifact format ids, the content-format list, the format
    registry, ARTIFACT_FORMAT_IDS-derived Evidence subjects and the byte
    classifier (placed before the plist and executable probes, since the magic is
    unambiguous).

A sequence mismatch is reported as dirty and a checksum mismatch as a
limitation rather than a refusal: a dirty hive is precisely what an analyst is
handed. A bin or cell that overruns, an unexpected signature, or a tail the walk
did not reach stops it with a diagnostic naming the offset, so no fact is
reported for bytes that were not examined.

Intentionally not included: key nodes, value records and typed value decoding,
subkey and value indexes, class data, security descriptors and .LOG1/.LOG2
replay. They are named in the reader limitation and are the next steps in
docs/specs/native/registry-hive/tasks.md.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/domain/windows/registryHive.ts
    produces every parsed fact; RegistryHiveArtifactReader reads bytes and
    classifyArtifactBytes selects the format. No existing reader or classifier
    path changed, and no superseded representation was left behind.
  • Contribution scope fit and linked maintainer decision: format inspection is
    listed as supported in CONTRIBUTING.md#contribution-scope, and this reads one
    caller-selected local file. It adds no target execution, injection, mutation,
    protection recovery, network access or host registry access, so no maintainer
    scope decision is required — the same reading recorded in
    docs/specs/native/windows-shortcut/plan.md.
  • CLI and MCP/tool-catalog contract: unchanged. The new format is reachable
    through the existing inspect_artifact routing; no command or tool was added.
  • Provider, bridge, target-format, or platform compatibility: offline and
    platform-independent; no Windows API, registry mount or privilege is involved.
  • Evidence, artifact, provenance, or reconstruction contract: the
    regf-hive metadata kind is added to the format-metadata union, and comparison
    declares that its fields come from the file's own bytes.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • 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/domain/windows/registryHive.test.ts (10) covers a
    clean hive, a mismatched sequence pair, a wrong checksum, a cell crossing its
    bin, a cell size that is not a multiple of eight, a declared bin span longer
    than the file, a missing regf signature, a short file, the fixed ceiling and
    uneven chunk feeding. src/artifacts/RegistryHiveArtifactReader.test.ts (2)
    drives the real inventory pipeline for a clean and a dirty hive.
    ArtifactGraphConstruction.test.ts adds classification under SYSTEM,
    NTUSER.DAT and a neutral name; artifactFormats.test.ts extends the
    reader-format union.
  • Base reproduction or other evidence: on origin/main (b2f3dc81f) a hive file
    classifies as file; the new case asserts regf-hive.
  • Remaining proof gaps: the fixtures are synthesized. No real hive written by a
    Windows host was run, and no .LOG1/.LOG2 behaviour is claimed.

Validation performed

  • npm run check:fast — typecheck and lint passed.
  • npm run docs:check — passed (9 readme-consistency tests).
  • npx vitest run src/artifacts/ src/domain/ — 585 files, 12451 tests passed,
    1 skipped.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. A file that was previously file
    now reports regf-hive only when it actually begins with regf.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; no provider or
    host interaction.
  • Security, privacy, process, or containment review: reads one caller-selected
    regular file under a fixed 512 MiB ceiling, never writes to it, and reports
    malformed structure as a failure instead of guessing.

Author readiness

Human owner: @2SinceJuly

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

Depends on #9885.

Summary

Part of #9424 (base block, hive bins, and cell spans only).

inspect_artifact recognises REGF from its bytes and reports what the base block and hive bins declare.

The whole-file ceiling is regf.hive_max_file_bytes, seeded by REA_REGF_HIVE_MAX_FILE_BYTES (default 512 MiB, floor 4096 bytes, maximum 8 GiB). Each inventory reads the accepted runtime snapshot. A file above the effective ceiling names the setting, the current value, its source (default, setting, or runtime), and the allowed range. update_analysis_settings changes it for the next operation (update_mode: "runtime", pending_restart: false). A value outside the range is rejected and leaves the current ceiling unchanged.

Still open on #9424

Key nodes, typed values, .LOG1/.LOG2 replay, key-path queries, and real hive fixtures stay out of this PR.

Validation performed

  • npm run check:fast and oxfmt --check passed on f700a32f4.
  • node scripts/verify/rea-numeric-limits.mjs passed.
  • Registry hive reader and domain tests passed (15 tests).
Open in Web Open in Cursor 

REA had no offline REGF inspection: inspect-artifact treated a SYSTEM,
SOFTWARE or NTUSER.DAT file as an ordinary file, so an analyst holding one
outside a Windows host could not ask even whether its header was well formed.

Recognise the regf magic from the bytes under any name, then report the base
block's versions, sequence pair, checksum status and the hive-bin and cell
spans those bins declare. A sequence mismatch is reported as dirty and a
checksum mismatch as a limitation rather than a refusal, because a dirty hive
is exactly what gets handed to an analyst. A bin or cell that overruns, an
unexpected signature or an unread tail stops the walk with a diagnostic naming
the offset, so no fact is reported for bytes that were not examined.

Key nodes, value records, security descriptors and .LOG1/.LOG2 replay are not
decoded and are named in the reader limitation; they are the next steps in
docs/specs/native/registry-hive/tasks.md.

Verified with npm run check:fast, npm run docs:check, and the src/artifacts
and src/domain suites (585 files, 12451 tests). Fixtures are synthesized; no
real hive written by a Windows host was tested.
@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-10T15:03:48.474280Z
We couldn’t complete this review. Comment @codex review to try again.
b445018 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

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

2SinceJuly and others added 3 commits November 10, 2026 23:36
check:ci:fast failed on format:check for the four files added in the
previous commit. oxfmt line-wraps the long import, constructor call,
coverageOf signature and the path array; no behavior changes.
REA_REGF_HIVE_MAX_FILE_BYTES defaults to 512 MiB, with a 4096-byte floor
and an 8 GiB maximum. A file past the effective ceiling names the setting,
its source, and the range, and says to restart REA. There is no runtime
override.
REA_REGF_HIVE_MAX_FILE_BYTES still seeds regf.hive_max_file_bytes. Each
inventory reads the accepted snapshot, and update_analysis_settings
changes the next call inside the existing floor and maximum.
Part of morluto#9881. Record every numeric REA_ limit and fail static checks when one is neither a runtime analysis setting nor a documented exception with a reason.
Part of morluto#9881. Add effect immediate or next_process and keep rea_restart_required, restart_required, and restartRequired as compatibility aliases.
Callers read update_mode to see whether update_analysis_settings can change a limit, and pending_restart only when a configured value is not active in this process.
GitHub CI tests the merge with main. Main now removes copied
authentication even when command cleanup fails, which the evaluation
command test still required to remain.
Main removes copied authentication even when command cleanup stays
incomplete, and CI tests that merge. Keep the incomplete-cleanup
diagnostics and the retained run directory, and expect auth.json to be gone.
Depends on morluto#9885. That branch replaces rea_restart_required with
update_mode and pending_restart and forbids the legacy fields.
…tions

The numeric-limit check now treats REA_WEB_BUNDLE_ENDPOINT_LITERAL_CANDIDATES as a count limit and does not count registry text as a producer.
Invalid ChangeTime settings now carry update_mode and pending_restart through the configuration error and its projection, including startup parsing. Runtime recoveries name update_analysis_settings instead of telling the caller to restart REA.
Depends on morluto#9885. The hive limit uses update_mode and pending_restart,
and the setting declares updateMode so the numeric-limit check accepts it.
Discovery no longer treats comments or registration-list entries as producers. The three limits moving on their own PRs must join ANALYSIS_SETTINGS; the exception registry cannot classify them.
artifact_limits and web-network budgets report update_mode parameter because update_analysis_settings cannot change them. The legacy-name scan no longer reads docs, and the 2026-11-09 Ghidra receipts are restored to the fields they recorded.
A quoted name after an identifier, call, or optional chain is a producer. Only declaration arrays and comments stay out of discovery.
cursoragent and others added 21 commits November 10, 2026 23:19
Property access, element access, and helper-call arguments are producers. Comments and array literals are excluded by the tree, so a later argument such as read(environment, "REA_NEW_MAX_BYTES") stays classified.
Relative links from the limit inventory into src escape the documentation
site base. Point them at the repository files instead.
analysis_timeout_ms, max_heap_mb, and command_timeout_ms keep the source chosen by the caller, the runtime override, or the built-in default. A request value reports update_mode parameter because update_analysis_settings cannot change that call.
Main already expects copied auth.json to be removed when evaluation
cleanup stays incomplete, and the run directory to remain.
Main left describe("Ghidra bridge script processor context contract")
with no tests after moving that check to the real provider probe.
Vitest rejects the empty suite during source tests.
…all guard dependency-free

Object bindings, in-checks, and object keys that a spread can copy are producers. The architecture guard skips the TypeScript parse until typescript6 is installed, and the inventory links stay inside the published site.
The changelog and the limit migration now name runtime, restart, and parameter. parameter is the mode for a value this call supplied.
The fork credential cannot update workflow files. Leave
ghidra-bridge-sources.yml at the revision already on this branch.
This branch cannot update ghidra-bridge-sources.yml, so that workflow
still launches ReaArmContextProbe.java. Restore that script beside the
renamed probe.
A one-test suite named for the bridge script was collected with no tests in the full source run, which failed the file. The same assertion now sits directly on the file.
Keep the Ghidra bridge context assertion on the file. Main's empty suite is the collection failure.
The main merge dropped the fs import that the file-level assertion uses.
Depends on morluto#9885. Bring the allowlist, tracked-limit rules,
parameter update mode, and restored historical receipts.
# Conflicts:
#	docs/specs/README.md
#	src/artifacts/ArtifactReader.ts
#	src/artifacts/artifactFormats.test.ts
#	src/artifacts/artifactFormats.ts
#	src/artifacts/inventory/ArtifactGraphConstruction.ts
#	src/domain/artifactFormatMetadata.ts
#	src/domain/artifactGraph.ts
#	src/domain/evidenceSubject.ts
#	src/ghidra/GhidraFunctionValues.test.ts
@2SinceJuly

Copy link
Copy Markdown
Contributor Author

Merged origin/main in 3f7bf4796. Conflicts were all format-enum additions (main's ntfs-mft from #9911 beside this branch's regf-hive); both sides are kept in every list, descriptor table and metadata union.

artifactFormatMetadata.ts needed more than a union: the two sides each added a schema block at the same anchor, so the file was rebuilt from both sides rather than resolved hunk by hunk, and MFT_INLINE_HEADER_LIMIT's import was restored.

Verified: tsc --noEmit clean, oxfmt --check clean, src/domain/windows/ + src/artifacts/ + GhidraFunctionValues.test.ts + TargetFormatVocabularies.test.ts (1610 passed, 1 skipped). CI has not re-run on this head.

main moved the shared NTFS schemas into windows/ntfsMftAttributes.ts and grew the settings model. Conflict in src/domain/artifactFormatMetadata.ts resolved by keeping main's shared import and dropping the branch-local ntfsFileReferenceSchema duplicate; the rest auto-merged.
@2SinceJuly

Copy link
Copy Markdown
Contributor Author

Closing this rather than merging it: main now carries the same capability, further along than this branch.

  • src/domain/numericLimitRegistry.ts exists on main and enforces the same invariant — every numeric REA_ limit is either a runtime ANALYSIS_SETTINGS entry or a declared restart-only registry row.
  • The three limits this branch added as policy: "per-call" (REA_BRIDGE_MAX_REQUEST_BYTES, REA_DEBUGGER_COMMAND_DEADLINE_MS, REA_DEBUGGER_MAX_COMMAND_OUTPUT_BYTES) are now runtime settings in src/domain/analysisSettingDefinitions.ts, so the per-call policy this branch introduced is no longer needed.
  • main's registry also added provenance witnesses — external-reader and generated-control — for limits that the TypeScript scan cannot see, plus read: "construction". The check itself grew from 145 to 618 lines.
  • The 38-file conflict surface is that divergence: this branch rewrites the pre-refactor call sites that main has since deleted.

Nothing in this branch is lost work worth salvaging — rewriting it onto the current registry would mean porting the witness model, which is a smaller change than the diff here.

@morluto morluto added enhancement New feature or request area: runtime Process capture and runtime observation labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants