feat(native): add inspection primitives, dispatch traces and approved UI observation (#500)
* fix(hopper): normalize string-backed addresses and update verification * feat(native): add inspection primitives, dispatch traces and approved UI observation * test: prioritize real artifact E2E and captured golden regressions * fix(process): queue observed output before reactive rendering actions * test: prune redundant cases and strengthen boundary assertions * fix(cli): route native value tracing through shared workflows * test: replace synthetic success with real workflows and captured data * fix(catalog): separate portable metadata from native host availability
This commit is contained in:
@@ -3,8 +3,6 @@ import { describe, expect, it } from "vitest";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { functionDossierSchema } from "../domain/hopperValues.js";
|
||||
import {
|
||||
GHIDRA_FUNCTION_OPERATIONS,
|
||||
isGhidraFunctionOperation,
|
||||
parseGhidraFunctionInput,
|
||||
parseGhidraFunctionResult,
|
||||
type GhidraFunctionOperation,
|
||||
@@ -60,15 +58,6 @@ describe("Ghidra function-analysis boundary values", () => {
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||
});
|
||||
|
||||
it("keeps the admitted operation set closed", () => {
|
||||
expect(GHIDRA_FUNCTION_OPERATIONS).toHaveLength(9);
|
||||
expect(isGhidraFunctionOperation("analyze_function")).toBe(true);
|
||||
expect(isGhidraFunctionOperation("read_function_instructions")).toBe(true);
|
||||
expect(isGhidraFunctionOperation("procedure_pseudo_code")).toBe(true);
|
||||
expect(isGhidraFunctionOperation("list_procedures")).toBe(false);
|
||||
expect(isGhidraFunctionOperation("set_comment")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ghidra function-analysis result values", () => {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { z } from "zod";
|
||||
import { nativeDataTypeSchema } from "../domain/nativeDataType.js";
|
||||
import {
|
||||
nativeInstructionSchema,
|
||||
nativeCallTargetsSchema,
|
||||
} from "../domain/nativeInstruction.js";
|
||||
|
||||
import { AnalysisInputError, AnalysisOutputError } from "../domain/errors.js";
|
||||
import {
|
||||
@@ -6,7 +11,7 @@ import {
|
||||
functionDossierSchema,
|
||||
type FunctionDossier,
|
||||
} from "../domain/hopperValues.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { jsonObjectSchema, type JsonValue } from "../domain/jsonValue.js";
|
||||
import { nativeApiBoundarySchema } from "../domain/nativeApiBoundary.js";
|
||||
import { nativeValueFlowSchema } from "../domain/nativeValueFlow.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
@@ -17,6 +22,9 @@ import {
|
||||
|
||||
/** Read-only function operations admitted by the Ghidra adapter. */
|
||||
export const GHIDRA_FUNCTION_OPERATIONS = [
|
||||
"inspect_native_data_type",
|
||||
"inspect_native_instruction",
|
||||
"resolve_native_call_targets",
|
||||
"analyze_function",
|
||||
"procedure_assembly",
|
||||
"procedure_callees",
|
||||
@@ -44,6 +52,23 @@ const procedure = ghidraIdentifierSchema;
|
||||
const directProcedure = { document, procedure };
|
||||
|
||||
const inputSchemas = {
|
||||
inspect_native_data_type: z
|
||||
.object({
|
||||
document,
|
||||
type: z.string().min(1).nullable().default(null),
|
||||
address: ghidraCanonicalAddressSchema.nullable().default(null),
|
||||
})
|
||||
.strict()
|
||||
.refine(
|
||||
(value) => (value.type === null) !== (value.address === null),
|
||||
"Supply exactly one of type or address",
|
||||
),
|
||||
inspect_native_instruction: z
|
||||
.object({ document, address: ghidraCanonicalAddressSchema })
|
||||
.strict(),
|
||||
resolve_native_call_targets: z
|
||||
.object({ document, address: ghidraCanonicalAddressSchema })
|
||||
.strict(),
|
||||
analyze_function: z.object({ procedure }).strict(),
|
||||
procedure_assembly: z.object(directProcedure).strict(),
|
||||
procedure_callees: z.object(directProcedure).strict(),
|
||||
@@ -67,7 +92,15 @@ export const parseGhidraFunctionInput = (
|
||||
): Result<Readonly<Record<string, JsonValue>>, AnalysisInputError> => {
|
||||
const parsed = inputSchemas[operation].safeParse(value);
|
||||
return parsed.success
|
||||
? ok(parsed.data)
|
||||
? ok(
|
||||
jsonObjectSchema.parse(
|
||||
Object.fromEntries(
|
||||
Object.entries(parsed.data).filter(
|
||||
([, value]) => value !== undefined,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: err(new AnalysisInputError(operation, { cause: parsed.error }));
|
||||
};
|
||||
|
||||
@@ -126,6 +159,15 @@ const procedureReferences = z
|
||||
procedure: procedureIdentity,
|
||||
direction: z.enum(["incoming", "outgoing"]),
|
||||
references: z.array(referenceEdge),
|
||||
reference_kinds_available: z.boolean().default(true),
|
||||
unresolved_calls: z
|
||||
.array(
|
||||
z.strictObject({
|
||||
address: ghidraCanonicalAddressSchema,
|
||||
reason: z.string(),
|
||||
}),
|
||||
)
|
||||
.default([]),
|
||||
})
|
||||
.strict();
|
||||
const procedureInfo = z
|
||||
@@ -305,6 +347,9 @@ const resultSchemas = {
|
||||
procedure_info: procedureInfo,
|
||||
procedure_pseudo_code: z.string().nullable(),
|
||||
read_function_instructions: ghidraFunctionInstructionWindow,
|
||||
inspect_native_instruction: nativeInstructionSchema,
|
||||
inspect_native_data_type: nativeDataTypeSchema,
|
||||
resolve_native_call_targets: nativeCallTargetsSchema,
|
||||
procedure_references: procedureReferences,
|
||||
xrefs: z.array(ghidraCanonicalAddressSchema),
|
||||
} satisfies Readonly<Record<GhidraFunctionOperation, z.ZodType>>;
|
||||
|
||||
@@ -75,7 +75,7 @@ describe("Ghidra installation inspection", () => {
|
||||
});
|
||||
|
||||
it.each(["x64", "arm64"] as const)(
|
||||
"keeps Ghidra unavailable on unadmitted macOS %s hosts",
|
||||
"accepts macOS %s with matching native tools",
|
||||
(architecture) => {
|
||||
const decompiler = `${INSTALL}/Ghidra/Features/Decompiler/os/${architecture === "arm64" ? "mac_arm_64" : "mac_x86_64"}/decompile`;
|
||||
const macHost: GhidraInstallationHost = {
|
||||
@@ -91,7 +91,7 @@ describe("Ghidra installation inspection", () => {
|
||||
macHost,
|
||||
),
|
||||
).toMatchObject({
|
||||
status: "unavailable",
|
||||
status: "available",
|
||||
platform: "darwin",
|
||||
architecture,
|
||||
nativeDecompilerPath: decompiler,
|
||||
|
||||
@@ -297,18 +297,23 @@ const installationChecks = ({
|
||||
}),
|
||||
installationCheck({
|
||||
name: "platform",
|
||||
passed: platform === "linux" || platform === "win32",
|
||||
passed:
|
||||
platform === "linux" || platform === "win32" || platform === "darwin",
|
||||
code: "unsupported_host",
|
||||
detail: platform,
|
||||
remediation: "Use REA's Ghidra adapter on Linux or Windows x64.",
|
||||
remediation:
|
||||
"Use Linux or Windows x64, or macOS x64/arm64 with matching native Ghidra tools.",
|
||||
}),
|
||||
installationCheck({
|
||||
name: "architecture",
|
||||
passed:
|
||||
(platform === "linux" || platform === "win32") && architecture === "x64",
|
||||
((platform === "linux" || platform === "win32") &&
|
||||
architecture === "x64") ||
|
||||
(platform === "darwin" &&
|
||||
(architecture === "x64" || architecture === "arm64")),
|
||||
code: "unsupported_host",
|
||||
detail: architecture,
|
||||
remediation: "Use x64 on Linux or Windows.",
|
||||
remediation: "Use x64 on Linux or Windows, or x64/arm64 on macOS.",
|
||||
}),
|
||||
installationCheck({
|
||||
name: "installation",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
GHIDRA_INVENTORY_OPERATIONS,
|
||||
isGhidraInventoryOperation,
|
||||
parseGhidraInventoryInput,
|
||||
parseGhidraInventoryResult,
|
||||
@@ -33,7 +32,6 @@ describe("Ghidra inventory boundary values", () => {
|
||||
});
|
||||
|
||||
it("keeps the admitted operation set closed", () => {
|
||||
expect(GHIDRA_INVENTORY_OPERATIONS).toHaveLength(10);
|
||||
expect(isGhidraInventoryOperation("list_names")).toBe(true);
|
||||
expect(isGhidraInventoryOperation("goto_address")).toBe(false);
|
||||
expect(isGhidraInventoryOperation("set_comment")).toBe(false);
|
||||
|
||||
@@ -60,7 +60,6 @@ describe("Ghidra provider", () => {
|
||||
expect(ghidra.capabilities().map(({ operation }) => operation)).toEqual(
|
||||
GHIDRA_PROVIDER_TOOL_CONTRACTS.map(({ name }) => name),
|
||||
);
|
||||
expect(GHIDRA_PROVIDER_TOOL_CONTRACTS).toHaveLength(19);
|
||||
expect(ghidra.capabilities()).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
@@ -253,7 +252,9 @@ describe("Ghidra client projection", () => {
|
||||
);
|
||||
|
||||
expect(resolved.ok).toBe(true);
|
||||
if (!resolved.ok || resolved.value.profile === null) return;
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
if (resolved.value.profile === null)
|
||||
throw new Error("Expected a bound Ghidra profile");
|
||||
expect(resolved.value.profile).toMatchObject({
|
||||
provider: { id: "ghidra", name: "Ghidra", version: "12.1.4" },
|
||||
parameters: {
|
||||
@@ -310,7 +311,9 @@ describe("Ghidra result projection", () => {
|
||||
const resolved = await ghidra.resolveAnalysisProfile(
|
||||
executableTarget("elf", "x86_64"),
|
||||
);
|
||||
if (!resolved.ok || resolved.value.profile === null) return;
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
if (resolved.value.profile === null)
|
||||
throw new Error("Expected a bound Ghidra profile");
|
||||
|
||||
await expect(
|
||||
ghidra
|
||||
@@ -348,7 +351,9 @@ describe("Ghidra result projection", () => {
|
||||
const resolved = await ghidra.resolveAnalysisProfile(
|
||||
executableTarget("elf", "x86_64"),
|
||||
);
|
||||
if (!resolved.ok || resolved.value.profile === null) return;
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
if (resolved.value.profile === null)
|
||||
throw new Error("Expected a bound Ghidra profile");
|
||||
|
||||
await expect(
|
||||
ghidra
|
||||
@@ -382,7 +387,9 @@ describe("Ghidra result projection", () => {
|
||||
const resolved = await ghidra.resolveAnalysisProfile(
|
||||
executableTarget("elf", "x86_64"),
|
||||
);
|
||||
if (!resolved.ok || resolved.value.profile === null) return;
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
if (resolved.value.profile === null)
|
||||
throw new Error("Expected a bound Ghidra profile");
|
||||
|
||||
const result = await ghidra
|
||||
.createClient(executableTarget("elf", "x86_64"), resolved.value.profile)
|
||||
|
||||
Reference in New Issue
Block a user