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

Add an explicit attached native IDA MCP compatibility profile while preserving the legacy and headless workflows. Keep recorded input identity, complete source observations and the user's open GUI database. Batch unique callee lookups, conservatively prefilter literal strings, preserve Unicode matching and unavailable caller coverage, and require distinct-function switching in native verification.

Verified with Windows IDA Pro 9.3 and the native MCP plugin built from c9d15d98e8a143fc74f6e14037c48f63889b6d6c with a loopback listener. Production CLI/MCP and an unchanged Windows whoami.exe passed. Windows IDA Free was not used. No personal paths or license registration information are included.

Validation: 200 focused tests, static and documentation checks, architecture guards and discovery passed. Historical same-main warm task measurements improved from 675 to 317 ms; response token estimates fell from 16618 to 11509. Fresh-start, overall CPU and memory improvement were not established. Detailed scope is in experiments/analysis-efficiency/ida-native-windows.md.

Co-authored-by: imissapixel <140405963+imissapixel@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
Co-authored-by: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com>
This commit is contained in:
Fernando Pereira
2026-10-13 03:10:21 +08:00
committed by GitHub
co-authored by morluto N0zoM1z0
parent f76163c246
commit d1aaeee400
19 changed files with 1524 additions and 149 deletions
+42 -4
View File
@@ -19,7 +19,7 @@ const requestSchema = z.object({
.passthrough()
.optional(),
});
const fixture = async (redirectUrl?: string, cycle = false) => {
const fixture = async (redirectUrl?: string, cycle = false, native = false) => {
const methods: string[] = [];
const headers: (string | undefined)[] = [];
const server = createServer(async (request, response) => {
@@ -47,7 +47,7 @@ const fixture = async (redirectUrl?: string, cycle = false) => {
input.method === "initialize"
? {
protocolVersion: input.params?.protocolVersion,
capabilities: { tools: {} },
capabilities: { tools: {}, ...(native ? { resources: {} } : {}) },
serverInfo: {
name: "ida-transport-fixture",
version: "observed-server-version",
@@ -72,7 +72,32 @@ const fixture = async (redirectUrl?: string, cycle = false) => {
}
: {}),
}
: { content: [], structuredContent: { observed: true } };
: input.method === "resources/read"
? {
contents: [
{
uri: "ida://idb/metadata",
mimeType: "application/json",
text: JSON.stringify({
path: "/fixture/input.i64",
sha256: "a".repeat(64),
base: "0x1000",
module: "input",
}),
},
],
}
: native
? {
content: [
{
type: "text",
text: JSON.stringify([{ observed: true }]),
},
],
structuredContent: { result: [], _output_truncated: true },
}
: { content: [], structuredContent: { observed: true } };
response.writeHead(200, { "Content-Type": "application/json" });
response.end(JSON.stringify({ jsonrpc: "2.0", id: input.id, result }));
});
@@ -93,7 +118,8 @@ const fixture = async (redirectUrl?: string, cycle = false) => {
{
url: `http://127.0.0.1:${address.port}/mcp`,
headers: { Authorization: "Bearer transport-fixture-secret" },
mode: "headless",
mode: native ? "attached" : "headless",
...(native ? { protocol: "native" as const } : {}),
timeoutMs: 2000,
},
{},
@@ -138,3 +164,15 @@ it("rejects nonterminating SDK pagination instead of returning a partial tool ca
methods.filter((method) => method === "tools/list").length,
).toBeGreaterThan(2);
});
it("reads native metadata resources and complete JSON text through the real SDK transport", async () => {
const { connection, methods } = await fixture(undefined, false, true);
expect(await connection.connect()).toEqual(["first", "second"]);
expect(await connection.call("first", {})).toEqual([{ observed: true }]);
expect(await connection.readResource?.("ida://idb/metadata")).toMatchObject({
path: "/fixture/input.i64",
sha256: "a".repeat(64),
});
await expect(connection.readResource?.("ida://other")).rejects.toThrow();
expect(methods).toContain("resources/read");
});
@@ -28,6 +28,29 @@ const armSession = () =>
leafRoots: ["0x2000", "0x3000"],
});
it("keeps unknown caller coverage and callee diagnostics in an ARM64 dossier", async () => {
const { client } = await armSession();
try {
const result = await client.execute("analyze_function", {
procedure: "main",
});
if (!result.ok) throw result.error;
expect(result.value.relationshipCoverage).toMatchObject({
status: "unknown",
reason: "Upstream xrefs do not establish direct caller relationships.",
diagnostics: expect.arrayContaining([
expect.stringContaining("targets IDA does not recognize as functions"),
]),
});
expect(result.value.result).toMatchObject({
callers: [],
callees: [{ address: "0x2000" }, { address: "0x3000" }],
});
} finally {
await client.close();
}
});
it("shows the callee edges of an ARM64 procedure in the call graph", async () => {
const { client, producer } = await armSession();
try {
@@ -0,0 +1,68 @@
import { execFile } from "node:child_process";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { promisify } from "node:util";
import { expect, it } from "vitest";
const execute = promisify(execFile);
it.each([
{ protocol: "native", flags: [], required: true },
{
protocol: "native",
flags: ["--second-procedure", "other", "--second-marker", "unique"],
required: false,
},
{ protocol: "legacy", flags: [], required: false },
{ protocol: "modern", flags: [], required: false },
])(
"enforces native switching requirements for $protocol with $flags",
async ({ protocol, flags, required }) => {
const root = await mkdtemp(join(tmpdir(), "rea-ida-verifier-options-"));
try {
const config = join(root, "ida.json");
await writeFile(
config,
JSON.stringify({
url: "http://127.0.0.1:13337/mcp",
mode: protocol === "modern" ? "headless" : "attached",
...(protocol === "native" ? { protocol } : {}),
}),
);
// The absent target stops accepted option sets at admission, before any provider call.
await expect(
execute(
process.execPath,
[
"scripts/verify-real-ida.mjs",
"--target",
join(root, "absent"),
...flags,
],
{
cwd: process.cwd(),
env: { ...process.env, REA_IDA_MCP_CONFIG: config },
timeout: 10_000,
},
),
).rejects.toMatchObject(
required
? {
stdout: "",
stderr: expect.stringContaining(
"Native IDA verification requires --second-procedure and --second-marker",
),
}
: {
stderr: "",
stdout: expect.stringContaining(
'"failed_phase": "target admission"',
),
},
);
} finally {
await rm(root, { recursive: true, force: true });
}
},
);
+5 -1
View File
@@ -10,6 +10,10 @@ REA_EXPORT REA_NOINLINE int rea_fixture_add(int left, int right) {
return left + right + 7;
}
REA_EXPORT REA_NOINLINE int rea_fixture_subtract(int left, int right) {
return left - right - 13;
}
int main(void) {
return rea_fixture_add(11, 24);
return rea_fixture_add(11, 24) + rea_fixture_subtract(24, 11);
}
+12 -9
View File
@@ -113,10 +113,13 @@ export class RecordingIdaMcp implements IdaMcpConnection {
if (overridden !== undefined) return overridden;
if (["idb_open", "idb_list", "idb_close", "server_health"].includes(name))
return this.lifecycle(name, args);
return this.read(name);
return this.read(name, args);
}
private read(name: string): JsonValue {
private read(
name: string,
args: Readonly<Record<string, JsonValue>>,
): JsonValue {
const fn = { address: "0x1000", name: "main", size: "0x20" };
const asm = {
name: "main",
@@ -153,13 +156,13 @@ export class RecordingIdaMcp implements IdaMcpConnection {
case "get_function_by_name":
return fn;
case "lookup_funcs":
return [
{
query: "main",
fn: { addr: fn.address, name: fn.name, size: fn.size },
error: null,
},
];
if (!Array.isArray(args.queries))
throw new Error("Invalid fixture lookup queries");
return args.queries.map((query) => ({
query,
fn: { addr: fn.address, name: fn.name, size: fn.size },
error: null,
}));
case "decompile_function":
return this.pseudocode;
case "decompile":