Repository navigation
fix(ghidra): fail doctor when the JVM os.arch selects an unvalidated decompiler directory #2792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b23460b
53bb0c1
295d81c
d005343
c523d1a
f2b98fd
5f84c61
5730da1
62e4229
1dbfac8
ff42107
3f4e900
5dcd55e
9d70fa8
5eed95c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…rrides
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,6 +208,12 @@ interface GhidraInstallationObservation { | |
| * selects its native decompiler directory from this value. | ||
| */ | ||
| readonly javaOsArch?: string; | ||
| /** | ||
| * Observed JVM os.name; omitted when the probe cannot establish it. Ghidra | ||
| * selects its native decompiler OS directory from the JVM OS/architecture | ||
| * pair, so a non-host value selects an unvalidated directory. | ||
| */ | ||
| readonly javaOsName?: string; | ||
| readonly checks: readonly GhidraInstallationCheck[]; | ||
| } | ||
|
|
||
|
|
@@ -254,6 +260,12 @@ export interface GhidraJavaObservation { | |
| * decompiler directory. Omitted when the probe cannot establish it. | ||
| */ | ||
| readonly osArch?: string; | ||
| /** | ||
| * Observed JVM os.name property, which Ghidra uses with os.arch to select | ||
| * its native decompiler OS directory. Omitted when the probe cannot | ||
| * establish it. | ||
| */ | ||
| readonly osName?: string; | ||
| } | ||
|
|
||
| /** A bounded executable-header probe: a small prefix plus the whole file size. */ | ||
|
|
@@ -337,6 +349,9 @@ export const inspectGhidraInstallation = ( | |
| ...(coordinates.java?.osArch === undefined | ||
| ? {} | ||
| : { javaOsArch: coordinates.java.osArch }), | ||
| ...(coordinates.java?.osName === undefined | ||
| ? {} | ||
| : { javaOsName: coordinates.java.osName }), | ||
| checks, | ||
| }; | ||
| if (failed !== undefined) | ||
|
|
@@ -569,6 +584,7 @@ export const ghidraInstallationDiagnostics = ( | |
| java_version: inspection.javaVersion, | ||
| java_vm_name: inspection.javaVmName ?? null, | ||
| java_os_arch: inspection.javaOsArch ?? null, | ||
| java_os_name: inspection.javaOsName ?? null, | ||
| platform: inspection.platform, | ||
| architecture: inspection.architecture, | ||
| checks: inspection.checks.map((check) => ({ | ||
|
|
@@ -650,7 +666,11 @@ const nativeDecompilerCheck = ({ | |
| // not the host process architecture. A JDK running under emulation (for | ||
| // example x86_64 under Rosetta on Apple silicon) selects a directory that | ||
| // was never validated, so every analysis fails after a passing doctor. | ||
| // Ghidra resolves the OS directory from the JVM os.name/os.arch pair, so a | ||
| // JVM reporting a non-host os.name (for example through -Dos.name=Windows) | ||
| // selects a different OS directory even when os.arch matches. | ||
| const osArch = coordinates.java?.osArch; | ||
| const osName = coordinates.java?.osName; | ||
| const selectedDirectory = jvmOsArchNativeDirectory(platform, osArch); | ||
| const validatedDirectory = NATIVE_PLATFORMS[platform]?.[architecture]; | ||
| // Without a JVM observation the java check reports the missing runtime; | ||
|
|
@@ -679,6 +699,23 @@ const nativeDecompilerCheck = ({ | |
| detail: `JVM reports os.arch=${osArch}, so Ghidra selects its native decompiler from os/${selectedDirectory}, but the validated decompiler targets ${validatedDirectory} (host ${platform}/${architecture})`, | ||
| remediation: `Point JAVA_HOME at a JDK whose architecture matches the built decompiler (${validatedDirectory}). REA does not build or install native tools.`, | ||
| }); | ||
| if (osName === undefined) | ||
| return installationCheck({ | ||
| name: "native_decompiler", | ||
| passed: false, | ||
| code: "executable_missing", | ||
| detail: | ||
| "The Java probe did not report os.name; the JVM-selected native decompiler OS directory is unknown and cannot be matched to the validated host platform", | ||
| remediation: `Point JAVA_HOME at a JDK whose reported operating system matches the host platform (${platform}). REA does not build or install native tools.`, | ||
| }); | ||
| if (!jvmOsNameMatchesPlatform(platform, osName) && path !== null) | ||
| return installationCheck({ | ||
| name: "native_decompiler", | ||
| passed: false, | ||
| code: "executable_missing", | ||
| detail: `JVM reports os.name=${osName}, which does not match the validated host platform ${platform} (host ${platform}/${architecture})`, | ||
| remediation: `Point JAVA_HOME at a JDK whose reported operating system matches the host platform (${platform}). REA does not build or install native tools.`, | ||
| }); | ||
| } | ||
| return installationCheck({ | ||
| name: "native_decompiler", | ||
|
|
@@ -694,6 +731,23 @@ const nativeDecompilerCheck = ({ | |
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * Whether a JVM os.name value selects the host platform's native OS directory. | ||
| * Unknown values never align with the validated host directory; admission | ||
| * must not treat them as matching. | ||
| */ | ||
| const jvmOsNameMatchesPlatform = ( | ||
| platform: NodeJS.Platform, | ||
| osName: string, | ||
| ): boolean => { | ||
| const normalized = osName.toLowerCase(); | ||
| if (platform === "win32") return normalized.startsWith("windows"); | ||
| if (platform === "darwin") | ||
| return normalized.startsWith("mac") || normalized.startsWith("darwin"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a macOS host's selected JDK reports AGENTS.md reference: AGENTS.md:L21-L21 Useful? React with 👍 / 👎. |
||
| if (platform === "linux") return normalized.startsWith("linux"); | ||
| return false; | ||
| }; | ||
|
|
||
| /** | ||
| * Map a JVM os.arch value to the Ghidra native directory that JVM selects. | ||
| * Unknown values stay unknown; admission must not treat them as aligned with | ||
|
|
@@ -850,6 +904,7 @@ const systemGhidraInstallationHost = (): GhidraInstallationHost => ({ | |
| const home = javaProperty(output, "java.home"); | ||
| const vmName = javaProperty(output, "java.vm.name"); | ||
| const osArch = javaProperty(output, "os.arch"); | ||
|
morluto marked this conversation as resolved.
Resolved
morluto marked this conversation as resolved.
Resolved
|
||
| const osName = javaProperty(output, "os.name"); | ||
| const bits = Number.parseInt( | ||
| javaProperty(output, "sun.arch.data.model") ?? "0", | ||
| 10, | ||
|
|
@@ -861,6 +916,7 @@ const systemGhidraInstallationHost = (): GhidraInstallationHost => ({ | |
| home, | ||
| ...(vmName === null ? {} : { vmName }), | ||
| ...(osArch === null ? {} : { osArch }), | ||
| ...(osName === null ? {} : { osName }), | ||
| bits, | ||
| runtime: executablePath( | ||
| (process.platform === "win32" ? win32 : posix).join( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.