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(comparison): keep unnamed reference endpoints distinct or unknown (#3809)
Kaoru0822847b7328cf73
diff --git a/src/domain/functionComparison.test.ts b/src/domain/functionComparison.test.tsindex a8f645838..adcceaa52 100644--- a/src/domain/functionComparison.test.ts+++ b/src/domain/functionComparison.test.ts@@ -599,11 +599,20 @@ describe("function comparison ordering controls", () => {makeEvidence("e", rightWithoutNativeApi),);- expect(comparison.status).toBe("unchanged");- for (const dimension of ["calls", "references", "strings_names"] as const)+ for (const dimension of ["calls", "strings_names"] as const)expect(comparison.dimensions.find((item) => item.dimension === dimension),).toMatchObject({ status: "unchanged" });+ // Unnamed endpoints in different artifacts have no stable identity.+ expect(+ comparison.dimensions.find((item) => item.dimension === "references"),+ ).toMatchObject({+ status: "unknown",+ limitations: expect.arrayContaining([+ expect.stringContaining("Unnamed reference endpoints"),+ ]),+ });+ expect(comparison.status).toBe("unknown");});});@@ -1274,3 +1283,48 @@ it.each([}},);++describe("function comparison unnamed reference endpoints", () => {+ it("distinguishes unnamed reference targets by address within one artifact", () => {+ const unnamedTarget = (target: string) =>+ functionDossierSchema.parse({+ ...dossierWithReference("0x1000", "call"),+ outgoing_references: [+ {+ ...dossierWithReference("0x1000", "call").outgoing_references[0],+ target_address: target,+ target_procedure: null,+ },+ ],+ });+ const reference = (left: string, right: string, digits = ["a", "a"]) =>+ compareFunctions(+ observe(digits[0] ?? "a", unnamedTarget(left)),+ observe(digits[1] ?? "a", unnamedTarget(right)),+ ).dimensions.find(({ dimension }) => dimension === "references");+ expect(reference("0x1010", "0x1020")).toMatchObject({ status: "changed" });+ expect(reference("0x1010", "0x1010")).toMatchObject({+ status: "unchanged",+ });+ // Across artifacts the same address does not identify the same target.+ expect(reference("0x1010", "0x1010", ["a", "b"])).toMatchObject({+ status: "unknown",+ });+ });++ it("keeps known reference-kind changes beside unnamed endpoints", () => {+ const unnamed = (kind: "call" | "data") => {+ const edge = dossierWithReference("0x1000", kind).outgoing_references[0];+ return functionDossierSchema.parse({+ ...dossierWithReference("0x1000", kind),+ outgoing_references: [{ ...edge, target_procedure: null }],+ });+ };+ expect(+ compareFunctions(+ observe("a", unnamed("call")),+ observe("b", unnamed("data")),+ ).dimensions.find(({ dimension }) => dimension === "references"),+ ).toMatchObject({ status: "changed" });+ });+});diff --git a/src/domain/functionComparisonDimensions.ts b/src/domain/functionComparisonDimensions.tsindex f935e228b..0f9eb91bd 100644--- a/src/domain/functionComparisonDimensions.ts+++ b/src/domain/functionComparisonDimensions.ts@@ -253,13 +253,23 @@ const swiftLiteralCoverage = (? "absent": "complete";+const hasUnnamedEndpoint = (snapshot: FunctionSnapshot): boolean =>+ [+ ...snapshot.dossier.incoming_references,+ ...snapshot.dossier.outgoing_references,+ ].some(+ (edge) => edge.source_procedure === null || edge.target_procedure === null,+ );+const compareReferences = (left: FunctionSnapshot,right: FunctionSnapshot,context: ComparisonContext,): FunctionDimension => {- const leftProjection = referenceProjection(left);- const rightProjection = referenceProjection(right);+ const sameArtifact =+ left.subject.digest.sha256 === right.subject.digest.sha256;+ const leftProjection = referenceProjection(left, sameArtifact);+ const rightProjection = referenceProjection(right, sameArtifact);if (leftProjection.length === 0 && rightProjection.length === 0)return compareValues("references",@@ -284,9 +294,28 @@ const compareReferences = ("Reference endpoints differ independently of provider reference-kind metadata.",],});- const leftKinds = referenceKindProjection(left);- const rightKinds = referenceKindProjection(right);- if (leftKinds !== null && rightKinds !== null)+ const leftKinds = referenceKindProjection(left, sameArtifact);+ const rightKinds = referenceKindProjection(right, sameArtifact);+ const kindsKnown = leftKinds !== null && rightKinds !== null;+ // Differing known edge kinds are a change whatever the endpoint identity.+ if (+ kindsKnown &&+ canonicalJson(leftKinds, "Function comparison") !==+ canonicalJson(rightKinds, "Function comparison")+ )+ return compareValues("references", leftKinds, rightKinds, context);+ // Equal projections with unknown endpoints do not establish equal targets.+ if (!sameArtifact && (hasUnnamedEndpoint(left) || hasUnnamedEndpoint(right)))+ return unresolvedDimension({+ dimension: "references",+ links: context.links,+ leftCount: leftProjection.length,+ rightCount: rightProjection.length,+ limitations: [+ "Unnamed reference endpoints have no stable identity across different artifacts, so equal named endpoints do not establish equal references.",+ ],+ });+ if (kindsKnown)return compareValues("references", leftKinds, rightKinds, context);return unresolvedDimension({dimension: "references",diff --git a/src/domain/functionComparisonNormalization.ts b/src/domain/functionComparisonNormalization.tsindex f32220b0b..85b7d0e44 100644--- a/src/domain/functionComparisonNormalization.ts+++ b/src/domain/functionComparisonNormalization.ts@@ -72,22 +72,52 @@ export const normalizeCfg = (return graph;};-export const referenceProjection = (snapshot: FunctionSnapshot) =>- sorted([- ...snapshot.dossier.incoming_references.map((item) => ({- direction: "in",- source: item.source_procedure?.name ?? null,- target: item.target_procedure?.name ?? null,- })),- ...snapshot.dossier.outgoing_references.map((item) => ({- direction: "out",- source: item.source_procedure?.name ?? null,- target: item.target_procedure?.name ?? null,+type ReferenceEdge = FunctionSnapshot["dossier"]["outgoing_references"][number];++/**+ * A named endpoint survives relocation. An unnamed endpoint is identified+ * only by its address, which names one location only within one artifact;+ * across artifacts it stays unknown (null).+ */+const referenceEndpoint = (+ procedure: ReferenceEdge["source_procedure"],+ address: string,+ sameArtifact: boolean,+): string | { readonly address: string } | null =>+ procedure !== null ? procedure.name : sameArtifact ? { address } : null;++export const referenceProjection = (+ snapshot: FunctionSnapshot,+ sameArtifact: boolean,+) =>+ sorted(+ [+ ...snapshot.dossier.incoming_references.map((item) => ({+ direction: "in",+ item,+ })),+ ...snapshot.dossier.outgoing_references.map((item) => ({+ direction: "out",+ item,+ })),+ ].map(({ direction, item }) => ({+ direction,+ source: referenceEndpoint(+ item.source_procedure,+ item.source_address,+ sameArtifact,+ ),+ target: referenceEndpoint(+ item.target_procedure,+ item.target_address,+ sameArtifact,+ ),})),- ]);+ );export const referenceKindProjection = (snapshot: FunctionSnapshot,+ sameArtifact: boolean,): readonly unknown[] | null => {const edges = [...snapshot.dossier.incoming_references.map((edge) => ({@@ -108,8 +138,16 @@ export const referenceKindProjection = ();return {direction,- source: edge.source_procedure?.name ?? null,- target: edge.target_procedure?.name ?? null,+ source: referenceEndpoint(+ edge.source_procedure,+ edge.source_address,+ sameArtifact,+ ),+ target: referenceEndpoint(+ edge.target_procedure,+ edge.target_address,+ sameArtifact,+ ),type: edge.kind.type,flow: edge.kind.flow,call: edge.kind.call,