avoid calling GhidraScriptUtils.getScriptSourceDirectories

- when called from the GUI, the bundle host manages paths
- when used to find a script by name, use findScriptByName
This commit is contained in:
Jason P. Leasure
2020-04-28 17:23:08 -04:00
parent 2b49816c6c
commit 7ee2467016
7 changed files with 135 additions and 156 deletions
@@ -59,34 +59,31 @@ public class PythonScript extends GhidraScript {
throw new AssertException("Could not get Ghidra Python interpreter!");
}
}
for (ResourceFile dir : GhidraScriptUtil.getScriptSourceDirectories()) {
ResourceFile scriptSource = new ResourceFile(dir, scriptName);
if (scriptSource.exists()) {
GhidraScriptProvider provider = GhidraScriptUtil.getProvider(scriptSource);
GhidraScript ghidraScript = provider.getScriptInstance(scriptSource, writer);
if (ghidraScript == null) {
throw new IllegalArgumentException("Script does not exist: " + scriptName);
}
if (scriptState == state) {
updateStateFromVariables();
}
if (ghidraScript instanceof PythonScript) {
ghidraScript.set(scriptState, monitor, writer);
PythonScript pythonScript = (PythonScript) ghidraScript;
interpreter.execFile(pythonScript.getSourceFile(), pythonScript);
}
else {
ghidraScript.execute(scriptState, monitor, writer);
}
if (scriptState == state) {
loadVariablesFromState();
}
return;
ResourceFile scriptSource = GhidraScriptUtil.findScriptByName(scriptName);
if (scriptSource != null) {
GhidraScriptProvider provider = GhidraScriptUtil.getProvider(scriptSource);
GhidraScript ghidraScript = provider.getScriptInstance(scriptSource, writer);
if (ghidraScript == null) {
throw new IllegalArgumentException("Script does not exist: " + scriptName);
}
if (scriptState == state) {
updateStateFromVariables();
}
if (ghidraScript instanceof PythonScript) {
ghidraScript.set(scriptState, monitor, writer);
PythonScript pythonScript = (PythonScript) ghidraScript;
interpreter.execFile(pythonScript.getSourceFile(), pythonScript);
}
else {
ghidraScript.execute(scriptState, monitor, writer);
}
if (scriptState == state) {
loadVariablesFromState();
}
return;
}
throw new IllegalArgumentException("Script does not exist: " + scriptName);
}