19 package org.sleuthkit.autopsy.modules.fileextmismatch;
 
   21 import java.util.HashMap;
 
   23 import java.util.logging.Level;
 
   24 import org.openide.util.NbBundle;
 
   25 import org.openide.util.NbBundle.Messages;
 
   40 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
 
   49     "CannotRunFileTypeDetection=Unable to run file type detection.",
 
   50     "FileExtMismatchIngestModule.readError.message=Could not read settings." 
   56     private final FileExtMismatchDetectorModuleSettings 
settings;
 
   57     private HashMap<String, Set<String>> mimeTypeToExtsMap = 
new HashMap<>();
 
   59     private static final HashMap<Long, IngestJobTotals> totalsForIngestJobs = 
new HashMap<>();
 
   66         private long processTime = 0;
 
   67         private long numFiles = 0;
 
   76     private static synchronized void addToTotals(
long ingestJobId, 
long processTimeInc) {
 
   78         if (ingestJobTotals == null) {
 
   80             totalsForIngestJobs.put(ingestJobId, ingestJobTotals);
 
   85         totalsForIngestJobs.put(ingestJobId, ingestJobTotals);
 
   89         this.settings = settings;
 
   94         jobId = context.getJobId();
 
   98             mimeTypeToExtsMap = FileExtMismatchSettings.readSettings().getMimeTypeToExtsMap();
 
  100         } 
catch (FileExtMismatchSettings.FileExtMismatchSettingsException ex) {
 
  108     @Messages({
"FileExtMismatchIngestModule.indexError.message=Failed to index file extension mismatch artifact for keyword search."})
 
  113             logger.log(Level.WARNING, 
"Exception while getting open case.", ex); 
 
  116         if (this.settings.skipKnownFiles() && (abstractFile.getKnown() == FileKnown.KNOWN)) {
 
  121         if ((abstractFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS)
 
  122             || (abstractFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)
 
  123             || (abstractFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)
 
  124             || (abstractFile.isFile() == 
false)) {
 
  129         if ((abstractFile.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.UNALLOC))
 
  130             || (abstractFile.isDirNameFlagSet(TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC))) {
 
  135             long startTime = System.currentTimeMillis();
 
  137             boolean mismatchDetected = compareSigTypeToExt(abstractFile);
 
  139             addToTotals(jobId, System.currentTimeMillis() - startTime);
 
  141             if (mismatchDetected) {
 
  143                 BlackboardArtifact bart = abstractFile.newArtifact(ARTIFACT_TYPE.TSK_EXT_MISMATCH_DETECTED);
 
  152                 } 
catch (Blackboard.BlackboardException ex) {
 
  153                     logger.log(Level.SEVERE, 
"Unable to index blackboard artifact " + bart.getArtifactID(), ex); 
 
  159         } 
catch (TskException ex) {
 
  160             logger.log(Level.WARNING, 
"Error matching file signature", ex); 
 
  173         String currActualExt = abstractFile.getNameExtension();
 
  176         if (settings.skipFilesWithNoExtension() && currActualExt.isEmpty()) {
 
  179         String currActualSigType = detector.
getMIMEType(abstractFile);
 
  180         if (settings.getCheckType() != CHECK_TYPE.ALL) {
 
  181             if (settings.getCheckType() == CHECK_TYPE.NO_TEXT_FILES) {
 
  182                 if (!currActualExt.isEmpty() && currActualSigType.equals(
"text/plain")) { 
 
  186             if (settings.getCheckType() == CHECK_TYPE.ONLY_MEDIA_AND_EXE) {
 
  187                 if (!FileExtMismatchDetectorModuleSettings.MEDIA_AND_EXE_MIME_TYPES.contains(currActualSigType)) {
 
  194         Set<String> allowedExtSet = mimeTypeToExtsMap.get(currActualSigType);
 
  195         if (allowedExtSet != null) {
 
  197             for (String e : allowedExtSet) {
 
  198                 if (e.equals(currActualExt)) {
 
  213             synchronized (
this) {
 
  214                 jobTotals = totalsForIngestJobs.remove(jobId);
 
  216             if (jobTotals != null) {
 
  217                 StringBuilder detailsSb = 
new StringBuilder();
 
  218                 detailsSb.append(
"<table border='0' cellpadding='4' width='280'>"); 
 
  220                 detailsSb.append(
"<tr><td>").append( 
 
  221                         NbBundle.getMessage(
this.getClass(), 
"FileExtMismatchIngestModule.complete.totalProcTime"))
 
  222                         .append(
"</td><td>").append(jobTotals.
processTime).append(
"</td></tr>\n"); 
 
  223                 detailsSb.append(
"<tr><td>").append( 
 
  224                         NbBundle.getMessage(
this.getClass(), 
"FileExtMismatchIngestModule.complete.totalFiles"))
 
  225                         .append(
"</td><td>").append(jobTotals.
numFiles).append(
"</td></tr>\n"); 
 
  226                 detailsSb.append(
"</table>"); 
 
  229                         NbBundle.getMessage(this.getClass(),
 
  230                                 "FileExtMismatchIngestModule.complete.svcMsg.text"),
 
  231                         detailsSb.toString()));
 
synchronized long decrementAndGet(long jobId)
 
FileTypeDetector detector
 
synchronized long incrementAndGet(long jobId)
 
static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml)
 
String getMIMEType(AbstractFile file)
 
boolean compareSigTypeToExt(AbstractFile abstractFile)
 
void postMessage(final IngestMessage message)
 
SleuthkitCase getSleuthkitCase()
 
static void error(String title, String message)
 
void startUp(IngestJobContext context)
 
final FileExtMismatchDetectorModuleSettings settings
 
synchronized static Logger getLogger(String name)
 
static Case getCurrentCaseThrows()
 
ProcessResult process(AbstractFile abstractFile)
 
static Blackboard blackboard
 
static synchronized void addToTotals(long ingestJobId, long processTimeInc)
 
static synchronized IngestServices getInstance()