-import or -process modes. In order for recursive processing of files to
- * occur, the user must have specified a directory (and not a specific file)
- * for the Headless Analyzer to import or process.
+ * -import or -process modes. In order for recursive processing of
+ * files to occur, the user must have specified a project folder to process or a directory or
+ * supported {@link GFileSystem} container file to import
*
- * @param enabled if true, enables recursive processing
+ * @param enabled if true, enables recursive import/processing
*/
public void enableRecursiveProcessing(boolean enabled) {
+ enableRecursiveProcessing(enabled, null);
+ }
+
+ /**
+ * This method can be used to enable recursive processing of files during
+ * -import or -process modes. In order for recursive processing of
+ * files to occur, the user must have specified a project folder to process or a directory or
+ * supported {@link GFileSystem} container file to import
+ *
+ * @param enabled if true, enables recursive import/processing
+ * @param depth maximum container recursion depth (could be null to use default)
+ */
+ public void enableRecursiveProcessing(boolean enabled, Integer depth) {
this.recursive = enabled;
+ if (depth != null) {
+ this.recursiveDepth = depth;
+ }
}
/**
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/importer/AutoImporter.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/importer/AutoImporter.java
index ae2984a4c4..6804fee2a1 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/importer/AutoImporter.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/importer/AutoImporter.java
@@ -17,7 +17,6 @@ package ghidra.app.util.importer;
import java.io.File;
import java.io.IOException;
-import java.nio.file.AccessMode;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
@@ -25,8 +24,8 @@ import java.util.function.Predicate;
import generic.stl.Pair;
import ghidra.app.util.Option;
import ghidra.app.util.bin.ByteProvider;
-import ghidra.app.util.bin.FileByteProvider;
import ghidra.app.util.opinion.*;
+import ghidra.formats.gfilesystem.FSRL;
import ghidra.formats.gfilesystem.FileSystemService;
import ghidra.framework.model.*;
import ghidra.program.model.address.AddressFactory;
@@ -83,8 +82,49 @@ public final class AutoImporter {
String projectFolderPath, Object consumer, MessageLog messageLog, TaskMonitor monitor)
throws IOException, CancelledException, DuplicateNameException, InvalidNameException,
VersionException, LoadException {
- return importFresh(file, project, projectFolderPath, consumer, messageLog,
- monitor, LoaderService.ACCEPT_ALL, LoadSpecChooser.CHOOSE_THE_FIRST_PREFERRED, null,
+ return importByUsingBestGuess(fileToFsrl(file), project, projectFolderPath, consumer,
+ messageLog, monitor);
+ }
+
+ /**
+ * Automatically imports the given {@link FSRL} with the best matching {@link Loader} for the
+ * {@link File}'s format.
+ * + * Note that when the import completes, the returned {@link Loaded} {@link Program}s are not + * saved to a project. That is the responsibility of the caller (see + * {@link LoadResults#save(Project, Object, MessageLog, TaskMonitor)}). + *
+ * It is also the responsibility of the caller to release the returned {@link Loaded}
+ * {@link Program}s with {@link LoadResults#release(Object)} when they are no longer needed.
+ *
+ * @param fsrl The {@link FSRL} to import
+ * @param project The {@link Project}. Loaders can use this to take advantage of existing
+ * {@link DomainFolder}s and {@link DomainFile}s to do custom behaviors such as loading
+ * libraries. Could be null if there is no project.
+ * @param projectFolderPath A suggested project folder path for the {@link Loaded}
+ * {@link Program}s. This is just a suggestion, and a {@link Loader} implementation
+ * reserves the right to change it for each {@link Loaded} result. The {@link Loaded} results
+ * should be queried for their true project folder paths using
+ * {@link Loaded#getProjectFolderPath()}.
+ * @param consumer A consumer
+ * @param messageLog The log
+ * @param monitor A task monitor
+ * @return The {@link LoadResults} which contains one ore more {@link Loaded} {@link Program}s
+ * (created but not saved)
+ * @throws IOException if there was an IO-related problem loading
+ * @throws CancelledException if the operation was cancelled
+ * @throws DuplicateNameException if the load resulted in a {@link Program} naming conflict
+ * @throws InvalidNameException if an invalid {@link Program} name was used during load
+ * @throws VersionException if there was an issue with database versions, probably due to a
+ * failed language upgrade
+ * @throws LoadException if nothing was loaded
+ */
+ public static LoadResults
+ * Note that when the import completes, the returned {@link Loaded} {@link Program}s are not
+ * saved to a project. That is the responsibility of the caller (see
+ * {@link LoadResults#save(Project, Object, MessageLog, TaskMonitor)}).
+ *
+ * It is also the responsibility of the caller to release the returned {@link Loaded}
+ * {@link Program}s with {@link LoadResults#release(Object)} when they are no longer needed.
+ *
+ * @param fsrl The {@link FSRL} to import
+ * @param project The {@link Project}. Loaders can use this to take advantage of existing
+ * {@link DomainFolder}s and {@link DomainFile}s to do custom behaviors such as loading
+ * libraries. Could be null if there is no project.
+ * @param projectFolderPath A suggested project folder path for the {@link Loaded}
+ * {@link Program}s. This is just a suggestion, and a {@link Loader} implementation
+ * reserves the right to change it for each {@link Loaded} result. The {@link Loaded} results
+ * should be queried for their true project folder paths using
+ * {@link Loaded#getProjectFolderPath()}.
+ * @param loaderClass The {@link Loader} class to use
+ * @param loaderArgs A {@link List} of optional {@link Loader}-specific arguments
+ * @param consumer A consumer
+ * @param messageLog The log
+ * @param monitor A task monitor
+ * @return The {@link LoadResults} which contains one ore more {@link Loaded} {@link Program}s
+ * (created but not saved)
+ * @throws IOException if there was an IO-related problem loading
+ * @throws CancelledException if the operation was cancelled
+ * @throws DuplicateNameException if the load resulted in a {@link Program} naming conflict
+ * @throws InvalidNameException if an invalid {@link Program} name was used during load
+ * @throws VersionException if there was an issue with database versions, probably due to a
+ * failed language upgrade
+ * @throws LoadException if nothing was loaded
+ */
+ public static LoadResults
+ * Note that when the import completes, the returned {@link Loaded} {@link Program}s are not
+ * saved to a project. That is the responsibility of the caller (see
+ * {@link LoadResults#save(Project, Object, MessageLog, TaskMonitor)}).
+ *
+ * It is also the responsibility of the caller to release the returned {@link Loaded}
+ * {@link Program}s with {@link LoadResults#release(Object)} when they are no longer needed.
+ *
+ * @param fsrl The {@link FSRL} to import
+ * @param project The {@link Project}. Loaders can use this to take advantage of existing
+ * {@link DomainFolder}s and {@link DomainFile}s to do custom behaviors such as loading
+ * libraries. Could be null if there is no project.
+ * @param projectFolderPath A suggested project folder path for the {@link Loaded}
+ * {@link Program}s. This is just a suggestion, and a {@link Loader} implementation
+ * reserves the right to change it for each {@link Loaded} result. The {@link Loaded} results
+ * should be queried for their true project folder paths using
+ * {@link Loaded#getProjectFolderPath()}.
+ * @param language The desired {@link Language}
+ * @param compilerSpec The desired {@link CompilerSpec compiler specification}
+ * @param consumer A consumer
+ * @param messageLog The log
+ * @param monitor A task monitor
+ * @return The {@link LoadResults} which contains one ore more {@link Loaded} {@link Program}s
+ * (created but not saved)
+ * @throws IOException if there was an IO-related problem loading
+ * @throws CancelledException if the operation was cancelled
+ * @throws DuplicateNameException if the load resulted in a {@link Program} naming conflict
+ * @throws InvalidNameException if an invalid {@link Program} name was used during load
+ * @throws VersionException if there was an issue with database versions, probably due to a
+ * failed language upgrade
+ * @throws LoadException if nothing was loaded
+ */
+ public static LoadResults
+ * Note that when the import completes, the returned {@link Loaded} {@link Program}s are not
+ * saved to a project. That is the responsibility of the caller (see
+ * {@link LoadResults#save(Project, Object, MessageLog, TaskMonitor)}).
+ *
+ * It is also the responsibility of the caller to release the returned {@link Loaded}
+ * {@link Program}s with {@link LoadResults#release(Object)} when they are no longer needed.
+ *
+ * @param fsrl The {@link FSRL} to import
+ * @param project The {@link Project}. Loaders can use this to take advantage of existing
+ * {@link DomainFolder}s and {@link DomainFile}s to do custom behaviors such as loading
+ * libraries. Could be null if there is no project.
+ * @param projectFolderPath A suggested project folder path for the {@link Loaded}
+ * {@link Program}s. This is just a suggestion, and a {@link Loader} implementation
+ * reserves the right to change it for each {@link Loaded} result. The {@link Loaded} results
+ * should be queried for their true project folder paths using
+ * {@link Loaded#getProjectFolderPath()}.
+ * @param loaderClass The {@link Loader} class to use
+ * @param loaderArgs A {@link List} of optional {@link Loader}-specific arguments
+ * @param language The desired {@link Language}
+ * @param compilerSpec The desired {@link CompilerSpec compiler specification}
+ * @param consumer A consumer
+ * @param messageLog The log
+ * @param monitor A task monitor
+ * @return The {@link LoadResults} which contains one ore more {@link Loaded} {@link Program}s
+ * (created but not saved)
+ * @throws IOException if there was an IO-related problem loading
+ * @throws CancelledException if the operation was cancelled
+ * @throws DuplicateNameException if the load resulted in a {@link Program} naming conflict
+ * @throws InvalidNameException if an invalid {@link Program} name was used during load
+ * @throws VersionException if there was an issue with database versions, probably due to a
+ * failed language upgrade
+ */
+ public static LoadResults
+ * Note that when the import completes, the returned {@link Loaded} {@link Program}s are not
+ * saved to a project. That is the responsibility of the caller (see
+ * {@link LoadResults#save(Project, Object, MessageLog, TaskMonitor)}).
+ *
+ * It is also the responsibility of the caller to release the returned {@link Loaded}
+ * {@link Program}s with {@link LoadResults#release(Object)} when they are no longer needed.
+ *
+ * @param fsrl The {@link FSRL} to import
+ * @param project The {@link Project}. Loaders can use this to take advantage of existing
+ * {@link DomainFolder}s and {@link DomainFile}s to do custom behaviors such as loading
+ * libraries. Could be null if there is no project.
+ * @param projectFolderPath A suggested project folder path for the {@link Loaded}
+ * {@link Program}s. This is just a suggestion, and a {@link Loader} implementation
+ * reserves the right to change it for each {@link Loaded} result. The {@link Loaded} results
+ * should be queried for their true project folder paths using
+ * {@link Loaded#getProjectFolderPath()}.
+ * @param loaderFilter A {@link Predicate} used to choose what {@link Loader}(s) get used
+ * @param loadSpecChooser A {@link LoadSpecChooser} used to choose what {@link LoadSpec}(s) get
+ * used
+ * @param importNameOverride The name to use for the imported thing. Null to use the
+ * {@link Loader}'s preferred name.
+ * @param optionChooser A {@link OptionChooser} used to choose what {@link Loader} options get
+ * used
+ * @param consumer A consumer
+ * @param messageLog The log
+ * @param monitor A task monitor
+ * @return The {@link LoadResults} which contains one ore more {@link Loaded} {@link Program}s
+ * (created but not saved)
+ * @throws IOException if there was an IO-related problem loading
+ * @throws CancelledException if the operation was cancelled
+ * @throws DuplicateNameException if the load resulted in a {@link Program} naming conflict
+ * @throws InvalidNameException if an invalid {@link Program} name was used during load
+ * @throws VersionException if there was an issue with database versions, probably due to a
+ * failed language upgrade
+ * @throws LoadException if nothing was loaded
+ */
+ public static LoadResults Affects -import or -process modes – used for determining whether to process files in current directory or files in current directory + all its subfolders.
Specifies one or more executables (or directories of executables) to import. When importing a
- directory, a folder with the same name will be created in the Ghidra project. When using the
-
Operating system-specific wildcard characters can be used when importing files and/or directories.
Please see the Wildcards section for more details.
@@ -395,11 +396,17 @@ The Headless Analyzer uses the command-line parameters discussed below. See
+
If present, enables recursive descent into directories and project sub-folders when a directory/
folder has been specified in
+ Specifying a positive integer value for the optional
diff --git a/GhidraDocs/GhidraClass/Intermediate/HeadlessAnalyzer.html b/GhidraDocs/GhidraClass/Intermediate/HeadlessAnalyzer.html
index 0c7eee8d3e..de112c8e14 100644
--- a/GhidraDocs/GhidraClass/Intermediate/HeadlessAnalyzer.html
+++ b/GhidraDocs/GhidraClass/Intermediate/HeadlessAnalyzer.html
@@ -34,7 +34,7 @@
[-scriptPath "<path1>[;<path2>...]"]
[-propertiesPath "<path1>[;<path2>...]"]
[-log <path to log file>] [-scriptlog <path to script log file>]
- [-overwrite] [-recursive] [-readOnly] [-deleteProject]
+ [-overwrite] [-recursive [<depth>]] [-readOnly] [-deleteProject]
[-noanalysis]
[-processor <languageID>] [-cspec <compilerSpecID>]
[-analysisTimeoutPerFile <timeout in seconds>]
@@ -263,11 +263,12 @@