Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(ghidra): do not run Java from a relative JAVA_HOME in doctor and setup

Kaoru0822c3f169823f69
diff --git a/src/ghidra/GhidraInstallation.test.ts b/src/ghidra/GhidraInstallation.test.ts
index 3c6d46354..9f42a84ab 100644
--- a/src/ghidra/GhidraInstallation.test.ts
+++ b/src/ghidra/GhidraInstallation.test.ts
@@ -413,6 +413,36 @@ describe("Ghidra configuration paths", () => {
},
);
+ it.each([
+ ["linux", "./jdk"],
+ ["linux", ""],
+ ["win32", "jdk"],
+ ] as const)(
+ "does not run Java from a relative JAVA_HOME (%s %o)",
+ (platform, javaHome) => {
+ const probed: string[] = [];
+ const result = inspectGhidraInstallation(
+ {
+ installDir: platform === "win32" ? WINDOWS_INSTALL : INSTALL,
+ javaHome,
+ platform,
+ architecture: "x64",
+ },
+ host({
+ probeJava: (command) => {
+ probed.push(command);
+ return JAVA;
+ },
+ }),
+ );
+ expect(probed).toEqual([]);
+ expect(result).toMatchObject({
+ status: "unavailable",
+ rejection: { code: "not_configured" },
+ });
+ },
+ );
+
it("judges absolute paths by the inspected platform", () => {
const result = inspectGhidraInstallation(
{ installDir: "C:\\ghidra", platform: "win32", architecture: "x64" },
diff --git a/src/ghidra/GhidraInstallation.ts b/src/ghidra/GhidraInstallation.ts
index d0906fb52..bf1371715 100644
--- a/src/ghidra/GhidraInstallation.ts
+++ b/src/ghidra/GhidraInstallation.ts
@@ -292,10 +292,15 @@ const installationCoordinates = (
? undefined
: ghidraApplicationProperties(properties),
javaCommand,
- java: host.probeJava(
- javaCommand,
- ghidraJavaEnvironment(options.javaHome, process.env, platform),
- ),
+ // The configuration check rejects a relative JAVA_HOME. Probing it would
+ // run whatever `bin/java` the current directory holds.
+ java:
+ options.javaHome === undefined || path.isAbsolute(options.javaHome)
+ ? host.probeJava(
+ javaCommand,
+ ghidraJavaEnvironment(options.javaHome, process.env, platform),
+ )
+ : undefined,
};
};