feat(ida): support optional native IDA Free MCP in attached mode

This commit is contained in:
Fernando
2026-10-10 12:21:17 +01:00
parent 3cd80cbb88
commit 0b60a2ce90
13 changed files with 678 additions and 64 deletions
+27 -6
View File
@@ -19,7 +19,9 @@ import type { AnalysisProfileCommitment } from "../domain/analysisProfile.js";
import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js";
import { err, ok, type Result } from "../domain/result.js";
import type { IdaConfiguration } from "./IdaConfiguration.js";
import { idaProtocol } from "./IdaConfiguration.js";
import type { IdaMcpConnection } from "./IdaMcpConnection.js";
import { nativeTools } from "./IdaNativeProtocol.js";
import { IdaOperationRunner } from "./IdaOperationRunner.js";
import {
IDA_LIMITATIONS,
@@ -67,6 +69,7 @@ const modernTools = [
"xrefs_to",
];
const operationSet: ReadonlySet<string> = new Set(IDA_OPERATIONS);
const isIdaOperation = (operation: string): operation is IdaOperation =>
operationSet.has(operation);
const wasCancelled = (options: ExecutionOptions | undefined): boolean =>
@@ -149,12 +152,15 @@ export class IdaSessionClient implements AnalysisClient {
"This integration admits read-only analysis operations only.",
),
);
if (operation === "procedure_callers" && this.config.mode === "headless")
if (
operation === "procedure_callers" &&
idaProtocol(this.config) !== "legacy"
)
return err(
new AnalysisCapabilityUnavailableError(
"ida",
operation,
"The modern upstream profile does not prove direct callers.",
"This upstream profile does not prove direct callers.",
),
);
if (operation !== "health") {
@@ -193,7 +199,7 @@ export class IdaSessionClient implements AnalysisClient {
);
const runner = new IdaOperationRunner(
this.connection,
this.config.mode === "attached" ? "legacy" : "modern",
idaProtocol(this.config),
this.#database,
);
const result = await runner.run(operation, parameters);
@@ -282,11 +288,15 @@ export class IdaSessionClient implements AnalysisClient {
async #initialize(): Promise<void> {
const tools = new Set(await this.connection.connect());
const expected =
this.config.mode === "attached" ? legacyTools : modernTools;
this.config.protocol === "native"
? nativeTools
: this.config.mode === "attached"
? legacyTools
: modernTools;
const missing = expected.filter((name) => !tools.has(name));
if (missing.length > 0)
throw new AnalysisProtocolError(
`IDA MCP ${this.config.mode} compatibility profile is missing tools: ${missing.join(", ")}. Attached mode requires the legacy 1.4 profile; headless mode requires the database supervisor profile. See docs/ida-provider.md.`,
`IDA MCP ${this.config.protocol === "native" ? "native attached" : this.config.mode} compatibility profile is missing tools: ${missing.join(", ")}. See docs/ida-provider.md.`,
);
if (this.config.mode === "headless") {
this.#workspace = await IdaWorkspace.allocate(
@@ -336,10 +346,21 @@ export class IdaSessionClient implements AnalysisClient {
}
}
async #nativeMetadata(): Promise<JsonValue> {
if (this.connection.readResource === undefined)
throw new AnalysisProtocolError(
"Native IDA MCP requires resources/read for recorded input metadata.",
);
return this.connection.readResource("ida://idb/metadata");
}
async #observe(): Promise<JsonValue> {
let identity: string;
if (this.config.mode === "attached") {
const raw = await this.connection.call("get_metadata", {});
const raw =
this.config.protocol === "native"
? await this.#nativeMetadata()
: await this.connection.call("get_metadata", {});
const metadata = legacyMetadataSchema.parse(raw);
if (metadata.sha256.toLowerCase() !== this.target.sha256.toLowerCase())
throw new AnalysisProtocolError(