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,4 +1,5 @@
|
||||
import type {
|
||||
AnalysisExecution,
|
||||
AnalysisOperation,
|
||||
ExecutionOptions,
|
||||
} from "./AnalysisProvider.js";
|
||||
@@ -17,6 +18,13 @@ type AnalysisCall = (
|
||||
selectorOrigin?: ExecutionOptions["selectorOrigin"],
|
||||
) => Promise<Result<JsonValue, AnalysisError>>;
|
||||
|
||||
type RelationshipCall = (
|
||||
name: AnalysisOperation,
|
||||
arguments_: Readonly<Record<string, JsonValue>>,
|
||||
signal?: AbortSignal,
|
||||
selectorOrigin?: ExecutionOptions["selectorOrigin"],
|
||||
) => Promise<Result<AnalysisExecution, AnalysisError>>;
|
||||
|
||||
export interface CallPathTraceInput {
|
||||
readonly start: string;
|
||||
readonly goal?: string | undefined;
|
||||
@@ -42,6 +50,7 @@ interface TraceState {
|
||||
readonly error: ReturnType<typeof projectAnalysisError>;
|
||||
}>;
|
||||
readonly residual: Set<string>;
|
||||
readonly limitations: Set<string>;
|
||||
queueIndex: number;
|
||||
traversalPath: string[];
|
||||
}
|
||||
@@ -63,6 +72,7 @@ interface DiscoveredEdge {
|
||||
/** Trace direct caller/callee relationships until the graph is exhausted or the goal is reached. */
|
||||
export const traceCallPath = async (
|
||||
call: AnalysisCall,
|
||||
callRelationship: RelationshipCall,
|
||||
input: CallPathTraceInput,
|
||||
signal?: AbortSignal,
|
||||
): EnhancedResult => {
|
||||
@@ -88,7 +98,7 @@ export const traceCallPath = async (
|
||||
if (address === undefined) break;
|
||||
const current = state.visited.get(address);
|
||||
if (current === undefined) continue;
|
||||
const found = await expandAddress(call, {
|
||||
const found = await expandAddress(callRelationship, {
|
||||
input: resolvedInput,
|
||||
state,
|
||||
address,
|
||||
@@ -106,12 +116,13 @@ const createTraceState = (input: CallPathTraceInput): TraceState => ({
|
||||
edges: new Map(),
|
||||
failures: [],
|
||||
residual: new Set(),
|
||||
limitations: new Set(),
|
||||
queueIndex: 0,
|
||||
traversalPath: input.goal === input.start ? [input.start] : [],
|
||||
});
|
||||
|
||||
const expandAddress = async (
|
||||
call: AnalysisCall,
|
||||
call: RelationshipCall,
|
||||
expansion: AddressExpansion,
|
||||
): Promise<boolean> => {
|
||||
const { input, state, address, current, signal } = expansion;
|
||||
@@ -127,7 +138,7 @@ const expandAddress = async (
|
||||
state.residual.add(`Call relationships were unavailable for ${address}.`);
|
||||
return false;
|
||||
}
|
||||
const related = parseRelatedAddresses(result.value, relation);
|
||||
const related = parseRelatedAddresses(result.value.result, relation);
|
||||
if (!related.ok) {
|
||||
state.failures.push({
|
||||
address,
|
||||
@@ -136,6 +147,12 @@ const expandAddress = async (
|
||||
state.residual.add(`Call relationships were unreadable for ${address}.`);
|
||||
return false;
|
||||
}
|
||||
for (const limitation of result.value.limitations) {
|
||||
state.limitations.add(limitation);
|
||||
state.residual.add(
|
||||
`Call relationships for ${address} are limited: ${limitation}`,
|
||||
);
|
||||
}
|
||||
for (const relatedAddress of sortedUniqueAddresses(related.value)) {
|
||||
recordEdge(input, state, {
|
||||
address,
|
||||
@@ -215,6 +232,7 @@ const projectTrace = (input: CallPathTraceInput, state: TraceState) => ({
|
||||
residual_unknowns: [...state.residual],
|
||||
limitations: [
|
||||
"Direct provider call relationships may omit unresolved indirect calls.",
|
||||
...state.limitations,
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import type {
|
||||
AnalysisExecution,
|
||||
AnalysisOperation,
|
||||
AnalysisOperationPort,
|
||||
ExecutionOptions,
|
||||
@@ -166,6 +167,8 @@ export class EnhancedTools {
|
||||
return traceCallPath(
|
||||
(name, arguments_, operationSignal, selectorOrigin) =>
|
||||
this.#call(name, arguments_, operationSignal, selectorOrigin),
|
||||
(name, arguments_, operationSignal, selectorOrigin) =>
|
||||
this.#observe(name, arguments_, operationSignal, selectorOrigin),
|
||||
call.input,
|
||||
signal,
|
||||
);
|
||||
@@ -359,7 +362,7 @@ export class EnhancedTools {
|
||||
const level = String(current.depth);
|
||||
graph[level] ??= [];
|
||||
|
||||
const result = await this.#call(
|
||||
const result = await this.#observe(
|
||||
tool,
|
||||
{ procedure: current.address },
|
||||
signal,
|
||||
@@ -373,7 +376,7 @@ export class EnhancedTools {
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const related = parseRelatedAddresses(result.value, relation);
|
||||
const related = parseRelatedAddresses(result.value.result, relation);
|
||||
if (!related.ok) {
|
||||
graph[level].push({
|
||||
address: current.address,
|
||||
@@ -386,6 +389,9 @@ export class EnhancedTools {
|
||||
address: current.address,
|
||||
status: "ok",
|
||||
calls: [...related.value],
|
||||
...(result.value.limitations.length === 0
|
||||
? {}
|
||||
: { limitations: [...result.value.limitations] }),
|
||||
});
|
||||
for (const address of related.value) {
|
||||
if (!discovered.has(address)) {
|
||||
@@ -523,13 +529,28 @@ export class EnhancedTools {
|
||||
signal?: AbortSignal,
|
||||
selectorOrigin?: ExecutionOptions["selectorOrigin"],
|
||||
): Promise<Result<JsonValue, AnalysisError>> {
|
||||
const execution = await this.#observe(
|
||||
name,
|
||||
arguments_,
|
||||
signal,
|
||||
selectorOrigin,
|
||||
);
|
||||
return execution.ok ? ok(execution.value.result) : execution;
|
||||
}
|
||||
|
||||
async #observe(
|
||||
name: AnalysisOperation,
|
||||
arguments_: Readonly<Record<string, JsonValue>>,
|
||||
signal?: AbortSignal,
|
||||
selectorOrigin?: ExecutionOptions["selectorOrigin"],
|
||||
): Promise<Result<AnalysisExecution, AnalysisError>> {
|
||||
if (isAborted(signal)) return err(new AnalysisCancelledError(name));
|
||||
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;
|
||||
return execution;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user