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
public abstract class AbstractFileExtractorTask extends Task
Common base class for tasks that need to extract files from a GFileSystem location.
-
-
Field Summary
Fields Modifier and Type Field Description protected GFileSystemfsprotected java.io.FilerootOutputDirectory-
Fields inherited from class ghidra.util.task.Task
taskMonitor, waitForTaskCompleted
-
-
Constructor Summary
Constructors Constructor Description AbstractFileExtractorTask(java.lang.String title, boolean canCancel, boolean hasProgress, boolean isModal, java.io.File rootOutputDir)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidextractFile(GFile srcFile, java.io.File outputFile, TaskMonitor monitor)protected java.io.InputStreamgetSourceFileInputStream(GFile file, TaskMonitor monitor)longgetTotalBytesExportedCount()Return the number of bytes that were exported.intgetTotalDirsExportedCount()Return the number of directories that were exported.intgetTotalFilesExportedCount()Return the number of files that were exported.protected booleanhandleUnexpectedException(GFile file, java.lang.Exception e)Allows custom handling of exceptions that occur during file extraction.protected java.lang.StringmapSourceFilenameToDest(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 voidprocessDirectory(GFile srcGFileDirectory, java.io.File destDirectory, TaskMonitor monitor)Extract the contents of a directory in aGFileSysteminto a local file system directory.protected voidprocessFile(GFile srcFile, java.io.File destFSFile, TaskMonitor monitor)protected voidstartExtract(GFileSystem fs, GFile srcDir, TaskMonitor monitor)Starts the file extraction process.-
Methods inherited from class ghidra.util.task.Task
addTaskListener, canCancel, cancel, getStatusTextAlignment, getTaskTitle, hasProgress, isModal, monitoredRun, notifyTaskListeners, run, setHasProgress
-
-
-
-
Field Detail
-
fs
protected GFileSystem fs
-
rootOutputDirectory
protected java.io.File rootOutputDirectory
-
-
Constructor Detail
-
AbstractFileExtractorTask
public AbstractFileExtractorTask(java.lang.String title, boolean canCancel, boolean hasProgress, boolean isModal, java.io.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 Detail
-
startExtract
protected void startExtract(GFileSystem fs, GFile srcDir, TaskMonitor monitor) throws CancelledException, java.io.IOException
Starts the file extraction process.- Parameters:
fs- theGFileSystemthat holds the filessrcDir- the starting directory to extract, ifnull, start at root of file systemrootOutputDirectory- the destination directorymonitor-TaskMonitorthat will be updated with progress and checked for cancel- Throws:
CancelledExceptionjava.io.IOException
-
processDirectory
protected void processDirectory(GFile srcGFileDirectory, java.io.File destDirectory, TaskMonitor monitor) throws java.io.IOException, CancelledException
Extract the contents of a directory in aGFileSysteminto a local file system directory.The destination directory is created if not present.
- Parameters:
srcGFileDirectory- if null, directory is filesystem rootdestDirectory- destination / output directorymonitor-TaskMonitorto watch and update with progress- Throws:
java.io.IOException- if IO problem.CancelledException
-
processFile
protected void processFile(GFile srcFile, java.io.File destFSFile, TaskMonitor monitor) throws java.io.IOException, CancelledException
- Throws:
java.io.IOExceptionCancelledException
-
mapSourceFilenameToDest
protected java.lang.String mapSourceFilenameToDest(GFile srcFile) throws java.io.IOException
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:
java.io.IOException- thrown if name is not mappable and the extract process should stop
-
handleUnexpectedException
protected boolean handleUnexpectedException(GFile file, java.lang.Exception e)
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, java.io.File outputFile, TaskMonitor monitor) throws CancelledException, CryptoException
- Throws:
CancelledExceptionCryptoException
-
getSourceFileInputStream
protected java.io.InputStream getSourceFileInputStream(GFile file, TaskMonitor monitor) throws CancelledException, java.io.IOException
- Throws:
CancelledExceptionjava.io.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
-
-