feat(ida): add read-only GUI and headless MCP providers (#754)

This commit is contained in:
N0zoM1z0
2026-10-07 01:47:05 +08:00
committed by GitHub
parent c8e66c704a
commit 8238232485
50 changed files with 3770 additions and 43 deletions
+2
View File
@@ -159,6 +159,8 @@ type CapabilityAvailability =
};
export type CapabilityDescriptor = CapabilityAvailability & {
/** Live external state must be re-observed, including after snapshot import. */
readonly cachePolicy?: "snapshot" | "live";
readonly provider: ProviderIdentity;
readonly operation: Exclude<AnalysisOperation, "health">;
readonly effects: CapabilityEffects;
+1
View File
@@ -68,6 +68,7 @@ export const isSnapshotCacheable = (
(!CURSOR_DEFAULT_OPERATIONS.has(operation) ||
typeof parameters.address === "string") &&
descriptor?.effects.mutatesArtifact === false &&
descriptor.cachePolicy !== "live" &&
descriptor.effects.mayWriteFilesystem === false &&
descriptor.effects.changesPermissions === false;
+10
View File
@@ -114,6 +114,16 @@ export class BinarySession
);
}
/** External live state cannot be replayed by a direct or composed CLI workflow. */
allowsSnapshotReplay(operation: AnalysisOperation): boolean {
const capabilities = this.#active?.route.capabilities;
const descriptor = capabilities?.get(operation);
if (descriptor !== undefined) return descriptor.cachePolicy !== "live";
return ![...(capabilities?.values() ?? [])].some(
({ cachePolicy }) => cachePolicy === "live",
);
}
/** Return the selected immutable profile, optionally scoped to an operation. */
analysisProfile(
operation?: AnalysisOperation,
+29 -18
View File
@@ -2,6 +2,7 @@ import type { ExecutableFormatHint } from "../domain/dosCom.js";
import { parseConfig } from "../config.js";
import type { JsonValue } from "../domain/jsonValue.js";
import { EnhancedTools } from "./EnhancedTools.js";
import { executeFunctionAnalysisEvidence } from "./FunctionAnalysisEvidence.js";
import { createBinarySession, createManagedBinarySession } from "./runtime.js";
import { silentLogger, type Logger } from "../logger.js";
import { createEvidence } from "../domain/evidence.js";
@@ -201,7 +202,7 @@ const runAnalysis = async (
const evidenceProfile = analysisProfileForEvidence(session, tool);
const bindingProfile = session.analysisProfile();
if (
tool !== "trace_native_ui_action" &&
canReplayDirectTool(session, tool) &&
snapshot !== undefined &&
evidenceProfile !== undefined &&
bindingProfile !== undefined
@@ -245,6 +246,12 @@ const runAnalysis = async (
}
};
const canReplayDirectTool = (
session: ReturnType<typeof createBinarySession>,
tool: Parameters<typeof runAnalysis>[1],
): boolean =>
tool !== "trace_native_ui_action" && session.allowsSnapshotReplay(tool);
const executeAnalysisTool = async (input: {
readonly session: ReturnType<typeof createBinarySession>;
readonly openedTarget: BinaryTarget;
@@ -258,9 +265,19 @@ const executeAnalysisTool = async (input: {
readonly evidenceProfile: AnalysisProfileCommitment | undefined;
}): Promise<{ readonly output: JsonValue; readonly evidence?: Evidence }> => {
const { session, tool, signal, evidenceProfile } = input;
if (tool === "analyze_function") {
const result = await executeFunctionAnalysisEvidence(
session,
input.arguments,
input.openedTarget,
{ signal },
);
return result.ok
? { output: result.value, evidence: result.value }
: { output: cliError(result.error) };
}
if (
tool === "binary_overview" ||
tool === "analyze_function" ||
tool === "inspect_native_api" ||
tool === "inspect_native_dispatch_metadata" ||
tool === "trace_feature" ||
@@ -273,22 +290,16 @@ const executeAnalysisTool = async (input: {
signal,
);
if (!result.ok) return { output: cliError(result.error) };
const evidence = createEvidence(
input.openedTarget,
tool === "analyze_function"
? session.providerIdentity(tool)
: REA_WORKFLOW_PROVIDER,
{
operation: tool,
parameters: input.arguments,
result: result.value,
...(evidenceProfile === undefined
? {}
: { analysisProfile: evidenceProfile }),
confidence: "derived",
limitations: ["Derived by an REA composed workflow."],
},
);
const evidence = createEvidence(input.openedTarget, REA_WORKFLOW_PROVIDER, {
operation: tool,
parameters: input.arguments,
result: result.value,
...(evidenceProfile === undefined
? {}
: { analysisProfile: evidenceProfile }),
confidence: "derived",
limitations: ["Derived by an REA composed workflow."],
});
return { output: evidence, evidence };
}
const result = await session.execute(tool, input.arguments, { signal });
+1 -1
View File
@@ -32,7 +32,7 @@ import {
} from "./DoctorScope.js";
/** Deep provider IDs whose readiness can be selected explicitly by doctor. */
export const DOCTOR_PROVIDER_IDS = ["hopper", "ghidra"] as const;
export const DOCTOR_PROVIDER_IDS = ["hopper", "ghidra", "ida"] as const;
/** One actionable environment diagnostic. */
export interface DoctorCheck {
readonly name: string;
@@ -0,0 +1,54 @@
import type {
AnalysisOperationPort,
ExecutionOptions,
} from "./AnalysisProvider.js";
import { toolContract } from "../contracts/toolContracts.js";
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
import type { BinaryTarget } from "../domain/binaryTarget.js";
import { createEvidence } from "../domain/evidence.js";
import { parseFunctionDossier } from "../domain/hopperValues.js";
import { jsonObjectSchema, type JsonValue } from "../domain/jsonValue.js";
import { err, ok } from "../domain/result.js";
import { projectInputIssues } from "../domain/inputIssueProjection.js";
/** Preserve the provider's observations when presenting a validated function dossier. */
export const executeFunctionAnalysisEvidence = async (
analysis: AnalysisOperationPort,
parameters: Readonly<Record<string, JsonValue>>,
target: BinaryTarget | undefined,
options?: ExecutionOptions,
) => {
const input =
toolContract("analyze_function").inputSchema.safeParse(parameters);
if (!input.success)
return err(
new AnalysisInputError(
"analyze_function",
{ cause: input.error },
projectInputIssues(input.error.issues, parameters),
),
);
const arguments_ = jsonObjectSchema.parse(input.data);
const execution = await analysis.execute(
"analyze_function",
arguments_,
options,
);
if (!execution.ok) return execution;
const dossier = parseFunctionDossier(execution.value.result);
if (!dossier.ok) return dossier;
const observation = execution.value;
return ok(
createEvidence(observation.subject ?? target, observation.provider, {
operation: "analyze_function",
parameters: arguments_,
result: dossier.value,
rawResult: observation.rawResult,
limitations: observation.limitations,
locations: observation.locations,
...(observation.analysisProfile === undefined
? {}
: { analysisProfile: observation.analysisProfile }),
}),
);
};
+6 -1
View File
@@ -2,6 +2,7 @@ import type { AppConfig } from "../config.js";
import type { BinarySession } from "./BinarySession.js";
import { HopperProvider } from "../hopper/HopperProvider.js";
import { GhidraProvider } from "../ghidra/GhidraProvider.js";
import { IdaProvider } from "../ida/IdaProvider.js";
import { silentLogger, type Logger } from "../logger.js";
import { GENERATED_AUXILIARY_PROVIDERS } from "../generatedMcpToolCatalog.js";
import { AnalysisProviderRegistry } from "./AnalysisProviderRegistry.js";
@@ -22,6 +23,7 @@ export const createBinarySession = (
): BinarySession => {
const hopper = new HopperProvider(config, logger);
const ghidra = new GhidraProvider(config, logger);
const ida = new IdaProvider(config);
const auxiliary = new Map(
GENERATED_AUXILIARY_PROVIDERS.map((provider) => [
provider.identity.id,
@@ -42,7 +44,10 @@ export const createBinarySession = (
});
};
return composeBinarySession(
new AnalysisProviderRegistry([hopper, ghidra], config.analysisProvider),
new AnalysisProviderRegistry(
[hopper, ghidra, ida],
config.analysisProvider,
),
[
lazyProvider("rea-artifact-graph", async () => {
const { ArtifactProvider } =