feat(native): inspect oversized retained function dossiers via bounded views
Add caller-selected native dossier facets with preserved Evidence identity, provenance, unknowns and transport recovery. Refs #1247 and #1065. Co-authored-by: jhuang-tw <77732008+jhuang-tw@users.noreply.github.com> Co-authored-by: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { resolveJavaScriptSourceMapReference } from "../javascript/javascriptSourceMapPaths.js";
|
||||
import { functionDossierSchema } from "../hopperValues.js";
|
||||
import { ghidraFunctionDossier } from "../ghidraValues.fixture.js";
|
||||
import { JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE } from "../../contracts/javascript/javascriptRuntimeReconciliationExample.js";
|
||||
import {
|
||||
analysisViewBindJavaScriptGraphs,
|
||||
@@ -48,21 +50,190 @@ const javascriptParent = (
|
||||
limitations: JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE.limitations,
|
||||
});
|
||||
|
||||
it("accepts caller-selected page sizes and rejects malformed bounds", () => {
|
||||
const input = {
|
||||
source: { kind: "retained-evidence", evidence_id: `ev_${"a".repeat(64)}` },
|
||||
view: { kind: "page", collection: "sections", offset: 0, limit: 500 },
|
||||
};
|
||||
expect(inspectAnalysisViewInputSchema.safeParse(input).success).toBe(true);
|
||||
for (const limit of [0, -1, 0.5, Infinity, Number.MAX_SAFE_INTEGER + 1])
|
||||
expect(
|
||||
inspectAnalysisViewInputSchema.safeParse({
|
||||
...input,
|
||||
view: { ...input.view, limit },
|
||||
}).success,
|
||||
).toBe(false);
|
||||
const nativeParent = (
|
||||
result: unknown = ghidraFunctionDossier(),
|
||||
): AnalysisViewParent => ({
|
||||
evidenceId: "ev_" + "b".repeat(64),
|
||||
operation: "analyze_function",
|
||||
normalizedResult: result,
|
||||
limitations: ["Retained provider limitation"],
|
||||
artifact: { path: "/fixtures/example.exe", sha256: "a".repeat(64) },
|
||||
});
|
||||
|
||||
it("projects native procedure and bounded assembly and high-pcode with exact parent identity", () => {
|
||||
const parent = nativeParent();
|
||||
const procedure = projectAnalysisView(parent, {
|
||||
kind: "native",
|
||||
facet: "procedure",
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
});
|
||||
if (!procedure.ok) throw procedure.error;
|
||||
expect(procedure.value).toMatchObject({
|
||||
kind: "native",
|
||||
parent_operation: "analyze_function",
|
||||
artifact: parent.artifact,
|
||||
item: { address: "0x401000" },
|
||||
});
|
||||
expect(procedure.value.view_digest).not.toBe(parent.evidenceId.slice(3));
|
||||
const assembly = projectAnalysisView(parent, {
|
||||
kind: "native",
|
||||
facet: "assembly",
|
||||
offset: 0,
|
||||
limit: 1,
|
||||
});
|
||||
if (!assembly.ok) throw assembly.error;
|
||||
expect(assembly.value).toMatchObject({
|
||||
coverage: { examined: 1, total: 2, next_offset: 1 },
|
||||
item: ["0x401000: CALL 0x401020"],
|
||||
});
|
||||
const flow = projectAnalysisView(parent, {
|
||||
kind: "native",
|
||||
facet: "value_flow_operations",
|
||||
offset: 0,
|
||||
limit: 1,
|
||||
});
|
||||
if (!flow.ok) throw flow.error;
|
||||
expect(flow.value).toMatchObject({ item: [{ opcode: "COPY" }] });
|
||||
});
|
||||
|
||||
it("rejects invalid native parents, unsupported source operations and singleton offsets", () => {
|
||||
const view = {
|
||||
kind: "native",
|
||||
facet: "assembly",
|
||||
offset: 0,
|
||||
limit: 4,
|
||||
} as const;
|
||||
expect(projectAnalysisView(nativeParent({}), view)).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisInputError" },
|
||||
});
|
||||
expect(
|
||||
projectAnalysisView({ ...nativeParent(), artifact: null }, view),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisInputError" },
|
||||
});
|
||||
expect(projectAnalysisView(layoutParent(), view)).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisInputError" },
|
||||
});
|
||||
expect(projectAnalysisView(javascriptParent(), view)).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisInputError" },
|
||||
});
|
||||
expect(
|
||||
projectAnalysisView(nativeParent(), {
|
||||
kind: "native",
|
||||
facet: "procedure",
|
||||
offset: 1,
|
||||
limit: 2,
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||
});
|
||||
|
||||
it("preserves native API limitations and unavailable residual unknowns", () => {
|
||||
const original = functionDossierSchema.parse(ghidraFunctionDossier());
|
||||
const view = {
|
||||
kind: "native",
|
||||
facet: "procedure",
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
} as const;
|
||||
const unavailable = projectAnalysisView(
|
||||
nativeParent({
|
||||
...original,
|
||||
native_api: {
|
||||
available: false,
|
||||
reason: "No decompiler",
|
||||
residual_unknowns: ["Calling convention unresolved"],
|
||||
},
|
||||
}),
|
||||
view,
|
||||
);
|
||||
if (!unavailable.ok) throw unavailable.error;
|
||||
expect(unavailable.value.unknowns).toContain("Calling convention unresolved");
|
||||
const available = projectAnalysisView(nativeParent(), view);
|
||||
if (!available.ok) throw available.error;
|
||||
if (!original.native_api?.available) throw new Error("expected API fixture");
|
||||
expect(available.value.limitations).toEqual(
|
||||
expect.arrayContaining(original.native_api.limitations),
|
||||
);
|
||||
});
|
||||
|
||||
it("reports the malformed native dossier field", () => {
|
||||
const result = projectAnalysisView(
|
||||
nativeParent({
|
||||
...functionDossierSchema.parse(ghidraFunctionDossier()),
|
||||
pseudocode: 12,
|
||||
}),
|
||||
{
|
||||
kind: "native",
|
||||
facet: "pseudocode",
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
},
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
issues: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
path: ["source", "normalized_result", "pseudocode"],
|
||||
}),
|
||||
]),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("native pseudocode pages do not split surrogate pairs", () => {
|
||||
const original = functionDossierSchema.parse(ghidraFunctionDossier());
|
||||
const parent = nativeParent({ ...original, pseudocode: "ab😀cd" });
|
||||
expect(
|
||||
projectAnalysisView(parent, {
|
||||
kind: "native",
|
||||
facet: "pseudocode",
|
||||
offset: 3,
|
||||
limit: 2,
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||
const safe = projectAnalysisView(parent, {
|
||||
kind: "native",
|
||||
facet: "pseudocode",
|
||||
offset: 2,
|
||||
limit: 3,
|
||||
});
|
||||
if (!safe.ok) throw safe.error;
|
||||
expect(safe.value).toMatchObject({
|
||||
item: { text: "😀c", unit: "utf16-code-units" },
|
||||
coverage: { examined: 3, next_offset: 5 },
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ kind: "page", collection: "sections", offset: 0, limit: 500 },
|
||||
{ kind: "native", facet: "assembly", offset: 0, limit: 500 },
|
||||
])(
|
||||
"accepts caller-selected page sizes and rejects malformed bounds: $kind",
|
||||
(view) => {
|
||||
const input = {
|
||||
source: {
|
||||
kind: "retained-evidence",
|
||||
evidence_id: `ev_${"a".repeat(64)}`,
|
||||
},
|
||||
view,
|
||||
};
|
||||
expect(inspectAnalysisViewInputSchema.safeParse(input).success).toBe(true);
|
||||
for (const limit of [0, -1, 0.5, Infinity, Number.MAX_SAFE_INTEGER + 1])
|
||||
expect(
|
||||
inspectAnalysisViewInputSchema.safeParse({
|
||||
...input,
|
||||
view: { ...input.view, limit },
|
||||
}).success,
|
||||
).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it("projects layout summary, facet, item, and stable pages", () => {
|
||||
const parent = layoutParent();
|
||||
const layout = analysisViewLayoutFixture();
|
||||
|
||||
Reference in New Issue
Block a user