fix(ghidra): harden location resolution and provider lifecycle
Preserve boundary diagnostics, resolve procedure names before bare hex addresses, and launch the inspected JVM directly on macOS for verifiable startup cancellation. Keep private socket paths within host limits and retain ownership when cleanup is incomplete. Exercise the fixes through real CLI/MCP Ghidra workflows and provider-boundary integration tests, replacing redundant unit coverage.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdir, mkdtemp, readdir, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
@@ -8,6 +11,7 @@ import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { parseEvidence } from "../../dist/domain/evidence.js";
|
||||
import { analysisProfileSchema } from "../../dist/domain/analysisProfile.js";
|
||||
import { nativeValueTraceSchema } from "../../dist/domain/native/nativeValueTrace.js";
|
||||
import { verifyGhidraBoundaries } from "./real-ghidra-boundaries.mjs";
|
||||
|
||||
const defaultEntrypoint = fileURLToPath(new URL("../rea.mjs", import.meta.url));
|
||||
const environment = () => ({
|
||||
@@ -72,6 +76,33 @@ export async function verifyNativeValueE2e(
|
||||
procedure,
|
||||
globalAddress,
|
||||
{ entrypoint = defaultEntrypoint } = {},
|
||||
) {
|
||||
const workspace = await mkdtemp(join(tmpdir(), "rea-native-values-e2e-"));
|
||||
const runtime = join(
|
||||
workspace,
|
||||
`runtime${process.platform === "darwin" ? " with spaces" : ""}-${"x".repeat(100)}`,
|
||||
);
|
||||
await mkdir(runtime);
|
||||
const env = { ...environment(), TMPDIR: runtime };
|
||||
try {
|
||||
return await verifyNativeValueAdapters(
|
||||
target,
|
||||
procedure,
|
||||
globalAddress,
|
||||
entrypoint,
|
||||
env,
|
||||
);
|
||||
} finally {
|
||||
await rm(workspace, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
async function verifyNativeValueAdapters(
|
||||
target,
|
||||
procedure,
|
||||
globalAddress,
|
||||
entrypoint,
|
||||
env,
|
||||
) {
|
||||
const { stdout } = await promisify(execFile)(
|
||||
process.execPath,
|
||||
@@ -90,7 +121,7 @@ export async function verifyNativeValueE2e(
|
||||
"5000",
|
||||
"--json",
|
||||
],
|
||||
{ env: environment(), timeout: 240000, maxBuffer: 72 * 1024 * 1024 },
|
||||
{ env, timeout: 240000, maxBuffer: 72 * 1024 * 1024 },
|
||||
);
|
||||
const evidence = parseEvidence(JSON.parse(stdout));
|
||||
assert.equal(evidence.operation, "trace_native_values");
|
||||
@@ -114,16 +145,17 @@ export async function verifyNativeValueE2e(
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
env: environment(),
|
||||
env,
|
||||
stderr: "pipe",
|
||||
});
|
||||
const client = new Client({ name: "native-values-real-e2e", version: "1" });
|
||||
let boundaries;
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const opened = await client.callTool(
|
||||
{
|
||||
name: "open_binary",
|
||||
arguments: { path: target.path, provider: "ghidra" },
|
||||
arguments: { path: target.path, provider_id: "ghidra" },
|
||||
},
|
||||
{ timeout: 180000 },
|
||||
);
|
||||
@@ -168,14 +200,11 @@ export async function verifyNativeValueE2e(
|
||||
analyzed.structuredContent?.evidence,
|
||||
);
|
||||
assert.equal(functionEvidence.operation, "analyze_function");
|
||||
assert.equal(functionEvidence.provider.id, "rea-workflow");
|
||||
assert.equal(functionEvidence.provider.id, "ghidra");
|
||||
const functionProfile = analysisProfileSchema.parse(
|
||||
functionEvidence.analysis_profile,
|
||||
);
|
||||
assert.deepEqual(
|
||||
functionProfile.parameters.upstream_analysis_profile,
|
||||
upstreamProfile,
|
||||
);
|
||||
assert.deepEqual(functionProfile, upstreamProfile);
|
||||
assert.deepEqual(
|
||||
functionEvidence.normalized_result,
|
||||
analyzed.structuredContent?.result,
|
||||
@@ -219,6 +248,12 @@ export async function verifyNativeValueE2e(
|
||||
evidence,
|
||||
);
|
||||
}
|
||||
boundaries = await verifyGhidraBoundaries(client, {
|
||||
target,
|
||||
procedure,
|
||||
entrypoint,
|
||||
env,
|
||||
});
|
||||
const closed = await client.callTool({
|
||||
name: "close_binary",
|
||||
arguments: {},
|
||||
@@ -229,6 +264,13 @@ export async function verifyNativeValueE2e(
|
||||
arguments: {},
|
||||
});
|
||||
assert.equal(status.structuredContent?.result?.open, false);
|
||||
assert.deepEqual(
|
||||
(await readdir(env.TMPDIR)).filter((name) =>
|
||||
name.startsWith("rea-ghidra-"),
|
||||
),
|
||||
[],
|
||||
"Ghidra left runtime files after close",
|
||||
);
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
@@ -239,6 +281,7 @@ export async function verifyNativeValueE2e(
|
||||
stdio_mcp: true,
|
||||
inline_evidence: true,
|
||||
direct_function_comparison: true,
|
||||
boundaries,
|
||||
nodes: cliGraph.total_nodes,
|
||||
edges: cliGraph.total_edges,
|
||||
decompilations: cliGraph.decompilations,
|
||||
|
||||
@@ -0,0 +1,505 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash, randomUUID } from "node:crypto";
|
||||
import { access, readFile, readdir, stat } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
import { promisify } from "node:util";
|
||||
import Ajv from "ajv/dist/2020.js";
|
||||
import addFormats from "ajv-formats";
|
||||
import { mcpTextValue, requireMcpResult } from "./mcp-verifier-results.mjs";
|
||||
|
||||
/** Probe real Ghidra location, annotation and error contracts through public adapters. */
|
||||
export async function verifyGhidraBoundaries(
|
||||
client,
|
||||
{ target, procedure, entrypoint, env },
|
||||
) {
|
||||
const options = { timeout: 180000 };
|
||||
const catalog = await client.listTools();
|
||||
const ajv = new Ajv({ strict: false });
|
||||
addFormats(ajv);
|
||||
const validators = new Map();
|
||||
for (const tool of catalog.tools) {
|
||||
for (const key of ["inputSchema", "outputSchema"])
|
||||
assert.ok(
|
||||
ajv.validateSchema(tool[key]),
|
||||
`${tool.name} ${key}: ${JSON.stringify(ajv.errors)}`,
|
||||
);
|
||||
validators.set(tool.name, ajv.compile(tool.outputSchema));
|
||||
}
|
||||
let successfulCalls = 0;
|
||||
let rejectedCalls = 0;
|
||||
const call = async (name, args = {}) => {
|
||||
const reply = await client.callTool({ name, arguments: args }, options);
|
||||
const result = requireMcpResult(reply, name);
|
||||
const validate = validators.get(name);
|
||||
assert.ok(validate, `${name} missing from catalog`);
|
||||
assert.ok(
|
||||
validate(reply.structuredContent),
|
||||
`${name}: ${JSON.stringify(validate.errors)}`,
|
||||
);
|
||||
assert.deepEqual(reply.structuredContent, JSON.parse(mcpTextValue(reply)));
|
||||
successfulCalls++;
|
||||
return result;
|
||||
};
|
||||
const invalid = async (name, args, diagnostic) => {
|
||||
const reply = await client.callTool({ name, arguments: args }, options);
|
||||
assert.equal(
|
||||
reply.isError,
|
||||
true,
|
||||
`${name} accepted ${JSON.stringify(args)}`,
|
||||
);
|
||||
if (diagnostic !== undefined) {
|
||||
const error = reply.structuredContent?.error;
|
||||
assert.equal(error?.code, "invalid_request");
|
||||
assert.equal(error?.details?.operation, name);
|
||||
assert.match(JSON.stringify(error.details.issues), diagnostic);
|
||||
}
|
||||
rejectedCalls++;
|
||||
};
|
||||
const cli = async (command, value, flags = []) => {
|
||||
const { stdout } = await promisify(execFile)(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
command,
|
||||
target.path,
|
||||
value,
|
||||
"--provider",
|
||||
"ghidra",
|
||||
"--json",
|
||||
...flags,
|
||||
],
|
||||
{ env, timeout: 240000, maxBuffer: 72 * 1024 * 1024 },
|
||||
);
|
||||
return JSON.parse(stdout).normalized_result;
|
||||
};
|
||||
const original = await call("analyze_function", { procedure });
|
||||
const roots = (await readdir(env.TMPDIR)).filter((name) =>
|
||||
name.startsWith("rea-ghidra-"),
|
||||
);
|
||||
assert.equal(roots.length, 1, "Expected one owned Ghidra runtime");
|
||||
const runtimeRoot = join(env.TMPDIR, roots[0]);
|
||||
const { endpoint_path: socketPath } = JSON.parse(
|
||||
await readFile(join(runtimeRoot, "ownership.json"), "utf8"),
|
||||
);
|
||||
const socketRoot = dirname(socketPath);
|
||||
assert.ok(
|
||||
Buffer.byteLength(join(runtimeRoot, "bridge.sock"), "utf8") > 107,
|
||||
"Fixture must exceed Unix socket path capacity",
|
||||
);
|
||||
assert.ok(Buffer.byteLength(socketPath, "utf8") <= 103);
|
||||
assert.notEqual(socketRoot, runtimeRoot);
|
||||
assert.equal((await stat(socketRoot)).mode & 0o777, 0o700);
|
||||
const address = original.procedure.address;
|
||||
const name = original.procedure.name;
|
||||
const baseline = await call("inspect_native_instruction", { address });
|
||||
assert.equal(baseline.status, "decoded");
|
||||
const bytes = await call("read_bytes", { address, length: baseline.length });
|
||||
assert.equal(bytes.bytes_hex, baseline.bytes);
|
||||
const largeRead = await call("read_bytes", {
|
||||
address,
|
||||
length: Number.MAX_SAFE_INTEGER,
|
||||
});
|
||||
assert.equal(largeRead.requested_bytes, Number.MAX_SAFE_INTEGER);
|
||||
assert.equal(largeRead.complete, false);
|
||||
assert.ok(largeRead.returned_bytes >= baseline.length);
|
||||
assert.equal(largeRead.bytes_hex.length, largeRead.returned_bytes * 2);
|
||||
for (const spelling of [
|
||||
address.toUpperCase(),
|
||||
address.slice(2).toUpperCase(),
|
||||
`ram:${address.toUpperCase()}`,
|
||||
]) {
|
||||
assert.deepEqual(
|
||||
await call("inspect_native_instruction", { address: spelling }),
|
||||
baseline,
|
||||
);
|
||||
assert.deepEqual(
|
||||
await call("read_bytes", { address: spelling, length: baseline.length }),
|
||||
bytes,
|
||||
);
|
||||
assert.equal(await call("address_name", { address: spelling }), name);
|
||||
assert.equal(
|
||||
await call("procedure_address", { procedure: spelling }),
|
||||
address,
|
||||
);
|
||||
assert.equal(
|
||||
(await call("resolve_containing_procedure", { address: spelling }))
|
||||
.procedure.address,
|
||||
address,
|
||||
);
|
||||
}
|
||||
assert.deepEqual(
|
||||
await cli("inspect-native-instruction", address.toUpperCase()),
|
||||
baseline,
|
||||
);
|
||||
const interior = `0x${(BigInt(address) + 1n).toString(16)}`;
|
||||
assert.equal(
|
||||
(await call("inspect_native_instruction", { address: interior })).status,
|
||||
"not-instruction-boundary",
|
||||
);
|
||||
assert.equal(
|
||||
(await call("inspect_native_instruction", { address: "0x0" })).status,
|
||||
"outside-memory",
|
||||
);
|
||||
assert.equal(
|
||||
(await call("resolve_native_call_targets", { address })).status,
|
||||
"not-call",
|
||||
);
|
||||
const directEdge = original.outgoing_references.find(
|
||||
(edge) => edge.kind.call && !edge.kind.computed,
|
||||
);
|
||||
assert.ok(directEdge, "Source fixture lacks a direct call");
|
||||
const direct = await call("resolve_native_call_targets", {
|
||||
address: directEdge.source_address,
|
||||
});
|
||||
assert.equal(direct.status, "direct");
|
||||
assert.ok(
|
||||
direct.targets.some(
|
||||
(candidate) =>
|
||||
candidate.address === directEdge.target_address &&
|
||||
candidate.status === "direct",
|
||||
),
|
||||
);
|
||||
const indirectProcedure = (await call("list_procedures")).find((item) =>
|
||||
item.value.endsWith("rea_ghidra_inventory_indirect"),
|
||||
);
|
||||
assert.ok(indirectProcedure);
|
||||
const references = await call("procedure_references", {
|
||||
procedure: indirectProcedure.address,
|
||||
});
|
||||
assert.ok(
|
||||
references.unresolved_calls.length > 0,
|
||||
"Targetless calls must remain visible",
|
||||
);
|
||||
for (const site of references.unresolved_calls) {
|
||||
const unresolved = await call("resolve_native_call_targets", {
|
||||
address: site.address,
|
||||
});
|
||||
assert.equal(unresolved.status, "unresolved");
|
||||
assert.deepEqual(unresolved.targets, []);
|
||||
assert.ok(unresolved.limitations.length > 0);
|
||||
}
|
||||
const strings = await call("list_strings");
|
||||
assert.ok(strings.length > 0);
|
||||
assert.equal(
|
||||
(await call("inspect_native_instruction", { address: strings[0].address }))
|
||||
.status,
|
||||
"data",
|
||||
);
|
||||
|
||||
await invalid(
|
||||
"inspect_native_instruction",
|
||||
{ address: "not-an-address" },
|
||||
/hexadecimal/u,
|
||||
);
|
||||
await invalid(
|
||||
"inspect_native_instruction",
|
||||
{ address: `missing:${address}` },
|
||||
/missing:0x/u,
|
||||
);
|
||||
await invalid(
|
||||
"address_name",
|
||||
{ address: `0x${(BigInt(address) + 2n ** 64n).toString(16)}` },
|
||||
/invalid Ghidra address/u,
|
||||
);
|
||||
await invalid(
|
||||
"procedure_address",
|
||||
{ procedure: "rea_missing_procedure" },
|
||||
/rea_missing_procedure/u,
|
||||
);
|
||||
await invalid(
|
||||
"search_procedures",
|
||||
{ pattern: "[", mode: "regex" },
|
||||
/Invalid regex pattern.*index/u,
|
||||
);
|
||||
await invalid(
|
||||
"list_procedures",
|
||||
{ document: "rea_missing_program" },
|
||||
/rea_missing_program.*active program/u,
|
||||
);
|
||||
for (const changes of [
|
||||
{},
|
||||
{ name: "" },
|
||||
{ comment: null },
|
||||
{ name: "entry", approve: true },
|
||||
])
|
||||
await invalid("annotate_native_function", {
|
||||
procedure: address,
|
||||
...changes,
|
||||
});
|
||||
|
||||
let cliError;
|
||||
try {
|
||||
await cli("search", "[", ["--kind", "procedures", "--mode", "regex"]);
|
||||
} catch (error) {
|
||||
assert.equal(error.code, 1);
|
||||
cliError = JSON.parse(error.stdout);
|
||||
}
|
||||
assert.equal(cliError?.code, "invalid_request");
|
||||
assert.equal(cliError?.details?.operation, "search_procedures");
|
||||
assert.match(
|
||||
JSON.stringify(cliError?.details?.issues),
|
||||
/Invalid regex pattern.*index/u,
|
||||
);
|
||||
|
||||
// Prime both inventories before editing so stale names cannot hide in caches.
|
||||
await call("list_names");
|
||||
await call("list_procedures");
|
||||
const changes = {
|
||||
procedure: address,
|
||||
name: "dead",
|
||||
comment: "Regular\n註記",
|
||||
inline_comment: "Inline\n註記",
|
||||
};
|
||||
const updated = await call("annotate_native_function", changes);
|
||||
assert.deepEqual(updated.annotations, {
|
||||
address,
|
||||
name: changes.name,
|
||||
comment: changes.comment,
|
||||
inline_comment: changes.inline_comment,
|
||||
});
|
||||
assert.deepEqual(updated.effects, {
|
||||
scope: "session-analysis-database",
|
||||
source_bytes_modified: false,
|
||||
persists_after_close: false,
|
||||
});
|
||||
assert.equal(updated.dossier.procedure.name, changes.name);
|
||||
assert.equal(
|
||||
await call("procedure_address", { procedure: changes.name }),
|
||||
address,
|
||||
);
|
||||
assert.equal(
|
||||
(await call("procedure_info", { procedure: changes.name })).entrypoint,
|
||||
address,
|
||||
);
|
||||
assert.equal(
|
||||
(await call("read_function_instructions", { procedure: changes.name }))
|
||||
.procedure.address,
|
||||
address,
|
||||
);
|
||||
assert.equal(
|
||||
(await call("analyze_function", { procedure: changes.name })).procedure
|
||||
.name,
|
||||
changes.name,
|
||||
);
|
||||
assert.equal(await call("address_name", { address }), changes.name);
|
||||
for (const inventory of ["list_names", "list_procedures"])
|
||||
assert.ok(
|
||||
(await call(inventory)).some(
|
||||
(item) => item.address === address && item.value === changes.name,
|
||||
),
|
||||
);
|
||||
assert.ok(
|
||||
(
|
||||
await call("search_procedures", { pattern: "dead", case_sensitive: true })
|
||||
).some((item) => item.address === address),
|
||||
);
|
||||
|
||||
await invalid(
|
||||
"annotate_native_function",
|
||||
{
|
||||
procedure: changes.name,
|
||||
name: "invalid name\n",
|
||||
comment: "MUST ROLL BACK",
|
||||
inline_comment: "MUST ROLL BACK",
|
||||
},
|
||||
/Invalid function name/u,
|
||||
);
|
||||
const retained = await call("annotate_native_function", {
|
||||
procedure: changes.name,
|
||||
name: changes.name,
|
||||
});
|
||||
assert.deepEqual(retained.annotations, updated.annotations);
|
||||
const cleared = await call("annotate_native_function", {
|
||||
procedure: changes.name,
|
||||
comment: "",
|
||||
inline_comment: "",
|
||||
});
|
||||
assert.equal(cleared.annotations.comment, null);
|
||||
assert.equal(cleared.annotations.inline_comment, null);
|
||||
assert.equal(cleared.annotations.name, changes.name);
|
||||
assert.deepEqual(
|
||||
await call("read_bytes", { address, length: baseline.length }),
|
||||
bytes,
|
||||
);
|
||||
assert.equal(
|
||||
createHash("sha256")
|
||||
.update(await readFile(target.path))
|
||||
.digest("hex"),
|
||||
target.sha256,
|
||||
);
|
||||
const cliUpdated = await cli("annotate-native-function", name, [
|
||||
"--name",
|
||||
changes.name,
|
||||
"--comment",
|
||||
changes.comment,
|
||||
"--inline-comment",
|
||||
changes.inline_comment,
|
||||
]);
|
||||
assert.deepEqual(cliUpdated.annotations, updated.annotations);
|
||||
assert.deepEqual(cliUpdated.effects, updated.effects);
|
||||
await call("annotate_native_function", {
|
||||
procedure: address,
|
||||
name: "0xordinary",
|
||||
});
|
||||
assert.equal(
|
||||
await call("procedure_address", { procedure: "0xordinary" }),
|
||||
address,
|
||||
);
|
||||
assert.equal(await call("address_name", { address }), "0xordinary");
|
||||
await call("close_binary");
|
||||
await assert.rejects(access(socketRoot), { code: "ENOENT" });
|
||||
await assert.rejects(access(runtimeRoot), { code: "ENOENT" });
|
||||
await call("open_binary", { path: target.path, provider_id: "ghidra" });
|
||||
assert.equal(await call("procedure_address", { procedure: name }), address);
|
||||
assert.equal(await call("address_name", { address }), name);
|
||||
assert.deepEqual(
|
||||
(await call("analyze_function", { procedure: address })).comments,
|
||||
original.comments,
|
||||
);
|
||||
assert.equal(
|
||||
createHash("sha256")
|
||||
.update(await readFile(target.path))
|
||||
.digest("hex"),
|
||||
target.sha256,
|
||||
);
|
||||
await verifyStartupCancellation(client, call, target, env, options);
|
||||
return {
|
||||
mocked: false,
|
||||
catalog_tools: catalog.tools.length,
|
||||
successful_calls: successfulCalls,
|
||||
rejected_calls: rejectedCalls,
|
||||
cli_mcp_parity: true,
|
||||
mutation_rollback: true,
|
||||
source_immutable: true,
|
||||
reopen_discards_edits: true,
|
||||
long_tmpdir_private_socket_cleanup: true,
|
||||
real_startup_cancellation_cleanup: true,
|
||||
};
|
||||
}
|
||||
|
||||
async function verifyStartupCancellation(client, call, target, env, options) {
|
||||
await call("close_binary");
|
||||
await call("open_binary", { path: target.path, provider_id: "ghidra" });
|
||||
// The composite provider selects the target lazily. Use a fresh search input
|
||||
// so persisted immutable snapshots cannot bypass actual provider startup.
|
||||
const request = {
|
||||
name: "search_procedures",
|
||||
arguments: { pattern: `startup-cancellation-${randomUUID()}` },
|
||||
};
|
||||
const controller = new AbortController();
|
||||
let settled = false;
|
||||
let outcome;
|
||||
const pending = client
|
||||
.callTool(request, { ...options, signal: controller.signal })
|
||||
.then(
|
||||
(reply) => {
|
||||
settled = true;
|
||||
outcome = reply;
|
||||
return { reply };
|
||||
},
|
||||
(error) => {
|
||||
settled = true;
|
||||
outcome = String(error);
|
||||
return { error };
|
||||
},
|
||||
);
|
||||
const deadline = Date.now() + 30000;
|
||||
let launched;
|
||||
try {
|
||||
while (Date.now() < deadline && !settled) {
|
||||
const roots = (await readdir(env.TMPDIR)).filter((name) =>
|
||||
name.startsWith("rea-ghidra-"),
|
||||
);
|
||||
if (roots.length === 1) {
|
||||
const root = join(env.TMPDIR, roots[0]);
|
||||
try {
|
||||
const ownership = JSON.parse(
|
||||
await readFile(join(root, "ownership.json"), "utf8"),
|
||||
);
|
||||
const endpointPath = ownership.endpoint_path;
|
||||
// Observe the JVM inside the owned process group before the bridge
|
||||
// publishes its socket. A log file can appear after analysis finishes.
|
||||
const { stdout } = await promisify(execFile)("ps", [
|
||||
"-axo",
|
||||
"pid=,pgid=,comm=",
|
||||
]);
|
||||
const javaProcess = stdout.split("\n").find((line) => {
|
||||
const fields = line.trim().split(/\s+/u);
|
||||
return (
|
||||
Number(fields[1]) === ownership.process_group_id &&
|
||||
/(?:^|\/)java$/u.test(fields.slice(2).join(" "))
|
||||
);
|
||||
});
|
||||
if (javaProcess === undefined) {
|
||||
await delay(25);
|
||||
continue;
|
||||
}
|
||||
const javaPid = Number(javaProcess.trim().split(/\s+/u)[0]);
|
||||
await assert.rejects(access(endpointPath), { code: "ENOENT" });
|
||||
process.kill(ownership.pid, 0);
|
||||
launched = {
|
||||
root,
|
||||
socketRoot: dirname(endpointPath),
|
||||
pid: ownership.pid,
|
||||
javaPid,
|
||||
};
|
||||
break;
|
||||
} catch (error) {
|
||||
if (error.code !== "ENOENT") throw error;
|
||||
}
|
||||
}
|
||||
await delay(25);
|
||||
}
|
||||
assert.ok(
|
||||
launched,
|
||||
`No real headless process was observed before cancellation: ${JSON.stringify(outcome)}`,
|
||||
);
|
||||
assert.equal(
|
||||
settled,
|
||||
false,
|
||||
"Cancellation must interrupt pending provider work",
|
||||
);
|
||||
} finally {
|
||||
controller.abort();
|
||||
await pending;
|
||||
}
|
||||
const cleanupDeadline = Date.now() + 30000;
|
||||
while (Date.now() < cleanupDeadline) {
|
||||
const processGone = [launched.pid, launched.javaPid].every((pid) => {
|
||||
try {
|
||||
process.kill(pid, 0);
|
||||
return false;
|
||||
} catch (error) {
|
||||
if (error.code === "ESRCH") return true;
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
try {
|
||||
await access(launched.root);
|
||||
} catch (error) {
|
||||
if (error.code === "ENOENT" && processGone) break;
|
||||
if (error.code === "ENOENT") {
|
||||
await delay(25);
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
await delay(25);
|
||||
}
|
||||
await assert.rejects(access(launched.root), { code: "ENOENT" });
|
||||
await assert.rejects(access(launched.socketRoot), { code: "ENOENT" });
|
||||
assert.throws(() => process.kill(launched.pid, 0), { code: "ESRCH" });
|
||||
assert.throws(() => process.kill(launched.javaPid, 0), { code: "ESRCH" });
|
||||
assert.equal(
|
||||
(await call("binary_session")).open,
|
||||
true,
|
||||
"Cancellation must preserve the selected target",
|
||||
);
|
||||
assert.deepEqual(
|
||||
await call(request.name, request.arguments),
|
||||
[],
|
||||
"A cancelled startup must allow a fresh provider query",
|
||||
);
|
||||
}
|
||||
@@ -255,7 +255,7 @@ export async function assertSession(
|
||||
session.provider.version !== SUPPORTED_GHIDRA_VERSION ||
|
||||
session.profile_digest !== expectedDigest ||
|
||||
session.target.sha256 !== expectedTargetSha256 ||
|
||||
session.read_only !== true ||
|
||||
session.read_only !== false ||
|
||||
session.analysis_complete !== true ||
|
||||
session.analysis_timed_out !== false ||
|
||||
session.capabilities.length !== GHIDRA_SESSION_CAPABILITIES.length ||
|
||||
@@ -279,7 +279,12 @@ export function assertRuntimeCoordinates(coordinates) {
|
||||
}
|
||||
|
||||
export async function assertCleanup(coordinates) {
|
||||
for (const name of ["runtime_root", "endpoint_path", "project_root"]) {
|
||||
for (const name of [
|
||||
"runtime_root",
|
||||
"endpoint_path",
|
||||
"project_root",
|
||||
"socket_root",
|
||||
]) {
|
||||
const path = coordinates[name];
|
||||
if (typeof path === "string" && (await exists(path)))
|
||||
throw new Error(`Ghidra cleanup left ${name}: ${path}`);
|
||||
|
||||
@@ -99,7 +99,7 @@ try {
|
||||
});
|
||||
const target = await call("open_binary", {
|
||||
path: targetPath,
|
||||
provider: "ghidra",
|
||||
provider_id: "ghidra",
|
||||
});
|
||||
opened = true;
|
||||
assert.equal(target.format, "dos-mz");
|
||||
@@ -562,9 +562,8 @@ async function evidenceCall(name, arguments_) {
|
||||
normalized_result: result.structuredContent?.result,
|
||||
});
|
||||
assert.equal(evidence.subject.digest.sha256, sha256);
|
||||
assert.equal(evidence.provider.id, "rea-workflow");
|
||||
assert.equal(evidence.analysis_profile.provider.id, "rea-workflow");
|
||||
assertProfile(evidence.analysis_profile.parameters.upstream_analysis_profile);
|
||||
assert.equal(evidence.provider.id, "ghidra");
|
||||
assertProfile(evidence.analysis_profile);
|
||||
return evidence;
|
||||
}
|
||||
async function cliEvidence(command, procedure, options = []) {
|
||||
|
||||
@@ -214,7 +214,7 @@ async function verifyTarget(path, sha256, fixtures, variant) {
|
||||
});
|
||||
const target = await call(client, "open_binary", {
|
||||
path,
|
||||
provider: "ghidra",
|
||||
provider_id: "ghidra",
|
||||
});
|
||||
opened = true;
|
||||
assert.equal(target.sha256, sha256);
|
||||
|
||||
Reference in New Issue
Block a user