Merge remote-tracking branch

'origin/GP-781_jpleasu_scriptPath_parser--SQUASHED' into patch
This commit is contained in:
ghidra1 2021-03-17 19:13:21 -04:00
commit 0429e754c8
2 changed files with 27 additions and 12 deletions

View file

@ -293,9 +293,10 @@ public class HeadlessAnalyzer {
}
}
GhidraScriptUtil.initialize(new BundleHost(), options.scriptPaths);
List<String> parsedScriptPaths = parseScriptPaths(options.scriptPaths);
GhidraScriptUtil.initialize(new BundleHost(), parsedScriptPaths);
try {
initializeScriptPaths();
showConfiguredScriptPaths();
compileScripts();
Msg.info(HeadlessAnalyzer.class, "HEADLESS: execution starts");
@ -400,9 +401,10 @@ public class HeadlessAnalyzer {
}
}
GhidraScriptUtil.initialize(new BundleHost(), options.scriptPaths);
List<String> parsedScriptPaths = parseScriptPaths(options.scriptPaths);
GhidraScriptUtil.initialize(new BundleHost(), parsedScriptPaths);
try {
initializeScriptPaths();
showConfiguredScriptPaths();
compileScripts();
Msg.info(HeadlessAnalyzer.class, "HEADLESS: execution starts");
@ -668,10 +670,23 @@ public class HeadlessAnalyzer {
}
}
/**
* Gather paths where scripts may be found.
*/
private void initializeScriptPaths() {
private List<String> parseScriptPaths(List<String> scriptPaths) {
List<String> parsedScriptPaths = new ArrayList<>();
for (String path : scriptPaths) {
ResourceFile pathFile = Path.fromPathString(path);
String absPath = pathFile.getAbsolutePath();
if (pathFile.exists()) {
parsedScriptPaths.add(absPath);
}
else {
Msg.warn(this, "REPORT: Could not find -scriptPath entry, skipping: " + absPath);
}
}
return parsedScriptPaths;
}
private void showConfiguredScriptPaths() {
StringBuffer buf = new StringBuffer("HEADLESS Script Paths:");
for (ResourceFile dir : GhidraScriptUtil.getScriptSourceDirectories()) {
buf.append("\n ");
@ -856,8 +871,8 @@ public class HeadlessAnalyzer {
Class<?> c = Class.forName(className, true, classLoaderForDotClassScripts);
// Get parent folder to pass to GhidraScript
File parentFile = new File(
c.getResource(c.getSimpleName() + ".class").toURI()).getParentFile();
File parentFile = new File(c.getResource(c.getSimpleName() + ".class").toURI())
.getParentFile();
currScript = (GhidraScript) c.getConstructor().newInstance();
currScript.setScriptArgs(scriptArgs);

View file

@ -313,7 +313,7 @@ The Headless Analyzer uses the command-line parameters discussed below. See <a h
<LI>
<a name="scriptPath"><typewriter>-scriptPath &quot;&lt;path1&gt;[;&lt;path2&gt;...]&quot;</typewriter></a>
<br>Specifies the search path(s) for scripts, including secondary scripts (a script invoked from
another script). A path may start with <typewriter>$GHIDRA_SCRIPT</typewriter>, which corresponds
another script). A path may start with <typewriter>$GHIDRA_HOME</typewriter>, which corresponds
to the Ghidra installation directory, or <typewriter>$USER_HOME</typewriter>, which corresponds
to the user&apos;s home directory. On Unix systems, these home variables must be escaped using a
&apos;<typewriter>\</typewriter>&apos; (backslash) character.
@ -344,7 +344,7 @@ The Headless Analyzer uses the command-line parameters discussed below. See <a h
<LI>
<a name="propertiesPath"><typewriter>-propertiesPath &quot;&lt;path1&gt;[;&lt;path2&gt;&hellip;]&quot;</typewriter></a>
<br>Specifies path(s) that contain <typewriter>.properties</typewriter> files used by scripts or
secondary/subscripts. A path may start with <typewriter>$GHIDRA_SCRIPT</typewriter>, which
secondary/subscripts. A path may start with <typewriter>$GHIDRA_HOME</typewriter>, which
corresponds to the Ghidra installation directory, or <typewriter>$USER_HOME</typewriter>, which
corresponds to the user&apos;s home directory. On Unix systems these home variables must be
escaped with a &apos;\&apos; character.