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 <morluto@users.noreply.github.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-06 01:57:20 +08:00
committed by GitHub
co-authored by morluto morluto
parent d1e5c0e1fd
commit 5f3ba3e688
3 changed files with 72 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
/Users/will/dev/active/rea/node_modules
+70
View File
@@ -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") =>
@@ -198,7 +198,7 @@ export const project = <Input, Output>(
): 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;