19 package org.sleuthkit.autopsy.modules.filetypeid;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.logging.Level;
26 import org.openide.util.NbBundle;
46 "CannotRunFileTypeDetection=Unable to run file type detection."
52 private static final HashMap<Long, IngestJobTotals> totalsForIngestJobs =
new HashMap<>();
70 logger.log(Level.SEVERE,
"Failed to create file type detector", ex);
84 jobId = context.getJobId();
101 long startTime = System.currentTimeMillis();
102 String mimeType = fileTypeDetector.
getMIMEType(file);
103 file.setMIMEType(mimeType);
104 FileType fileType = detectUserDefinedFileType(file);
105 if (fileType != null && fileType.createInterestingFileHit()) {
106 createInterestingFileHit(file, fileType);
108 addToTotals(jobId, (System.currentTimeMillis() - startTime));
110 }
catch (Exception e) {
111 logger.log(Level.WARNING, String.format(
"Error while attempting to determine file type of file %d", file.getId()), e);
127 FileType retValue = null;
129 CustomFileTypesManager customFileTypesManager = CustomFileTypesManager.getInstance();
130 List<FileType> fileTypesList = customFileTypesManager.getUserDefinedFileTypes();
131 for (FileType fileType : fileTypesList) {
132 if (fileType.matches(file)) {
149 BlackboardArtifact artifact;
150 artifact = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT);
151 Collection<BlackboardAttribute> attributes =
new ArrayList<>();
152 BlackboardAttribute setNameAttribute =
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME,
FileTypeIdModuleFactory.getModuleName(), fileType.getInterestingFilesSetName());
153 attributes.add(setNameAttribute);
154 BlackboardAttribute ruleNameAttribute =
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY,
FileTypeIdModuleFactory.getModuleName(), fileType.getMimeType());
155 attributes.add(ruleNameAttribute);
156 artifact.addAttributes(attributes);
160 logger.log(Level.SEVERE, String.format(
"Unable to index TSK_INTERESTING_FILE_HIT blackboard artifact %d (file obj_id=%d)", artifact.getArtifactID(), file.getId()), ex);
162 }
catch (TskCoreException ex) {
163 logger.log(Level.SEVERE, String.format(
"Unable to create TSK_INTERESTING_FILE_HIT artifact for file (obj_id=%d)", file.getId()), ex);
175 synchronized (
this) {
176 jobTotals = totalsForIngestJobs.remove(jobId);
178 if (jobTotals != null) {
179 StringBuilder detailsSb =
new StringBuilder();
180 detailsSb.append(
"<table border='0' cellpadding='4' width='280'>");
182 detailsSb.append(
"<tr><td>")
183 .append(NbBundle.getMessage(
this.getClass(),
"FileTypeIdIngestModule.complete.totalProcTime"))
184 .append(
"</td><td>").append(jobTotals.matchTime).append(
"</td></tr>\n");
185 detailsSb.append(
"<tr><td>")
186 .append(NbBundle.getMessage(
this.getClass(),
"FileTypeIdIngestModule.complete.totalFiles"))
187 .append(
"</td><td>").append(jobTotals.numFiles).append(
"</td></tr>\n");
188 detailsSb.append(
"</table>");
190 NbBundle.getMessage(this.getClass(),
191 "FileTypeIdIngestModule.complete.srvMsg.text"),
192 detailsSb.toString()));
204 private static synchronized void addToTotals(
long jobId,
long matchTimeInc) {
206 if (ingestJobTotals == null) {
208 totalsForIngestJobs.put(jobId, ingestJobTotals);
211 ingestJobTotals.matchTime += matchTimeInc;
212 ingestJobTotals.numFiles++;
213 totalsForIngestJobs.put(jobId, ingestJobTotals);
synchronized long decrementAndGet(long jobId)
boolean isDetectable(String mimeType)
FileTypeDetector fileTypeDetector
synchronized long incrementAndGet(long jobId)
static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml)
void startUp(IngestJobContext context)
String getMIMEType(AbstractFile file)
ProcessResult process(AbstractFile file)
void postMessage(final IngestMessage message)
void createInterestingFileHit(AbstractFile file, FileType fileType)
static boolean isMimeTypeDetectable(String mimeType)
Blackboard getBlackboard()
synchronized void indexArtifact(BlackboardArtifact artifact)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
FileType detectUserDefinedFileType(AbstractFile file)
static synchronized void addToTotals(long jobId, long matchTimeInc)
static synchronized IngestServices getInstance()