From 56dfef0c306d5224946c3107b6e7dba2c56d6dcf Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Tue, 30 Sep 2025 05:47:18 -0400 Subject: [PATCH] GP-6022: Support environment variables in launch.properties --- .../java/ghidra/launch/LaunchProperties.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/LaunchProperties.java b/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/LaunchProperties.java index b516f00613..92fb71359d 100644 --- a/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/LaunchProperties.java +++ b/GhidraBuild/LaunchSupport/src/main/java/ghidra/launch/LaunchProperties.java @@ -18,6 +18,7 @@ package ghidra.launch; import java.io.*; import java.text.ParseException; import java.util.*; +import java.util.Map.Entry; import ghidra.launch.JavaFinder.Platform; @@ -160,6 +161,7 @@ public class LaunchProperties { } String key = line.substring(0, equalsIndex).trim(); String value = line.substring(equalsIndex + 1, line.length()).trim(); + value = expandEnvVars(value); List valueList = map.get(key); if (valueList == null) { valueList = new ArrayList<>(); @@ -173,4 +175,21 @@ public class LaunchProperties { } return map; } + + /** + * Expands ${var}-style environment variables in the given string. Expansion only + * happens if the environment variable is set. + * + * @param text The string to expand environment variables in + * @return The given string, but with set environment variables expanded + */ + private static String expandEnvVars(String text) { + Map envMap = System.getenv(); + for (Entry entry : envMap.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + text = text.replaceAll("\\$\\{" + key + "\\}", value.replace("\\", "\\\\")); + } + return text; + } }