mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-01-05 04:04:04 -05:00
GP-6193: Environment variables can now be set in launch.properties using ENVVARS= or ENVVARS_[PLATFORM]=
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ public class LaunchSupport {
|
||||
* <li><b>-jdk_home_check: </b> Verify that the specified Java home directory contains a
|
||||
* supported version of java. No output is produced.</li>
|
||||
* <li><b>-vmargs: </b> Get JVM arguments and output on stdout (one per line).</li>
|
||||
* <li><b>-envvars: </b> Get environment variables and output on stdout (one per line).</li>
|
||||
* </ul>
|
||||
* Optional arguments supported by -java_home and -jdk_home:
|
||||
* <ul>
|
||||
@@ -114,6 +115,9 @@ public class LaunchSupport {
|
||||
case "-vmargs":
|
||||
exitCode = handleVmArgs(appConfig);
|
||||
break;
|
||||
case "-envvars":
|
||||
exitCode = handleEnvVars(appConfig);
|
||||
break;
|
||||
default:
|
||||
System.err.println("LaunchSupport received illegal argument: " + mode);
|
||||
break;
|
||||
@@ -351,4 +355,24 @@ public class LaunchSupport {
|
||||
appConfig.getLaunchProperties().getVmArgList().forEach(e -> System.out.print(e + "\r\n"));
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles getting the environment variables. If they are successfully determined, they are
|
||||
* printed to STDOUT as a new-line delimited string that can be parsed and added to the
|
||||
* environment, and an exit code that indicates success is returned.
|
||||
|
||||
* @param appConfig The appConfig configuration that defines what we support.
|
||||
* @return A suggested exit code based on whether or not the environment variables were
|
||||
* successfully gotten.
|
||||
*/
|
||||
private static int handleEnvVars(AppConfig appConfig) {
|
||||
if (appConfig.getLaunchProperties() == null) {
|
||||
System.err.println("Launch properties file was not specified!");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Force newline style to make cross-platform parsing consistent
|
||||
appConfig.getLaunchProperties().getEnvVarList().forEach(e -> System.out.print(e + "\r\n"));
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,16 @@ public class LaunchProperties {
|
||||
*/
|
||||
public static String VMARGS_PLATFORM = "VMARGS_" + JavaFinder.getCurrentPlatform();
|
||||
|
||||
/**
|
||||
* The environment variables to use to launch (all platforms).
|
||||
*/
|
||||
public static String ENVVARS = "ENVVARS";
|
||||
|
||||
/**
|
||||
* The environment variables to use to launch (current platform only).
|
||||
*/
|
||||
public static String ENVVARS_PLATFORM = "ENVVARS_" + JavaFinder.getCurrentPlatform();
|
||||
|
||||
private Map<String, List<String>> propertyMap;
|
||||
private File launchPropertiesFile;
|
||||
|
||||
@@ -132,6 +142,26 @@ public class LaunchProperties {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link List} of environment variables to use for the launch for the current
|
||||
* {@link Platform platform}.
|
||||
*
|
||||
* @return A {@link List} of environment variables to use for the launch for the current
|
||||
* {@link Platform}
|
||||
*/
|
||||
public List<String> getEnvVarList() {
|
||||
List<String> ret = new ArrayList<>();
|
||||
List<String> envVarList = propertyMap.get(ENVVARS);
|
||||
if (envVarList != null) {
|
||||
ret.addAll(envVarList);
|
||||
}
|
||||
List<String> envVarPlatformList = propertyMap.get(ENVVARS_PLATFORM);
|
||||
if (envVarPlatformList != null) {
|
||||
ret.addAll(envVarPlatformList);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses and gets the launch properties from the given launch properties file.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Getting Started with Ghidra
|
||||
The information provided in this document is effective as of Ghidra 12.0 and is subject to change
|
||||
The information provided in this document is effective as of Ghidra 12.1 and is subject to change
|
||||
with future releases.
|
||||
|
||||
## Table of Contents
|
||||
@@ -458,9 +458,10 @@ There are several ways you can get help with using Ghidra:
|
||||
* GUI icons may not render correctly in some configurations of Linux. Setting
|
||||
`VMARGS=-Dsun.java2d.opengl` to `true` in `<GhidraInstallDir>/support/launch.properties` may fix
|
||||
this issue.
|
||||
* Non-reparenting window managers such as Xmonad and Sway may render Ghidra windows as blank. This
|
||||
is a known java issue (https://bugs.openjdk.org/browse/JDK-8058197) which can only be addressed
|
||||
by setting the environment variable `_JAVA_AWT_WM_NONREPARENTING=1` prior to launching Ghidra.
|
||||
* Non-reparenting window managers such as XMonad and Sway may render Ghidra windows as blank. This
|
||||
is a known java issue (https://bugs.openjdk.org/browse/JDK-8058197) which can be addressed by
|
||||
uncommenting `#ENVVARS_LINUX=_JAVA_AWT_WM_NONREPARENTING=1` in
|
||||
`<GhidraInstallDir>/support/launch.properties`.
|
||||
|
||||
### macOS
|
||||
* Building new Ghidra module extensions on macOS (OS X) using a network drive (including a
|
||||
|
||||
Reference in New Issue
Block a user