mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 02:07:42 +00:00
Only adding logical file set if there are files remaining. Bug fixes. Optimizations
This commit is contained in:
parent
cb7a93d081
commit
0c46e2d2d7
@ -22,6 +22,7 @@ import java.io.File;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -30,6 +31,7 @@ import java.util.UUID;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.openide.util.Lookup;
|
||||||
import org.sleuthkit.autopsy.casemodule.Case;
|
import org.sleuthkit.autopsy.casemodule.Case;
|
||||||
import org.sleuthkit.autopsy.casemodule.LocalDiskDSProcessor;
|
import org.sleuthkit.autopsy.casemodule.LocalDiskDSProcessor;
|
||||||
import org.sleuthkit.autopsy.casemodule.LocalFilesDSProcessor;
|
import org.sleuthkit.autopsy.casemodule.LocalFilesDSProcessor;
|
||||||
@ -113,11 +115,23 @@ class AddArchiveTask implements Runnable {
|
|||||||
// extract contents of ZIP archive into destination folder
|
// extract contents of ZIP archive into destination folder
|
||||||
progressMonitor.setProgressText(String.format("Extracting archive contents to: %s", destinationFolder.toString()));
|
progressMonitor.setProgressText(String.format("Extracting archive contents to: %s", destinationFolder.toString()));
|
||||||
List<String> extractedFiles = ArchiveUtil.unpackArchiveFile(archivePath, destinationFolder.toString());
|
List<String> extractedFiles = ArchiveUtil.unpackArchiveFile(archivePath, destinationFolder.toString());
|
||||||
|
int numExtractedFilesRemaining = extractedFiles.size();
|
||||||
|
|
||||||
|
// lookup all AutomatedIngestDataSourceProcessors so that we only do it once
|
||||||
|
Collection<? extends AutoIngestDataSourceProcessor> processorCandidates = Lookup.getDefault().lookupAll(AutoIngestDataSourceProcessor.class);
|
||||||
|
|
||||||
// do processing
|
// do processing
|
||||||
for (String file : extractedFiles) {
|
for (String file : extractedFiles) {
|
||||||
|
|
||||||
|
// we only care about files, skip directories
|
||||||
|
File fileObject = new File(file);
|
||||||
|
if (fileObject.isDirectory()) {
|
||||||
|
numExtractedFilesRemaining--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// identify all "valid" DSPs that can process this file
|
// identify all "valid" DSPs that can process this file
|
||||||
List<AutoIngestDataSourceProcessor> validDataSourceProcessors = getValidDataSourceProcessors(Paths.get(file), errorMessages);
|
List<AutoIngestDataSourceProcessor> validDataSourceProcessors = getValidDataSourceProcessors(Paths.get(file), errorMessages, processorCandidates);
|
||||||
if (validDataSourceProcessors.isEmpty()) {
|
if (validDataSourceProcessors.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -145,7 +159,7 @@ class AddArchiveTask implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy it to a different folder
|
// Copy it to a different folder
|
||||||
FileUtils.copyFileToDirectory(new File(file), newFolder.toFile());
|
FileUtils.copyFileToDirectory(fileObject, newFolder.toFile());
|
||||||
Path newFilePath = Paths.get(newFolder.toString(), FilenameUtils.getName(file));
|
Path newFilePath = Paths.get(newFolder.toString(), FilenameUtils.getName(file));
|
||||||
|
|
||||||
// Try each DSP in decreasing order of confidence
|
// Try each DSP in decreasing order of confidence
|
||||||
@ -192,7 +206,8 @@ class AddArchiveTask implements Runnable {
|
|||||||
// one of the DSPs successfully processed the data source. delete the
|
// one of the DSPs successfully processed the data source. delete the
|
||||||
// copy of the data source in the original extracted archive folder.
|
// copy of the data source in the original extracted archive folder.
|
||||||
// otherwise the data source is going to be added again as a logical file.
|
// otherwise the data source is going to be added again as a logical file.
|
||||||
FileUtils.deleteQuietly(Paths.get(file).toFile());
|
numExtractedFilesRemaining--;
|
||||||
|
FileUtils.deleteQuietly(fileObject);
|
||||||
} else {
|
} else {
|
||||||
// none of the DSPs were able to process the data source. delete the
|
// none of the DSPs were able to process the data source. delete the
|
||||||
// copy of the data source in the temporary folder. the data source is
|
// copy of the data source in the temporary folder. the data source is
|
||||||
@ -203,28 +218,30 @@ class AddArchiveTask implements Runnable {
|
|||||||
|
|
||||||
// after all archive contents have been examined (and moved to separate folders if necessary),
|
// after all archive contents have been examined (and moved to separate folders if necessary),
|
||||||
// add remaining extracted contents as one logical file set
|
// add remaining extracted contents as one logical file set
|
||||||
progressMonitor.setProgressText(String.format("Adding: %s", destinationFolder.toString()));
|
if (numExtractedFilesRemaining > 0) {
|
||||||
logger.log(Level.INFO, "Adding directory {0} as logical file set", destinationFolder.toString());
|
progressMonitor.setProgressText(String.format("Adding: %s", destinationFolder.toString()));
|
||||||
synchronized (archiveDspLock) {
|
logger.log(Level.INFO, "Adding directory {0} as logical file set", destinationFolder.toString());
|
||||||
UUID taskId = UUID.randomUUID();
|
synchronized (archiveDspLock) {
|
||||||
currentCase.notifyAddingDataSource(taskId);
|
UUID taskId = UUID.randomUUID();
|
||||||
DataSource internalDataSource = new DataSource(deviceId, destinationFolder);
|
currentCase.notifyAddingDataSource(taskId);
|
||||||
DataSourceProcessorCallback internalArchiveDspCallBack = new AddDataSourceCallback(currentCase, internalDataSource, taskId, archiveDspLock);
|
DataSource internalDataSource = new DataSource(deviceId, destinationFolder);
|
||||||
|
DataSourceProcessorCallback internalArchiveDspCallBack = new AddDataSourceCallback(currentCase, internalDataSource, taskId, archiveDspLock);
|
||||||
|
|
||||||
// folder where archive was extracted to
|
// folder where archive was extracted to
|
||||||
List<String> pathsList = new ArrayList<>();
|
List<String> pathsList = new ArrayList<>();
|
||||||
pathsList.add(destinationFolder.toString());
|
pathsList.add(destinationFolder.toString());
|
||||||
|
|
||||||
// use archive file name as the name of the logical file set
|
// use archive file name as the name of the logical file set
|
||||||
String archiveFileName = FilenameUtils.getName(archivePath);
|
String archiveFileName = FilenameUtils.getName(archivePath);
|
||||||
|
|
||||||
LocalFilesDSProcessor localFilesDSP = new LocalFilesDSProcessor();
|
LocalFilesDSProcessor localFilesDSP = new LocalFilesDSProcessor();
|
||||||
localFilesDSP.run(deviceId, archiveFileName, pathsList, progressMonitor, internalArchiveDspCallBack);
|
localFilesDSP.run(deviceId, archiveFileName, pathsList, progressMonitor, internalArchiveDspCallBack);
|
||||||
|
|
||||||
archiveDspLock.wait();
|
archiveDspLock.wait();
|
||||||
|
|
||||||
// at this point we got the content object(s) from the current DSP
|
// at this point we got the content object(s) from the current DSP
|
||||||
newDataSources.addAll(internalDataSource.getContent());
|
newDataSources.addAll(internalDataSource.getContent());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
criticalErrorOccurred = true;
|
criticalErrorOccurred = true;
|
||||||
@ -254,23 +271,23 @@ class AddArchiveTask implements Runnable {
|
|||||||
*
|
*
|
||||||
* @return Ordered list of applicable DSPs
|
* @return Ordered list of applicable DSPs
|
||||||
*/
|
*/
|
||||||
private List<AutoIngestDataSourceProcessor> getValidDataSourceProcessors(Path dataSourcePath, List<String> errorMessages) {
|
private List<AutoIngestDataSourceProcessor> getValidDataSourceProcessors(Path dataSourcePath, List<String> errorMessages,
|
||||||
Map<AutoIngestDataSourceProcessor, Integer> validDataSourceProcessorsMap;
|
Collection<? extends AutoIngestDataSourceProcessor> processorCandidates) {
|
||||||
|
|
||||||
|
// Get an ordered list of data source processors to try
|
||||||
|
List<AutoIngestDataSourceProcessor> validDataSourceProcessors;
|
||||||
try {
|
try {
|
||||||
validDataSourceProcessorsMap = DataSourceProcessorUtility.getDataSourceProcessor(dataSourcePath);
|
validDataSourceProcessors = DataSourceProcessorUtility.getOrderedListOfDataSourceProcessors(dataSourcePath, processorCandidates);
|
||||||
} catch (AutoIngestDataSourceProcessor.AutoIngestDataSourceProcessorException ex) {
|
} catch (AutoIngestDataSourceProcessor.AutoIngestDataSourceProcessorException ex) {
|
||||||
criticalErrorOccurred = true;
|
criticalErrorOccurred = true;
|
||||||
errorMessages.add(ex.getMessage());
|
errorMessages.add(ex.getMessage());
|
||||||
logger.log(Level.SEVERE, String.format("Critical error occurred while extracting archive %s", archivePath), ex); //NON-NLS
|
logger.log(Level.SEVERE, String.format("Critical error occurred while extracting archive %s", archivePath), ex); //NON-NLS
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
if (validDataSourceProcessorsMap.isEmpty()) {
|
if (validDataSourceProcessors.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get an ordered list of data source processors to try
|
|
||||||
List<AutoIngestDataSourceProcessor> validDataSourceProcessors = DataSourceProcessorUtility.orderDataSourceProcessorsByConfidence(validDataSourceProcessorsMap);
|
|
||||||
|
|
||||||
for (Iterator<AutoIngestDataSourceProcessor> iterator = validDataSourceProcessors.iterator(); iterator.hasNext();) {
|
for (Iterator<AutoIngestDataSourceProcessor> iterator = validDataSourceProcessors.iterator(); iterator.hasNext();) {
|
||||||
AutoIngestDataSourceProcessor selectedProcessor = iterator.next();
|
AutoIngestDataSourceProcessor selectedProcessor = iterator.next();
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ import javax.swing.JPanel;
|
|||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
import org.openide.util.lookup.ServiceProvider;
|
import org.openide.util.lookup.ServiceProvider;
|
||||||
import org.openide.util.lookup.ServiceProviders;
|
import org.openide.util.lookup.ServiceProviders;
|
||||||
|
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor;
|
||||||
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorCallback;
|
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorCallback;
|
||||||
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorProgressMonitor;
|
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorProgressMonitor;
|
||||||
import org.sleuthkit.autopsy.datasourceprocessors.AutoIngestDataSourceProcessor;
|
import org.sleuthkit.autopsy.datasourceprocessors.AutoIngestDataSourceProcessor;
|
||||||
@ -39,6 +40,7 @@ import org.sleuthkit.autopsy.datasourceprocessors.AutoIngestDataSourceProcessor;
|
|||||||
* be used independently of the wizard.
|
* be used independently of the wizard.
|
||||||
*/
|
*/
|
||||||
@ServiceProviders(value={
|
@ServiceProviders(value={
|
||||||
|
@ServiceProvider(service=DataSourceProcessor.class),
|
||||||
@ServiceProvider(service=AutoIngestDataSourceProcessor.class)}
|
@ServiceProvider(service=AutoIngestDataSourceProcessor.class)}
|
||||||
)
|
)
|
||||||
@NbBundle.Messages({
|
@NbBundle.Messages({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user