mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
* feat(ghidra)!: verify the bridge on Ghidra 12.2 Admit 12.x from minor 2 upward, with 12.2 and JDK 25 as the verified pair. The bridge now calls the four-argument storage API added in 12.2, so 12.1.x cannot compile it and is no longer accepted. BREAKING CHANGE: Ghidra 12.1.x is rejected. Use Ghidra 12.2 or another 12.x build at or above minor 2, and a JDK inside that installation's declared range (25 or newer for the verified 12.2 build). * docs(ghidra): point remaining lanes at Ghidra 12.2 The Windows, 6502, and m68k prerequisites still named 12.1.4 and JDK 21, which the verified-build check now rejects. The bridge compile lane names the 12.2 jars it actually compiles against. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(ghidra): admit the JDK the verified install declares The Java home framing probe still reported JDK 21 while the verified installation fixture now declares a minimum of 25, so doctor admission failed before the path framing was checked. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(ghidra): derive admitted install fixtures from the verified release Boundary hosts and assertions still named Ghidra 12.1.4 after admission moved to 12.2, so list_procedures evidence and completed property reads disagreed with the install the provider actually reported. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(ghidra): record the exact 12.2 Clang switch-recovery defect Ghidra 12.2 stays the verified build. Sessions and decompiler results on that exact version name upstream issue 9996 and the 12.2.1 fix commit. Other version strings, including 12.2.1, do not carry the limitation. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(ghidra): check switch-defect facts instead of the warning sentence The policy test keeps the structured defect record and checks that the owning formatter delivers its id, commit, release, and scope fields. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(browser): name the Playwright launch boundary the lifecycle catalog checks Main retitled that case with a platform placeholder. The coverage catalog still required the old literal, so the merged full suite reported a missing title. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(browser): point the lifecycle catalog at main's launch title The merged suite uses main's platform-specific Playwright launch test. The coverage catalog now names that title, and this branch keeps main's test body so the merge stays clean. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(browser): cover the platform launch title on this branch The lifecycle catalog names main's platform launch title. This branch now has that quoted test too, so the check passes before and after the merge. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(ghidra): record the exact 12.2 masked byte-switch defect Ghidra 12.2 leaves an AArch64 and-0xff byte-offset switch unrecovered. Exact 12.2 sessions now cite open upstream issue 10154, and the AArch64 lane expects that jump table to stay unrecovered. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(browser): keep one platform launch environment check The second launch test repeated the selected environment check. The remaining test is the parameterized title, and the launcher forwards SYSTEMROOT on win32 so that assertion holds. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(ghidra): keep the open switch defect on admitted builds The exact-version check cleared ghidra-10154 on every build except 12.2. That defect stays on admitted releases until one is known to fix it. ghidra-9996 still clears after the exact 12.2 build. Co-authored-by: morluto <morluto@users.noreply.github.com> * style(docs): format the Ghidra testing-lane table The AArch64 jump-table row wrapped past the formatter width and failed static checks. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(ghidra): give the masked switch its full byte range The unrecovered oracle now uses 256 readable table bytes, and the same object must still recover its compare-bounded switch. Co-authored-by: morluto <morluto@users.noreply.github.com> * docs(website): point Ghidra setup at 12.2 and JDK 25 The public setup pages still told new users to install Ghidra 12.1.4 and JDK 21, which this release rejects. Changed setup sentences are extracted and left untranslated so those editions use the English page. Co-authored-by: morluto <morluto@users.noreply.github.com> * docs(website): keep catalog edits to the changed setup strings The catalog check compares active message ids, not a full rewrite. Restore the previous catalogs and update only the Ghidra 12.2 setup strings, leaving their translations empty. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(ghidra): apply the closed switch defect from the parsed patch 12.2, 12.2.0, and 12.2.0 with a suffix all precede 12.2.1, so they keep ghidra-9996. The masked-switch table lists all 256 byte entries. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(ghidra): share the AArch64 switch fixture compiler invocation --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
305 lines
11 KiB
TypeScript
305 lines
11 KiB
TypeScript
import { chmod, mkdir, readFile, symlink, writeFile } from "node:fs/promises";
|
|
import { delimiter, isAbsolute, join } from "node:path";
|
|
import { setTimeout as delay } from "node:timers/promises";
|
|
import { expect } from "vitest";
|
|
import { elf, thinMach } from "../../../src/domain/binaryTarget.fixture.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
import {
|
|
observeOwnedProcessGroups,
|
|
systemProcessOwnershipHost,
|
|
} from "../../../src/process/ProcessOwnershipObservation.js";
|
|
import { resolveProcessScenarioRuntimePaths } from "../../../src/process/capture/ProcessScenarioRuntimeValidation.js";
|
|
import { processScenarioSchema } from "../../../src/domain/process/processScenario.js";
|
|
|
|
cliTest.skipIf(!["darwin", "linux"].includes(process.platform)).for([
|
|
["missing", "missing_dependency", "runtime_missing"],
|
|
["nonzero", "runtime_failure", "runtime_unavailable"],
|
|
["properties", "config_drift", "version_unresolved"],
|
|
] as const)(
|
|
"preserves the %s Java prerequisite result through doctor",
|
|
async ([failure, classification, code], { cli }) => {
|
|
const root = await createTestTempDirectory("rea-java-doctor-");
|
|
const jdk = join(root, "jdk");
|
|
const install = join(root, "ghidra");
|
|
const platform = process.platform === "darwin" ? "mac" : "linux";
|
|
const architecture = process.arch === "arm64" ? "arm_64" : "x86_64";
|
|
const native = join(
|
|
install,
|
|
"Ghidra/Features/Decompiler/os",
|
|
`${platform}_${architecture}`,
|
|
"decompile",
|
|
);
|
|
for (const path of [
|
|
join(jdk, "bin"),
|
|
join(install, "support"),
|
|
join(install, "Ghidra"),
|
|
join(native, ".."),
|
|
])
|
|
await mkdir(path, { recursive: true });
|
|
await writeFile(
|
|
join(install, "Ghidra/application.properties"),
|
|
"application.version=12.2\napplication.java.min=25\n",
|
|
);
|
|
await writeFile(
|
|
join(install, "support/analyzeHeadless"),
|
|
"#!/bin/sh\nexit 99\n",
|
|
);
|
|
await chmod(join(install, "support/analyzeHeadless"), 0o700);
|
|
await writeFile(
|
|
native,
|
|
process.platform === "darwin"
|
|
? thinMach(
|
|
0xfeedfacf,
|
|
process.arch === "arm64" ? 0x0100000c : 0x01000007,
|
|
)
|
|
: elf(2, 1, process.arch === "arm64" ? 183 : 62),
|
|
);
|
|
await chmod(native, 0o700);
|
|
if (failure !== "missing") {
|
|
const body =
|
|
failure === "nonzero"
|
|
? 'process.stderr.write("controlled runtime failure\\n"); process.exit(7);'
|
|
: `process.stdout.write(${JSON.stringify(`java.home = ${jdk}\nos.arch = aarch64\n`)});`;
|
|
await writeFile(
|
|
join(jdk, "bin/java"),
|
|
`#!${process.execPath}\n${body}\n`,
|
|
);
|
|
await chmod(join(jdk, "bin/java"), 0o700);
|
|
}
|
|
const result = await cli.run({
|
|
arguments: ["doctor", "--provider", "ghidra", "--json"],
|
|
environment: {
|
|
JAVA_HOME: jdk,
|
|
GHIDRA_INSTALL_DIR: install,
|
|
REA_LOG_LEVEL: "silent",
|
|
},
|
|
});
|
|
expect(result.exitCode, `${result.stdout}\n${result.stderr}`).toBe(1);
|
|
expect(result.json).toMatchObject({
|
|
checks: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
name: "ghidra-java",
|
|
classification,
|
|
ok: false,
|
|
}),
|
|
]),
|
|
providerInspections: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: "ghidra",
|
|
checks: expect.arrayContaining([
|
|
expect.objectContaining({ name: "java", code }),
|
|
]),
|
|
}),
|
|
]),
|
|
});
|
|
if (failure === "nonzero")
|
|
expect(result.json).toMatchObject({
|
|
checks: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
name: "ghidra-java",
|
|
detail: expect.stringContaining("Java exited 7"),
|
|
details: expect.objectContaining({
|
|
output: expect.objectContaining({
|
|
stderr: "controlled runtime failure\n",
|
|
exit_code: 7,
|
|
stderr_bytes: 27,
|
|
}),
|
|
}),
|
|
}),
|
|
]),
|
|
});
|
|
if (failure === "properties")
|
|
expect(result.json).toMatchObject({
|
|
checks: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
name: "ghidra-java",
|
|
details: expect.objectContaining({
|
|
properties: expect.objectContaining({ home: jdk, version: null }),
|
|
}),
|
|
}),
|
|
]),
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest.skipIf(!["darwin", "linux"].includes(process.platform))(
|
|
"doctor returns its own deadline result for a SIGTERM-resistant selected Java command",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-java-doctor-deadline-");
|
|
const jdk = join(root, "jdk");
|
|
const install = join(root, "ghidra");
|
|
const started = join(root, "java-started.json");
|
|
const release = join(root, "release-java");
|
|
await mkdir(join(jdk, "bin"), { recursive: true });
|
|
await mkdir(join(install, "Ghidra"), { recursive: true });
|
|
await writeFile(
|
|
join(install, "Ghidra/application.properties"),
|
|
"application.version=12.2\napplication.java.min=25\n",
|
|
);
|
|
await writeFile(
|
|
join(jdk, "bin/java"),
|
|
`#!${process.execPath}
|
|
const fs = require("node:fs");
|
|
process.on("SIGTERM", () => {});
|
|
fs.writeFileSync(${JSON.stringify(`${started}.tmp`)}, JSON.stringify({ pid: process.pid, runId: process.env.REA_PROCESS_RUN_ID }));
|
|
fs.renameSync(${JSON.stringify(`${started}.tmp`)}, ${JSON.stringify(started)});
|
|
setInterval(() => { if (fs.existsSync(${JSON.stringify(release)})) process.exit(0); }, 50);
|
|
setTimeout(() => process.exit(92), 12000);
|
|
`,
|
|
{ mode: 0o700 },
|
|
);
|
|
const pending = cli.run({
|
|
arguments: ["doctor", "--provider", "ghidra", "--json"],
|
|
environment: {
|
|
JAVA_HOME: jdk,
|
|
GHIDRA_INSTALL_DIR: install,
|
|
REA_LOG_LEVEL: "silent",
|
|
},
|
|
});
|
|
// Capture the actual group while the selected process is alive; the PID
|
|
// alone is never used as cleanup authority. Release is a private protocol.
|
|
let identity: { pid: number; runId: string } | undefined;
|
|
let processGroupId: number | undefined;
|
|
try {
|
|
for (let attempt = 0; attempt < 80; attempt++) {
|
|
try {
|
|
identity = JSON.parse(
|
|
await readFile(started, "utf8"),
|
|
) as typeof identity;
|
|
} catch (cause: unknown) {
|
|
if (
|
|
!(
|
|
cause instanceof Error &&
|
|
"code" in cause &&
|
|
cause.code === "ENOENT"
|
|
)
|
|
)
|
|
throw cause;
|
|
}
|
|
if (identity !== undefined) break;
|
|
await delay(50);
|
|
}
|
|
if (identity === undefined)
|
|
throw new Error("Selected Java command did not start");
|
|
expect(identity.runId).toEqual(expect.any(String));
|
|
processGroupId = (await systemProcessOwnershipHost.listProcesses()).find(
|
|
(entry) => entry.pid === identity?.pid,
|
|
)?.processGroupId;
|
|
expect(processGroupId).toBeDefined();
|
|
const result = await pending;
|
|
expect(result.exitCode, `${result.stdout}\n${result.stderr}`).toBe(1);
|
|
expect(result.signal).toBeNull();
|
|
expect(result.json).toMatchObject({
|
|
providerInspections: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: "ghidra",
|
|
checks: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
name: "java",
|
|
code: "runtime_unavailable",
|
|
details: expect.objectContaining({
|
|
process_error_code: "ETIMEDOUT",
|
|
}),
|
|
}),
|
|
]),
|
|
}),
|
|
]),
|
|
});
|
|
if (processGroupId !== undefined) {
|
|
const observed = await observeOwnedProcessGroups(identity.runId, [
|
|
processGroupId,
|
|
]);
|
|
expect(observed.get(processGroupId)).toEqual({ state: "empty" });
|
|
}
|
|
} finally {
|
|
await writeFile(release, "release");
|
|
await pending;
|
|
if (identity !== undefined && processGroupId !== undefined) {
|
|
for (let attempt = 0; attempt < 40; attempt++) {
|
|
const observed = await observeOwnedProcessGroups(identity.runId, [
|
|
processGroupId,
|
|
]);
|
|
if (observed.get(processGroupId)?.state === "empty") break;
|
|
await delay(50);
|
|
}
|
|
const observed = await observeOwnedProcessGroups(identity.runId, [
|
|
processGroupId,
|
|
]);
|
|
expect(observed.get(processGroupId)).toEqual({ state: "empty" });
|
|
}
|
|
}
|
|
},
|
|
);
|
|
|
|
cliTest.skipIf(!["darwin", "linux"].includes(process.platform))(
|
|
"doctor discovers Ghidra through an empty PATH component without executing its launchers",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-ghidra-cwd-doctor-");
|
|
const install = join(root, "installation");
|
|
const marker = join(root, "launcher-execution");
|
|
const bin = join(root, "bin");
|
|
await mkdir(bin);
|
|
const hostPath = process.env.PATH?.split(delimiter)
|
|
.filter((directory) => isAbsolute(directory))
|
|
.join(delimiter);
|
|
await symlink(
|
|
(
|
|
await resolveProcessScenarioRuntimePaths(
|
|
processScenarioSchema.parse({
|
|
executable: "ps",
|
|
working_directory: process.cwd(),
|
|
}),
|
|
{ PATH: hostPath },
|
|
process.platform,
|
|
)
|
|
).executable,
|
|
join(bin, "ps"),
|
|
);
|
|
await mkdir(join(install, "Ghidra"), { recursive: true });
|
|
await mkdir(join(install, "support"), { recursive: true });
|
|
await writeFile(
|
|
join(install, "Ghidra/application.properties"),
|
|
"application.version=12.2\napplication.java.min=25\n",
|
|
);
|
|
await writeFile(marker, "unexecuted");
|
|
const launcher = `#!${process.execPath}\nrequire("node:fs").writeFileSync(${JSON.stringify(marker)}, "executed");\n`;
|
|
for (const name of ["ghidraRun", "support/analyzeHeadless"])
|
|
await writeFile(join(install, name), launcher, { mode: 0o700 });
|
|
await symlink(join(install, "ghidraRun"), join(root, "ghidra"));
|
|
|
|
const result = await cli.run({
|
|
arguments: ["doctor", "--provider", "ghidra", "--json"],
|
|
cwd: root,
|
|
environment: {
|
|
// Keep CWD discovery first while admitting only the ownership prerequisite.
|
|
PATH: ["", bin].join(delimiter),
|
|
JAVA_HOME: join(root, "missing-jdk"),
|
|
REA_LOG_LEVEL: "silent",
|
|
},
|
|
});
|
|
// The fixture deliberately has no JDK or native decompiler. Discovery must
|
|
// retain the selected installation while reporting those later failures.
|
|
expect(result.exitCode, `${result.stdout}\n${result.stderr}`).toBe(1);
|
|
expect(result.json).toMatchObject({
|
|
providerInspections: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: "ghidra",
|
|
configured: true,
|
|
checks: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
name: "configuration",
|
|
ok: true,
|
|
code: null,
|
|
detail: install,
|
|
}),
|
|
expect.objectContaining({ name: "installation", ok: true }),
|
|
expect.objectContaining({ name: "headless", ok: true }),
|
|
]),
|
|
}),
|
|
]),
|
|
});
|
|
expect(await readFile(marker, "utf8")).toBe("unexecuted");
|
|
},
|
|
);
|