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 Details

    • fs

      protected GFileSystem fs
    • rootOutputDirectory

      protected File rootOutputDirectory
  • Constructor Details

  • Method Details

    • startExtract

      protected void startExtract(GFileSystem fs, GFile srcDir, TaskMonitor monitor) throws CancelledException, IOException
      Starts the file extraction process.
      Parameters:
      fs - the GFileSystem that holds the files
      srcDir - the starting directory to extract, if null, start at root of file system
      monitor - 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 a GFileSystem into a local file system directory.

      The destination directory is created if not present.

      Parameters:
      srcGFileDirectory - if null, directory is filesystem root
      destDirectory - destination / output directory
      monitor - 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

      protected String mapSourceFilenameToDest(GFile srcFile) throws 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:
      IOException - thrown if name is not mappable and the extract process should stop
    • handleUnexpectedException

      protected boolean handleUnexpectedException(GFile file, 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 happened
      e - 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