From 02567fd35550336b1a3fe74716492271f5d74ea2 Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Fri, 12 Dec 2025 11:00:56 -0500 Subject: [PATCH] GP-6193: Environment variables can now be set in launch.properties using ENVVARS= or ENVVARS_[PLATFORM]= --- .../Common/support/launch.properties | 5 +++- Ghidra/RuntimeScripts/Linux/support/launch.sh | 15 ++++++++-- .../RuntimeScripts/Windows/support/launch.bat | 10 +++++++ .../src/main/java/LaunchSupport.java | 24 +++++++++++++++ .../java/ghidra/launch/LaunchProperties.java | 30 +++++++++++++++++++ GhidraDocs/GettingStarted.md | 9 +++--- 6 files changed, 85 insertions(+), 8 deletions(-) diff --git a/Ghidra/RuntimeScripts/Common/support/launch.properties b/Ghidra/RuntimeScripts/Common/support/launch.properties index 14f0096465..aaf0472b08 100644 --- a/Ghidra/RuntimeScripts/Common/support/launch.properties +++ b/Ghidra/RuntimeScripts/Common/support/launch.properties @@ -24,6 +24,9 @@ VMARGS_LINUX=-Dsun.java2d.uiScale=1 VMARGS_LINUX=-Dawt.useSystemAAFontSettings=on VMARGS_WINDOWS=-Dsun.java2d.d3d=false +# Fix blank windows on non-parenting windows managers such as XMonad and Sway +#ENVVARS_LINUX=_JAVA_AWT_WM_NONREPARENTING=1 + # The Ghidra application establishes the default SSLContext for all # secure client connections based upon Java's default TLS protocol enablement. # Setting this property will restrict the enabled TLS protocol versions for @@ -42,7 +45,7 @@ VMARGS=-Djdk.tls.client.protocols=TLSv1.2,TLSv1.3 # SSL/TLS connections. This VMARG should only be uncommented while actively troubleshooting # since it will log a significant amount of data. # -# See the "Troubleshoting JSSE" section of the following internet hosted document: +# See the "Troubleshooting JSSE" section of the following internet hosted document: # https://docs.oracle.com/en/java/javase/17/security/java-secure-socket-extension-jsse-reference-guide.html # # NOTE: When this debug logging is enabled be sure to launch Ghidra with debugGhidra instead of diff --git a/Ghidra/RuntimeScripts/Linux/support/launch.sh b/Ghidra/RuntimeScripts/Linux/support/launch.sh index 167835405d..5a8ec3c514 100755 --- a/Ghidra/RuntimeScripts/Linux/support/launch.sh +++ b/Ghidra/RuntimeScripts/Linux/support/launch.sh @@ -43,9 +43,9 @@ function showUsage() { exit 1 } -VMARGS_FROM_CALLER= # Passed in from the outer script as one long string, no spaces -VMARGS_FROM_LAUNCH_SH=() # Defined in this script, added to array -VMARGS_FROM_LAUNCH_PROPS=() # Retrieved from LaunchSupport, added to array +VMARGS_FROM_CALLER= # Passed in from the outer script as one long string, no spaces +VMARGS_FROM_LAUNCH_SH=() # Defined in this script, added to array +VMARGS_FROM_LAUNCH_PROPS=() # Retrieved from LaunchSupport, added to array ARGS=() INDEX=0 @@ -169,6 +169,15 @@ if [ ! $? -eq 0 ]; then fi JAVA_CMD="${LS_JAVA_HOME}/bin/java" +# Get the configurable environment variables from the launch properties +# Only set them if they are currently unset or empty +while IFS=$'\r\n' read -r line; do + IFS='=' read -r key value <<< "$line" + if [ -z ${!key} ]; then + export $key=$value + fi +done < <("${JAVA_CMD}" -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" -envvars) + # Get the configurable VM arguments from the launch properties while IFS=$'\r\n' read -r line; do VMARGS_FROM_LAUNCH_PROPS+=("$line") diff --git a/Ghidra/RuntimeScripts/Windows/support/launch.bat b/Ghidra/RuntimeScripts/Windows/support/launch.bat index 92f5ffddbb..f317f53dd4 100644 --- a/Ghidra/RuntimeScripts/Windows/support/launch.bat +++ b/Ghidra/RuntimeScripts/Windows/support/launch.bat @@ -168,6 +168,16 @@ if "%LS_JAVA_HOME%" == "" ( ) set "JAVA_CMD=%LS_JAVA_HOME%\bin\java" +:: Get the configurable environment variables from the launch properties +:: Only set them if they are currently undefined +for /f "delims=*" %%i in ('call "%JAVA_CMD%" -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" -envvars') do ( + for /f "tokens=1* delims==" %%a in ("%%i") do ( + if not defined %%a ( + set %%a=%%b + ) + ) +) + :: Get the configurable VM arguments from the launch properties for /f "delims=*" %%i in ('call "%JAVA_CMD%" -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" -vmargs') do set VMARG_LIST=!VMARG_LIST! %%i diff --git a/GhidraBuild/LaunchSupport/src/main/java/LaunchSupport.java b/GhidraBuild/LaunchSupport/src/main/java/LaunchSupport.java index 414e70fb03..bca5dea6e6 100644 --- a/GhidraBuild/LaunchSupport/src/main/java/LaunchSupport.java +++ b/GhidraBuild/LaunchSupport/src/main/java/LaunchSupport.java @@ -44,6 +44,7 @@ public class LaunchSupport { *
  • -jdk_home_check: Verify that the specified Java home directory contains a * supported version of java. No output is produced.
  • *
  • -vmargs: Get JVM arguments and output on stdout (one per line).
  • + *
  • -envvars: Get environment variables and output on stdout (one per line).
  • * * Optional arguments supported by -java_home and -jdk_home: *