diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java index e18ca98a78..f63589fdac 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java @@ -293,9 +293,10 @@ public class HeadlessAnalyzer { } } - GhidraScriptUtil.initialize(new BundleHost(), options.scriptPaths); + List 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 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 parseScriptPaths(List scriptPaths) { + List 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); diff --git a/Ghidra/RuntimeScripts/Common/support/analyzeHeadlessREADME.html b/Ghidra/RuntimeScripts/Common/support/analyzeHeadlessREADME.html index 00b7bd9cb9..dfbea0d5de 100644 --- a/Ghidra/RuntimeScripts/Common/support/analyzeHeadlessREADME.html +++ b/Ghidra/RuntimeScripts/Common/support/analyzeHeadlessREADME.html @@ -313,7 +313,7 @@ The Headless Analyzer uses the command-line parameters discussed below. See -scriptPath "<path1>[;<path2>...]"
Specifies the search path(s) for scripts, including secondary scripts (a script invoked from - another script). A path may start with $GHIDRA_SCRIPT, which corresponds + another script). A path may start with $GHIDRA_HOME, which corresponds to the Ghidra installation directory, or $USER_HOME, which corresponds to the user's home directory. On Unix systems, these home variables must be escaped using a '\' (backslash) character. @@ -344,7 +344,7 @@ The Headless Analyzer uses the command-line parameters discussed below. See -propertiesPath "<path1>[;<path2>…]"
Specifies path(s) that contain .properties files used by scripts or - secondary/subscripts. A path may start with $GHIDRA_SCRIPT, which + secondary/subscripts. A path may start with $GHIDRA_HOME, which corresponds to the Ghidra installation directory, or $USER_HOME, which corresponds to the user's home directory. On Unix systems these home variables must be escaped with a '\' character.