fix(ida): preserve non-x86 call edges and workflow uncertainty (#1906)
* test(ida): expect callee edges from the call graph on non-x86 targets * fix(ida): read callee edges from the call graph on non-x86 targets * test(ida): pin address order of call graph additions * docs(ida): describe the call graph source for non-x86 callees * test(ida): pin the x86 baseline, the call graph reader and its failure modes * fix(ida): check the call graph root, scope truncation to the root and degrade without callgraph * test(ida): expect managed PE off the x86 path, possible-truncation wording and a complete ARM64 traversal * fix(ida): keep managed PE and x86 reads off the call graph path and qualify truncation * test(ida): answer only expected leaf roots and assert the requested call graph roots * test(ida): expect a call graph the producer cannot give consistently to fail the callee read * fix(ida): fail the callee read when the call graph cannot be obtained consistently * fix(ida): preserve call edge authority and workflow uncertainty * fix(ida): preserve explicit root call graph caps --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
co-authored by
morluto
parent
c2cf7dcb86
commit
0ae38e1e31
@@ -1,19 +1,82 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import type { AnalysisOperationPort } from "../../../src/application/AnalysisProvider.js";
|
||||
import { createAnalysisExecution } from "../../../src/application/AnalysisProvider.js";
|
||||
import { EnhancedTools } from "../../../src/application/EnhancedTools.js";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisOutputError,
|
||||
} from "../../../src/domain/analysisErrorCore.js";
|
||||
import { err } from "../../../src/domain/result.js";
|
||||
import { err, ok as resultOk } from "../../../src/domain/result.js";
|
||||
|
||||
import { closeEnhancedToolResources, connect } from "./enhancedToolsHarness.js";
|
||||
import { observed as ok } from "../../fixtures/analysisExecution.js";
|
||||
|
||||
afterEach(closeEnhancedToolResources);
|
||||
|
||||
const relationshipExecution = (
|
||||
result: unknown,
|
||||
limitations: readonly string[] = [],
|
||||
) =>
|
||||
resultOk(
|
||||
createAnalysisExecution(
|
||||
result,
|
||||
{ id: "fixture", name: "Fixture analysis provider", version: "1" },
|
||||
{ limitations },
|
||||
),
|
||||
);
|
||||
|
||||
describe("enhanced MCP tools", () => {
|
||||
it("preserves per-node relationship limitations and keeps observed edges", async () => {
|
||||
const limitation = "ARM64 call targets are only partially resolved.";
|
||||
const client = await connect({
|
||||
execute: async (name, arguments_) => {
|
||||
if (name === "procedure_address")
|
||||
return relationshipExecution(String(arguments_.procedure));
|
||||
if (name !== "procedure_callees")
|
||||
throw new Error(`Unexpected operation: ${name}`);
|
||||
return relationshipExecution(
|
||||
arguments_.procedure === "0x1" ? ["0x2"] : [],
|
||||
arguments_.procedure === "0x1" ? [limitation] : [],
|
||||
);
|
||||
},
|
||||
});
|
||||
const graph = await client.callTool({
|
||||
name: "get_call_graph",
|
||||
arguments: { address: "0x1", direction: "forward" },
|
||||
});
|
||||
expect(graph.isError).not.toBe(true);
|
||||
expect(graph.structuredContent).toMatchObject({
|
||||
normalized_result: {
|
||||
"0": [
|
||||
{
|
||||
address: "0x1",
|
||||
status: "ok",
|
||||
calls: ["0x2"],
|
||||
limitations: [limitation],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const trace = await client.callTool({
|
||||
name: "trace_call_path",
|
||||
arguments: { start: "0x1", goal: "0x2" },
|
||||
});
|
||||
expect(trace.isError).not.toBe(true);
|
||||
expect(trace.structuredContent).toMatchObject({
|
||||
normalized_result: {
|
||||
goal_status: "reached",
|
||||
traversal_path: ["0x1", "0x2"],
|
||||
edges: [{ source_address: "0x1", target_address: "0x2" }],
|
||||
truncated: true,
|
||||
residual_unknowns: [
|
||||
`Call relationships for 0x1 are limited: ${limitation}`,
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("returns every batch item in caller order with its own result", async () => {
|
||||
const addresses = Array.from(
|
||||
{ length: 37 },
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
import { EnhancedTools } from "../../../../src/application/EnhancedTools.js";
|
||||
import {
|
||||
callGraphSession,
|
||||
edge,
|
||||
graphRow,
|
||||
removeCallGraphSessions,
|
||||
} from "../../../fixtures/idaCallGraph.js";
|
||||
|
||||
afterEach(removeCallGraphSessions);
|
||||
|
||||
const requestedRoots = (producer: {
|
||||
calls: { name: string; args: unknown }[];
|
||||
}) =>
|
||||
producer.calls
|
||||
.filter(({ name }) => name === "callgraph")
|
||||
.map(
|
||||
({ args }) =>
|
||||
z.object({ roots: z.array(z.string()) }).parse(args).roots[0],
|
||||
)
|
||||
.sort();
|
||||
|
||||
const armSession = () =>
|
||||
callGraphSession({
|
||||
callees: [],
|
||||
callgraph: graphRow([edge("0x1000", "0x2000"), edge("0x1000", "0x3000")]),
|
||||
leafRoots: ["0x2000", "0x3000"],
|
||||
});
|
||||
|
||||
it("shows the callee edges of an ARM64 procedure in the call graph", async () => {
|
||||
const { client, producer } = await armSession();
|
||||
try {
|
||||
const result = await new EnhancedTools(client).execute("get_call_graph", {
|
||||
address: "main",
|
||||
});
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
expect(
|
||||
result.value,
|
||||
"the root lists both observed callees instead of an empty observed list",
|
||||
).toMatchObject({
|
||||
"0": [
|
||||
{
|
||||
address: "0x1000",
|
||||
status: "ok",
|
||||
calls: ["0x2000", "0x3000"],
|
||||
limitations: expect.arrayContaining([
|
||||
"This relationship read does not establish calls to targets IDA does not recognize as functions; imports and other non-function call targets remain unknown.",
|
||||
]),
|
||||
},
|
||||
],
|
||||
"1": [
|
||||
{
|
||||
address: "0x2000",
|
||||
status: "ok",
|
||||
calls: [],
|
||||
limitations: expect.arrayContaining([
|
||||
"This relationship read does not establish calls to targets IDA does not recognize as functions; imports and other non-function call targets remain unknown.",
|
||||
]),
|
||||
},
|
||||
{
|
||||
address: "0x3000",
|
||||
status: "ok",
|
||||
calls: [],
|
||||
limitations: expect.arrayContaining([
|
||||
"This relationship read does not establish calls to targets IDA does not recognize as functions; imports and other non-function call targets remain unknown.",
|
||||
]),
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(
|
||||
requestedRoots(producer),
|
||||
"each reachable procedure is read once, with exactly its own root",
|
||||
).toEqual(["0x1000", "0x2000", "0x3000"]);
|
||||
} finally {
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("reaches an ARM64 callee in a call path", async () => {
|
||||
const { client } = await armSession();
|
||||
try {
|
||||
const result = await new EnhancedTools(client).execute("trace_call_path", {
|
||||
start: "main",
|
||||
goal: "0x3000",
|
||||
});
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
expect(
|
||||
result.value,
|
||||
"the goal is reached through the observed edge",
|
||||
).toMatchObject({
|
||||
goal_status: "reached",
|
||||
traversal_path: ["0x1000", "0x3000"],
|
||||
});
|
||||
} finally {
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("traverses every ARM64 callee in a call path without a goal and records no failure", async () => {
|
||||
const { client, producer } = await armSession();
|
||||
try {
|
||||
const result = await new EnhancedTools(client).execute("trace_call_path", {
|
||||
start: "main",
|
||||
});
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
expect(
|
||||
result.value,
|
||||
"the whole reachable graph is visited with exactly the observed edges and no failure",
|
||||
).toMatchObject({
|
||||
goal_status: "not_requested",
|
||||
nodes: [
|
||||
{ address: "0x1000", depth: 0 },
|
||||
{ address: "0x2000", depth: 1 },
|
||||
{ address: "0x3000", depth: 1 },
|
||||
],
|
||||
edges: [
|
||||
{ source_address: "0x1000", target_address: "0x2000" },
|
||||
{ source_address: "0x1000", target_address: "0x3000" },
|
||||
],
|
||||
failures: [],
|
||||
truncated: true,
|
||||
limitations: expect.arrayContaining([
|
||||
"This relationship read does not establish calls to targets IDA does not recognize as functions; imports and other non-function call targets remain unknown.",
|
||||
]),
|
||||
residual_unknowns: expect.arrayContaining([
|
||||
expect.stringContaining("Call relationships for 0x1000 are limited:"),
|
||||
]),
|
||||
});
|
||||
expect(
|
||||
requestedRoots(producer),
|
||||
"each reachable procedure is read once, with exactly its own root",
|
||||
).toEqual(["0x1000", "0x2000", "0x3000"]);
|
||||
} finally {
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves missing callgraph coverage through direct, graph, and trace workflows", async () => {
|
||||
const { client, producer } = await callGraphSession({
|
||||
tools: [
|
||||
"idb_open",
|
||||
"idb_list",
|
||||
"idb_close",
|
||||
"server_health",
|
||||
"list_funcs",
|
||||
"lookup_funcs",
|
||||
"find_regex",
|
||||
"decompile",
|
||||
"disasm",
|
||||
"callees",
|
||||
"xrefs_to",
|
||||
],
|
||||
callees: [
|
||||
{ addr: "0x3000", name: "bogus_non_x86_match", type: "internal" },
|
||||
],
|
||||
});
|
||||
try {
|
||||
const direct = await client.execute("procedure_callees", {
|
||||
procedure: "main",
|
||||
});
|
||||
if (!direct.ok) throw direct.error;
|
||||
expect(
|
||||
direct.value.result,
|
||||
"the x86-only producer result is ignored",
|
||||
).toEqual([]);
|
||||
expect(direct.value.limitations).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("callgraph was unavailable"),
|
||||
expect.stringContaining("targets IDA does not recognize as functions"),
|
||||
]),
|
||||
);
|
||||
|
||||
const application = new EnhancedTools(client);
|
||||
const graph = await application.execute("get_call_graph", {
|
||||
address: "main",
|
||||
});
|
||||
if (!graph.ok) throw graph.error;
|
||||
expect(graph.value).toMatchObject({
|
||||
"0": [
|
||||
{
|
||||
status: "ok",
|
||||
calls: [],
|
||||
limitations: expect.arrayContaining([
|
||||
expect.stringContaining("callgraph was unavailable"),
|
||||
]),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const trace = await application.execute("trace_call_path", {
|
||||
start: "main",
|
||||
goal: "0x3000",
|
||||
});
|
||||
if (!trace.ok) throw trace.error;
|
||||
expect(trace.value).toMatchObject({
|
||||
goal_status: "not_reached",
|
||||
edges: [],
|
||||
limitations: expect.arrayContaining([
|
||||
expect.stringContaining("callgraph was unavailable"),
|
||||
]),
|
||||
residual_unknowns: expect.arrayContaining([
|
||||
expect.stringContaining("Call relationships for 0x1000 are limited:"),
|
||||
]),
|
||||
});
|
||||
expect(
|
||||
producer.calls.some(({ name }) => name === "callees"),
|
||||
"the inaccurate fallback is never queried",
|
||||
).toBe(false);
|
||||
expect(
|
||||
producer.calls.some(({ name }) => name === "callgraph"),
|
||||
"an unadvertised tool is never requested",
|
||||
).toBe(false);
|
||||
} finally {
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("records a failed ARM64 call graph read as the node's error, not as a complete node", async () => {
|
||||
const { client } = await callGraphSession({
|
||||
callees: [],
|
||||
callgraphTruncatedOutput: true,
|
||||
});
|
||||
try {
|
||||
const result = await new EnhancedTools(client).execute("get_call_graph", {
|
||||
address: "main",
|
||||
});
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
expect(
|
||||
result.value,
|
||||
"the transport-truncated graph is a recorded failure and no callee list is invented",
|
||||
).toEqual({
|
||||
"0": [
|
||||
{
|
||||
address: "0x1000",
|
||||
status: "error",
|
||||
error: expect.objectContaining({ code: "unreadable_output" }),
|
||||
},
|
||||
],
|
||||
});
|
||||
} finally {
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves an explicit root cap below the edge limit through every relationship workflow", async () => {
|
||||
const { client } = await callGraphSession({
|
||||
callees: [],
|
||||
callgraph: graphRow([edge("0x1000", "0x2000")], { per_func_capped: true }),
|
||||
leafRoots: ["0x2000"],
|
||||
});
|
||||
const limitation =
|
||||
"Upstream callgraph was truncated; additional callees remain unknown.";
|
||||
try {
|
||||
const direct = await client.execute("procedure_callees", {
|
||||
procedure: "main",
|
||||
});
|
||||
if (!direct.ok) throw direct.error;
|
||||
expect(direct.value.limitations).toContain(limitation);
|
||||
expect(direct.value.result).toEqual(["0x2000"]);
|
||||
const application = new EnhancedTools(client);
|
||||
const graph = await application.execute("get_call_graph", {
|
||||
address: "main",
|
||||
});
|
||||
if (!graph.ok) throw graph.error;
|
||||
expect(graph.value).toMatchObject({
|
||||
"0": [
|
||||
{
|
||||
calls: ["0x2000"],
|
||||
limitations: expect.arrayContaining([limitation]),
|
||||
},
|
||||
],
|
||||
});
|
||||
const trace = await application.execute("trace_call_path", {
|
||||
start: "main",
|
||||
});
|
||||
if (!trace.ok) throw trace.error;
|
||||
expect(trace.value).toMatchObject({
|
||||
truncated: true,
|
||||
residual_unknowns: expect.arrayContaining([
|
||||
`Call relationships for 0x1000 are limited: ${limitation}`,
|
||||
]),
|
||||
});
|
||||
} finally {
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user