19 package org.sleuthkit.autopsy.modules.fileextmismatch;
21 import java.util.Collections;
22 import java.util.HashMap;
24 import java.util.logging.Level;
25 import org.openide.util.NbBundle;
26 import org.openide.util.NbBundle.Messages;
42 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
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);
118 if (this.settings.skipKnownFiles() && (abstractFile.getKnown() == FileKnown.KNOWN)) {
123 if ((abstractFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS)
124 || (abstractFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)
125 || (abstractFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)
126 || (abstractFile.isFile() ==
false)) {
131 if ((abstractFile.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.UNALLOC))
132 || (abstractFile.isDirNameFlagSet(TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC))) {
137 long startTime = System.currentTimeMillis();
139 boolean mismatchDetected = compareSigTypeToExt(abstractFile);
141 addToTotals(jobId, System.currentTimeMillis() - startTime);
143 if (mismatchDetected) {
145 BlackboardArtifact bart = abstractFile.newArtifact(ARTIFACT_TYPE.TSK_EXT_MISMATCH_DETECTED);
151 logger.log(Level.SEVERE,
"Unable to index blackboard artifact " + bart.getArtifactID(), ex);
158 }
catch (TskException ex) {
159 logger.log(Level.WARNING,
"Error matching file signature", ex);
172 String currActualExt = abstractFile.getNameExtension();
175 if (settings.skipFilesWithNoExtension() && currActualExt.isEmpty()) {
178 String currActualSigType = detector.
getMIMEType(abstractFile);
179 if (settings.getCheckType() != CHECK_TYPE.ALL) {
180 if (settings.getCheckType() == CHECK_TYPE.NO_TEXT_FILES) {
181 if (!currActualExt.isEmpty() && currActualSigType.equals(
"text/plain")) {
185 if (settings.getCheckType() == CHECK_TYPE.ONLY_MEDIA_AND_EXE) {
186 if (!FileExtMismatchDetectorModuleSettings.MEDIA_AND_EXE_MIME_TYPES.contains(currActualSigType)) {
193 Set<String> allowedExtSet = mimeTypeToExtsMap.get(currActualSigType);
194 if (allowedExtSet != null) {
196 for (String e : allowedExtSet) {
197 if (e.equals(currActualExt)) {
212 synchronized (
this) {
213 jobTotals = totalsForIngestJobs.remove(jobId);
215 if (jobTotals != null) {
216 StringBuilder detailsSb =
new StringBuilder();
217 detailsSb.append(
"<table border='0' cellpadding='4' width='280'>");
219 detailsSb.append(
"<tr><td>").append(
220 NbBundle.getMessage(
this.getClass(),
"FileExtMismatchIngestModule.complete.totalProcTime"))
221 .append(
"</td><td>").append(jobTotals.
processTime).append(
"</td></tr>\n");
222 detailsSb.append(
"<tr><td>").append(
223 NbBundle.getMessage(
this.getClass(),
"FileExtMismatchIngestModule.complete.totalFiles"))
224 .append(
"</td><td>").append(jobTotals.
numFiles).append(
"</td></tr>\n");
225 detailsSb.append(
"</table>");
228 NbBundle.getMessage(this.getClass(),
229 "FileExtMismatchIngestModule.complete.svcMsg.text"),
230 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)
void fireModuleDataEvent(ModuleDataEvent moduleDataEvent)
Blackboard getBlackboard()
static void error(String title, String message)
void startUp(IngestJobContext context)
synchronized void indexArtifact(BlackboardArtifact artifact)
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()