* fix(ghidra): fail doctor when the JVM os.arch selects an unvalidated decompiler directory probeJava now also reads the JVM os.arch property. When it maps to a different native decompiler directory than the one validated from the host architecture (for example an x86_64 JDK under Rosetta on Apple silicon selecting os/mac_x86_64 while only mac_arm_64 was built), the native_decompiler check fails with a remediation pointing at a matching-arch JDK instead of reporting a healthy installation that fails every analysis. Unknown os.arch values keep the previous behavior. * fix(ghidra): tighten JVM arch remediation and cover os.arch extraction Address review findings on the JVM os.arch decompiler-directory check: - The remediation no longer suggests building the decompiler for the JVM-selected directory, which could never clear the check; it only advises pointing JAVA_HOME at a matching-architecture JDK. - Add a test running the real Java probe against captured -XshowSettings:properties output, asserting os.arch reaches the installation diagnostics. - Document the JDK-architecture prerequisite in the Ghidra setup guide. * fix(ghidra): refuse unrecognized JVM native architectures * docs(ghidra): align doctor prerequisites with JVM architecture admission * fix(ghidra): reject unreported JVM architecture * test(ghidra): separate JVM and executable admission cases * fix(ghidra): defer decompiler arch validation when Java is absent * fix(ghidra): reject JVM native architecture override * fix(ghidra): validate JVM platform overrides * fix(ghidra): validate JVM os.name and helper-environment platform overrides * test(ci): isolate report fixtures and declare PowerPC Java bounds * test(ghidra): provide observed JVM platform in PowerPC fixture * fix(ghidra): parse quoted JVM environment options before admission --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
282 lines
8.5 KiB
TypeScript
282 lines
8.5 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import { runDoctor, type DoctorHost } from "../application/Doctor.js";
|
|
import { createDoctorHostFixture } from "../application/Doctor.fixture.js";
|
|
import { providerRegistrationEnvironment } from "../application/SetupRegistrationEnvironment.js";
|
|
import { WINDOWS_NATIVE_AUTHORITY_UNAVAILABLE_REASON } from "../process/WindowsAuthority.js";
|
|
import * as windowsAuthority from "../process/WindowsAuthority.js";
|
|
import {
|
|
inspectGhidraInstallation,
|
|
type GhidraInstallationHost,
|
|
type GhidraInstallationInspection,
|
|
} from "./GhidraInstallation.js";
|
|
import { projectGhidraDoctorInspection } from "./GhidraDoctor.js";
|
|
|
|
const INSTALL = "/opt/ghidra_12.1.4_PUBLIC";
|
|
const installationHost = (
|
|
overrides: Partial<GhidraInstallationHost> = {},
|
|
platform: NodeJS.Platform = "linux",
|
|
): GhidraInstallationHost => ({
|
|
readText: () => "application.version=12.1.4\napplication.java.min=21\n",
|
|
executable: () => true,
|
|
probeJava: () => ({
|
|
osArch: "amd64",
|
|
osName: platform === "win32" ? "Windows 11" : "Linux",
|
|
version: "21.0.11",
|
|
major: 21,
|
|
home: "/usr/lib/jvm/jdk-21",
|
|
bits: 64,
|
|
runtime: "jdk",
|
|
}),
|
|
...overrides,
|
|
});
|
|
|
|
const inspection = (
|
|
options: {
|
|
readonly installDir?: string;
|
|
readonly architecture?: NodeJS.Architecture;
|
|
readonly platform?: NodeJS.Platform;
|
|
} = { installDir: INSTALL },
|
|
overrides: Partial<GhidraInstallationHost> = {},
|
|
): GhidraInstallationInspection =>
|
|
inspectGhidraInstallation(
|
|
{
|
|
environment: {},
|
|
platform: options.platform ?? "linux",
|
|
architecture: options.architecture ?? "x64",
|
|
...(options.installDir === undefined
|
|
? {}
|
|
: { installDir: options.installDir }),
|
|
},
|
|
installationHost(overrides, options.platform ?? "linux"),
|
|
);
|
|
|
|
const doctorHost = (
|
|
ghidra: GhidraInstallationInspection,
|
|
hopperAvailable = false,
|
|
): DoctorHost =>
|
|
createDoctorHostFixture({
|
|
platform: "linux",
|
|
architecture: "x64",
|
|
macosVersion: () => Promise.resolve(undefined),
|
|
linuxDistribution: () =>
|
|
Promise.resolve({
|
|
id: "ubuntu",
|
|
versionId: "24.04",
|
|
packageFamily: "deb",
|
|
hopperSetupSupported: true,
|
|
}),
|
|
validTarget: () => Promise.resolve(true),
|
|
executable: (path) =>
|
|
Promise.resolve(hopperAvailable && path.includes("Hopper")),
|
|
supportedLinuxHopper: () => Promise.resolve(true),
|
|
linuxDemoRuntimeCheck: () =>
|
|
Promise.resolve({
|
|
name: "hopper-demo-runtime",
|
|
ok: true,
|
|
classification: "healthy",
|
|
}),
|
|
brewHopperPath: () => Promise.resolve(undefined),
|
|
manualHopperPaths: () => Promise.resolve([]),
|
|
providerInspections: () =>
|
|
Promise.resolve([projectGhidraDoctorInspection(ghidra)]),
|
|
});
|
|
|
|
describe("Ghidra doctor integration", () => {
|
|
it("accepts a valid BYO Ghidra engine when Hopper is absent", async () => {
|
|
const result = await runDoctor(undefined, doctorHost(inspection()));
|
|
|
|
expect(result.healthy).toBe(true);
|
|
expect(result.hopperPath).toBeUndefined();
|
|
expect(result.providerInspections?.[0]).toMatchObject({
|
|
id: "ghidra",
|
|
available: true,
|
|
providerVersion: "12.1.4",
|
|
registrationEnvironment: {
|
|
GHIDRA_INSTALL_DIR: INSTALL,
|
|
JAVA_HOME: "/usr/lib/jvm/jdk-21",
|
|
},
|
|
});
|
|
expect(
|
|
result.checks.find(({ name }) => name === "ghidra-java"),
|
|
).toMatchObject({
|
|
ok: true,
|
|
detail: expect.stringContaining("21.0.11"),
|
|
});
|
|
});
|
|
|
|
it.each([
|
|
[
|
|
"bad installation",
|
|
inspection({ installDir: INSTALL }, { readText: () => undefined }),
|
|
"ghidra-installation",
|
|
],
|
|
[
|
|
"wrong version",
|
|
inspection(
|
|
{ installDir: INSTALL },
|
|
{
|
|
readText: () => "application.version=11.4\napplication.java.min=21\n",
|
|
},
|
|
),
|
|
"ghidra-version",
|
|
],
|
|
[
|
|
"missing analyzeHeadless",
|
|
inspection({ installDir: INSTALL }, { executable: () => false }),
|
|
"ghidra-headless",
|
|
],
|
|
[
|
|
"wrong Java",
|
|
inspection(
|
|
{ installDir: INSTALL },
|
|
{
|
|
probeJava: () => ({
|
|
osArch: "amd64",
|
|
osName: "Linux",
|
|
version: "17.0.12",
|
|
major: 17,
|
|
home: "/usr/lib/jvm/jdk-17",
|
|
bits: 64,
|
|
runtime: "jdk",
|
|
}),
|
|
},
|
|
),
|
|
"ghidra-java",
|
|
],
|
|
[
|
|
"missing Java minimum",
|
|
inspection(
|
|
{ installDir: INSTALL },
|
|
{ readText: () => "application.version=12.1.4\n" },
|
|
),
|
|
"ghidra-java",
|
|
],
|
|
[
|
|
"unsupported architecture",
|
|
inspection({ installDir: INSTALL, architecture: "arm" }),
|
|
"ghidra-architecture",
|
|
],
|
|
] as const)("distinguishes %s", async (_label, ghidra, checkName) => {
|
|
const result = await runDoctor(undefined, doctorHost(ghidra, true));
|
|
|
|
expect(result.healthy).toBe(false);
|
|
expect(result.checks.find(({ name }) => name === checkName)).toMatchObject({
|
|
ok: false,
|
|
remediation: expect.any(String),
|
|
});
|
|
});
|
|
|
|
it("treats unconfigured Ghidra as optional when Hopper is healthy", async () => {
|
|
const result = await runDoctor(undefined, doctorHost(inspection({}), true));
|
|
|
|
expect(result.healthy).toBe(true);
|
|
expect(result.checks.find(({ name }) => name === "ghidra")).toMatchObject({
|
|
ok: false,
|
|
classification: "missing_analysis_engine",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("Windows Ghidra doctor authority", () => {
|
|
beforeEach(() => {
|
|
vi.spyOn(windowsAuthority, "hasWindowsNativeAuthority").mockReturnValue(
|
|
false,
|
|
);
|
|
vi.spyOn(
|
|
windowsAuthority,
|
|
"windowsNativeAuthorityUnavailableReason",
|
|
).mockReturnValue(WINDOWS_NATIVE_AUTHORITY_UNAVAILABLE_REASON);
|
|
});
|
|
afterEach(() => vi.restoreAllMocks());
|
|
it("distinguishes a valid Windows installation from unavailable native authority", async () => {
|
|
const ghidra = inspection({
|
|
installDir: "C:\\tools\\ghidra_12.1.4_PUBLIC",
|
|
platform: "win32",
|
|
});
|
|
const result = await runDoctor(undefined, {
|
|
...doctorHost(ghidra),
|
|
platform: "win32",
|
|
architecture: "x64",
|
|
linuxDistribution: () => Promise.resolve(undefined),
|
|
});
|
|
|
|
expect(result.healthy).toBe(false);
|
|
expect(result.providerInspections?.[0]).toMatchObject({
|
|
available: false,
|
|
providerVersion: "12.1.4",
|
|
registrationEnvironment: {
|
|
GHIDRA_INSTALL_DIR: "C:\\tools\\ghidra_12.1.4_PUBLIC",
|
|
},
|
|
});
|
|
expect(
|
|
providerRegistrationEnvironment(result.providerInspections ?? []),
|
|
).toMatchObject({
|
|
GHIDRA_INSTALL_DIR: "C:\\tools\\ghidra_12.1.4_PUBLIC",
|
|
});
|
|
expect(result.checks.find(({ name }) => name === "host")).toMatchObject({
|
|
ok: true,
|
|
detail: "win32 x64",
|
|
});
|
|
expect(result.checks.find(({ name }) => name === "ghidra")).toMatchObject({
|
|
ok: true,
|
|
});
|
|
expect(
|
|
result.checks.find(({ name }) => name === "ghidra-java"),
|
|
).toMatchObject({ ok: true });
|
|
expect(
|
|
result.checks.find(({ name }) => name === "ghidra-native_authority"),
|
|
).toMatchObject({
|
|
ok: false,
|
|
classification: "unsupported_host",
|
|
detail: WINDOWS_NATIVE_AUTHORITY_UNAVAILABLE_REASON,
|
|
remediation: expect.stringContaining("cannot enable"),
|
|
});
|
|
});
|
|
|
|
it("fails provider-scoped Windows readiness without blaming installation", async () => {
|
|
const ghidra = inspection({
|
|
installDir: "C:\\tools\\ghidra_12.1.4_PUBLIC",
|
|
platform: "win32",
|
|
});
|
|
const result = await runDoctor(
|
|
undefined,
|
|
{
|
|
...doctorHost(ghidra),
|
|
platform: "win32",
|
|
linuxDistribution: () => Promise.resolve(undefined),
|
|
},
|
|
{ providers: ["ghidra"] },
|
|
);
|
|
expect(result.healthy).toBe(false);
|
|
expect(result.scope_checks).toContainEqual(
|
|
expect.objectContaining({
|
|
name: "ghidra-native_authority",
|
|
classification: "unsupported_host",
|
|
detail: WINDOWS_NATIVE_AUTHORITY_UNAVAILABLE_REASON,
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("keeps missing Windows Java actionable as a dependency failure", () => {
|
|
const projected = projectGhidraDoctorInspection(
|
|
inspection(
|
|
{
|
|
installDir: "C:\\tools\\ghidra_12.1.4_PUBLIC",
|
|
platform: "win32",
|
|
},
|
|
{ probeJava: () => undefined },
|
|
),
|
|
);
|
|
expect(projected.available).toBe(false);
|
|
expect(projected.checks).toContainEqual(
|
|
expect.objectContaining({
|
|
name: "java",
|
|
ok: false,
|
|
classification: "missing_dependency",
|
|
remediation: expect.any(String),
|
|
}),
|
|
);
|
|
});
|
|
});
|