Files
reverse-engineering-anything/src/cli.ts
T
8d6552e928 feat(config): persist provider settings in a user config file (#3023)
* feat(config): persist provider settings in a user config file

Providers currently rediscover install paths from scratch in every
process, so a path set once (for example GHIDRA_INSTALL_DIR) silently
reverts on the next run. Introduce ~/.config/rea/rea.json as the
user-owned persistence layer and merge it into the environment
snapshot before configuration parsing, keeping env > config file >
auto-detect precedence on both the CLI and MCP entry points.

Add a rea config command (list/get/set/unset) as the write surface,
reporting the effective value and where it came from.

* fix(config): address review findings on persistence safety and CLI surface

- stage config writes beside the file and rename into place so an
  interrupted write cannot leave partial JSON (greptile #4, codex #11)
- convert unreadable config files into configuration errors on the CLI
  seam instead of escaping raw filesystem errors (greptile #5, codex #15)
- keep injected runtimes without a config root isolated from the host
  account's rea.json (codex #18)
- surface the config file error on stderr when doctor falls back to the
  raw environment (greptile #3, codex #16)
- route the config command through logCliCommand and return documents so
  --json stays parseable and failures exit non-zero (greptile #2,
  codex #10)
- reject empty --set values, unknown --set/--unset/--get names, and --get
  combined with mutations (greptile #1/#7, codex #9/#12/#13/#17)
- cover the new behavior in the boundary tests and stop leaking one
  temporary home per run (greptile #8)

* fix(config): validate and back up persisted provider settings

* fix(config): keep saved provider defaults out of client registrations

* fix(config): preserve provider discovery and budgets for saved settings

* fix(config): check only settings needed by the IDA deadline lookup

* fix(config): share effective provider settings and verify config file reads

* fix(doctor): share selected settings with Hopper and ILSpy probes

* fix(config): resolve the destination of first-time saves

* fix(doctor): preserve unresolved provider location inputs

* fix(doctor): honor inherited IDA deadline overrides

* fix(config): show empty environment overrides

* fix(setup): preserve client-selected saved configuration roots

---------

Co-authored-by: Jackzigen <zigenhan@gmail.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-11-21 22:02:35 +00:00

167 lines
7.1 KiB
TypeScript

import type { FridaInstrumentationPort } from "./ports/frida/FridaInstrumentationPort.js";
import {
CURRENT_ENTRYPOINT_PATH,
isDirectEntrypoint,
} from "./process/CurrentEntrypointPath.js";
import {
CLI_COMMAND_REGISTRATIONS,
CLI_REGISTRATION_ORDER,
type CliCommandModules,
} from "./cli/cliCommandRegistrations.js";
import type { CliResultOutput } from "./cli/cliResultOutput.js";
import { createCliShell } from "./cli/cliShell.js";
import type { CliInstance } from "./cli/types.js";
import { createDirectAnalysis } from "./composition/directAnalysis.js";
import * as setupModule from "./cli/setupCommands.js";
import * as coreAnalysisModule from "./cli/coreAnalysisCommands.js";
import * as reverseEngineeringModule from "./cli/reverseEngineeringCommands.js";
import * as cutterModule from "./cli/cutterCommands.js";
import * as userConfigModule from "./cli/userConfigCommands.js";
import * as utilityModule from "./cli/utilityCommands.js";
import * as binaryDiagnosticsModule from "./cli/binaryDiagnosticsCommands.js";
import * as wasmModule from "./cli/wasmCommands.js";
import * as apkSignatureModule from "./cli/apkSignatureCommands.js";
import * as captureModule from "./cli/captureCommands.js";
import * as signalModule from "./cli/signalCommands.js";
import * as evmModule from "./cli/evmCommands.js";
import * as desktopApplicationModule from "./cli/desktopApplicationCommands.js";
import * as releaseExposureModule from "./cli/releaseExposureCommands.js";
import * as goModule from "./cli/goCommands.js";
import * as il2cppModule from "./cli/il2cppCommands.js";
import * as modelModule from "./cli/modelCommands.js";
import * as gpuModule from "./cli/gpuCommands.js";
import * as rustModule from "./cli/rustCommands.js";
import * as pythonPycModule from "./cli/pythonPycCommands.js";
import * as nugetNupkgModule from "./cli/nugetNupkgCommands.js";
import * as erlangModule from "./cli/erlangCommands.js";
import * as v8CodeCacheModule from "./cli/v8CodeCacheCommands.js";
import * as mavenGradleMetadataModule from "./cli/mavenGradleMetadataCommands.js";
import * as sqliteModule from "./cli/sqliteCommands.js";
import * as artifactModule from "./cli/artifactCommands.js";
import * as managedModule from "./cli/managedCommands.js";
import * as firmwareModule from "./cli/firmwareCommands.js";
import * as uefiModule from "./cli/uefiCommands.js";
import * as androidModule from "./cli/androidCommands.js";
import * as pcapModule from "./cli/pcapCommands.js";
import * as flutterModule from "./cli/flutterCommands.js";
import * as fridaModule from "./cli/fridaCommands.js";
import * as apktoolModule from "./cli/apktoolCommands.js";
import * as jebModule from "./cli/jebCommands.js";
import * as adbModule from "./cli/adbCommands.js";
import * as browserModule from "./cli/browserCommands.js";
import * as webRuntimeModule from "./cli/webRuntimeCommands.js";
import * as webNetworkCaptureModule from "./cli/webNetworkCaptureCommands.js";
import * as advancedBrowserModule from "./cli/browserAdvancedCommands.js";
import * as browserScenarioModule from "./cliBrowserScenarioCommands.js";
import * as electronModule from "./cli/electronCommands.js";
import * as javaScriptRuntimeObservationModule from "./cli/javascriptRuntimeCommands.js";
import * as guidanceModule from "./cli/guidanceCommands.js";
import * as guidedWorkflowModule from "./cli/guidedWorkflowCommands.js";
import * as analysisViewModule from "./cli/analysisViewCommands.js";
import * as evidenceModule from "./cliEvidenceCommands.js";
import * as environmentModule from "./cli/environmentCommands.js";
import * as processModule from "./cli/processCommands.js";
import * as desktopCaptureModule from "./cli/desktopCaptureCommands.js";
import * as javaScriptRecoveryModule from "./cli/javascriptRecoveryCommands.js";
import * as webScriptModule from "./cli/webScriptCommands.js";
import * as webModuleModule from "./cli/webModuleCommands.js";
import * as webSourceLocationModule from "./cli/webSourceLocationCommands.js";
import * as applicationModule from "./cli/applicationCommands.js";
import * as nativeFunctionMatchingModule from "./cli/nativeFunctionMatchingCommands.js";
export { closeCliResources } from "./cli/cliResources.js";
const CLI_COMMAND_MODULES: CliCommandModules = {
setup: setupModule,
coreAnalysis: coreAnalysisModule,
reverseEngineering: reverseEngineeringModule,
cutter: cutterModule,
utility: utilityModule,
userConfig: userConfigModule,
binaryDiagnostics: binaryDiagnosticsModule,
wasm: wasmModule,
apkSignature: apkSignatureModule,
capture: captureModule,
signal: signalModule,
evm: evmModule,
desktopApplication: desktopApplicationModule,
releaseExposure: releaseExposureModule,
go: goModule,
il2cpp: il2cppModule,
model: modelModule,
gpu: gpuModule,
rust: rustModule,
pythonPyc: pythonPycModule,
nugetNupkg: nugetNupkgModule,
erlang: erlangModule,
v8CodeCache: v8CodeCacheModule,
mavenGradleMetadata: mavenGradleMetadataModule,
sqlite: sqliteModule,
artifact: artifactModule,
managed: managedModule,
firmware: firmwareModule,
uefi: uefiModule,
android: androidModule,
pcap: pcapModule,
flutter: flutterModule,
frida: fridaModule,
apktool: apktoolModule,
jeb: jebModule,
adb: adbModule,
browser: browserModule,
webRuntime: webRuntimeModule,
webNetworkCapture: webNetworkCaptureModule,
advancedBrowser: advancedBrowserModule,
browserScenario: browserScenarioModule,
electron: electronModule,
javaScriptRuntimeObservation: javaScriptRuntimeObservationModule,
guidance: guidanceModule,
guidedWorkflow: guidedWorkflowModule,
analysisView: analysisViewModule,
evidence: evidenceModule,
environment: environmentModule,
process: processModule,
desktopCapture: desktopCaptureModule,
javaScriptRecovery: javaScriptRecoveryModule,
webScript: webScriptModule,
webModule: webModuleModule,
webSourceLocation: webSourceLocationModule,
application: applicationModule,
nativeFunctionMatching: nativeFunctionMatchingModule,
};
/**
* Build the complete one-shot Incur CLI without starting Hopper at import time.
* Analysis commands acquire and close their own sessions; bare `mcp` and
* `--mcp` are intercepted by the executable dispatcher before this module loads.
* One-shot commands load only their own registrars; see `cli/cliLoader.ts`.
*/
export const createCli = (
selectedEnvironment: Readonly<
Record<string, string | undefined>
> = process.env,
resultOutput?: CliResultOutput,
fridaInstrumentation?: FridaInstrumentationPort,
savedDefaults?: ReadonlySet<string>,
): CliInstance =>
createCliShell({
selectedEnvironment,
resultOutput,
fridaInstrumentation,
savedDefaults,
createAnalysis: createDirectAnalysis,
registrations: CLI_REGISTRATION_ORDER.map((id) => ({
registration: CLI_COMMAND_REGISTRATIONS[id],
module: CLI_COMMAND_MODULES[id],
})),
});
// Direct execution needs a visible failure pointing to the dispatcher. Imports
// only expose the registry. A normal exit lets piped stderr drain completely.
if (isDirectEntrypoint(CURRENT_ENTRYPOINT_PATH, import.meta.url)) {
process.stderr.write(
"dist/cli.js is the command registry, not the CLI entry point. Run `rea` (scripts/rea.mjs) instead.\n",
);
process.exitCode = 1;
}