GP-6580: PyGhidra will now try to use the JAVA_HOME environment variable

to call LaunchSupport if java was not on the PATH
This commit is contained in:
Ryan Kurtz
2026-03-19 06:25:51 -04:00
parent 1ed07f6900
commit 64add1c0fa
2 changed files with 14 additions and 1 deletions
@@ -579,6 +579,8 @@ __3.1.0__
[`py.typed`](https://typing.python.org/en/latest/spec/distributing.html#packaging-type-information)
marker file to inform type checkers that typing is supported.
* The PyGhidra interactive console no longer restarts when a `SyntaxError` occurs.
* PyGhidra will now try to use the `JAVA_HOME` environment variable to call `LaunchSupport` if java
was not on the `PATH`.
__3.0.2__
* Fixed an issue that prevented [`pyghidra.analysis_properties()`](#pyghidraanalysis_properties)
@@ -314,7 +314,18 @@ class PyGhidraLauncher:
launch_support = self.install_dir / "support" / "LaunchSupport.jar"
if not launch_support.exists():
raise ValueError(f"{launch_support} does not exist")
cmd = f'java -cp "{launch_support}" LaunchSupport "{self.install_dir}" -jdk_home -save'
# Check to see if java is on the PATH. If not, use JAVA_HOME.
# NOTE: shutils.which() is not enough...macOS puts a stub java on the PATH which
# will prevent that from working as expected, so you have to actually run it.
java_cmd = 'java'
if not shutil.which(java_cmd) or subprocess.run([java_cmd, "-version"]).returncode != 0:
java_home_dir = os.environ.get('JAVA_HOME')
if java_home_dir and os.path.isdir(java_home_dir):
java_cmd = java_home_dir + "/bin/java"
else:
raise ValueError("Java was not found in PATH or JAVA_HOME...cannot run LaunchSupport")
cmd = f'"{java_cmd}" -cp "{launch_support}" LaunchSupport "{self.install_dir}" -jdk_home -save'
home = subprocess.check_output(cmd, encoding="utf-8", shell=True)
self._java_home = Path(home.rstrip())
return self._java_home