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 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.java index 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 { // -recursive boolean recursive; - int recursiveDepth; + Integer recursiveDepth; // 'null' means use default depth, which is different for files vs dirs // -readOnly boolean 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.html index 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 <depth> 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). - + 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. +