mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 13:24:20 +00:00
* refactor(ida)!: remove the legacy ida-pro-mcp 1.4 attached protocol Attached IDA analysis now has one protocol, the native ida-free-mcp plugin. The legacy 1.4 GUI proxy branches, response schemas, tool profile, GUI navigation effects and plain-text reply kind are removed. A stored registration that still names "protocol": "legacy" is refused at configuration with a REA_IDA_MCP_CONFIG constraint naming the migration section; it is never read as another protocol and the file is not rewritten. Native and headless request/response handling is unchanged. Refs #10516 BREAKING CHANGE: "protocol": "legacy" IDA registrations are refused. Before (accepted, ida-pro-mcp 1.4 GUI proxy): {"mode": "attached", "protocol": "legacy", "command": "python", "args": ["/path/ida_pro_mcp/server.py", "--ida-rpc", "http://127.0.0.1:13337"]} After (native plugin for an open GUI database): {"mode": "attached", "protocol": "native", "url": "http://127.0.0.1:13337/mcp"} or an ida-pro-mcp 2.x database supervisor in headless mode: {"mode": "headless", "command": "idalib-mcp", "args": ["--stdio", "--max-workers", "1"]} procedure_callers is no longer available from any IDA profile, and IDA procedure_assembly/read_function_instructions no longer advertise may_show_ui. See docs/providers/ida-provider.md#migrate-a-legacy-attached-registration. * test(ida): deliver null metadata overrides and compare legacy refusal with its owner
150 lines
5.0 KiB
TypeScript
150 lines
5.0 KiB
TypeScript
import { rm } from "node:fs/promises";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { z } from "zod";
|
|
import { functionDossierSchema } from "../../../../src/domain/native/functionDossier.js";
|
|
import {
|
|
jsonValueSchema,
|
|
type JsonValue,
|
|
} from "../../../../src/domain/jsonValue.js";
|
|
import { IdaSessionClient } from "../../../../src/ida/IdaSessionClient.js";
|
|
import { createIdaTarget, RecordingIdaMcp } from "../../../fixtures/idaMcp.js";
|
|
|
|
type IdentityCase = {
|
|
label: string;
|
|
fields: Readonly<Record<string, JsonValue>>;
|
|
};
|
|
|
|
const observationsSchema = z.object({
|
|
observations: z.array(
|
|
z.object({ tool: z.string(), result: jsonValueSchema }),
|
|
),
|
|
});
|
|
const observation = (raw: unknown, tool: string) =>
|
|
observationsSchema.parse(raw).observations.find((item) => item.tool === tool)
|
|
?.result;
|
|
|
|
const roots: string[] = [];
|
|
afterEach(async () => {
|
|
for (const root of roots.splice(0))
|
|
await rm(root, { recursive: true, force: true });
|
|
});
|
|
|
|
const session = async (
|
|
mode: "attached" | "headless",
|
|
fields: Readonly<Record<string, JsonValue>>,
|
|
) => {
|
|
const { root, target } = await createIdaTarget();
|
|
roots.push(root);
|
|
const producer = new RecordingIdaMcp(target, mode);
|
|
const fn = { addr: "0x1000", name: "main", ...fields };
|
|
const inventory = [{ data: [fn], next_offset: null }];
|
|
const lookup = [{ query: "main", fn, error: null }];
|
|
producer.overrideCall = (name) => {
|
|
switch (name) {
|
|
case "list_funcs":
|
|
return inventory;
|
|
case "lookup_funcs":
|
|
return lookup;
|
|
case "callees":
|
|
return [{ callees: [], more: false }];
|
|
default:
|
|
return undefined;
|
|
}
|
|
};
|
|
const client = new IdaSessionClient(
|
|
{
|
|
command: "fixture",
|
|
args: [],
|
|
env: {},
|
|
mode,
|
|
protocol: mode === "attached" ? "native" : "modern",
|
|
timeoutMs: 1000,
|
|
workspaceRoot: root,
|
|
},
|
|
target,
|
|
producer,
|
|
);
|
|
return { client, inventoryObservation: inventory, lookupObservation: lookup };
|
|
};
|
|
|
|
describe.each(["attached", "headless"] as const)(
|
|
"%s IDA function identity boundary",
|
|
(mode) => {
|
|
it.each<IdentityCase>([
|
|
{ label: "omitted", fields: {} },
|
|
{ label: "null", fields: { size: null } },
|
|
{ label: "malformed text", fields: { size: "unknown extent" } },
|
|
{ label: "malformed object", fields: { size: { unavailable: true } } },
|
|
])(
|
|
"retains usable inventory and dossier identity with $label size and preserves exact observations",
|
|
async ({ fields }) => {
|
|
const fixture = await session(mode, fields);
|
|
try {
|
|
const inventory = await fixture.client.execute("list_procedures", {});
|
|
if (!inventory.ok) throw inventory.error;
|
|
expect(inventory.value.result).toEqual([
|
|
{ address: "0x1000", value: "main" },
|
|
]);
|
|
expect(observation(inventory.value.rawResult, "list_funcs")).toEqual(
|
|
fixture.inventoryObservation,
|
|
);
|
|
|
|
const analyzed = await fixture.client.execute("analyze_function", {
|
|
procedure: "main",
|
|
});
|
|
if (!analyzed.ok) throw analyzed.error;
|
|
const dossier = functionDossierSchema.parse(analyzed.value.result);
|
|
expect(dossier.procedure).toMatchObject({
|
|
address: "0x1000",
|
|
name: "main",
|
|
body: { available: false, reason: expect.any(String) },
|
|
});
|
|
expect(observation(analyzed.value.rawResult, "lookup_funcs")).toEqual(
|
|
fixture.lookupObservation,
|
|
);
|
|
} finally {
|
|
expect((await fixture.client.close()).ok).toBe(true);
|
|
}
|
|
},
|
|
);
|
|
|
|
it.each<IdentityCase>([
|
|
{ label: "address", fields: { address: "invalid", addr: "invalid" } },
|
|
{ label: "name", fields: { name: null } },
|
|
])("rejects malformed $label despite unused size", async ({ fields }) => {
|
|
const fixture = await session(mode, {
|
|
...fields,
|
|
size: "unknown extent",
|
|
});
|
|
try {
|
|
for (const operation of [
|
|
"list_procedures",
|
|
"procedure_address",
|
|
] as const) {
|
|
const result = await fixture.client.execute(
|
|
operation,
|
|
operation === "procedure_address" ? { procedure: "main" } : {},
|
|
);
|
|
if (result.ok) throw new Error("Expected malformed identity to fail");
|
|
expect(result.error._tag).toBe("AnalysisOutputError");
|
|
const partial = result.error.partialObservation;
|
|
if (partial === undefined || !("raw_result" in partial))
|
|
throw new Error("Expected retained IDA Evidence");
|
|
expect(
|
|
observation(
|
|
partial.raw_result,
|
|
operation === "list_procedures" ? "list_funcs" : "lookup_funcs",
|
|
),
|
|
).toEqual(
|
|
operation === "list_procedures"
|
|
? fixture.inventoryObservation
|
|
: fixture.lookupObservation,
|
|
);
|
|
}
|
|
} finally {
|
|
expect((await fixture.client.close()).ok).toBe(true);
|
|
}
|
|
});
|
|
},
|
|
);
|