Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(native): preserve unresolved calls in untyped route fallback (#2757)
Iven Koo48b90fbaa497
diff --git a/src/application/native/EnhancedNativeInvestigation.test.ts b/src/application/native/EnhancedNativeInvestigation.test.tsindex 087b5981f..e81dcb8b1 100644--- a/src/application/native/EnhancedNativeInvestigation.test.ts+++ b/src/application/native/EnhancedNativeInvestigation.test.ts@@ -199,6 +199,49 @@ const testAnalysis = (});describe("native UI action trace", () => {+ it("retains Hopper targetless call evidence alongside fallback callee routes", async () => {+ const result = await new EnhancedTools(+ testAnalysis({+ procedure_address: () => execution("procedure_address", "0x1000"),+ procedure_references: (parameters) =>+ ok(+ createAnalysisExecution(+ {+ reference_kinds_available: false,+ references: [],+ unresolved_calls:+ parameters.procedure === "0x1000"+ ? [{ address: "0x1008", reason: "No static target" }]+ : [],+ },+ { id: "hopper", name: "Hopper", version: "fixture" },+ ),+ ),+ }),+ ).execute("trace_native_ui_action", { action: "0x1000" });+ if (!result.ok) throw result.error;+ const trace = nativeInvestigationTraceSchema.parse(result.value);+ expect(trace.edges).toContainEqual(+ expect.objectContaining({+ relation: "provider_call",+ to: "native:function:0x2000",+ }),+ );+ expect(trace.unresolved).toContainEqual(+ expect.objectContaining({+ from: "native:function:0x1000",+ to: null,+ reason: "No static target",+ evidence: [+ expect.objectContaining({+ description: "Hopper reported an unresolved call: No static target",+ location: { address: "0x1008", file_offset: null },+ artifact_sha256: target,+ }),+ ],+ }),+ );+ });it("accepts an explicit native seed without an authored UI connection", async () => {const result = await new EnhancedTools(testAnalysis({diff --git a/src/application/native/NativeCallRoutes.test.ts b/src/application/native/NativeCallRoutes.test.tsindex e54a55dc5..135807c3e 100644--- a/src/application/native/NativeCallRoutes.test.ts+++ b/src/application/native/NativeCallRoutes.test.ts@@ -7,6 +7,59 @@ import { err, ok } from "../../domain/result.js";import { AnalysisCancelledError } from "../../domain/analysisErrorCore.js";const provider = { id: "fixture", name: "Fixture", version: "1" };+describe("untyped native call route fallback", () => {+ it.each([{ callees: [] }, { callees: ["0x2000"] }])(+ "preserves targetless calls and their provider when fallback callees are $callees",+ async ({ callees }) => {+ const calls: string[] = [];+ const referenceProvider = { ...provider, id: "hopper", name: "Hopper" };+ const fallbackProvider = { ...provider, id: "fallback" };+ const signal = new AbortController().signal;+ const unknown = { address: "0x1008", reason: "No static target" };+ const result = await readNativeCallRoutes(+ {+ execute: async (operation, parameters, options) => {+ calls.push(operation);+ expect(parameters.procedure).toBe("0x1000");+ expect(options).toEqual({ signal, selectorOrigin: "provider" });+ return ok(+ createAnalysisExecution(+ operation === "procedure_references"+ ? {+ reference_kinds_available: false,+ references: [],+ unresolved_calls: [unknown],+ }+ : callees,+ operation === "procedure_references"+ ? referenceProvider+ : fallbackProvider,+ ),+ );+ },+ },+ "0x1000",+ signal,+ "provider",+ );+ expect(calls).toEqual(["procedure_references", "procedure_callees"]);+ expect(result).toEqual({+ ok: true,+ value: {+ provider: fallbackProvider,+ routes: callees.map((address) => ({+ address,+ site: "0x1000",+ relation: "provider_call",+ resolution: "inferred",+ })),+ unknowns: [{ ...unknown, provider: referenceProvider }],+ },+ });+ },+ );+});+describe("typed native call routes", () => {it("preserves computed targets, ambiguity and targetless call sites", async () => {const reference = jsonValueSchema.parse(ghidraReferenceEdge());diff --git a/src/application/native/NativeCallRoutes.ts b/src/application/native/NativeCallRoutes.tsindex fe77f61e9..9848ab86d 100644--- a/src/application/native/NativeCallRoutes.ts+++ b/src/application/native/NativeCallRoutes.ts@@ -2,12 +2,12 @@ import { z } from "zod";import type {AnalysisOperationPort,ExecutionOptions,+ ProviderIdentity,} from "../AnalysisProvider.js";import {parseRelatedAddresses,referenceKindSchema,} from "../../domain/hopperValues.js";-import { err, ok } from "../../domain/result.js";import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";const referencesSchema = z.object({@@ -40,15 +40,29 @@ export const readNativeCallRoutes = async ({ procedure, direction: "outgoing" },options,);+ let unknowns: Array<{+ address: string;+ reason: string;+ provider: ProviderIdentity;+ }> = [];if (execution.ok) {const parsed = referencesSchema.safeParse(execution.value.result);if (!parsed.success)- return err(- new AnalysisOutputError(+ return {+ ok: false as const,+ error: new AnalysisOutputError("procedure_references","Invalid typed call references",),- );+ unknowns,+ };+ // Missing detailed reference flags do not invalidate observed targetless+ // calls. Keep their producing provider even if another provider supplies+ // the fallback callee inventory.+ unknowns = parsed.data.unresolved_calls.map((call) => ({+ ...call,+ provider: execution.value.provider,+ }));const references = parsed.data.references;if (parsed.data.reference_kinds_available === true ||@@ -64,45 +78,52 @@ export const readNativeCallRoutes = async (targets.add(call.target_address);countBySite.set(call.source_address, targets);}- return ok({- provider: execution.value.provider,- routes: calls.map((call) => ({- address: call.target_procedure?.address ?? call.target_address,- site: call.source_address,- relation:- call.kind.available && (call.kind.computed || call.kind.indirect)- ? ("indirect_call" as const)- : ("direct_call" as const),- resolution:- (countBySite.get(call.source_address)?.size ?? 0) > 1- ? ("ambiguous" as const)- : call.kind.available &&- (call.kind.computed || call.kind.indirect)- ? ("resolved" as const)- : ("observed" as const),- })),- unknowns: parsed.data.unresolved_calls,- });+ return {+ ok: true as const,+ value: {+ provider: execution.value.provider,+ routes: calls.map((call) => ({+ address: call.target_procedure?.address ?? call.target_address,+ site: call.source_address,+ relation:+ call.kind.available && (call.kind.computed || call.kind.indirect)+ ? ("indirect_call" as const)+ : ("direct_call" as const),+ resolution:+ (countBySite.get(call.source_address)?.size ?? 0) > 1+ ? ("ambiguous" as const)+ : call.kind.available &&+ (call.kind.computed || call.kind.indirect)+ ? ("resolved" as const)+ : ("observed" as const),+ })),+ unknowns,+ },+ };}} else if (execution.error._tag !== "AnalysisCapabilityUnavailableError")- return err(execution.error);+ return { ok: false as const, error: execution.error, unknowns };const callees = await analysis.execute("procedure_callees",{ procedure },options,);- if (!callees.ok) return callees;+ if (!callees.ok)+ return { ok: false as const, error: callees.error, unknowns };const parsed = parseRelatedAddresses(callees.value.result, "callees");return parsed.ok- ? ok({- provider: callees.value.provider,- routes: parsed.value.map((address) => ({- address,- site: procedure,- relation: "provider_call" as const,- resolution: "inferred" as const,- })),- unknowns: [],- })- : parsed;+ ? {+ ok: true as const,+ value: {+ provider: callees.value.provider,+ routes: parsed.value.map((address) => ({+ address,+ site: procedure,+ relation: "provider_call" as const,+ resolution: "inferred" as const,+ })),+ unknowns,+ },+ }+ : { ok: false as const, error: parsed.error, unknowns };};diff --git a/src/application/native/NativeUiActionTrace.ts b/src/application/native/NativeUiActionTrace.tsindex 141b31bc0..8a6affdf7 100644--- a/src/application/native/NativeUiActionTrace.ts+++ b/src/application/native/NativeUiActionTrace.ts@@ -414,28 +414,15 @@ const addDirectCallees = async (input: {"provider",);examined += 1;- if (!execution.ok) {- if (execution.error._tag === "AnalysisCancelledError")- return { error: execution.error };- const id = `unknown-callees:${current.address}`;- edges.set(id, {- id,- from: current.node.id,- to: null,- relation: "direct_call",- resolution: "unresolved",- reason: projectAnalysisError(execution.error).message,- evidence: [],- limitations: [- "The provider could not enumerate resolved direct callees.",- ],- });- continue;- }- for (const unknown of execution.value.unknowns) {+ if (!execution.ok && execution.error._tag === "AnalysisCancelledError")+ return { error: execution.error };+ const unknowns = execution.ok+ ? execution.value.unknowns+ : execution.unknowns;+ for (const [index, unknown] of unknowns.entries()) {if (edges.size >= input.input.max_edges) {truncated = true;- omitted++;+ omitted += unknowns.length - index;break;}const id = `unknown-dispatch:${current.address}:${unknown.address}`;@@ -449,7 +436,8 @@ const addDirectCallees = async (input: {evidence: [{kind: "reference",- description: unknown.reason,+ provider: unknown.provider,+ description: `${unknown.provider.name} reported an unresolved call: ${unknown.reason}`,location: { address: unknown.address, file_offset: null },artifact_path: null,artifact_sha256: input.targetSha256,@@ -458,6 +446,27 @@ const addDirectCallees = async (input: {limitations: [],});}+ if (!execution.ok) {+ if (edges.size >= input.input.max_edges) {+ truncated = true;+ omitted += 1;+ continue;+ }+ const id = `unknown-callees:${current.address}`;+ edges.set(id, {+ id,+ from: current.node.id,+ to: null,+ relation: "direct_call",+ resolution: "unresolved",+ reason: projectAnalysisError(execution.error).message,+ evidence: [],+ limitations: [+ "The provider could not enumerate resolved direct callees.",+ ],+ });+ continue;+ }for (const [index, route] of execution.value.routes.entries()) {const address = route.address;if (edges.size >= input.input.max_edges) {@@ -469,6 +478,7 @@ const addDirectCallees = async (input: {const evidence = [{kind: "reference" as const,+ provider: execution.value.provider,description: `${execution.value.provider.name} reported ${route.relation} from ${current.address} to ${address}`,location: { address: route.site, file_offset: null },artifact_path: null,diff --git a/src/domain/native/objcSwiftMetadata.ts b/src/domain/native/objcSwiftMetadata.tsindex 5778e5dd7..a360c3202 100644--- a/src/domain/native/objcSwiftMetadata.ts+++ b/src/domain/native/objcSwiftMetadata.ts@@ -1,4 +1,5 @@import { z } from "zod";+import { providerSchema } from "../evidence.js";import {compareUnicodeCodePoints,@@ -115,6 +116,7 @@ export const nativeMetadataEvidenceSchema = z.strictObject({"decompiler",]),description: z.string().min(1),+ provider: providerSchema.optional(),location: nativeMetadataLocationSchema,artifact_path: z.string().min(1).nullable().default(null),artifact_sha256: z