19 package org.sleuthkit.autopsy.modules.fileextmismatch;
 
   21 import java.text.MessageFormat;
 
   22 import java.util.Collections;
 
   23 import java.util.HashMap;
 
   25 import java.util.logging.Level;
 
   26 import org.openide.util.NbBundle;
 
   27 import org.openide.util.NbBundle.Messages;
 
   51     "CannotRunFileTypeDetection=Unable to run file type detection.",
 
   52     "FileExtMismatchIngestModule.readError.message=Could not read settings." 
   58     private final FileExtMismatchDetectorModuleSettings 
settings;
 
   59     private HashMap<String, Set<String>> mimeTypeToExtsMap = 
new HashMap<>();
 
   61     private static final HashMap<Long, IngestJobTotals> totalsForIngestJobs = 
new HashMap<>();
 
   68         private long processTime = 0;
 
   69         private long numFiles = 0;
 
   78     private static synchronized void addToTotals(
long ingestJobId, 
long processTimeInc) {
 
   80         if (ingestJobTotals == null) {
 
   82             totalsForIngestJobs.put(ingestJobId, ingestJobTotals);
 
   87         totalsForIngestJobs.put(ingestJobId, ingestJobTotals);
 
   91         this.settings = settings;
 
   96         jobId = context.getJobId();
 
  100             mimeTypeToExtsMap = FileExtMismatchSettings.readSettings().getMimeTypeToExtsMap();
 
  102         } 
catch (FileExtMismatchSettings.FileExtMismatchSettingsException ex) {
 
  110     @Messages({
"FileExtMismatchIngestModule.indexError.message=Failed to index file extension mismatch artifact for keyword search."})
 
  115             logger.log(Level.WARNING, 
"Exception while getting open case.", ex); 
 
  126                 || (abstractFile.
isFile() == 
false)) {
 
  137             long startTime = System.currentTimeMillis();
 
  139             boolean mismatchDetected = compareSigTypeToExt(abstractFile);
 
  141             addToTotals(jobId, System.currentTimeMillis() - startTime);
 
  143             if (mismatchDetected) {
 
  144                 String justification = MessageFormat.format(
"File has MIME type of {0}", detector.
getMIMEType(abstractFile));
 
  149                         null, null, justification, Collections.emptyList())
 
  150                         .getAnalysisResult();
 
  160                     logger.log(Level.SEVERE, 
"Unable to index blackboard artifact " + bart.
getArtifactID(), ex); 
 
  167             logger.log(Level.WARNING, 
"Error matching file signature", ex); 
 
  183         if (settings.skipFilesWithNoExtension() && currActualExt.isEmpty()) {
 
  186         String currActualSigType = detector.
getMIMEType(abstractFile);
 
  187         if (settings.getCheckType() != CHECK_TYPE.ALL) {
 
  188             if (settings.getCheckType() == CHECK_TYPE.NO_TEXT_FILES) {
 
  189                 if (!currActualExt.isEmpty() && currActualSigType.equals(
"text/plain")) { 
 
  193             if (settings.getCheckType() == CHECK_TYPE.ONLY_MEDIA_AND_EXE) {
 
  194                 if (!FileExtMismatchDetectorModuleSettings.MEDIA_AND_EXE_MIME_TYPES.contains(currActualSigType)) {
 
  201         Set<String> allowedExtSet = mimeTypeToExtsMap.get(currActualSigType);
 
  202         if (allowedExtSet != null) {
 
  204             for (String e : allowedExtSet) {
 
  205                 if (e.equals(currActualExt)) {
 
  220             synchronized (
this) {
 
  221                 jobTotals = totalsForIngestJobs.remove(jobId);
 
  223             if (jobTotals != null) {
 
  224                 StringBuilder detailsSb = 
new StringBuilder();
 
  225                 detailsSb.append(
"<table border='0' cellpadding='4' width='280'>"); 
 
  227                 detailsSb.append(
"<tr><td>").append( 
 
  228                         NbBundle.getMessage(
this.getClass(), 
"FileExtMismatchIngestModule.complete.totalProcTime"))
 
  229                         .append(
"</td><td>").append(jobTotals.
processTime).append(
"</td></tr>\n"); 
 
  230                 detailsSb.append(
"<tr><td>").append( 
 
  231                         NbBundle.getMessage(
this.getClass(), 
"FileExtMismatchIngestModule.complete.totalFiles"))
 
  232                         .append(
"</td><td>").append(jobTotals.
numFiles).append(
"</td></tr>\n"); 
 
  233                 detailsSb.append(
"</table>"); 
 
  236                         NbBundle.getMessage(this.getClass(),
 
  237                                 "FileExtMismatchIngestModule.complete.svcMsg.text"),
 
  238                         detailsSb.toString()));
 
void postArtifact(BlackboardArtifact artifact, String moduleName)
synchronized long decrementAndGet(long jobId)
boolean isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM flag)
Blackboard getBlackboard()
FileTypeDetector detector
TskData.TSK_DB_FILES_TYPE_ENUM getType()
AnalysisResultAdded newAnalysisResult(BlackboardArtifact.Type artifactType, Score score, String conclusion, String configuration, String justification, Collection< BlackboardAttribute > attributesList)
String getNameExtension()
static final Type TSK_EXT_MISMATCH_DETECTED
synchronized long incrementAndGet(long jobId)
static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml)
String getMIMEType(AbstractFile file)
TskData.FileKnown getKnown()
boolean compareSigTypeToExt(AbstractFile abstractFile)
boolean isMetaFlagSet(TSK_FS_META_FLAG_ENUM metaFlag)
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()
static final Score SCORE_LIKELY_NOTABLE
ProcessResult process(AbstractFile abstractFile)
static Blackboard blackboard
static synchronized void addToTotals(long ingestJobId, long processTimeInc)
static synchronized IngestServices getInstance()