From 5f3ba3e6886b6b3186711e025da14875dc3c9684 Mon Sep 17 00:00:00 2001 From: Rudy Mizrahi Celekli <47457359+rudycelekli@users.noreply.github.com> Date: Mon, 5 Oct 2026 13:57:20 -0400 Subject: [PATCH] fix(comparison): match generated names without swallowing symbol prefixes (#596) * fix(comparison): match generated names without swallowing symbol prefixes Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> * test(comparison): cover symbol identity and callee dimensions Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> --------- Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> Co-authored-by: morluto --- node_modules | 1 + src/domain/functionComparison.test.ts | 70 +++++++++++++++++++ src/domain/functionComparisonNormalization.ts | 2 +- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 120000 node_modules diff --git a/node_modules b/node_modules new file mode 120000 index 000000000..5f738a710 --- /dev/null +++ b/node_modules @@ -0,0 +1 @@ +/Users/will/dev/active/rea/node_modules \ No newline at end of file diff --git a/src/domain/functionComparison.test.ts b/src/domain/functionComparison.test.ts index 6b6f78a50..0bd081d97 100644 --- a/src/domain/functionComparison.test.ts +++ b/src/domain/functionComparison.test.ts @@ -102,6 +102,76 @@ const observe = ( }, ); +describe("function comparison normalized identity", () => { + it.each(["sub_deallocate", "sub_deadbeef_handler", "fcn.dispatch"])( + "recognizes the explicit symbol %s without a generated-name prefix false positive", + (name) => { + const named = (base: "0x1000" | "0x2000") => + functionDossierSchema.parse({ + ...dossier("return 0;", base), + procedure: { + address: base, + name, + signature: "int helper(void)", + locals: [], + }, + }); + const result = compareFunctions( + observe("b", named("0x1000")), + observe("c", named("0x2000")), + ); + expect(result.function_match).toMatchObject({ + status: "matched", + method: "symbol", + }); + expect( + result.dimensions.find(({ dimension }) => dimension === "identity"), + ).toMatchObject({ status: "unchanged" }); + }, + ); + + it.each(["sub_deadbeef", "fcn.00401000"])( + "keeps %s as an address-derived name", + (name) => { + const generated = (base: "0x1000" | "0x2000") => + functionDossierSchema.parse({ + ...dossier("return 0;", base), + procedure: { + address: base, + name, + signature: "int helper(void)", + locals: [], + }, + }); + const result = compareFunctions( + observe("d", generated("0x1000")), + observe("e", generated("0x2000")), + ); + expect(result.function_match.status).toBe("ambiguous"); + expect( + result.dimensions.find(({ dimension }) => dimension === "identity"), + ).toMatchObject({ status: "unknown" }); + }, + ); + it.each([ + { name: "sub_deallocate", status: "unchanged" }, + { name: "sub_deadbeef", status: "unknown" }, + ])("preserves the calls dimension for callee $name", ({ name, status }) => { + const calling = (base: "0x1000" | "0x2000") => + functionDossierSchema.parse({ + ...dossier("return helper();", base), + callees: [{ address: base === "0x1000" ? "0x1010" : "0x2010", name }], + }); + const result = compareFunctions( + observe("6", calling("0x1000")), + observe("7", calling("0x2000")), + ); + expect( + result.dimensions.find(({ dimension }) => dimension === "calls"), + ).toMatchObject({ status }); + }); +}); + describe("function comparison CFG address normalization", () => { it("matches CFG successors by numeric address", () => { const make = (base: "0x1000" | "0x2000") => diff --git a/src/domain/functionComparisonNormalization.ts b/src/domain/functionComparisonNormalization.ts index 1d7dce3f8..8ce89dddf 100644 --- a/src/domain/functionComparisonNormalization.ts +++ b/src/domain/functionComparisonNormalization.ts @@ -198,7 +198,7 @@ export const project = ( ): Output[] => collection.items.map(mapper); export const isAutoName = (name: string): boolean => - /^(?:sub_[0-9a-f]+|fcn\.)/iu.test(name); + /^(?:sub_[0-9a-f]+|fcn\.[0-9a-f]+)$/iu.test(name); const parseAddress = (value: string): bigint | null => /^0x[0-9a-f]+$/iu.test(value) ? BigInt(value) : null;