Files
reverse-engineering-anything/src/cli.ts
T
SandivandVincent Koc f5055cd2ed fix(process): report denied inspection as typed cleanup failures (#9261)
* fix(process): report denied inspection as typed cleanup failures

Preserve the native ps diagnostic through owned-worker cleanup and finalize one-shot JavaScript analysis before Evidence delivery. Retain mandatory inspection and existing cleanup authority.

Preserve the inspector diagnostic when the initial process-table read succeeds but pre-signal revalidation fails, and remove the unreachable typed-error branch so retained artifact retry failures project through the existing cleanup contract.

* fix(resources): preserve independent close failure ownership

* fix(cli): retain cleanup recovery and nested close evidence

* refactor(providers): classify rejected closes at the shared boundary

* test(cli): preserve bundle metadata and physical inspection failures

* fix(cli): preserve the JavaScript failure envelope after finalization

* test(cli): validate the JavaScript error envelope at its boundary

* fix(providers): preserve unnamed close failure resources

* fix(cli): retain invocation owners through outer cleanup

* test(cli): distinguish reported cleanup failures from uncaught errors

* fix(cli): compose each runtime’s declared cleanup owners

* test(cli): preserve the original cleanup rejection

* test(cli): allow cleanup retry recovery after a reported failure

* fix(cli): report final cleanup after returned results

* fix(cli): preserve launcher executable mode

* test(cli): retain invocation cleanup in file sessions

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
2026-11-30 19:38:45 +08:00

184 lines
8.0 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 type { CliJavaScriptAnalysisHost } from "./cli/javascriptApplicationAnalysis.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 labviewModule from "./cli/labviewCommands.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 debPackageModule from "./cli/debPackageCommands.js";
import * as nugetNupkgModule from "./cli/nugetNupkgCommands.js";
import * as vsixPackageModule from "./cli/vsixPackageCommands.js";
import * as ociImageLayoutModule from "./cli/ociImageLayoutCommands.js";
import * as yaraModule from "./cli/yaraCommands.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 "./cli/browserScenarioCommands.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 sourceToBundleModule from "./cli/sourceToBundleCommand.js";
import * as staticObservedEndpointsModule from "./cli/staticObservedEndpointsCommand.js";
import * as analysisViewModule from "./cli/analysisViewCommands.js";
import * as evidenceModule from "./cli/evidenceCommands.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,
labview: labviewModule,
model: modelModule,
gpu: gpuModule,
rust: rustModule,
pythonPyc: pythonPycModule,
debPackage: debPackageModule,
nugetNupkg: nugetNupkgModule,
vsixPackage: vsixPackageModule,
ociImageLayout: ociImageLayoutModule,
yara: yaraModule,
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,
sourceToBundle: sourceToBundleModule,
staticObservedEndpoints: staticObservedEndpointsModule,
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 `cliLoader.ts`.
*/
export const createCli = (
selectedEnvironment: Readonly<
Record<string, string | undefined>
> = process.env,
resultOutput?: CliResultOutput,
fridaInstrumentation?: FridaInstrumentationPort,
savedDefaults?: ReadonlySet<string>,
javascriptAnalysis?: CliJavaScriptAnalysisHost,
): CliInstance =>
createCliShell({
selectedEnvironment,
resultOutput,
fridaInstrumentation,
savedDefaults,
javascriptAnalysis,
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;
}