feat(ida): support optional native IDA Free MCP in attached mode
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import { z } from "zod";
|
||||
import {
|
||||
nativeDecompileSchema,
|
||||
nativeDisassemblySchema,
|
||||
nativeCalleesSchema,
|
||||
nativeXrefsSchema,
|
||||
} from "./IdaNativeProtocol.js";
|
||||
import { analysisSearchInput } from "../contracts/analysisSearchContract.js";
|
||||
import {
|
||||
AnalysisInputError,
|
||||
@@ -60,7 +66,7 @@ export class IdaOperationRunner {
|
||||
readonly limitations: string[] = [];
|
||||
constructor(
|
||||
private readonly connection: IdaMcpConnection,
|
||||
private readonly protocol: "legacy" | "modern",
|
||||
private readonly protocol: "legacy" | "modern" | "native",
|
||||
private readonly database?: string,
|
||||
) {}
|
||||
|
||||
@@ -103,7 +109,7 @@ export class IdaOperationRunner {
|
||||
}
|
||||
|
||||
async resolve(query: string): Promise<IdaFunction> {
|
||||
if (this.protocol === "modern") {
|
||||
if (this.protocol !== "legacy") {
|
||||
const item = modernLookupSchema.parse(
|
||||
await this.call("lookup_funcs", { queries: [query] }),
|
||||
)[0];
|
||||
@@ -153,7 +159,7 @@ export class IdaOperationRunner {
|
||||
} else {
|
||||
const page = modernStringsSchema.parse(
|
||||
await this.call("find_regex", {
|
||||
pattern: "(?s).*",
|
||||
pattern: this.protocol === "native" ? "[\\s\\S]*" : "(?s).*",
|
||||
offset,
|
||||
limit: 100,
|
||||
}),
|
||||
@@ -182,7 +188,11 @@ export class IdaOperationRunner {
|
||||
let result: IdaDisassembly | undefined;
|
||||
let offset: number | null = 0;
|
||||
while (offset !== null) {
|
||||
const page = modernDisassemblySchema.parse(
|
||||
const page = (
|
||||
this.protocol === "native"
|
||||
? nativeDisassemblySchema
|
||||
: modernDisassemblySchema
|
||||
).parse(
|
||||
await this.call("disasm", {
|
||||
addr: fn.address,
|
||||
offset,
|
||||
@@ -216,6 +226,23 @@ export class IdaOperationRunner {
|
||||
.string()
|
||||
.nullable()
|
||||
.parse(await this.call("decompile_function", { address: fn.address }));
|
||||
if (this.protocol === "native") {
|
||||
const page = nativeDecompileSchema.parse(
|
||||
await this.call("decompile", { addr: fn.address }),
|
||||
);
|
||||
if (page.addr !== fn.address)
|
||||
throw new AnalysisProtocolError(
|
||||
"Native IDA pseudocode identifies a different function than the resolved entry.",
|
||||
);
|
||||
if (!page.ok || page.error !== undefined || page.pseudocode === undefined)
|
||||
throw new AnalysisProtocolError(
|
||||
`Native IDA decompilation failed: ${page.error ?? "missing pseudocode"}`,
|
||||
);
|
||||
this.limitations.push(
|
||||
"Native pseudocode is rendered GUI text; the upstream viewer traversal is bounded and does not establish complete source recovery.",
|
||||
);
|
||||
return page.pseudocode;
|
||||
}
|
||||
const result: string[] = [];
|
||||
let offset: number | null = 0;
|
||||
while (offset !== null) {
|
||||
@@ -245,9 +272,9 @@ export class IdaOperationRunner {
|
||||
return legacyXrefsSchema.parse(
|
||||
await this.call("get_xrefs_to", { address }),
|
||||
);
|
||||
const page = modernXrefsSchema.parse(
|
||||
await this.call("xrefs_to", { addrs: [address], limit: 1000 }),
|
||||
)[0];
|
||||
const page = (
|
||||
this.protocol === "native" ? nativeXrefsSchema : modernXrefsSchema
|
||||
).parse(await this.call("xrefs_to", { addrs: [address], limit: 1000 }))[0];
|
||||
if (page?.xrefs == null || page.error !== undefined)
|
||||
throw new AnalysisProtocolError(
|
||||
`IDA xrefs failed: ${page?.error ?? "missing references"}`,
|
||||
@@ -285,11 +312,13 @@ export class IdaOperationRunner {
|
||||
}
|
||||
} else if (direction === "callers") {
|
||||
this.limitations.push(
|
||||
"Modern upstream xrefs classify references as code or data, without proving call edges. Direct callers are unavailable in this profile.",
|
||||
"Upstream xrefs classify references as code or data, without proving call edges. Direct callers are unavailable in this profile.",
|
||||
);
|
||||
return [];
|
||||
} else {
|
||||
const page = modernCalleesSchema.parse(
|
||||
const page = (
|
||||
this.protocol === "native" ? nativeCalleesSchema : modernCalleesSchema
|
||||
).parse(
|
||||
await this.call("callees", { addrs: [fn.address], limit: 500 }),
|
||||
)[0];
|
||||
if (page?.callees == null || page.error !== undefined)
|
||||
@@ -357,7 +386,7 @@ export class IdaOperationRunner {
|
||||
case "procedure_assembly":
|
||||
return lines(await this.assembly(fn)).join("\n");
|
||||
case "procedure_callers":
|
||||
if (this.protocol === "modern")
|
||||
if (this.protocol !== "legacy")
|
||||
throw new AnalysisProtocolError(
|
||||
"This IDA MCP profile cannot distinguish direct callers from other code references.",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user