fix(ida): list each xref source address once (#15441)

* fix(ida): list each xref source address once

* test(ida): expect source addresses from the runner's xrefs read
This commit is contained in:
morluto
2026-12-01 06:35:57 +00:00
committed by GitHub
parent 34f6ac1ec3
commit f559766c55
3 changed files with 51 additions and 19 deletions
+2 -8
View File
@@ -59,7 +59,7 @@ it("rejects file coordinates before any symbol lookup", async () => {
});
});
it("projects the native xref source function and retains unused span evidence", async () => {
it("reads native xref rows as source addresses and retains the raw response", async () => {
const producer = new RecordingIdaMcp(target, "attached");
const runner = new IdaOperationRunner(producer, "native");
const response = [
@@ -77,13 +77,7 @@ it("projects the native xref source function and retains unused span evidence",
];
producer.overrideCall = (tool) =>
tool === "xrefs_to" ? response : undefined;
expect(await runner.xrefs("0x1000")).toEqual([
{
address: "0x1004",
type: "code",
function: { address: "0x1000", name: "main" },
},
]);
expect(await runner.xrefs("0x1000")).toEqual(["0x1004"]);
expect(runner.raw).toEqual([
{
tool: "xrefs_to",
+5 -11
View File
@@ -447,11 +447,8 @@ export class IdaOperationRunner {
return result.join("\n");
}
async xrefs(
address: string,
): Promise<
{ address: string; type: string; function: IdaFunction | null }[]
> {
/** Source addresses referencing `address`, each listed once. */
async xrefs(address: string): Promise<string[]> {
const page = (
this.protocol === "native" ? nativeXrefsSchema : modernXrefsSchema
).parse(await this.call("xrefs_to", { addrs: [address], limit: 1000 }))[0];
@@ -464,11 +461,8 @@ export class IdaOperationRunner {
this.limitations.push(
"Upstream xrefs_to capped results at 1000 references; additional references remain unknown.",
);
return page.xrefs.map((xref) => ({
address: xref.addr,
type: xref.type,
function: xref.fn,
}));
// Upstream rows are per (source, kind), so one source can appear as both code and data.
return [...new Set(page.xrefs.map(({ addr }) => addr))];
}
async relationships(
@@ -666,7 +660,7 @@ export class IdaOperationRunner {
if (operation === "xrefs") {
const inspectedAddress = idaAddressSchema.parse(parameters.address);
this.locations.push({ kind: "address", address: inspectedAddress });
return (await this.xrefs(inspectedAddress)).map(({ address }) => address);
return this.xrefs(inspectedAddress);
}
const fn = await this.resolve(
z.string().min(1).parse(parameters.procedure),
@@ -0,0 +1,44 @@
import { afterEach, expect, it } from "vitest";
import { EnhancedTools } from "../../../../src/application/EnhancedTools.js";
import {
callGraphSession,
removeCallGraphSessions,
} from "../../../fixtures/idaCallGraph.js";
afterEach(removeCallGraphSessions);
it("lists and counts each IDA xref source address once when it holds both code and data references", async () => {
const { client, producer } = await callGraphSession({ callees: [] });
const fixtureCall = producer.overrideCall;
producer.overrideCall = (name, args) =>
name === "xrefs_to"
? [
{
xrefs: [
{ addr: "0x2000", type: "code", fn: null },
{ addr: "0x2000", type: "data", fn: null },
{ addr: "0x3000", type: "code", fn: null },
],
more: false,
},
]
: fixtureCall?.(name, args);
try {
const direct = await client.execute("xrefs", { address: "0x1000" });
if (!direct.ok) throw direct.error;
expect(direct.value.result).toEqual(["0x2000", "0x3000"]);
const paged = await new EnhancedTools(client).executeValidated({
name: "find_xrefs_to_name",
input: { name: "main", limit: 10 },
});
if (!paged.ok) throw paged.error;
expect(paged.value).toMatchObject({
xrefs: ["0x2000", "0x3000"],
observed_xrefs: 2,
total_xrefs: 2,
});
} finally {
await client.close();
}
});