Ghidra is a software reverse engineering (SRE) framework
GP-4065: Headless -recusive depth now defaults to 1 if importing a file
Ryan Kurtz7ee84802b83b
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.javaindex ef1d1177c1..f13bab0445 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@@ -1656,10 +1656,13 @@ public class HeadlessAnalyzer {messageLog, TaskMonitor.DUMMY);}- private void processWithImport(FSRL fsrl, String folderPath, int depth, boolean isFirstTime)+ private void processWithImport(FSRL fsrl, String folderPath, Integer depth, boolean isFirstTime)throws IOException {try (RefdFile refdFile = fsService.getRefdFile(fsrl, TaskMonitor.DUMMY)) {GFile file = refdFile.file;+ if (depth == null && isFirstTime) {+ depth = file.isDirectory() ? 0 : 1; // set default depth+ }if ((options.recursive || isFirstTime) && file.isDirectory()) {processFS(file.getFilesystem(), file, folderPath, depth);return;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessOptions.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessOptions.javaindex 04d8cc0232..bfeb35e8fb 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessOptions.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessOptions.java@@ -63,7 +63,7 @@ public class HeadlessOptions {// -recursiveboolean recursive;- int recursiveDepth;+ Integer recursiveDepth; // 'null' means use default depth, which is different for files vs dirs// -readOnlyboolean readOnly;@@ -130,7 +130,7 @@ public class HeadlessOptions {propertiesFilePaths = new ArrayList<>();overwrite = false;recursive = false;- recursiveDepth = 0;+ recursiveDepth = null;readOnly = false;deleteProject = false;analyze = true;@@ -343,9 +343,7 @@ public class HeadlessOptions {*/public void enableRecursiveProcessing(boolean enabled, Integer depth) {this.recursive = enabled;- if (depth != null) {- this.recursiveDepth = depth;- }+ this.recursiveDepth = depth;}/**diff --git a/Ghidra/RuntimeScripts/Common/support/analyzeHeadlessREADME.html b/Ghidra/RuntimeScripts/Common/support/analyzeHeadlessREADME.htmlindex 737482a746..fee4b0070a 100644--- a/Ghidra/RuntimeScripts/Common/support/analyzeHeadlessREADME.html+++ b/Ghidra/RuntimeScripts/Common/support/analyzeHeadlessREADME.html@@ -404,9 +404,10 @@ The Headless Analyzer uses the command-line parameters discussed below. See <a hSpecifying a positive integer value for the optional <typewriter><depth></typewriter>argument enables recursive descent into supported container files (e.g., zip, tar, .a, etc).The depth value only applies to nested container files. Intermediate directories found within- each nested container file are not affected by the specified depth value. Specifying a depth- value of 0 has the same effect as not specifying any depth value (i.e., container files will not be recursed into).- </LI>+ each nested container file are not affected by the specified depth value. If a depth value is+ not specified, it will default to 0 if importing a directory, and 1 if importing a file. A+ depth of 0 will prevent recursing into any container files.+ </LI><br><br>