fix(ida): report a procedure IDA cannot resolve as invalid input (#1785)
* test(ida): expect a missing procedure to be reported as invalid input * test(ida): name the invalid_request code and its category for a missing procedure * fix(ida): report a procedure IDA cannot resolve as invalid input * test(ida): pin the missing-procedure issue shape and the lookups that stay unreadable * fix(ida): treat a lookup answer for another query as a producer fault * test(ida): expect an argument-independent issue path and pin legacy error replies and escaping * fix(ida): report a missing procedure without naming an argument path * test(ida): expect provider-derived selectors to stay producer faults in composed workflows * fix(ida): keep provider-derived procedure selectors out of the caller's input errors * test(ida): cover session forwarding, parameter hygiene and structured derived-node errors * docs(ida): describe when procedure resolution blames the caller
This commit is contained in:
@@ -19,6 +19,13 @@ import type { ProviderOperationHealth } from "../domain/providerOperationHealth.
|
||||
export interface ExecutionOptions {
|
||||
readonly signal?: AbortSignal;
|
||||
readonly progress?: ProgressReporter;
|
||||
/**
|
||||
* Set when a procedure selector came from provider output, such as a
|
||||
* revisited callee, rather than from the caller. A provider-derived
|
||||
* selector is never the caller's input mistake. Absent means the caller
|
||||
* supplied it.
|
||||
*/
|
||||
readonly selectorOrigin?: "provider";
|
||||
}
|
||||
|
||||
/** Closed operations accepted by provider-backed analysis sessions. */
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import type { AnalysisOperation } from "./AnalysisProvider.js";
|
||||
import type {
|
||||
AnalysisOperation,
|
||||
ExecutionOptions,
|
||||
} from "./AnalysisProvider.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { parseRelatedAddresses } from "../domain/hopperValues.js";
|
||||
@@ -11,6 +14,7 @@ type AnalysisCall = (
|
||||
name: AnalysisOperation,
|
||||
arguments_: Readonly<Record<string, JsonValue>>,
|
||||
signal?: AbortSignal,
|
||||
selectorOrigin?: ExecutionOptions["selectorOrigin"],
|
||||
) => Promise<Result<JsonValue, AnalysisError>>;
|
||||
|
||||
export interface CallPathTraceInput {
|
||||
@@ -114,7 +118,7 @@ const expandAddress = async (
|
||||
const relation = input.direction === "forward" ? "callees" : "callers";
|
||||
const tool =
|
||||
input.direction === "forward" ? "procedure_callees" : "procedure_callers";
|
||||
const result = await call(tool, { procedure: address }, signal);
|
||||
const result = await call(tool, { procedure: address }, signal, "provider");
|
||||
if (!result.ok) {
|
||||
state.failures.push({
|
||||
address,
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
createAnalysisExecution,
|
||||
type AnalysisOperation,
|
||||
type AnalysisOperationPort,
|
||||
} from "./AnalysisProvider.js";
|
||||
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { err, ok } from "../domain/result.js";
|
||||
import { EnhancedTools } from "./EnhancedTools.js";
|
||||
|
||||
const provider = { id: "fixture", name: "Fixture", version: "1" };
|
||||
|
||||
interface RecordedCall {
|
||||
readonly operation: AnalysisOperation;
|
||||
readonly procedure: unknown;
|
||||
readonly origin: unknown;
|
||||
}
|
||||
|
||||
/** Port that knows `main` (0x1000, calling 0x2000) and rejects `nosuch`. */
|
||||
const recordingPort = () => {
|
||||
const calls: RecordedCall[] = [];
|
||||
const sentParameters: Readonly<Record<string, JsonValue>>[] = [];
|
||||
const port: AnalysisOperationPort = {
|
||||
execute: async (operation, parameters, options) => {
|
||||
sentParameters.push(parameters);
|
||||
calls.push({
|
||||
operation,
|
||||
procedure: parameters.procedure,
|
||||
origin: options?.selectorOrigin,
|
||||
});
|
||||
const known = (value: JsonValue) =>
|
||||
ok(createAnalysisExecution(value, provider));
|
||||
if (parameters.procedure === "nosuch")
|
||||
return err(new AnalysisInputError(operation));
|
||||
switch (operation) {
|
||||
case "procedure_address":
|
||||
return known(parameters.procedure === "main" ? "0x1000" : "0x2000");
|
||||
case "procedure_callees":
|
||||
return known(parameters.procedure === "0x1000" ? ["0x2000"] : []);
|
||||
case "procedure_pseudo_code":
|
||||
return known("int main(void) { return 0; }");
|
||||
case "address_name":
|
||||
return known("main");
|
||||
default:
|
||||
throw new Error(`Unexpected operation: ${operation}`);
|
||||
}
|
||||
},
|
||||
};
|
||||
return { calls, sentParameters, tools: new EnhancedTools(port) };
|
||||
};
|
||||
|
||||
const of = (
|
||||
calls: readonly RecordedCall[],
|
||||
operation: AnalysisOperation,
|
||||
): RecordedCall[] => calls.filter((call) => call.operation === operation);
|
||||
|
||||
describe("selector origin of composed workflows", () => {
|
||||
it("marks every call-graph expansion as provider-derived and the root selector as caller-supplied", async () => {
|
||||
const { calls, tools } = recordingPort();
|
||||
|
||||
const result = await tools.execute("get_call_graph", { address: "main" });
|
||||
|
||||
expect(result.ok, "the graph is built").toBe(true);
|
||||
expect(
|
||||
of(calls, "procedure_address"),
|
||||
"the caller's selector carries no provider origin",
|
||||
).toEqual([
|
||||
{ operation: "procedure_address", procedure: "main", origin: undefined },
|
||||
]);
|
||||
expect(
|
||||
of(calls, "procedure_callees"),
|
||||
"the canonical start and every discovered callee are provider-derived",
|
||||
).toEqual([
|
||||
{
|
||||
operation: "procedure_callees",
|
||||
procedure: "0x1000",
|
||||
origin: "provider",
|
||||
},
|
||||
{
|
||||
operation: "procedure_callees",
|
||||
procedure: "0x2000",
|
||||
origin: "provider",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("marks trace expansions as provider-derived and the start and goal as caller-supplied", async () => {
|
||||
const { calls, tools } = recordingPort();
|
||||
|
||||
const result = await tools.execute("trace_call_path", {
|
||||
start: "main",
|
||||
goal: "0x2000",
|
||||
});
|
||||
|
||||
expect(result.ok, "the trace completes").toBe(true);
|
||||
expect(
|
||||
of(calls, "procedure_address").map(({ origin }) => origin),
|
||||
"start and goal resolutions are caller-supplied",
|
||||
).toEqual([undefined, undefined]);
|
||||
expect(
|
||||
of(calls, "procedure_callees").map(({ origin }) => origin),
|
||||
"expansion of the resolved start is provider-derived",
|
||||
).toEqual(["provider"]);
|
||||
});
|
||||
|
||||
it("marks the canonical retry of batch_decompile as derived and keeps the unresolved fallback caller-supplied", async () => {
|
||||
const { calls, tools } = recordingPort();
|
||||
|
||||
const result = await tools.execute("batch_decompile", {
|
||||
addresses: ["main", "nosuch"],
|
||||
});
|
||||
|
||||
expect(result.ok, "per-item failures do not fail the batch").toBe(true);
|
||||
expect(
|
||||
of(calls, "procedure_pseudo_code")
|
||||
.map(({ procedure, origin }) => [procedure, origin])
|
||||
.sort(([left], [right]) => String(left).localeCompare(String(right))),
|
||||
"the resolved canonical address is derived; the failed item keeps the caller's text",
|
||||
).toEqual([
|
||||
["0x1000", "provider"],
|
||||
["nosuch", undefined],
|
||||
]);
|
||||
});
|
||||
|
||||
it("never copies the origin into the parameters sent to the provider", async () => {
|
||||
const { sentParameters, tools } = recordingPort();
|
||||
|
||||
await tools.execute("get_call_graph", { address: "main" });
|
||||
await tools.execute("trace_call_path", { start: "main" });
|
||||
await tools.execute("batch_decompile", { addresses: ["main"] });
|
||||
|
||||
expect(
|
||||
sentParameters.length,
|
||||
"workflows issued provider calls",
|
||||
).toBeGreaterThan(0);
|
||||
expect(
|
||||
sentParameters.some((parameters) => "selectorOrigin" in parameters),
|
||||
"the origin travels in the options only, never in Evidence-bound parameters",
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -3,6 +3,7 @@ import { z } from "zod";
|
||||
import type {
|
||||
AnalysisOperation,
|
||||
AnalysisOperationPort,
|
||||
ExecutionOptions,
|
||||
} from "./AnalysisProvider.js";
|
||||
import type { EnhancedToolName } from "../contracts/enhancedInputs.js";
|
||||
import { enhancedInputSchemas } from "../contracts/enhancedInputs.js";
|
||||
@@ -163,8 +164,8 @@ export class EnhancedTools {
|
||||
);
|
||||
case "trace_call_path":
|
||||
return traceCallPath(
|
||||
(name, arguments_, operationSignal) =>
|
||||
this.#call(name, arguments_, operationSignal),
|
||||
(name, arguments_, operationSignal, selectorOrigin) =>
|
||||
this.#call(name, arguments_, operationSignal, selectorOrigin),
|
||||
call.input,
|
||||
signal,
|
||||
);
|
||||
@@ -267,6 +268,7 @@ export class EnhancedTools {
|
||||
"procedure_pseudo_code",
|
||||
{ procedure: resolved.ok ? resolved.value : address },
|
||||
signal,
|
||||
resolved.ok ? "provider" : undefined,
|
||||
);
|
||||
if (!result.ok)
|
||||
return {
|
||||
@@ -361,6 +363,7 @@ export class EnhancedTools {
|
||||
tool,
|
||||
{ procedure: current.address },
|
||||
signal,
|
||||
"provider",
|
||||
);
|
||||
if (!result.ok) {
|
||||
graph[level].push({
|
||||
@@ -518,13 +521,13 @@ export class EnhancedTools {
|
||||
name: AnalysisOperation,
|
||||
arguments_: Readonly<Record<string, JsonValue>>,
|
||||
signal?: AbortSignal,
|
||||
selectorOrigin?: ExecutionOptions["selectorOrigin"],
|
||||
): Promise<Result<JsonValue, AnalysisError>> {
|
||||
if (isAborted(signal)) return err(new AnalysisCancelledError(name));
|
||||
const execution = await this.analysis.execute(
|
||||
name,
|
||||
arguments_,
|
||||
signal === undefined ? {} : { signal },
|
||||
);
|
||||
const execution = await this.analysis.execute(name, arguments_, {
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
...(selectorOrigin === undefined ? {} : { selectorOrigin }),
|
||||
});
|
||||
if (isAborted(signal)) return err(new AnalysisCancelledError(name));
|
||||
return execution.ok ? ok(execution.value.result) : execution;
|
||||
}
|
||||
|
||||
@@ -497,7 +497,7 @@ export class BinarySession
|
||||
execute(
|
||||
name: Parameters<AnalysisOperationPort["execute"]>[0],
|
||||
arguments_: Readonly<Record<string, JsonValue>>,
|
||||
options?: { readonly signal?: AbortSignal },
|
||||
options?: Pick<ExecutionOptions, "signal" | "selectorOrigin">,
|
||||
): Promise<Result<AnalysisExecution, AnalysisError>> {
|
||||
const generation = this.#transitionGeneration;
|
||||
const call = this.#execute(name, arguments_, options, this.#transition);
|
||||
@@ -535,7 +535,7 @@ export class BinarySession
|
||||
async #execute(
|
||||
name: Parameters<AnalysisOperationPort["execute"]>[0],
|
||||
arguments_: Readonly<Record<string, JsonValue>>,
|
||||
options: { readonly signal?: AbortSignal } | undefined,
|
||||
options: Pick<ExecutionOptions, "signal" | "selectorOrigin"> | undefined,
|
||||
transition: Promise<void>,
|
||||
): Promise<Result<AnalysisExecution, AnalysisError>> {
|
||||
const transitioned = await this.#waitForTransition(
|
||||
|
||||
@@ -246,6 +246,40 @@ describe("native UI action trace", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("native UI action selector origin", () => {
|
||||
it("marks provider-reported function addresses as derived and the action seed as caller-supplied", async () => {
|
||||
const inner = testAnalysis({
|
||||
procedure_address: () => execution("procedure_address", "0x1000"),
|
||||
});
|
||||
const recorded: { operation: string; origin: unknown }[] = [];
|
||||
|
||||
const result = await new EnhancedTools({
|
||||
execute: async (operation, parameters, options) => {
|
||||
recorded.push({ operation, origin: options?.selectorOrigin });
|
||||
return inner.execute(operation, parameters);
|
||||
},
|
||||
}).execute("trace_native_ui_action", { action: "0x1000" });
|
||||
|
||||
expect(result.ok, "the trace completes").toBe(true);
|
||||
expect(
|
||||
recorded
|
||||
.filter(({ operation }) => operation === "procedure_address")
|
||||
.map(({ origin }) => origin),
|
||||
"the caller's action seed carries no provider origin",
|
||||
).toEqual([undefined]);
|
||||
const probes = recorded.filter(
|
||||
({ operation }) =>
|
||||
operation === "procedure_references" ||
|
||||
operation === "procedure_callees",
|
||||
);
|
||||
expect(probes.length, "relationships were probed").toBeGreaterThan(0);
|
||||
expect(
|
||||
probes.every(({ origin }) => origin === "provider"),
|
||||
"every relationship probe uses a provider-reported address",
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("bounded native UI tracing", () => {
|
||||
it("continues handler traversal from its own depth when another UI branch is deeper", async () => {
|
||||
const deepGraph = {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { z } from "zod";
|
||||
import type { AnalysisOperationPort } from "../AnalysisProvider.js";
|
||||
import type {
|
||||
AnalysisOperationPort,
|
||||
ExecutionOptions,
|
||||
} from "../AnalysisProvider.js";
|
||||
import {
|
||||
parseRelatedAddresses,
|
||||
referenceKindSchema,
|
||||
@@ -26,8 +29,12 @@ export const readNativeCallRoutes = async (
|
||||
analysis: AnalysisOperationPort,
|
||||
procedure: string,
|
||||
signal?: AbortSignal,
|
||||
selectorOrigin?: ExecutionOptions["selectorOrigin"],
|
||||
) => {
|
||||
const options = signal === undefined ? {} : { signal };
|
||||
const options = {
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
...(selectorOrigin === undefined ? {} : { selectorOrigin }),
|
||||
};
|
||||
const execution = await analysis.execute(
|
||||
"procedure_references",
|
||||
{ procedure, direction: "outgoing" },
|
||||
|
||||
@@ -411,6 +411,7 @@ const addDirectCallees = async (input: {
|
||||
input.analysis,
|
||||
current.address,
|
||||
input.signal,
|
||||
"provider",
|
||||
);
|
||||
examined += 1;
|
||||
if (!execution.ok) {
|
||||
|
||||
@@ -529,3 +529,32 @@ describe("bounded native value dependency composition", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("native value trace selector origin", () => {
|
||||
it("marks only the initial procedure as caller-supplied", async () => {
|
||||
const analyzed: { procedure: unknown; origin: unknown }[] = [];
|
||||
|
||||
const result = await traceNativeValues(
|
||||
{
|
||||
execute: async (operation, parameters, options) => {
|
||||
if (operation === "analyze_function")
|
||||
analyzed.push({
|
||||
procedure: parameters.procedure,
|
||||
origin: options?.selectorOrigin,
|
||||
});
|
||||
return analysis.execute(operation, parameters, options);
|
||||
},
|
||||
},
|
||||
{ procedure: "0x1000" },
|
||||
);
|
||||
|
||||
expect(result.ok, "the trace completes").toBe(true);
|
||||
expect(
|
||||
analyzed,
|
||||
"the caller's procedure is unmarked and the discovered callee is provider-derived",
|
||||
).toEqual([
|
||||
{ procedure: "0x1000", origin: undefined },
|
||||
{ procedure: "0x2000", origin: "provider" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,7 +57,10 @@ export const traceNativeValues = async (
|
||||
const execution = await analysis.execute(
|
||||
"analyze_function",
|
||||
{ procedure: next.procedure },
|
||||
signal === undefined ? {} : { signal },
|
||||
{
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
...(next.depth > 0 ? { selectorOrigin: "provider" as const } : {}),
|
||||
},
|
||||
);
|
||||
decompilations++;
|
||||
if (!execution.ok) {
|
||||
|
||||
Reference in New Issue
Block a user