fix(ghidra): admit Linux arm64 with matching native tools
This commit is contained in:
@@ -138,7 +138,7 @@ describe("Ghidra doctor integration", () => {
|
||||
],
|
||||
[
|
||||
"unsupported architecture",
|
||||
inspection({ installDir: INSTALL, architecture: "arm64" }),
|
||||
inspection({ installDir: INSTALL, architecture: "arm" }),
|
||||
"ghidra-architecture",
|
||||
],
|
||||
] as const)("distinguishes %s", async (_label, ghidra, checkName) => {
|
||||
|
||||
@@ -12,10 +12,12 @@ import {
|
||||
const INSTALL = "/opt/ghidra";
|
||||
const PROPERTIES = `${INSTALL}/Ghidra/application.properties`;
|
||||
const HEADLESS = `${INSTALL}/support/analyzeHeadless`;
|
||||
const LINUX_DECOMPILER = `${INSTALL}/Ghidra/Features/Decompiler/os/linux_x86_64/decompile`;
|
||||
const MAC_DECOMPILER = `${INSTALL}/Ghidra/Features/Decompiler/os/mac_arm_64/decompile`;
|
||||
const WINDOWS_INSTALL = "C:\\tools\\ghidra_12.1.4_PUBLIC";
|
||||
const WINDOWS_PROPERTIES = `${WINDOWS_INSTALL}\\Ghidra\\application.properties`;
|
||||
const WINDOWS_HEADLESS = `${WINDOWS_INSTALL}\\support\\analyzeHeadless.bat`;
|
||||
const WINDOWS_DECOMPILER = `${WINDOWS_INSTALL}\\Ghidra\\Features\\Decompiler\\os\\win_x86_64\\decompile.exe`;
|
||||
const JAVA: GhidraJavaObservation = {
|
||||
version: "21.0.11",
|
||||
major: SUPPORTED_GHIDRA_JAVA_MAJOR,
|
||||
@@ -31,7 +33,8 @@ const host = (
|
||||
path === PROPERTIES
|
||||
? `application.version=${SUPPORTED_GHIDRA_VERSION}\n`
|
||||
: undefined,
|
||||
executable: (path) => path === HEADLESS || path === MAC_DECOMPILER,
|
||||
executable: (path) =>
|
||||
path === HEADLESS || path === MAC_DECOMPILER || path === LINUX_DECOMPILER,
|
||||
probeJava: () => JAVA,
|
||||
...overrides,
|
||||
});
|
||||
@@ -108,28 +111,29 @@ describe("Ghidra installation inspection", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["x64", "arm64"] as const)(
|
||||
"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 = {
|
||||
...host({
|
||||
platform: "darwin",
|
||||
it.each([
|
||||
["darwin", "x64", "mac_x86_64"],
|
||||
["darwin", "arm64", "mac_arm_64"],
|
||||
["linux", "arm64", "linux_arm_64"],
|
||||
] as const)(
|
||||
"accepts %s/%s with the matching distribution or locally built native tool",
|
||||
(platform, architecture, nativeDirectory) => {
|
||||
for (const location of ["os", "build/os"]) {
|
||||
const decompiler = `${INSTALL}/Ghidra/Features/Decompiler/${location}/${nativeDirectory}/decompile`;
|
||||
expect(
|
||||
inspectGhidraInstallation(
|
||||
{ installDir: INSTALL, platform, architecture },
|
||||
host({
|
||||
executable: (path) => path === HEADLESS || path === decompiler,
|
||||
}),
|
||||
),
|
||||
).toMatchObject({
|
||||
status: "available",
|
||||
platform,
|
||||
architecture,
|
||||
executable: (path) => path === HEADLESS || path === decompiler,
|
||||
}),
|
||||
};
|
||||
expect(
|
||||
inspectGhidraInstallation(
|
||||
{ installDir: INSTALL, platform: "darwin", architecture },
|
||||
macHost,
|
||||
),
|
||||
).toMatchObject({
|
||||
status: "available",
|
||||
platform: "darwin",
|
||||
architecture,
|
||||
nativeDecompilerPath: decompiler,
|
||||
});
|
||||
nativeDecompilerPath: decompiler,
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -141,7 +145,8 @@ describe("Ghidra installation inspection", () => {
|
||||
path === WINDOWS_PROPERTIES
|
||||
? `application.version=${SUPPORTED_GHIDRA_VERSION}\n`
|
||||
: undefined,
|
||||
executable: (path) => path === WINDOWS_HEADLESS,
|
||||
executable: (path) =>
|
||||
path === WINDOWS_HEADLESS || path === WINDOWS_DECOMPILER,
|
||||
probeJava: (command, environment) => {
|
||||
expect(command).toBe("C:\\Java\\jdk-21\\bin\\java.exe");
|
||||
expect(environment.PATH).toMatch(/^C:\\Java\\jdk-21\\bin;/u);
|
||||
@@ -198,7 +203,7 @@ describe("Ghidra installation rejection diagnostics", () => {
|
||||
options: {
|
||||
installDir: INSTALL,
|
||||
platform: "linux" as const,
|
||||
architecture: "arm64" as const,
|
||||
architecture: "arm" as const,
|
||||
},
|
||||
override: {},
|
||||
failed: "architecture",
|
||||
@@ -237,6 +242,17 @@ describe("Ghidra installation rejection diagnostics", () => {
|
||||
failed: "headless",
|
||||
code: "executable_missing",
|
||||
},
|
||||
{
|
||||
name: "only a foreign-architecture decompiler on Linux arm64",
|
||||
options: {
|
||||
installDir: INSTALL,
|
||||
platform: "linux" as const,
|
||||
architecture: "arm64" as const,
|
||||
},
|
||||
override: {},
|
||||
failed: "native_decompiler",
|
||||
code: "executable_missing",
|
||||
},
|
||||
{
|
||||
name: "missing Java",
|
||||
options: {
|
||||
|
||||
@@ -22,6 +22,19 @@ import {
|
||||
|
||||
export { SUPPORTED_GHIDRA_JAVA_MAJOR, SUPPORTED_GHIDRA_VERSION };
|
||||
|
||||
const NATIVE_PLATFORMS: Readonly<
|
||||
Partial<
|
||||
Record<
|
||||
NodeJS.Platform,
|
||||
Readonly<Partial<Record<NodeJS.Architecture, string>>>
|
||||
>
|
||||
>
|
||||
> = {
|
||||
linux: { x64: "linux_x86_64", arm64: "linux_arm_64" },
|
||||
darwin: { x64: "mac_x86_64", arm64: "mac_arm_64" },
|
||||
win32: { x64: "win_x86_64" },
|
||||
};
|
||||
|
||||
/** Caller-owned paths and host coordinates used for one installation probe. */
|
||||
export interface GhidraInstallationOptions {
|
||||
readonly installDir?: string;
|
||||
@@ -228,14 +241,11 @@ const installationCoordinates = (
|
||||
"support",
|
||||
platform === "win32" ? "analyzeHeadless.bat" : "analyzeHeadless",
|
||||
);
|
||||
const decompilerPlatform =
|
||||
platform === "darwin"
|
||||
? architecture === "arm64"
|
||||
? "mac_arm_64"
|
||||
: "mac_x86_64"
|
||||
: null;
|
||||
const decompilerPlatform = NATIVE_PLATFORMS[platform]?.[architecture];
|
||||
const decompilerExecutable =
|
||||
platform === "win32" ? "decompile.exe" : "decompile";
|
||||
const nativeDecompilerPath =
|
||||
installDir === null || decompilerPlatform === null
|
||||
installDir === null || decompilerPlatform === undefined
|
||||
? null
|
||||
: ([
|
||||
path.join(
|
||||
@@ -245,7 +255,7 @@ const installationCoordinates = (
|
||||
"Decompiler",
|
||||
"os",
|
||||
decompilerPlatform,
|
||||
"decompile",
|
||||
decompilerExecutable,
|
||||
),
|
||||
path.join(
|
||||
installDir,
|
||||
@@ -255,7 +265,7 @@ const installationCoordinates = (
|
||||
"build",
|
||||
"os",
|
||||
decompilerPlatform,
|
||||
"decompile",
|
||||
decompilerExecutable,
|
||||
),
|
||||
].find((candidate) => host.executable(candidate)) ?? null);
|
||||
const properties =
|
||||
@@ -305,23 +315,18 @@ const installationChecks = ({
|
||||
}),
|
||||
installationCheck({
|
||||
name: "platform",
|
||||
passed:
|
||||
platform === "linux" || platform === "win32" || platform === "darwin",
|
||||
passed: NATIVE_PLATFORMS[platform] !== undefined,
|
||||
code: "unsupported_host",
|
||||
detail: platform,
|
||||
remediation:
|
||||
"Use Linux or Windows x64, or macOS x64/arm64 with matching native Ghidra tools.",
|
||||
"Use Linux or macOS x64/arm64, or Windows x64 with matching native Ghidra tools.",
|
||||
}),
|
||||
installationCheck({
|
||||
name: "architecture",
|
||||
passed:
|
||||
((platform === "linux" || platform === "win32") &&
|
||||
architecture === "x64") ||
|
||||
(platform === "darwin" &&
|
||||
(architecture === "x64" || architecture === "arm64")),
|
||||
passed: NATIVE_PLATFORMS[platform]?.[architecture] !== undefined,
|
||||
code: "unsupported_host",
|
||||
detail: architecture,
|
||||
remediation: "Use x64 on Linux or Windows, or x64/arm64 on macOS.",
|
||||
remediation: "Use x64/arm64 on Linux or macOS, or x64 on Windows.",
|
||||
}),
|
||||
installationCheck({
|
||||
name: "installation",
|
||||
@@ -346,15 +351,12 @@ const installationChecks = ({
|
||||
}),
|
||||
installationCheck({
|
||||
name: "native_decompiler",
|
||||
passed: platform !== "darwin" || coordinates.nativeDecompilerPath !== null,
|
||||
passed: coordinates.nativeDecompilerPath !== null,
|
||||
code: "executable_missing",
|
||||
detail:
|
||||
platform !== "darwin"
|
||||
? "not required on this platform"
|
||||
: (coordinates.nativeDecompilerPath ??
|
||||
"matching macOS native decompiler was not found"),
|
||||
remediation:
|
||||
"REA does not build native tools. Build Ghidra's native components for this macOS architecture or provide an installation containing Ghidra/Features/Decompiler/os/<platform>/decompile.",
|
||||
coordinates.nativeDecompilerPath ??
|
||||
`Matching native decompiler for ${platform}/${architecture} was not found`,
|
||||
remediation: `Provide an executable Ghidra/Features/Decompiler/os/${NATIVE_PLATFORMS[platform]?.[architecture] ?? "<platform>"}/${platform === "win32" ? "decompile.exe" : "decompile"}, or its build/os equivalent. REA does not build or install native tools.`,
|
||||
}),
|
||||
javaCheck(
|
||||
coordinates.java,
|
||||
|
||||
Reference in New Issue
Block a user