Files
rea/src/cli/cliCommandRegistrations.ts
T
bartman081523 d380dc2409 feat(uefi): add pure-TypeScript UEFI firmware analysis tools (#12342)
* feat(uefi): add pure-TS UEFI firmware volume/FFS parser with inspect/extract tools

Add a dependency-free rea-uefi provider that maps AMI/Aptio flash images:
- inspect_uefi_firmware: aligned _FVH discovery, volume-relative FFS walking,
  guided section/compression classification, conservative PSP-directory probing,
  embedded-volume rescan and leftover-region classification; incremental SHA-256
  and explicit integrity notes.
- extract_uefi_firmware: whole-image/volume/FFS-file/section extraction with
  LZMA-custom/LZMAF86 and AMD-zlib decoding, SafeOutputTree staging, derivations
  and extraction_gaps.
- UefiArtifactReader + 'uefi' format wiring across inventory/domain/contracts
  so parsed volumes and extracted PE32/TE files hand off to deep-provider
  analysis (open_binary -> Ghidra).

* feat(uefi): add inspect_uefi_nvram for AMI NVRAM variable stores

Add a pure-TypeScript tool that maps the vendor AMI NVRAM variable stores
(factory-default "StdDefaults" and peers) inside a flash image:
- scan the raw image for NVAR entry chains ("NVAR" + u16 total size +
  u32 attribute 0x8[23]FFFFFF + state + NUL-terminated name + data),
- recurse into a container entry whose data is itself an NVAR chain, so the
  StdDefaults setup variables surface as depth/parent_offset rows,
- report attributes, state, data range, SHA-256 and trailing padding per entry.

Verified against B550 AORUS Elite V2 FId: one StdDefaults store at 0x37090 with
the 11 expected nested variables (Setup, PlatformLang, AMITSESetup, XhciDID,
GcSensorVarName, PCI_COMMON, SioSetupData, UsbSupport, NetworkStackVar,
SecureBootSetup, Setup). Exposed as MCP tool and inspect-uefi-nvram CLI command.

* fix(uefi): address review on checksums, compression, guided sections, NVRAM bounds

- FFS file checksum: verify the two's-complement invariant (payload sum +
  stored byte == 0 mod 256) instead of comparing sums, and encode the correct
  complement in the fixture builder.
- Compression sections (type 0x01): use the 9-byte header and classify EFI
  standard compression instead of 'none', so extraction reports a gap rather
  than publishing compressed bytes as a raw section.
- GUID-defined sections: derive GUID/data-offset/attributes from the parsed
  common header size (compact or extended) and reject out-of-range payload
  offsets.
- AMI NVRAM: bound recursive chains to the enclosing container's data end and
  report partial coverage when a valid nested chain is cut by max_depth.

* fix(uefi): bound decode memory, serialize operations, enforce deadline, mark truncation

- LZMA worker: enforce max_output_bytes while decoding through a bounded output
  sink, so an oversized stream is rejected during expansion instead of after a
  full decompression plus a second Buffer copy.
- Provider: serialize admitted operations (the promised single decode-worker
  lane must not become one worker per overlapping call) and apply one
  whole-request deadline that covers every decode stage, not a fresh per-stream
  timer. close() drains the queue and the resource scope.
- Scan: track truncated sections of known type and report coverage partial
  instead of complete when a section declares more bytes than are present.

* fix(uefi): cancellable queue, timeout surfacing, availability and reader omissions

- Queue: check the caller signal before enqueue and when a job reaches the head,
  and race the queued promise against abort so a cancelled wait returns
  immediately instead of blocking behind the active request.
- Deadline: track the internal deadline and return AnalysisTimeoutError instead
  of the AnalysisCancelledError that runOwnedCommand reports for any external
  abort, preserving the real failure reason for CLI/MCP callers.
- CapabilityInventory: treat inspect_uefi_nvram like the other bundled rea-uefi
  tools so discovery does not demand Unblob for it.
- UefiArtifactReader: report image truncation through onOmission so inventory
  coverage reflects the unread suffix even when no volume was found.

* fix(uefi): limit early cancellation to unstarted jobs and preserve timeout cleanup

- #raceWithAbort only returns early for jobs that have not started; once a
  request is running, await it so worker cleanup and completed output are
  preserved instead of being discarded by a bare cancellation.
- Reclassify a deadline-induced cancellation as AnalysisTimeoutError while
  keeping its cause and cleanup observations, and never override a different
  primary failure.

* docs(licenses): record UEFI decoder dependency notices

* fix(uefi): preserve stream provenance and bound firmware analysis

* feat(uefi): decode LZMAF86 guided sections

* fix(uefi): validate publication before commit and order decoder cleanup

* fix(uefi): preserve unsupported volumes and extraction gaps

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-11-19 21:19:35 +00:00

508 lines
13 KiB
TypeScript

import {
TOOL_FAMILY_IDS,
type ToolFamilyId,
} from "../contracts/toolFamilyIds.js";
import { plain, withAnalysis } from "./cliCommandRegistration.js";
/** Every CLI command registrar; see `cliLoader.ts` for one-shot loading. */
export const CLI_COMMAND_REGISTRATIONS = {
setup: plain(
() => import("./setupCommands.js"),
(module, context) =>
module.registerSetupCommands(
context.cli,
context.logger,
context.environment,
),
),
coreAnalysis: withAnalysis(
() => import("./coreAnalysisCommands.js"),
(module, context) =>
module.registerCoreAnalysisCommands(
context.cli,
context.logger,
context.analysis.runDirectAnalysis,
context.environment,
),
),
reverseEngineering: plain(
() => import("./reverseEngineeringCommands.js"),
(module, context) =>
module.registerReverseEngineeringCommands(
context.cli,
context.logger,
context.environment,
),
),
cutter: plain(
() => import("./cutterCommands.js"),
(module, context) =>
module.registerCutterCommands(
context.cli,
context.logger,
context.environment,
),
),
utility: withAnalysis(
() => import("./utilityCommands.js"),
(module, context) =>
module.registerUtilityCommands(
context.cli,
context.logger,
context.environment,
context.analysis,
),
),
binaryDiagnostics: plain(
() => import("./binaryDiagnosticsCommands.js"),
(module, context) =>
module.registerBinaryDiagnosticsCommands(
context.cli,
context.logger,
context.environment,
),
),
wasm: plain(
() => import("./wasmCommands.js"),
(module, context) =>
module.registerWasmCommands(
context.cli,
context.logger,
context.environment,
),
),
apkSignature: plain(
() => import("./apkSignatureCommands.js"),
(module, context) =>
module.registerApkSignatureCommands(
context.cli,
context.logger,
context.environment,
),
),
capture: plain(
() => import("./captureCommands.js"),
(module, context) =>
module.registerCaptureCommands(
context.cli,
context.logger,
context.environment,
),
),
signal: plain(
() => import("./signalCommands.js"),
(module, context) =>
module.registerSignalCommands(
context.cli,
context.logger,
context.environment,
),
),
evm: plain(
() => import("./evmCommands.js"),
(module, context) =>
module.registerEvmCommands(
context.cli,
context.logger,
context.environment,
),
),
desktopApplication: plain(
() => import("./desktopApplicationCommands.js"),
(module, context) =>
module.registerDesktopApplicationCommands(context.cli, context.logger),
),
releaseExposure: plain(
() => import("./releaseExposureCommands.js"),
(module, context) =>
module.registerReleaseExposureCommands(
context.cli,
context.logger,
context.environment,
),
),
go: plain(
() => import("./goCommands.js"),
(module, context) => module.registerGoCommands(context.cli, context.logger),
),
il2cpp: plain(
() => import("./il2cppCommands.js"),
(module, context) =>
module.registerIl2cppCommands(context.cli, context.logger),
),
model: plain(
() => import("./modelCommands.js"),
(module, context) =>
module.registerModelCommands(context.cli, context.logger),
),
gpu: plain(
() => import("./gpuCommands.js"),
(module, context) =>
module.registerGpuCommands(context.cli, context.logger),
),
rust: plain(
() => import("./rustCommands.js"),
(module, context) =>
module.registerRustCommands(context.cli, context.logger),
),
pythonPyc: plain(
() => import("./pythonPycCommands.js"),
(module, context) =>
module.registerPythonPycCommands(context.cli, context.logger),
),
nugetNupkg: plain(
() => import("./nugetNupkgCommands.js"),
(module, context) =>
module.registerNugetNupkgCommands(context.cli, context.logger),
),
erlang: plain(
() => import("./erlangCommands.js"),
(module, context) =>
module.registerErlangCommands(context.cli, context.logger),
),
v8CodeCache: plain(
() => import("./v8CodeCacheCommands.js"),
(module, context) =>
module.registerV8CodeCacheCommands(context.cli, context.logger),
),
mavenGradleMetadata: plain(
() => import("./mavenGradleMetadataCommands.js"),
(module, context) =>
module.registerMavenGradleMetadataCommands(context.cli, context.logger),
),
sqlite: plain(
() => import("./sqliteCommands.js"),
(module, context) =>
module.registerSqliteCommands(
context.cli,
context.logger,
context.environment,
),
),
artifact: withAnalysis(
() => import("./artifactCommands.js"),
(module, context) =>
module.registerArtifactCommands(
context.cli,
context.logger,
context.analysis.runProviderAnalysis,
),
),
managed: withAnalysis(
() => import("./managedCommands.js"),
(module, context) =>
module.registerManagedCommands(
context.cli,
context.logger,
context.analysis,
),
),
firmware: plain(
() => import("./firmwareCommands.js"),
(module, context) =>
module.registerFirmwareCommands(
context.cli,
context.logger,
context.environment,
),
),
uefi: plain(
() => import("./uefiCommands.js"),
(module, context) =>
module.registerUefiCommands(context.cli, context.logger),
),
android: plain(
() => import("./androidCommands.js"),
(module, context) =>
module.registerAndroidCommands(
context.cli,
context.logger,
context.environment,
),
),
pcap: plain(
() => import("./pcapCommands.js"),
(module, context) =>
module.registerPcapCommands(
context.cli,
context.logger,
context.environment,
),
),
flutter: plain(
() => import("./flutterCommands.js"),
(module, context) =>
module.registerFlutterCommands(context.cli, context.logger),
),
frida: plain(
() => import("./fridaCommands.js"),
(module, context) =>
module.registerFridaCommands(
context.cli,
context.logger,
context.fridaInstrumentation,
),
),
apktool: plain(
() => import("./apktoolCommands.js"),
(module, context) =>
module.registerApktoolCommands(
context.cli,
context.logger,
context.environment,
),
),
jeb: plain(
() => import("./jebCommands.js"),
(module, context) =>
module.registerJebCommands(
context.cli,
context.logger,
context.environment,
),
),
adb: plain(
() => import("./adbCommands.js"),
(module, context) =>
module.registerAdbCommands(
context.cli,
context.logger,
context.environment,
),
),
browser: plain(
() => import("./browserCommands.js"),
(module, context) =>
module.registerBrowserCommands(
context.cli,
context.logger,
context.environment,
),
),
webRuntime: plain(
() => import("./webRuntimeCommands.js"),
(module, context) =>
module.registerWebRuntimeCommands(context.cli, context.logger),
),
webNetworkCapture: plain(
() => import("./webNetworkCaptureCommands.js"),
(module, context) =>
module.registerWebNetworkCaptureCommands(
context.cli,
context.logger,
context.environment,
),
),
advancedBrowser: plain(
() => import("./browserAdvancedCommands.js"),
(module, context) =>
module.registerAdvancedBrowserCommands(context.cli, context.logger),
),
browserScenario: plain(
() => import("../cliBrowserScenarioCommands.js"),
(module, context) =>
module.registerBrowserScenarioCommands(
context.cli,
context.logger,
context.environment,
),
),
electron: plain(
() => import("./electronCommands.js"),
(module, context) =>
module.registerElectronCommands(
context.cli,
context.logger,
context.environment,
),
),
javaScriptRuntimeObservation: plain(
() => import("./javascriptRuntimeCommands.js"),
(module, context) =>
module.registerJavaScriptRuntimeObservationCommands(
context.cli,
context.logger,
context.environment,
),
),
guidance: plain(
() => import("./guidanceCommands.js"),
(module, context) =>
module.registerGuidanceCommands(context.cli, context.logger),
),
guidedWorkflow: plain(
() => import("./guidedWorkflowCommands.js"),
(module, context) =>
module.registerGuidedWorkflowCommands(context.cli, context.logger),
),
analysisView: plain(
() => import("./analysisViewCommands.js"),
(module, context) =>
module.registerAnalysisViewCommands(context.cli, context.logger),
),
evidence: plain(
() => import("../cliEvidenceCommands.js"),
(module, context) =>
module.registerEvidenceCommands(context.cli, context.logger),
),
environment: plain(
() => import("./environmentCommands.js"),
(module, context) =>
module.registerEnvironmentCommands(
context.cli,
context.logger,
context.environment,
),
),
process: plain(
() => import("./processCommands.js"),
(module, context) =>
module.registerProcessCommands(
context.cli,
context.logger,
context.environment,
),
),
desktopCapture: plain(
() => import("./desktopCaptureCommands.js"),
(module, context) =>
module.registerDesktopCaptureCommands(
context.cli,
context.logger,
context.environment,
),
),
javaScriptRecovery: plain(
() => import("./javascriptRecoveryCommands.js"),
(module, context) =>
module.registerJavaScriptRecoveryCommands(
context.cli,
context.logger,
context.environment,
),
),
webScript: plain(
() => import("./webScriptCommands.js"),
(module, context) =>
module.registerWebScriptCommands(context.cli, context.logger),
),
webModule: plain(
() => import("./webModuleCommands.js"),
(module, context) =>
module.registerWebModuleCommands(
context.cli,
context.logger,
context.environment,
),
),
webSourceLocation: plain(
() => import("./webSourceLocationCommands.js"),
(module, context) =>
module.registerWebSourceLocationCommands(
context.cli,
context.logger,
context.environment,
),
),
application: plain(
() => import("./applicationCommands.js"),
(module, context) =>
module.registerApplicationCommands(context.cli, context.logger),
),
nativeFunctionMatching: plain(
() => import("./nativeFunctionMatchingCommands.js"),
(module, context) =>
module.registerNativeFunctionMatchingCommands(
context.cli,
context.logger,
context.environment,
),
),
};
export type CliCommandRegistrationId = keyof typeof CLI_COMMAND_REGISTRATIONS;
/** Each registrar's module, as `load` resolves it. */
export type CliCommandModules = {
readonly [Id in CliCommandRegistrationId]: Awaited<
ReturnType<(typeof CLI_COMMAND_REGISTRATIONS)[Id]["load"]>
>;
};
/**
* Registrars of setup and of each published tool family. Every family id must
* appear, so a new family decides its CLI commands; enhanced workflows are
* MCP tools whose CLI entry points live with core analysis.
*/
const CLI_FAMILY_REGISTRATIONS: {
readonly [
Family in "setup" | ToolFamilyId
]: readonly CliCommandRegistrationId[];
} = {
setup: ["setup"],
direct: ["coreAnalysis"],
enhanced: [],
native: ["reverseEngineering", "cutter", "utility", "binaryDiagnostics"],
artifact: [
"wasm",
"apkSignature",
"capture",
"signal",
"evm",
"desktopApplication",
"releaseExposure",
"go",
"il2cpp",
"model",
"gpu",
"rust",
"pythonPyc",
"nugetNupkg",
"erlang",
"v8CodeCache",
"mavenGradleMetadata",
"sqlite",
"artifact",
],
managed: ["managed"],
firmware: ["firmware"],
uefi: ["uefi"],
android: ["android"],
pcap: ["pcap"],
flutter: ["flutter"],
frida: ["frida"],
apktool: ["apktool"],
jeb: ["jeb"],
adb: ["adb"],
browser: [
"browser",
"webRuntime",
"webNetworkCapture",
"advancedBrowser",
"browserScenario",
],
electron: ["electron"],
"javascript-runtime": ["javaScriptRuntimeObservation"],
application: [
"guidance",
"guidedWorkflow",
"analysisView",
"evidence",
"environment",
"process",
"desktopCapture",
"javaScriptRecovery",
"webScript",
"webModule",
"webSourceLocation",
"application",
],
session: ["nativeFunctionMatching"],
};
/** Registration order: setup, then each family in catalog order. */
export const CLI_REGISTRATION_ORDER: readonly CliCommandRegistrationId[] = [
"setup" as const,
...TOOL_FAMILY_IDS,
].flatMap((family) => CLI_FAMILY_REGISTRATIONS[family]);