Package ghidra.formats.gfilesystem
Class AbstractFileExtractorTask
java.lang.Object
ghidra.util.task.Task
ghidra.formats.gfilesystem.AbstractFileExtractorTask
- All Implemented Interfaces:
MonitoredRunnable
- Direct Known Subclasses:
GFileSystemExtractAllTask
Common base class for tasks that need to extract files from a GFileSystem location.
-
Field Summary
Fields inherited from class ghidra.util.task.Task
taskMonitor, waitForTaskCompleted
-
Constructor Summary
ConstructorDescriptionAbstractFileExtractorTask
(String title, boolean canCancel, boolean hasProgress, boolean isModal, File rootOutputDir) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
extractFile
(GFile srcFile, File outputFile, TaskMonitor monitor) protected InputStream
getSourceFileInputStream
(GFile file, TaskMonitor monitor) long
Return the number of bytes that were exported.int
Return the number of directories that were exported.int
Return the number of files that were exported.protected boolean
handleUnexpectedException
(GFile file, Exception e) Allows custom handling of exceptions that occur during file extraction.protected String
mapSourceFilenameToDest
(GFile srcFile) Maps the untrusted, potentially hostile, filename of the source file to a name that is suitable to be used to create a file on the user's local file system.protected void
processDirectory
(GFile srcGFileDirectory, File destDirectory, TaskMonitor monitor) Extract the contents of a directory in aGFileSystem
into a local file system directory.protected void
processFile
(GFile srcFile, File destFSFile, TaskMonitor monitor) protected void
startExtract
(GFileSystem fs, GFile srcDir, TaskMonitor monitor) Starts the file extraction process.Methods inherited from class ghidra.util.task.Task
addTaskListener, canCancel, cancel, getStatusTextAlignment, getTaskTitle, getWaitForTaskCompleted, hasProgress, isCancelled, isModal, monitoredRun, notifyTaskListeners, run, setHasProgress
-
Field Details
-
fs
-
rootOutputDirectory
-
-
Constructor Details
-
AbstractFileExtractorTask
public AbstractFileExtractorTask(String title, boolean canCancel, boolean hasProgress, boolean isModal, File rootOutputDir) - Parameters:
title
- SeeTask(String, boolean, boolean, boolean)
canCancel
- SeeTask(String, boolean, boolean, boolean)
hasProgress
- SeeTask(String, boolean, boolean, boolean)
isModal
- SeeTask(String, boolean, boolean, boolean)
rootOutputDir
- base directory where files will be extracted to
-
-
Method Details
-
startExtract
protected void startExtract(GFileSystem fs, GFile srcDir, TaskMonitor monitor) throws CancelledException, IOException Starts the file extraction process.- Parameters:
fs
- theGFileSystem
that holds the filessrcDir
- the starting directory to extract, ifnull
, start at root of file systemmonitor
-TaskMonitor
that will be updated with progress and checked for cancel- Throws:
CancelledException
- if the extraction is cancelled.IOException
- if an exception occurs extracting the files.
-
processDirectory
protected void processDirectory(GFile srcGFileDirectory, File destDirectory, TaskMonitor monitor) throws IOException, CancelledException Extract the contents of a directory in aGFileSystem
into a local file system directory.The destination directory is created if not present.
- Parameters:
srcGFileDirectory
- if null, directory is filesystem rootdestDirectory
- destination / output directorymonitor
-TaskMonitor
to watch and update with progress- Throws:
IOException
- if IO problem.CancelledException
-
processFile
protected void processFile(GFile srcFile, File destFSFile, TaskMonitor monitor) throws IOException, CancelledException - Throws:
IOException
CancelledException
-
mapSourceFilenameToDest
Maps the untrusted, potentially hostile, filename of the source file to a name that is suitable to be used to create a file on the user's local file system.NOTE: This base implementation converts relative directory names to spelled-out versions of that directory, eg. "." becomes "dot".
If you wish to modify this behavior, override this method and return different mappings.
- Parameters:
srcFile
- source file- Returns:
- String name of the source file, possibly modified to be safer
- Throws:
IOException
- thrown if name is not mappable and the extract process should stop
-
handleUnexpectedException
Allows custom handling of exceptions that occur during file extraction.Return true if the exception should be ignored by the file extraction process, otherwise return false if it should be propagated up the call stack.
- Parameters:
file
- file that was being extracted when the exception happenede
- the exception- Returns:
- true if the exception should be suppressed, false if the exception should be thrown
-
extractFile
protected void extractFile(GFile srcFile, File outputFile, TaskMonitor monitor) throws CancelledException - Throws:
CancelledException
-
getSourceFileInputStream
protected InputStream getSourceFileInputStream(GFile file, TaskMonitor monitor) throws CancelledException, IOException - Throws:
CancelledException
IOException
-
getTotalFilesExportedCount
public int getTotalFilesExportedCount()Return the number of files that were exported.- Returns:
- the number of files that were exported
-
getTotalDirsExportedCount
public int getTotalDirsExportedCount()Return the number of directories that were exported.- Returns:
- the number of directories that were exported
-
getTotalBytesExportedCount
public long getTotalBytesExportedCount()Return the number of bytes that were exported.- Returns:
- the number of bytes that were exported
-