mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 03:33:25 +00:00
* refactor(ida): launch stdio registrations through the owned MCP transport IDA stdio servers now run as an owned process group (POSIX) or job (Windows) through OwnedMcpStdioTransport instead of the SDK's unowned child. Windows bare commands resolve against the registration PATH/PATHEXT and .cmd/.bat launchers run through the shared WindowsBatchCommand cmd.exe invocation. The frame limit is classified from the transport's typed OwnedMcpOutputLimitError instead of parsing SDK error text, detach no longer reaches into the SDK's private _process, and the per-operation byte budget is optional. * fix(ida): keep owned stdio cleanup observable and resolve Windows interpreter paths - StructuredContentMcpClient observes SDK-initiated closes like OwnedMcpClient, so a failed handshake with incomplete owned cleanup cannot reject unhandled. - OwnedMcpStdioTransport attaches an owner-redacted captured output to cleanup failures; IDA passes its retained stderr tail. - findWindowsExecutable resolves path-qualified commands at their own location with PATHEXT; IDA routes every Windows registration through it and refuses non-drive paths with an actionable remedy before the owned launcher. * fix(process): end a stalled stdio launch when the owned MCP transport closes OwnedMcpStdioTransport passes the launcher a signal it aborts with OwnerCancellation.ownerClosed when it stops, so IDA's Windows PATH/PATHEXT lookup stalled on an unreachable directory no longer holds close() open; IDA reports the interrupted lookup by its abort reason. The IDA environment tests use createTestTempDirectory for owned temporary roots. * fix(ida): bound the Windows command lookup by the registration timeout The PATH/PATHEXT search for a stdio registration now runs under a ProviderStartupDeadline of the registration's timeoutMs that also follows the transport's close signal. A lookup stalled on an unreachable PATH directory ends as an AnalysisTimeoutError (phase windows_path_lookup) instead of leaving connect() pending, matching Apktool's Windows lookup. * test(ida): stub REA's PATH again now that process inspection runs ps from fixed locations * test(ida): pass the required registration protocol in owned-stdio fixtures * fix(ida): report an uninspectable Windows command candidate with its path and code * refactor(ida): take the host platform from composition, not an ambient read * fix(verify): pass the host platform to the real IDA upstream check * fix(process): keep a failed launch's preparation cleanup owned by the stdio transport's close OwnedMcpStdioTransport discarded the launch rejection before a supervisor existed, so an ownership-helper preparation that transferred a cleanup owner (or reported a cleanup failure without one) was dropped and close() reported success. The transport's close now closes each transferred owner from processInspectionCleanupFailures, and reports a ProviderCleanupError naming the preparation resource until it does; a later close retries it.
190 lines
6.7 KiB
TypeScript
190 lines
6.7 KiB
TypeScript
import type { AnalysisSettingsReader } from "../domain/analysisSettings.js";
|
|
import { runtimeAnalysisConfig } from "../config/runtimeAnalysisSettings.js";
|
|
import { isAppleDispatchMetadataTarget } from "../domain/native/objcSwiftMetadata.js";
|
|
import { snapshotEnvironment } from "../process/snapshotEnvironment.js";
|
|
import type { AppConfig } from "../config/types.js";
|
|
import type { BinarySession } from "../application/binary/BinarySession.js";
|
|
import { HopperProvider } from "../hopper/HopperProvider.js";
|
|
import { GhidraProvider } from "../ghidra/GhidraProvider.js";
|
|
import { createIdaMcpConnection } from "../ida/IdaMcpConnection.js";
|
|
import { IdaProvider } from "../ida/IdaProvider.js";
|
|
import { KunaProvider } from "../kuna/KunaProvider.js";
|
|
import type { Logger } from "pino";
|
|
import { auxiliaryAnalysisProviderDeclarations } from "./auxiliaryAnalysisProviders.js";
|
|
import { AnalysisProviderRegistry } from "../application/binary/AnalysisProviderRegistry.js";
|
|
import { composeBinarySession } from "../application/binary/BinarySessionComposition.js";
|
|
import { LazyAnalysisProvider } from "../application/binary/LazyAnalysisProvider.js";
|
|
import { ManagedStaticProvider } from "../dotnet/ManagedStaticProvider.js";
|
|
import { HOST_PLATFORM } from "../platform/HostPlatform.js";
|
|
import {
|
|
BUNDLE_ARTIFACT_RESOURCE_OPERATIONS,
|
|
BUNDLE_NATIVE_RESOURCE_OPERATIONS,
|
|
combineBundleResourceClients,
|
|
} from "../application/binary/BundleResourceSession.js";
|
|
|
|
/**
|
|
* Compose the target-switching runtime shared directly by CLI and MCP adapters.
|
|
* This is the sole production wiring point, so both adapters share identical
|
|
* provider selection, profile, lifecycle, and Evidence semantics.
|
|
*/
|
|
export const createBinarySession = (
|
|
config: AppConfig,
|
|
logger: Logger,
|
|
selectedEnvironment: Readonly<NodeJS.ProcessEnv>,
|
|
settings?: AnalysisSettingsReader,
|
|
): BinarySession =>
|
|
composeDeepBinarySession(
|
|
runtimeAnalysisConfig(config, settings),
|
|
logger,
|
|
selectedEnvironment,
|
|
undefined,
|
|
settings,
|
|
);
|
|
|
|
/** Prefer byte-backed dispatch inspection while retaining deep symbol fallback. */
|
|
export const createNativeDispatchBinarySession = (
|
|
config: AppConfig,
|
|
logger: Logger,
|
|
selectedEnvironment: Readonly<NodeJS.ProcessEnv>,
|
|
): BinarySession =>
|
|
composeDeepBinarySession(
|
|
runtimeAnalysisConfig(config),
|
|
logger,
|
|
selectedEnvironment,
|
|
"inspect_native_dispatch_metadata",
|
|
);
|
|
|
|
const composeDeepBinarySession = (
|
|
config: AppConfig,
|
|
logger: Logger,
|
|
selectedEnvironment: Readonly<NodeJS.ProcessEnv>,
|
|
inspection?: "inspect_native_dispatch_metadata",
|
|
settings?: AnalysisSettingsReader,
|
|
): BinarySession => {
|
|
const platform = HOST_PLATFORM.platform;
|
|
const environment = snapshotEnvironment(selectedEnvironment, platform);
|
|
const hopper = new HopperProvider(config, logger, environment);
|
|
const ghidra = new GhidraProvider(config, logger, environment);
|
|
const ida = new IdaProvider(config, environment, (registration, selected) =>
|
|
createIdaMcpConnection(registration, selected, {
|
|
platform: HOST_PLATFORM.platform,
|
|
}),
|
|
);
|
|
const kuna = new KunaProvider(environment, {
|
|
regexMatchingDeadline: config.regexMatchingDeadline,
|
|
regexWorkerHeapRequest: config.regexWorkerHeapRequest,
|
|
});
|
|
const auxiliaryDeclarations = auxiliaryAnalysisProviderDeclarations(
|
|
environment,
|
|
platform,
|
|
settings,
|
|
);
|
|
const nativeInspectionAvailable =
|
|
inspection !== undefined &&
|
|
auxiliaryDeclarations.some(({ capabilities }) =>
|
|
capabilities.some(
|
|
({ operation, available }) => operation === inspection && available,
|
|
),
|
|
);
|
|
return composeBinarySession(
|
|
new AnalysisProviderRegistry(
|
|
[hopper, ghidra, ida, kuna],
|
|
config.analysisProvider,
|
|
nativeInspectionAvailable ? isAppleDispatchMetadataTarget : undefined,
|
|
),
|
|
auxiliaryDeclarations.map(
|
|
(declaration) => new LazyAnalysisProvider(declaration),
|
|
),
|
|
createBundleResourceFactory(environment, platform, settings),
|
|
);
|
|
};
|
|
|
|
const createBundleResourceFactory = (
|
|
environment: Readonly<NodeJS.ProcessEnv>,
|
|
platform: NodeJS.Platform,
|
|
settings?: AnalysisSettingsReader,
|
|
) => {
|
|
return {
|
|
createClient: async (
|
|
root: import("../application/AppBundleExecutable.js").ResolvedAppBundleResourceRoot,
|
|
) => {
|
|
const [{ ArtifactProvider }, { NativeMacOSProvider }] = await Promise.all(
|
|
[
|
|
import("../artifacts/ArtifactProvider.js"),
|
|
import("../native/NativeMacOSProvider.js"),
|
|
],
|
|
);
|
|
const artifact = new ArtifactProvider(environment, platform, settings);
|
|
const native = new NativeMacOSProvider(environment, undefined, platform);
|
|
const capabilities = [
|
|
...artifact
|
|
.capabilities()
|
|
.filter(({ operation }) =>
|
|
BUNDLE_ARTIFACT_RESOURCE_OPERATIONS.has(operation),
|
|
),
|
|
...native
|
|
.capabilities()
|
|
.filter(({ operation }) =>
|
|
BUNDLE_NATIVE_RESOURCE_OPERATIONS.has(operation),
|
|
),
|
|
];
|
|
return {
|
|
client: combineBundleResourceClients(
|
|
artifact.createBundleResourceClient(root),
|
|
native.createBundleResourceClient(root),
|
|
),
|
|
capabilities,
|
|
};
|
|
},
|
|
};
|
|
};
|
|
|
|
/** Compose an execution-free managed session without native provider selection. */
|
|
export const createManagedBinarySession = (): BinarySession =>
|
|
composeBinarySession(new AnalysisProviderRegistry([]), [
|
|
new ManagedStaticProvider(),
|
|
]);
|
|
|
|
/** Compose the artifact operations without candidates for deep analysis engines. */
|
|
export const createArtifactBinarySession = (
|
|
selectedEnvironment: Readonly<NodeJS.ProcessEnv>,
|
|
platform: NodeJS.Platform = process.platform,
|
|
): Promise<BinarySession> =>
|
|
import("../artifacts/ArtifactProvider.js").then(({ ArtifactProvider }) =>
|
|
composeBinarySession(
|
|
new AnalysisProviderRegistry([]),
|
|
[
|
|
new ArtifactProvider(
|
|
snapshotEnvironment(selectedEnvironment, platform),
|
|
platform,
|
|
),
|
|
],
|
|
createBundleResourceFactory(
|
|
snapshotEnvironment(selectedEnvironment, platform),
|
|
platform,
|
|
),
|
|
),
|
|
);
|
|
|
|
/** Compose native inspection utilities without candidates for deep analysis. */
|
|
export const createNativeBinarySession = (
|
|
selectedEnvironment: Readonly<NodeJS.ProcessEnv>,
|
|
platform: NodeJS.Platform = process.platform,
|
|
): Promise<BinarySession> =>
|
|
import("../native/NativeMacOSProvider.js").then(({ NativeMacOSProvider }) =>
|
|
composeBinarySession(
|
|
new AnalysisProviderRegistry([]),
|
|
[
|
|
new NativeMacOSProvider(
|
|
snapshotEnvironment(selectedEnvironment, platform),
|
|
undefined,
|
|
platform,
|
|
),
|
|
],
|
|
createBundleResourceFactory(
|
|
snapshotEnvironment(selectedEnvironment, platform),
|
|
platform,
|
|
),
|
|
),
|
|
);
|