Skip to content

Ghidra is a software reverse engineering (SRE) framework

move static bundle vars to BundleHost

Jason P. Leasure6268ab9d3e4d
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java
index 1f054e0e3c..b7e889ba11 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java
@@ -34,7 +34,7 @@ import org.osgi.framework.wiring.*;
import org.osgi.service.log.*;
import generic.jar.ResourceFile;
-import ghidra.app.script.GhidraScriptUtil;
+import ghidra.framework.Application;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.*;
@@ -351,8 +351,21 @@ public class BundleHost {
}
}
+ public static Path getCompiledBundlesDir() {
+ return getOsgiDir().resolve("compiled-bundles");
+ }
+
+ public static Path getOsgiDir() {
+ Path usersettings = Application.getUserSettingsDirectory().toPath();
+ return usersettings.resolve("osgi");
+ }
+
+ static public Path getCacheDir() {
+ return BundleHost.getOsgiDir().resolve("felixcache");
+ }
+
private String makeCacheDir() throws IOException {
- Path cache_dir = GhidraScriptUtil.getOsgiDir().resolve("felixcache");
+ Path cache_dir = getCacheDir();
Files.createDirectories(cache_dir);
return cache_dir.toAbsolutePath().toString();
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java
index 9e2c6d3c80..08b615f863 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java
@@ -80,7 +80,7 @@ public class GhidraSourceBundle implements GhidraBundle {
this.bundleHost = bundleHost;
this.sourceDir = sourceDirectory;
this.symbolicName = BundleHost.getSymbolicNameFromSourceDir(sourceDir);
- this.binDir = GhidraScriptUtil.getCompiledBundlesDir().resolve(symbolicName);
+ this.binDir = BundleHost.getCompiledBundlesDir().resolve(symbolicName);
this.bundleLoc = "reference:file://" + getBinDir().toAbsolutePath().normalize().toString();
@@ -95,7 +95,7 @@ public class GhidraSourceBundle implements GhidraBundle {
static public Path getBindirFromScriptFile(ResourceFile sourceFile) {
ResourceFile tmpSourceDir = sourceFile.getParentFile();
String tmpSymbolicName = BundleHost.getSymbolicNameFromSourceDir(tmpSourceDir);
- return GhidraScriptUtil.getCompiledBundlesDir().resolve(tmpSymbolicName);
+ return BundleHost.getCompiledBundlesDir().resolve(tmpSymbolicName);
}
public String classNameForScript(ResourceFile sourceFile) {
@@ -634,7 +634,7 @@ public class GhidraSourceBundle implements GhidraBundle {
// no manifest, so create one with bndtools
Analyzer analyzer = new Analyzer();
analyzer.setJar(new Jar(bindir.toFile())); // give bnd the contents
- Stream<Object> bjars = Files.list(GhidraScriptUtil.getCompiledBundlesDir()).filter(
+ Stream<Object> bjars = Files.list(BundleHost.getCompiledBundlesDir()).filter(
f -> f.toString().endsWith(".jar")).map(f -> {
try {
return new Jar(f.toFile());
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScriptUtil.java b/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScriptUtil.java
index 779e4d0ac3..dace64a9c7 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScriptUtil.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScriptUtil.java
@@ -17,11 +17,11 @@ package ghidra.app.script;
import java.io.*;
import java.nio.file.Files;
-import java.nio.file.Path;
import java.util.*;
import java.util.stream.Collectors;
import generic.jar.ResourceFile;
+import ghidra.app.plugin.core.osgi.BundleHost;
import ghidra.framework.Application;
import ghidra.program.model.listing.Program;
import ghidra.util.Msg;
@@ -156,15 +156,6 @@ public class GhidraScriptUtil {
return scriptList;
}
- public static Path getOsgiDir() {
- Path usersettings = Application.getUserSettingsDirectory().toPath();
- return usersettings.resolve("osgi");
- }
-
- public static Path getCompiledBundlesDir() {
- return getOsgiDir().resolve("compiled-bundles");
- }
-
/**
* Returns the list of exploded bundle directories
* @return the list
@@ -174,7 +165,7 @@ public class GhidraScriptUtil {
@Deprecated
public static List<ResourceFile> getExplodedCompiledSourceBundlePaths() {
try {
- return Files.list(getOsgiDir()).filter(Files::isDirectory).map(
+ return Files.list(BundleHost.getOsgiDir()).filter(Files::isDirectory).map(
x -> new ResourceFile(x.toFile())).collect(Collectors.toList());
}
catch (IOException e) {
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/AbstractGhidraScriptMgrPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/AbstractGhidraScriptMgrPluginTest.java
index b4ed0bca65..01d77d2c6f 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/AbstractGhidraScriptMgrPluginTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/AbstractGhidraScriptMgrPluginTest.java
@@ -975,7 +975,7 @@ public abstract class AbstractGhidraScriptMgrPluginTest
protected void cleanupOldTestFiles() throws IOException {
// remove the compiled bundles directory so that any scripts we use will be recompiled
- wipe(GhidraScriptUtil.getCompiledBundlesDir());
+ wipe(BundleHost.getCompiledBundlesDir());
String myTestName = super.testName.getMethodName();