mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
* refactor(verify): give the android, electron, firmware, ghidra-seed, harmony, inspector and managed verifiers' roots to VerifierFixture Each root is removed only after the MCP clients, transports, owned processes and file handles that may still use it confirm cleanup; a failed cleanup retains and names the root. The verifier-fixture-root baseline shrinks from 90 files / 95 sites to 80 / 85. * fix(verify): keep nested Electron and inspector children owned by the fixture, and plain roots where Windows creates directories The Electron cancellation CLI and application, and each inspector target, now register their stop with the fixture (onceConfirmed keeps the early stop), so the root is removed only after they confirm. The android and inspector verifiers keep a plain directory as before: tools create directories beneath the root, which a private root blocks on Windows.
178 lines
5.6 KiB
JavaScript
178 lines
5.6 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import assert from "node:assert/strict";
|
|
import { writeFile } from "node:fs/promises";
|
|
import { isAbsolute, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import {
|
|
spawnOwnedProviderProcess,
|
|
ProviderProcessSupervisor,
|
|
} from "../../../dist/process/ProviderProcess.js";
|
|
import { cleanupOwnedProcessGroup } from "../../../dist/process/ProcessOwnership.js";
|
|
import { createVerifierRun } from "../../lib/verifier-run.mjs";
|
|
import {
|
|
VerifierFixture,
|
|
withVerifierFixture,
|
|
} from "../../lib/verifier-fixture.mjs";
|
|
|
|
const installation = process.env.GHIDRA_INSTALL_DIR;
|
|
assert.ok(
|
|
installation && isAbsolute(installation),
|
|
"Set GHIDRA_INSTALL_DIR to a local Ghidra installation",
|
|
);
|
|
assert.notEqual(
|
|
process.platform,
|
|
"win32",
|
|
"This direct headless regression requires a POSIX host; Windows uses its controlled provider lane",
|
|
);
|
|
const workspaceFixture = await VerifierFixture.open({
|
|
prefix: "rea-ghidra-seed-regression-",
|
|
});
|
|
const workspace = workspaceFixture.path;
|
|
const run = createVerifierRun();
|
|
let supervisor;
|
|
// The owned Ghidra process may still use the workspace: its stop confirms
|
|
// before the root is removed.
|
|
workspaceFixture.releaseAfter(async () => {
|
|
if (supervisor === undefined) return;
|
|
const stopped = await supervisor.stop();
|
|
assert.notEqual(stopped.status, "incomplete", JSON.stringify(stopped));
|
|
supervisor.dispose();
|
|
});
|
|
await withVerifierFixture(workspaceFixture, async () => {
|
|
const target = join(workspace, "seed-functions.bin");
|
|
const seeds = join(workspace, "seeds.tsv");
|
|
// Falling through from the lower entry reaches the higher entry. Creating
|
|
// the higher function first is what keeps the two function bodies separate.
|
|
await writeFile(target, Buffer.from([0x90, 0x90, 0xc3]));
|
|
await writeFile(
|
|
seeds,
|
|
[
|
|
"0x0\tfunction\tseed_low",
|
|
"0x100000000\tfunction\tout_of_range",
|
|
"0x1\tfunction\tseed_high",
|
|
"0x1000\tlabel\tseed_global",
|
|
"0x1000\tcode",
|
|
"",
|
|
].join("\n"),
|
|
);
|
|
const output = await runHeadless(target, "seed-regression", [
|
|
"-postScript",
|
|
"ReaSeedRegressionProbe.java",
|
|
seeds,
|
|
]);
|
|
// Headless can exit zero after a script fails, so require the probe's marker.
|
|
assert.ok(output.includes("REA_SEED_REGRESSION_OK "), output);
|
|
|
|
const analyzer = "Decompiler Switch Analysis";
|
|
const disabled = await runHeadless(target, "analyzer-regression-valid", [
|
|
"-preScript",
|
|
"ReaGhidraAnalysisOptions.java",
|
|
analyzer,
|
|
"-postScript",
|
|
"ReaAnalyzerOptionsRegressionProbe.java",
|
|
analyzer,
|
|
]);
|
|
assert.ok(
|
|
disabled.includes(`REA_ANALYZER_OPTIONS_DISABLED_OK ${analyzer}`),
|
|
disabled,
|
|
);
|
|
|
|
// Installed, but Ghidra registers it only for Objective-C 2 Mach-O programs.
|
|
const formatSpecificAnalyzer = "Objective-C Message Analyzer";
|
|
const notApplicable = await runHeadless(
|
|
target,
|
|
"analyzer-regression-not-applicable",
|
|
[
|
|
"-preScript",
|
|
"ReaGhidraAnalysisOptions.java",
|
|
`${analyzer},${formatSpecificAnalyzer}`,
|
|
"-postScript",
|
|
"ReaAnalyzerOptionsRegressionProbe.java",
|
|
analyzer,
|
|
],
|
|
);
|
|
assert.ok(
|
|
notApplicable.includes(
|
|
`REA_ANALYZER_OPTIONS_REPORT ${JSON.stringify({
|
|
format: "rea-ghidra-disabled-analyzers-v1",
|
|
analyzers: [
|
|
{ name: analyzer, status: "disabled" },
|
|
{ name: formatSpecificAnalyzer, status: "not_applicable" },
|
|
],
|
|
})}`,
|
|
),
|
|
notApplicable,
|
|
);
|
|
|
|
const unknownAnalyzer = "REA Unknown Analyzer";
|
|
const rejected = await runHeadless(target, "analyzer-regression-unknown", [
|
|
"-preScript",
|
|
"ReaGhidraAnalysisOptions.java",
|
|
`${analyzer},${unknownAnalyzer}`,
|
|
"-postScript",
|
|
"ReaAnalyzerOptionsRegressionProbe.java",
|
|
analyzer,
|
|
]);
|
|
assert.ok(
|
|
rejected.includes(
|
|
`REA_GHIDRA_DISABLED_ANALYZERS names ${unknownAnalyzer}, which is not an analyzer in this Ghidra installation`,
|
|
),
|
|
rejected,
|
|
);
|
|
assert.ok(
|
|
rejected.includes("Processing aborted as a result of pre-script."),
|
|
rejected,
|
|
);
|
|
assert.ok(!rejected.includes("REA_ANALYZER_OPTIONS_DISABLED_OK"), rejected);
|
|
});
|
|
console.log(
|
|
"Real Ghidra pre-script regression passed: descending function order, out-of-range seed, BSS label, BSS code rejection, analyzer option readback, not-applicable analyzer report, unknown-analyzer abort before post-scripts, and owned-process cleanup.",
|
|
);
|
|
|
|
async function runHeadless(target, project, scriptArguments) {
|
|
const launch = await spawnOwnedProviderProcess({
|
|
command: join(installation, "support", "analyzeHeadless"),
|
|
arguments: [
|
|
workspace,
|
|
project,
|
|
"-import",
|
|
target,
|
|
"-loader",
|
|
"BinaryLoader",
|
|
"-processor",
|
|
"x86:LE:32:default",
|
|
"-noanalysis",
|
|
"-readOnly",
|
|
"-deleteProject",
|
|
"-scriptPath",
|
|
[
|
|
fileURLToPath(new URL("../../../bridge/ghidra", import.meta.url)),
|
|
fileURLToPath(
|
|
new URL("../../../tests/conformance/ghidra", import.meta.url),
|
|
),
|
|
].join(";"),
|
|
...scriptArguments,
|
|
],
|
|
runId: run.run_id,
|
|
expectedCommand: null,
|
|
});
|
|
supervisor = new ProviderProcessSupervisor({
|
|
...launch,
|
|
ownsProcessLifetime: true,
|
|
cleanup: () => cleanupOwnedProcessGroup(launch.ownership),
|
|
});
|
|
assert.ok(
|
|
await supervisor.waitForExit(180_000),
|
|
"Ghidra seed regression exceeded its startup deadline",
|
|
);
|
|
const snapshot = supervisor.snapshot();
|
|
const output = `${snapshot.stdout.text}\n${snapshot.stderr.text}`;
|
|
assert.equal(snapshot.exitCode, 0, output);
|
|
const stopped = await supervisor.stop();
|
|
assert.notEqual(stopped.status, "incomplete", JSON.stringify(stopped));
|
|
supervisor.dispose();
|
|
supervisor = undefined;
|
|
return output;
|
|
}
|