diff --git a/Core/src/org/sleuthkit/autopsy/ingest/FileIngestPipeline.java b/Core/src/org/sleuthkit/autopsy/ingest/FileIngestPipeline.java index 436418712a1db7bbb834faa52379d44be4ea0d13..7c0b1e58ede95d3cb9a573c73c83d051d0b809f7 100755 --- a/Core/src/org/sleuthkit/autopsy/ingest/FileIngestPipeline.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/FileIngestPipeline.java @@ -21,10 +21,14 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.logging.Level; import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.datamodel.AbstractFile; +import org.sleuthkit.datamodel.TskCoreException; /** * This class manages a sequence of file level ingest modules for a data source @@ -136,10 +140,17 @@ synchronized List<IngestModuleError> process(FileIngestTask task) { break; } } - file.close(); + if (!this.job.isCancelled()) { + // Save any properties that have not already been saved to the database + try{ + file.save(Case.getCurrentCase().getSleuthkitCase()); + } catch (TskCoreException ex){ + Logger.getLogger(FileIngestPipeline.class.getName()).log(Level.SEVERE, "Failed to save data for file " + file.getId(), ex); //NON-NLS + } IngestManager.getInstance().fireFileIngestDone(file); } + file.close(); } FileIngestPipeline.ingestManager.setIngestTaskProgressCompleted(task); return errors; diff --git a/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/MSOfficeEmbeddedContentExtractor.java b/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/MSOfficeEmbeddedContentExtractor.java index 61376d31f1c73e534338d363d4986802a7240301..1844173ca0806ba6592498dbbb512e536976ebb6 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/MSOfficeEmbeddedContentExtractor.java +++ b/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/MSOfficeEmbeddedContentExtractor.java @@ -136,7 +136,7 @@ public String toString() { */ boolean isContentExtractionSupported(AbstractFile abstractFile) { try { - String abstractFileMimeType = fileTypeDetector.getFileType(abstractFile); + String abstractFileMimeType = fileTypeDetector.detectFileType(abstractFile); for (SupportedExtractionFormats s : SupportedExtractionFormats.values()) { if (s.toString().equals(abstractFileMimeType)) { abstractFileExtractionFormat = s; diff --git a/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/SevenZipExtractor.java b/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/SevenZipExtractor.java index 900329d3cbd806d2b7c8de837e75130fff686e78..829b56312b075779bd7553bdd301a77b80e01110 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/SevenZipExtractor.java +++ b/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/SevenZipExtractor.java @@ -142,7 +142,7 @@ public String toString() { */ boolean isSevenZipExtractionSupported(AbstractFile abstractFile) { try { - String abstractFileMimeType = fileTypeDetector.getFileType(abstractFile); + String abstractFileMimeType = fileTypeDetector.detectFileType(abstractFile); for (SupportedArchiveExtractionFormats s : SupportedArchiveExtractionFormats.values()) { if (s.toString().equals(abstractFileMimeType)) { return true; diff --git a/Core/src/org/sleuthkit/autopsy/modules/encryptiondetection/EncryptionDetectionFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/encryptiondetection/EncryptionDetectionFileIngestModule.java index da4e91882a4f07289291aae66925063f6b3f46ce..928e7ccb36b5b2791e000de09e6d13e238398c1e 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/encryptiondetection/EncryptionDetectionFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/encryptiondetection/EncryptionDetectionFileIngestModule.java @@ -189,7 +189,7 @@ private boolean isFileEncrypted(AbstractFile file) throws IOException, TskCoreEx * Qualify the MIME type. */ try { - String mimeType = fileTypeDetector.getFileType(file); + String mimeType = fileTypeDetector.detectFileType(file); if (mimeType != null && mimeType.equals("application/octet-stream")) { possiblyEncrypted = true; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java index a1d0809ae08abda32862419969b6b3ce17b0e912..86deac19033fbda50e7f93038f6f955b7a5fc2b9 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java @@ -251,7 +251,7 @@ ProcessResult processFile(AbstractFile f) { */ private boolean parsableFormat(AbstractFile f) { try { - String mimeType = fileTypeDetector.getFileType(f); + String mimeType = fileTypeDetector.detectFileType(f); if (mimeType != null) { return supportedMimeTypes.contains(mimeType); } else { diff --git a/Core/src/org/sleuthkit/autopsy/modules/fileextmismatch/FileExtMismatchIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/fileextmismatch/FileExtMismatchIngestModule.java index 5d557de8bf2dc714ac74beb73cd55c510fd06122..db4224a0a8153bc234a4d4f2123b5cd7ac6b9213 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/fileextmismatch/FileExtMismatchIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/fileextmismatch/FileExtMismatchIngestModule.java @@ -170,7 +170,7 @@ private boolean compareSigTypeToExt(AbstractFile abstractFile) throws TskCoreExc if (settings.skipFilesWithNoExtension() && currActualExt.isEmpty()) { return false; } - String currActualSigType = detector.getFileType(abstractFile); + String currActualSigType = detector.detectFileType(abstractFile); if (currActualSigType == null) { return false; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index 5851b9887cfabbe390eb4db5b97f7a2466d0b534..dcfc75a2b3ab8f95d0d9497a76f4ab5e77a0949d 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -173,11 +173,11 @@ private boolean isDetectableAsCustomType(List<FileType> customTypes, String mime private boolean isDetectableByTika(String mimeType) { return FileTypeDetector.getTikaDetectedTypes().contains(removeOptionalParameter(mimeType)); } - + /** * Gets the MIME type of a file, detecting it if it is not already known. If - * detection is necessary, the result is added to the case database. - * + * detection is necessary, the result is saved to the AbstractFile object + * * IMPORTANT: This method should only be called by ingest modules. All other * clients should call AbstractFile.getMIMEType, and may call * FileTypeDetector.detect, if AbstractFile.getMIMEType returns null. @@ -190,8 +190,8 @@ private boolean isDetectableByTika(String mimeType) { * @throws TskCoreException if detection is required and there is a problem * writing the result to the case database. */ - public String getFileType(AbstractFile file) throws TskCoreException { - return detect(file, true); + public String detectFileType(AbstractFile file) throws TskCoreException { + return detect(file, false); } /** @@ -213,6 +213,9 @@ public String detect(AbstractFile file) throws TskCoreException { /** * Detects the MIME type of a file. The result is saved to the case database * only if the add to case database flag is set. + * + * Ingest modules should not set addToCaseDb to true - the ingest process + * handles the database save. * * @param file The file to test. * @param addToCaseDb Whether the MIME type should be added to the case @@ -323,6 +326,7 @@ private String detect(AbstractFile file, boolean addToCaseDb) throws TskCoreExce Case.getCurrentCase().getSleuthkitCase().setFileMIMEType(file, mimeType); } + file.setMIMEType(mimeType); return mimeType; } @@ -474,7 +478,30 @@ public List<String> getUserDefinedTypes() { */ @Deprecated public String detectAndPostToBlackboard(AbstractFile file) throws TskCoreException { - return getFileType(file); + return detect(file, true); + } + + /** + * Gets the MIME type of a file, detecting it if it is not already known. If + * detection is necessary, the result is added to the case database. + * + * IMPORTANT: This method should only be called by ingest modules. All other + * clients should call AbstractFile.getMIMEType, and may call + * FileTypeDetector.detect, if AbstractFile.getMIMEType returns null. + * + * @param file The file. + * + * @return A MIME type name. If file type could not be detected or results + * were uncertain, octet-stream is returned. + * + * @throws TskCoreException if detection is required and there is a problem + * writing the result to the case database. + * + * @deprecated + */ + @Deprecated + public String getFileType(AbstractFile file) throws TskCoreException { + return detect(file, true); } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java index ef4e0add717a576d5a6d52eaf6bad5356f4014f2..ed6698bd322a5379923330120066b43185826e48 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java @@ -91,7 +91,7 @@ public ProcessResult process(AbstractFile file) { */ try { long startTime = System.currentTimeMillis(); - fileTypeDetector.getFileType(file); + fileTypeDetector.detect(file); addToTotals(jobId, (System.currentTimeMillis() - startTime)); return ProcessResult.OK; } catch (Exception e) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java index f022f6b657326a285e5bf94bfc003c4f4f7758ca..696a105416f73bb56f454c651e712d2e451ece3f 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java @@ -176,7 +176,8 @@ public ProcessResult process(AbstractFile file) { if (md5Hash == null || md5Hash.isEmpty()) { try { long calcstart = System.currentTimeMillis(); - md5Hash = HashUtility.calculateMd5(file); + md5Hash = HashUtility.calculateMd5Hash(file); + file.setMd5Hash(md5Hash); long delta = (System.currentTimeMillis() - calcstart); totals.totalCalctime.addAndGet(delta); @@ -205,20 +206,8 @@ public ProcessResult process(AbstractFile file) { foundBad = true; totals.totalKnownBadCount.incrementAndGet(); - try { - skCase.setKnown(file, TskData.FileKnown.BAD); - } catch (TskException ex) { - logger.log(Level.WARNING, "Couldn't set notable state for file " + name + " - see sleuthkit log for details", ex); //NON-NLS - services.postMessage(IngestMessage.createErrorMessage( - HashLookupModuleFactory.getModuleName(), - NbBundle.getMessage(this.getClass(), - "HashDbIngestModule.hashLookupErrorMsg", - name), - NbBundle.getMessage(this.getClass(), - "HashDbIngestModule.settingKnownBadStateErr", - name))); - ret = ProcessResult.ERROR; - } + file.setKnown(TskData.FileKnown.BAD); + String hashSetName = db.getDisplayName(); String comment = ""; @@ -262,13 +251,8 @@ public ProcessResult process(AbstractFile file) { try { long lookupstart = System.currentTimeMillis(); if (db.lookupMD5Quick(file)) { - try { - skCase.setKnown(file, TskData.FileKnown.KNOWN); - break; - } catch (TskException ex) { - logger.log(Level.WARNING, "Couldn't set known state for file " + name + " - see sleuthkit log for details", ex); //NON-NLS - ret = ProcessResult.ERROR; - } + file.setKnown(TskData.FileKnown.KNOWN); + break; } long delta = (System.currentTimeMillis() - lookupstart); totals.totalLookuptime.addAndGet(delta); diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index dbbca6394b8aa08d71515291b8c3e72ee883adf5..02968ddd56bb175e308485cb06fb9bee90f0d66b 100755 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -514,7 +514,7 @@ private void indexFile(AbstractFile aFile, boolean indexContent) { if (context.fileIngestIsCancelled()) { return; } - fileType = fileTypeDetector.getFileType(aFile); + fileType = fileTypeDetector.detectFileType(aFile); } catch (TskCoreException ex) { logger.log(Level.SEVERE, String.format("Could not detect format using fileTypeDetector for file: %s", aFile), ex); //NON-NLS return;