mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
update python & headless tests to manage GhidraScriptUtil resource
This commit is contained in:
parent
7ee2467016
commit
5f11c9cf7d
6 changed files with 117 additions and 93 deletions
|
@ -49,9 +49,15 @@ public class GhidraScriptRunner implements GhidraLaunchable {
|
|||
System.exit(0);
|
||||
}
|
||||
String logFile = null; //TODO get from arguments?
|
||||
GhidraScriptUtil.initialize(new BundleHost(), scriptPaths);
|
||||
try {
|
||||
initialize(layout, logFile, true);
|
||||
runScript(args[0]);
|
||||
}
|
||||
finally {
|
||||
GhidraScriptUtil.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void runScript(String string) throws Exception {
|
||||
GhidraScript ghidraScript = getGhidraScript(string);
|
||||
|
@ -188,8 +194,6 @@ public class GhidraScriptRunner implements GhidraLaunchable {
|
|||
* Gather paths where scripts may be found.
|
||||
*/
|
||||
private void initializeScriptPaths() {
|
||||
GhidraScriptUtil.initialize(new BundleHost(), scriptPaths);
|
||||
|
||||
StringBuffer buf = new StringBuffer("HEADLESS Script Paths:");
|
||||
for (ResourceFile dir : GhidraScriptUtil.getScriptSourceDirectories()) {
|
||||
buf.append("\n ");
|
||||
|
|
|
@ -293,6 +293,8 @@ public class HeadlessAnalyzer {
|
|||
}
|
||||
}
|
||||
|
||||
GhidraScriptUtil.initialize(new BundleHost(), options.scriptPaths);
|
||||
try {
|
||||
initializeScriptPaths();
|
||||
compileScripts();
|
||||
|
||||
|
@ -345,6 +347,10 @@ public class HeadlessAnalyzer {
|
|||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
GhidraScriptUtil.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the optional import file/directory list and process each imported file:
|
||||
|
@ -394,6 +400,8 @@ public class HeadlessAnalyzer {
|
|||
}
|
||||
}
|
||||
|
||||
GhidraScriptUtil.initialize(new BundleHost(), options.scriptPaths);
|
||||
try {
|
||||
initializeScriptPaths();
|
||||
compileScripts();
|
||||
|
||||
|
@ -417,8 +425,8 @@ public class HeadlessAnalyzer {
|
|||
options.deleteProject = true;
|
||||
}
|
||||
|
||||
Msg.info(this,
|
||||
"Creating " + (options.deleteProject ? "temporary " : "") + "project: " + locator);
|
||||
Msg.info(this, "Creating " + (options.deleteProject ? "temporary " : "") +
|
||||
"project: " + locator);
|
||||
project = getProjectManager().createProject(locator, null, false);
|
||||
}
|
||||
|
||||
|
@ -443,6 +451,10 @@ public class HeadlessAnalyzer {
|
|||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
GhidraScriptUtil.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the most recent analysis timed out.
|
||||
|
@ -660,8 +672,6 @@ public class HeadlessAnalyzer {
|
|||
* Gather paths where scripts may be found.
|
||||
*/
|
||||
private void initializeScriptPaths() {
|
||||
GhidraScriptUtil.initialize(new BundleHost(), options.scriptPaths);
|
||||
|
||||
StringBuffer buf = new StringBuffer("HEADLESS Script Paths:");
|
||||
for (ResourceFile dir : GhidraScriptUtil.getScriptSourceDirectories()) {
|
||||
buf.append("\n ");
|
||||
|
|
|
@ -87,8 +87,6 @@ public abstract class AbstractGhidraScriptMgrPluginTest
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
System.err.printf("===== Starting %s ======\n", testName.getMethodName());
|
||||
|
||||
setErrorGUIEnabled(false);
|
||||
|
||||
// change the eclipse port so that Eclipse doesn't try to edit the script when
|
||||
|
|
|
@ -22,6 +22,8 @@ import java.io.ByteArrayOutputStream;
|
|||
import org.junit.*;
|
||||
|
||||
import generic.jar.ResourceFile;
|
||||
import ghidra.app.plugin.core.osgi.BundleHost;
|
||||
import ghidra.app.script.GhidraScriptUtil;
|
||||
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
|
||||
|
||||
/**
|
||||
|
@ -35,6 +37,7 @@ public class PythonInterpreterTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
out = new ByteArrayOutputStream();
|
||||
GhidraScriptUtil.initialize(new BundleHost(), null);
|
||||
interpreter = GhidraPythonInterpreter.get();
|
||||
interpreter.setOut(out);
|
||||
interpreter.setErr(out);
|
||||
|
@ -44,6 +47,7 @@ public class PythonInterpreterTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
public void tearDown() throws Exception {
|
||||
out.reset();
|
||||
interpreter.cleanup();
|
||||
GhidraScriptUtil.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,10 +15,12 @@
|
|||
*/
|
||||
package ghidra.python;
|
||||
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
import ghidra.app.plugin.core.osgi.BundleHost;
|
||||
import ghidra.app.script.GhidraScriptUtil;
|
||||
import ghidra.framework.plugintool.PluginTool;
|
||||
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
|
||||
import ghidra.test.TestEnv;
|
||||
|
@ -36,12 +38,14 @@ public class PythonPluginTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
public void setUp() throws Exception {
|
||||
env = new TestEnv();
|
||||
tool = env.getTool();
|
||||
GhidraScriptUtil.initialize(new BundleHost(), null);
|
||||
tool.addPlugin(PythonPlugin.class.getName());
|
||||
plugin = env.getPlugin(PythonPlugin.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
GhidraScriptUtil.dispose();
|
||||
env.dispose();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ import org.junit.*;
|
|||
|
||||
import generic.jar.ResourceFile;
|
||||
import ghidra.app.plugin.core.console.ConsolePlugin;
|
||||
import ghidra.app.plugin.core.osgi.BundleHost;
|
||||
import ghidra.app.script.GhidraScriptUtil;
|
||||
import ghidra.app.script.GhidraState;
|
||||
import ghidra.app.services.ConsoleService;
|
||||
import ghidra.framework.Application;
|
||||
|
@ -45,12 +47,14 @@ public class PythonScriptTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
public void setUp() throws Exception {
|
||||
env = new TestEnv();
|
||||
tool = env.getTool();
|
||||
GhidraScriptUtil.initialize(new BundleHost(), null);
|
||||
tool.addPlugin(ConsolePlugin.class.getName());
|
||||
console = tool.getService(ConsoleService.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
GhidraScriptUtil.dispose();
|
||||
env.dispose();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue