Ghidra is a software reverse engineering (SRE) framework
Finding external modules from the classpath instead of the eclipse.project.dir property.
Ryan Kurtz3a12b5bbe26a
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.javaindex a790562835..16df91fe48 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java@@ -933,18 +933,6 @@ public abstract class ProcessorEmulatorTestAdapter extends TestCase implements EResourceFile myModuleRootDirectory =Application.getModuleContainingClass(getClass().getName());- if (myModuleRootDirectory == null) {- if (!SystemUtilities.isInDevelopmentMode()) {- Msg.warn(this, "Unable to identify pcodetest module directory!\n" +- "Project must contain Module.manifest file, and if developing module using Eclipse\n" +- "w/ GhidraDev the VM argument -Declipse.project.dir=<project-path> must be specified.");- }- else {- Msg.warn(this,- "Unable to identify pcodetest module directory! Project must contain Module.manifest file");- }- }-if (myModuleRootDirectory != null) {File myModuleRoot = myModuleRootDirectory.getFile(false);if (myModuleRoot != null) {@@ -954,6 +942,10 @@ public abstract class ProcessorEmulatorTestAdapter extends TestCase implements E}}}+ else {+ Msg.warn(this,+ "Unable to identify pcodetest module directory! Project must contain Module.manifest file");+ }if (resourcesTestDataDir == null || !resourcesTestDataDir.isDirectory()) {findTestResourceDirectory(DEFAULT_PROCESSOR_TEST_MODULE);diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/GhidraApplicationLayout.java b/Ghidra/Framework/Utility/src/main/java/ghidra/GhidraApplicationLayout.javaindex 64c7a1871a..06d8d26d1c 100644--- a/Ghidra/Framework/Utility/src/main/java/ghidra/GhidraApplicationLayout.java+++ b/Ghidra/Framework/Utility/src/main/java/ghidra/GhidraApplicationLayout.java@@ -22,6 +22,7 @@ import generic.jar.ResourceFile;import ghidra.framework.ApplicationProperties;import ghidra.framework.GModule;import ghidra.util.SystemUtilities;+import utilities.util.FileUtilities;import utility.application.ApplicationLayout;import utility.application.ApplicationUtilities;import utility.module.ModuleUtilities;@@ -141,24 +142,31 @@ public class GhidraApplicationLayout extends ApplicationLayout {// Find standard module root directories from within the application root directoriesCollection<ResourceFile> moduleRootDirectories =ModuleUtilities.findModuleRootDirectories(applicationRootDirs, new ArrayList<>());++ // Examine the classpath to look for modules outside of the application root directories.+ // These might exist if Ghidra was launched from an Eclipse project that resides+ // external to the Ghidra installation.+ for (String entry : System.getProperty("java.class.path", "").split(File.pathSeparator)) {+ final ResourceFile classpathEntry = new ResourceFile(entry);++ // We only care about directories (skip jars)+ if (!classpathEntry.isDirectory()) {+ continue;+ }- // If Ghidra was launched from our Eclipse GhidraDev plugin, we want to add the- // Eclipse module project (and it's dependent projects) to the list of module root- // directories so Ghidra can discover them.- String eclipseProjectDirProperty = System.getProperty("eclipse.project.dir");- if (eclipseProjectDirProperty != null && !eclipseProjectDirProperty.isEmpty()) {- ResourceFile eclipseProjectDir = new ResourceFile(eclipseProjectDirProperty);- if (ModuleUtilities.isModuleDirectory(eclipseProjectDir)) {- moduleRootDirectories.add(eclipseProjectDir);+ // Skip classpath entries that live in an application root directory...we've already+ // found those.+ if (applicationRootDirs.stream().anyMatch(dir -> FileUtilities.isPathContainedWithin(+ dir.getFile(false), classpathEntry.getFile(false)))) {+ continue;}- }- String eclipseProjectDependencies = System.getProperty("eclipse.project.dependencies");- if (eclipseProjectDependencies != null && !eclipseProjectDependencies.isEmpty()) {- for (String path : eclipseProjectDependencies.split(File.pathSeparator)) {- ResourceFile eclipseProjectDir = new ResourceFile(path);- if (ModuleUtilities.isModuleDirectory(eclipseProjectDir)) {- moduleRootDirectories.add(eclipseProjectDir);- }++ // We are going to assume that the classpath entry is in a subdirectory of the module+ // directory (i.e., bin/), so only check parent directory for the module.+ ResourceFile classpathEntryParent = classpathEntry.getParentFile();+ if (classpathEntryParent != null &&+ ModuleUtilities.isModuleDirectory(classpathEntryParent)) {+ moduleRootDirectories.add(classpathEntryParent);}}