fix(native): preserve compact reference provenance (#1438)
Co-authored-by: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com>
This commit is contained in:
co-authored by
N0zoM1z0
parent
2ec93ba166
commit
24d9337649
@@ -3,6 +3,11 @@ import { describe, expect, it } from "vitest";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { functionDossierSchema } from "../domain/hopperValues.js";
|
||||
import {
|
||||
compactReference,
|
||||
compactInstruction,
|
||||
compactCallTargets,
|
||||
} from "../domain/native/nativeInstruction.fixture.js";
|
||||
import {
|
||||
parseGhidraFunctionResult,
|
||||
type GhidraFunctionOperation,
|
||||
@@ -118,6 +123,75 @@ describe("Ghidra function-analysis result values", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ghidra compact reference provenance", () => {
|
||||
const operations = [
|
||||
["inspect_native_instruction", compactInstruction],
|
||||
["resolve_native_call_targets", compactCallTargets],
|
||||
] as const;
|
||||
|
||||
it.each(operations)(
|
||||
"preserves complete, legacy and unknown facts in %s",
|
||||
(operation, output) => {
|
||||
const complete = compactReference();
|
||||
const legacy = Object.fromEntries(
|
||||
Object.entries(complete).filter(
|
||||
([key]) =>
|
||||
![
|
||||
"source_address",
|
||||
"data",
|
||||
"read",
|
||||
"write",
|
||||
"primary",
|
||||
"provenance",
|
||||
"source",
|
||||
].includes(key),
|
||||
),
|
||||
);
|
||||
const unknown = {
|
||||
...legacy,
|
||||
source_address: null,
|
||||
data: null,
|
||||
read: null,
|
||||
write: null,
|
||||
primary: null,
|
||||
provenance: null,
|
||||
source: null,
|
||||
};
|
||||
for (const reference of [complete, legacy, unknown]) {
|
||||
const expected = output([reference]);
|
||||
const parsed = parseGhidraFunctionResult(operation, expected);
|
||||
if (!parsed.ok) throw parsed.error;
|
||||
expect(parsed.value).toEqual(expected);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each(operations)(
|
||||
"rejects malformed present provenance in %s",
|
||||
(operation, output) => {
|
||||
for (const [field, value] of [
|
||||
["source_address", 1],
|
||||
["data", "true"],
|
||||
["read", 1],
|
||||
["write", 0],
|
||||
["primary", "false"],
|
||||
["provenance", ""],
|
||||
["source", false],
|
||||
] as const) {
|
||||
expect(
|
||||
parseGhidraFunctionResult(
|
||||
operation,
|
||||
output([{ ...compactReference(), [field]: value }]),
|
||||
),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisOutputError" },
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("Ghidra jump-table mapping contract", () => {
|
||||
it("preserves evidenced defaults separately from cases and unresolved targets", () => {
|
||||
const dossier = functionDossierSchema.parse(ghidraFunctionDossier());
|
||||
|
||||
Reference in New Issue
Block a user