Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-6350: You can now set PyGhidra Java options via an assortment of environment variables (Closes #8942)

Ryan Kurtz7525f3c4be52
diff --git a/Ghidra/RuntimeScripts/Linux/support/pyghidraRun b/Ghidra/RuntimeScripts/Linux/support/pyghidraRun
index 5ed3758386..ba617b0b50 100755
--- a/Ghidra/RuntimeScripts/Linux/support/pyghidraRun
+++ b/Ghidra/RuntimeScripts/Linux/support/pyghidraRun
@@ -11,8 +11,11 @@
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}"
-# Add optional JVM args inside the quotes
-VMARG_LIST=""
+# Since JPype doesn't seem to pick up JDK_JAVA_OPTIONS automatically, include it ourselves
+VMARG_LIST="${JDK_JAVA_OPTIONS}"
+
+# Apply Java options from externally set environment variables
+VMARG_LIST="${VMARG_LIST} ${GHIDRA_JAVA_OPTIONS} ${PYGHIDRA_JAVA_OPTIONS}"
# Make sure Python3 is installed
if ! [ -x "$(command -v python3)" ] ; then
diff --git a/Ghidra/RuntimeScripts/Windows/support/pyghidraRun.bat b/Ghidra/RuntimeScripts/Windows/support/pyghidraRun.bat
index 96e331ec67..28ec04c8fe 100644
--- a/Ghidra/RuntimeScripts/Windows/support/pyghidraRun.bat
+++ b/Ghidra/RuntimeScripts/Windows/support/pyghidraRun.bat
@@ -22,8 +22,11 @@ setlocal enabledelayedexpansion
set DOUBLE_CLICKED=n
for /f "tokens=2" %%# in ("%cmdcmdline%") do if /i "%%#" equ "/c" set DOUBLE_CLICKED=y
-:: Add optional JVM args inside the quotes
-set VMARG_LIST=-Dsun.java2d.dpiaware=true
+:: Since JPype doesn't seem to pick up JDK_JAVA_OPTIONS automatically, include it ourselves
+set VMARG_LIST=%JDK_JAVA_OPTIONS%
+
+:: Apply Java options from externally set environment variables
+set VMARG_LIST=%VMARG_LIST% %GHIDRA_JAVA_OPTIONS% %PYGHIDRA_JAVA_OPTIONS% -Dsun.java2d.dpiaware=true
:: Make sure Python3 is installed
set PYTHON=py