GP-5138: GhidraDev/PyDev/PyGhidra integration

This commit is contained in:
Ryan Kurtz
2024-12-11 12:43:39 -05:00
parent 7c4d91f568
commit 31ee251a5c
35 changed files with 1300 additions and 315 deletions
@@ -78,20 +78,20 @@ public class LaunchSupport {
try {
File installDir = new File(installDirPath).getCanonicalFile(); // change relative path to absolute
JavaConfig javaConfig = new JavaConfig(installDir);
AppConfig appConfig = new AppConfig(installDir);
JavaFinder javaFinder = JavaFinder.create();
// Pass control to a mode-specific handler
switch (mode.toLowerCase()) {
case "-java_home":
exitCode = handleJavaHome(javaConfig, javaFinder, JavaFilter.ANY, ask, save);
exitCode = handleJavaHome(appConfig, javaFinder, JavaFilter.ANY, ask, save);
break;
case "-jdk_home":
exitCode =
handleJavaHome(javaConfig, javaFinder, JavaFilter.JDK_ONLY, ask, save);
handleJavaHome(appConfig, javaFinder, JavaFilter.JDK_ONLY, ask, save);
break;
case "-vmargs":
exitCode = handleVmArgs(javaConfig);
exitCode = handleVmArgs(appConfig);
break;
default:
System.err.println("LaunchSupport received illegal argument: " + mode);
@@ -109,7 +109,7 @@ public class LaunchSupport {
* Handles figuring out a Java home directory to use for the launch. If it is successfully
* determined, an exit code that indicates success is returned.
*
* @param javaConfig The Java configuration that defines what we support.
* @param appConfig The appConfig configuration that defines what we support.
* @param javaFinder The Java finder.
* @param javaFilter A filter used to restrict what kind of Java installations we search for.
* @param ask True to interact with the user to they can specify a Java home directory.
@@ -120,12 +120,12 @@ public class LaunchSupport {
* successfully determined.
* @throws IOException if there was a disk-related problem.
*/
private static int handleJavaHome(JavaConfig javaConfig, JavaFinder javaFinder,
private static int handleJavaHome(AppConfig appConfig, JavaFinder javaFinder,
JavaFilter javaFilter, boolean ask, boolean save) throws IOException {
if (ask) {
return askJavaHome(javaConfig, javaFinder, javaFilter);
return askJavaHome(appConfig, javaFinder, javaFilter);
}
return findJavaHome(javaConfig, javaFinder, javaFilter, save);
return findJavaHome(appConfig, javaFinder, javaFilter, save);
}
/**
@@ -133,7 +133,7 @@ public class LaunchSupport {
* found, its path is printed to STDOUT and an exit code that indicates success is
* returned. Otherwise, nothing is printed to STDOUT and an error exit code is returned.
*
* @param javaConfig The Java configuration that defines what we support.
* @param appConfig The application configuration that defines what we support.
* @param javaFinder The Java finder.
* @param javaFilter A filter used to restrict what kind of Java installations we search for.
* @param save True if the determined Java home directory should get saved to a file.
@@ -141,19 +141,19 @@ public class LaunchSupport {
* successfully determined.
* @throws IOException if there was a problem saving the java home to disk.
*/
private static int findJavaHome(JavaConfig javaConfig, JavaFinder javaFinder,
private static int findJavaHome(AppConfig appConfig, JavaFinder javaFinder,
JavaFilter javaFilter, boolean save) throws IOException {
File javaHomeDir;
LaunchProperties launchProperties = javaConfig.getLaunchProperties();
LaunchProperties launchProperties = appConfig.getLaunchProperties();
// PRIORITY 1: JAVA_HOME_OVERRIDE property
// If a valid java home override is specified in the launch properties, use that.
// Someone presumably wants to force that specific version.
javaHomeDir = launchProperties.getJavaHomeOverride();
if (javaConfig.isSupportedJavaHomeDir(javaHomeDir, javaFilter)) {
if (appConfig.isSupportedJavaHomeDir(javaHomeDir, javaFilter)) {
if (save) {
javaConfig.saveJavaHome(javaHomeDir);
appConfig.saveJavaHome(javaHomeDir);
}
System.out.println(javaHomeDir);
return EXIT_SUCCESS;
@@ -162,10 +162,10 @@ public class LaunchSupport {
// PRIORITY 2: Java on PATH
// This program (LaunchSupport) was started with the Java on the PATH. Try to use this one
// next because it is most likely the one that is being upgraded on the user's system.
javaHomeDir = javaFinder.findSupportedJavaHomeFromCurrentJavaHome(javaConfig, javaFilter);
javaHomeDir = javaFinder.findSupportedJavaHomeFromCurrentJavaHome(appConfig, javaFilter);
if (javaHomeDir != null) {
if (save) {
javaConfig.saveJavaHome(javaHomeDir);
appConfig.saveJavaHome(javaHomeDir);
}
System.out.println(javaHomeDir);
return EXIT_SUCCESS;
@@ -173,19 +173,19 @@ public class LaunchSupport {
// PRIORITY 3: Last used Java
// Check to see if a prior launch resulted in that Java being saved. If so, try to use that.
javaHomeDir = javaConfig.getSavedJavaHome();
if (javaConfig.isSupportedJavaHomeDir(javaHomeDir, javaFilter)) {
javaHomeDir = appConfig.getSavedJavaHome();
if (appConfig.isSupportedJavaHomeDir(javaHomeDir, javaFilter)) {
System.out.println(javaHomeDir);
return EXIT_SUCCESS;
}
// PRIORITY 4: Find all supported Java installations, and use the newest.
List<File> javaHomeDirs =
javaFinder.findSupportedJavaHomeFromInstallations(javaConfig, javaFilter);
javaFinder.findSupportedJavaHomeFromInstallations(appConfig, javaFilter);
if (!javaHomeDirs.isEmpty()) {
javaHomeDir = javaHomeDirs.iterator().next();
if (save) {
javaConfig.saveJavaHome(javaHomeDir);
appConfig.saveJavaHome(javaHomeDir);
}
System.out.println(javaHomeDir);
return EXIT_SUCCESS;
@@ -199,7 +199,7 @@ public class LaunchSupport {
* If a valid Java home directory was successfully determined, it is saved to the user's
* Java home save file, and an exit code that indicates success is returned.
*
* @param javaConfig The Java configuration that defines what we support.
* @param appConfig The application configuration that defines what we support.
* @param javaFinder The Java finder.
* @param javaFilter A filter used to restrict what kind of Java installations we search for.
* * @return A suggested exit code based on whether or not a valid Java home directory was
@@ -207,13 +207,13 @@ public class LaunchSupport {
* @throws IOException if there was a problem interacting with the user, or saving the java
* home location to disk.
*/
private static int askJavaHome(JavaConfig javaConfig, JavaFinder javaFinder,
private static int askJavaHome(AppConfig appConfig, JavaFinder javaFinder,
JavaFilter javaFilter) throws IOException {
String javaName = javaFilter.equals(JavaFilter.JDK_ONLY) ? "JDK" : "Java";
String javaRange;
int min = javaConfig.getMinSupportedJava();
int max = javaConfig.getMaxSupportedJava();
int min = appConfig.getMinSupportedJava();
int max = appConfig.getMaxSupportedJava();
if (min == max) {
javaRange = min + "";
}
@@ -226,7 +226,7 @@ public class LaunchSupport {
System.out.println("******************************************************************");
System.out.println(
javaName + " " + javaRange + " (" + javaConfig.getSupportedArchitecture() +
javaName + " " + javaRange + " (" + appConfig.getSupportedArchitecture() +
"-bit) could not be found and must be manually chosen!");
System.out.println("******************************************************************");
@@ -254,13 +254,13 @@ public class LaunchSupport {
continue;
}
try {
JavaVersion javaVersion = javaConfig.getJavaVersion(javaHomeDir, javaFilter);
if (javaConfig.isJavaVersionSupported(javaVersion)) {
JavaVersion javaVersion = appConfig.getJavaVersion(javaHomeDir, javaFilter);
if (appConfig.isJavaVersionSupported(javaVersion)) {
break;
}
System.out.println(
"Java version " + javaVersion + " is outside of supported range: [" +
javaRange + " " + javaConfig.getSupportedArchitecture() + "-bit]");
javaRange + " " + appConfig.getSupportedArchitecture() + "-bit]");
}
catch (FileNotFoundException e) {
System.out.println(
@@ -271,7 +271,7 @@ public class LaunchSupport {
}
}
File javaHomeSaveFile = javaConfig.saveJavaHome(javaHomeDir);
File javaHomeSaveFile = appConfig.saveJavaHome(javaHomeDir);
System.out.println("Saved changes to " + javaHomeSaveFile);
return EXIT_SUCCESS;
}
@@ -281,18 +281,18 @@ public class LaunchSupport {
* to STDOUT as a new-line delimited string that can be parsed and added to the command line,
* and an exit code that indicates success is returned.
* @param javaConfig The Java configuration that defines what we support.
* @param appConfig The appConfig configuration that defines what we support.
* @return A suggested exit code based on whether or not the VM arguments were successfully
* gotten.
*/
private static int handleVmArgs(JavaConfig javaConfig) {
if (javaConfig.getLaunchProperties() == null) {
private static int handleVmArgs(AppConfig appConfig) {
if (appConfig.getLaunchProperties() == null) {
System.out.println("Launch properties file was not specified!");
return EXIT_FAILURE;
}
// Force newline style to make cross-platform parsing consistent
javaConfig.getLaunchProperties().getVmArgList().forEach(e -> System.out.print(e + "\r\n"));
appConfig.getLaunchProperties().getVmArgList().forEach(e -> System.out.print(e + "\r\n"));
return EXIT_SUCCESS;
}
}