fix(domain): preserve derived byte counts and uncertain identity
This commit is contained in:
@@ -22,6 +22,26 @@ const exampleMethod = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe("managed decompiler reconstruction import", () => {
|
describe("managed decompiler reconstruction import", () => {
|
||||||
|
it("reports UTF-8 byte totals while preserving UTF-16 text lengths", () => {
|
||||||
|
const text = 'return "é"; // 😀';
|
||||||
|
const method = exampleMethod();
|
||||||
|
const result = importManagedReconstructionEvidence({
|
||||||
|
...MANAGED_RECONSTRUCTION_IMPORT_EXAMPLE,
|
||||||
|
methods: [
|
||||||
|
{
|
||||||
|
...method,
|
||||||
|
reconstruction: { ...method.reconstruction, text },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
if (!result.ok) throw result.error;
|
||||||
|
|
||||||
|
expect(result.value.normalized_result).toMatchObject({
|
||||||
|
summary: { total_text_bytes: 20 },
|
||||||
|
methods: [{ reconstruction: { text, text_length: 17 } }],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("rejects reconstruction text hash drift", () => {
|
it("rejects reconstruction text hash drift", () => {
|
||||||
expect(() =>
|
expect(() =>
|
||||||
importManagedReconstruction({
|
importManagedReconstruction({
|
||||||
|
|||||||
@@ -119,6 +119,34 @@ const observe = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
describe("function comparison normalized identity", () => {
|
describe("function comparison normalized identity", () => {
|
||||||
|
it("keeps differing generated names ambiguous and stable names mismatched", () => {
|
||||||
|
const named = (base: "0x1000" | "0x2000", name: string) =>
|
||||||
|
functionDossierSchema.parse({
|
||||||
|
...dossier("return 0;", base),
|
||||||
|
procedure: {
|
||||||
|
...procedure(base, name),
|
||||||
|
signature: "int helper(void)",
|
||||||
|
locals: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const generated = compareFunctions(
|
||||||
|
observe("1", named("0x1000", "sub_1000")),
|
||||||
|
observe("2", named("0x2000", "sub_2000")),
|
||||||
|
);
|
||||||
|
expect(generated.function_match.status).toBe("ambiguous");
|
||||||
|
expect(generated.status).toBe("unknown");
|
||||||
|
expect(
|
||||||
|
generated.dimensions.find(({ dimension }) => dimension === "identity"),
|
||||||
|
).toMatchObject({ status: "unknown" });
|
||||||
|
|
||||||
|
const stable = compareFunctions(
|
||||||
|
observe("3", named("0x1000", "firstFunction")),
|
||||||
|
observe("4", named("0x2000", "secondFunction")),
|
||||||
|
);
|
||||||
|
expect(stable.function_match.status).toBe("mismatched");
|
||||||
|
expect(stable.status).toBe("changed");
|
||||||
|
});
|
||||||
|
|
||||||
it.each(["sub_deallocate", "sub_deadbeef_handler", "fcn.dispatch"])(
|
it.each(["sub_deallocate", "sub_deadbeef_handler", "fcn.dispatch"])(
|
||||||
"recognizes the explicit symbol %s without a generated-name prefix false positive",
|
"recognizes the explicit symbol %s without a generated-name prefix false positive",
|
||||||
(name) => {
|
(name) => {
|
||||||
|
|||||||
@@ -16,24 +16,21 @@ export const functionMatch = (
|
|||||||
left: FunctionSnapshot,
|
left: FunctionSnapshot,
|
||||||
right: FunctionSnapshot,
|
right: FunctionSnapshot,
|
||||||
): FunctionComparisonResult["function_match"] => {
|
): FunctionComparisonResult["function_match"] => {
|
||||||
if (
|
const leftName = left.dossier.procedure.name;
|
||||||
!isAutoName(left.dossier.procedure.name) &&
|
const rightName = right.dossier.procedure.name;
|
||||||
left.dossier.procedure.name === right.dossier.procedure.name
|
const stableNames = !isAutoName(leftName) && !isAutoName(rightName);
|
||||||
)
|
if (stableNames && leftName === rightName)
|
||||||
return {
|
return {
|
||||||
status: "matched",
|
status: "matched",
|
||||||
method: "symbol",
|
method: "symbol",
|
||||||
left_name: left.dossier.procedure.name,
|
left_name: leftName,
|
||||||
right_name: right.dossier.procedure.name,
|
right_name: rightName,
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
status:
|
status: stableNames ? "mismatched" : "ambiguous",
|
||||||
left.dossier.procedure.name === right.dossier.procedure.name
|
|
||||||
? "ambiguous"
|
|
||||||
: "mismatched",
|
|
||||||
method: "explicit",
|
method: "explicit",
|
||||||
left_name: left.dossier.procedure.name,
|
left_name: leftName,
|
||||||
right_name: right.dossier.procedure.name,
|
right_name: rightName,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -204,7 +204,8 @@ const buildReconstructionSummary = (
|
|||||||
({ reconstruction }) => reconstruction.kind === "semantic-pseudocode",
|
({ reconstruction }) => reconstruction.kind === "semantic-pseudocode",
|
||||||
).length,
|
).length,
|
||||||
total_text_bytes: methods.reduce(
|
total_text_bytes: methods.reduce(
|
||||||
(total, { reconstruction }) => total + reconstruction.text_length,
|
(total, { reconstruction }) =>
|
||||||
|
total + Buffer.byteLength(reconstruction.text, "utf8"),
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user