GP-6132: Fixed a bug in the the PyGhidra headless analyzer that resulted in the wrong exception being thrown when a script tries to import a module that isn't found

This commit is contained in:
Ryan Kurtz
2025-11-18 14:15:44 -05:00
parent 72cb11adfb
commit 0d52943d1f
10 changed files with 40 additions and 67 deletions
@@ -18,7 +18,6 @@ package ghidra.pyghidra;
import org.junit.After;
import org.junit.Before;
import ghidra.app.plugin.core.osgi.BundleHost;
import ghidra.app.script.GhidraScriptUtil;
import ghidra.framework.plugintool.PluginTool;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
@@ -35,14 +34,14 @@ public class PyGhidraPluginTest extends AbstractGhidraHeadedIntegrationTest {
public void setUp() throws Exception {
env = new TestEnv();
PluginTool tool = env.getTool();
GhidraScriptUtil.initialize(new BundleHost(), null);
GhidraScriptUtil.acquireBundleHostReference();
tool.addPlugin(PyGhidraPlugin.class.getName());
env.getPlugin(PyGhidraPlugin.class);
}
@After
public void tearDown() throws Exception {
GhidraScriptUtil.dispose();
GhidraScriptUtil.releaseBundleHostReference();
env.dispose();
}
}
@@ -26,7 +26,6 @@ import javax.swing.KeyStroke;
import org.junit.*;
import generic.jar.ResourceFile;
import ghidra.app.plugin.core.osgi.BundleHost;
import ghidra.app.script.GhidraScriptUtil;
import ghidra.app.script.ScriptInfo;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
@@ -35,7 +34,7 @@ public class PythonScriptInfoTest extends AbstractGhidraHeadedIntegrationTest {
@Before
public void setUp() throws Exception {
GhidraScriptUtil.initialize(new BundleHost(), null);
GhidraScriptUtil.acquireBundleHostReference();
Path userScriptDir = java.nio.file.Paths.get(GhidraScriptUtil.USER_SCRIPTS_DIR);
if (Files.notExists(userScriptDir)) {
Files.createDirectories(userScriptDir);
@@ -44,7 +43,7 @@ public class PythonScriptInfoTest extends AbstractGhidraHeadedIntegrationTest {
@After
public void tearDown() throws Exception {
GhidraScriptUtil.dispose();
GhidraScriptUtil.releaseBundleHostReference();
}
@Test