19 package org.sleuthkit.autopsy.modules.interestingitems;
 
   21 import java.util.ArrayList;
 
   22 import java.util.Collection;
 
   23 import java.util.Collections;
 
   24 import java.util.List;
 
   26 import java.util.concurrent.ConcurrentHashMap;
 
   27 import java.util.logging.Level;
 
   28 import org.openide.util.NbBundle;
 
   29 import org.openide.util.NbBundle.Messages;
 
   52     "FilesIdentifierIngestModule.getFilesError=Error getting interesting files sets from file." 
   54 final class FilesIdentifierIngestModule implements FileIngestModule {
 
   56     private static final Object sharedResourcesLock = 
new Object();
 
   57     private static final Logger logger = Logger.getLogger(FilesIdentifierIngestModule.class.getName());
 
   58     private static final IngestModuleReferenceCounter refCounter = 
new IngestModuleReferenceCounter();
 
   59     private static final Map<Long, List<FilesSet>> interestingFileSetsByJob = 
new ConcurrentHashMap<>();
 
   60     private final FilesIdentifierIngestJobSettings settings;
 
   61     private final IngestServices services = IngestServices.getInstance();
 
   62     private IngestJobContext context;
 
   63     private Blackboard blackboard;
 
   71     FilesIdentifierIngestModule(FilesIdentifierIngestJobSettings settings) {
 
   72         this.settings = settings;
 
   79     public void startUp(IngestJobContext context) 
throws IngestModuleException {
 
   80         this.context = context;
 
   81         synchronized (FilesIdentifierIngestModule.sharedResourcesLock) {
 
   82             if (FilesIdentifierIngestModule.refCounter.incrementAndGet(context.getJobId()) == 1) {
 
   88                 List<FilesSet> filesSets = 
new ArrayList<>();
 
   90                     for (FilesSet set : FilesSetsManager.getInstance().getInterestingFilesSets().values()) {
 
   91                         if (settings.interestingFilesSetIsEnabled(set.getName())) {
 
   95                 } 
catch (FilesSetsManager.FilesSetsManagerException ex) {
 
   96                     throw new IngestModuleException(Bundle.FilesIdentifierIngestModule_getFilesError(), ex);
 
   98                 FilesIdentifierIngestModule.interestingFileSetsByJob.put(context.getJobId(), filesSets);
 
  107     @Messages({
"FilesIdentifierIngestModule.indexError.message=Failed to index interesting file hit artifact for keyword search."})
 
  108     public ProcessResult process(AbstractFile file) {
 
  111             currentCase = Case.getCurrentCaseThrows();      
 
  112         } 
catch (NoCurrentCaseException ex) {
 
  113             logger.log(Level.SEVERE, 
"Exception while getting open case.", ex); 
 
  114             return ProcessResult.ERROR;
 
  116         blackboard = currentCase.getServices().getBlackboard();
 
  119         if (file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
 
  120             return ProcessResult.OK;
 
  124         List<FilesSet> filesSets = FilesIdentifierIngestModule.interestingFileSetsByJob.get(this.context.getJobId());
 
  125         for (FilesSet filesSet : filesSets) {
 
  126             String ruleSatisfied = filesSet.fileIsMemberOf(file);
 
  127             if (ruleSatisfied != null) {
 
  131                     String moduleName = InterestingItemsIngestModuleFactory.getModuleName();
 
  133                     Collection<BlackboardAttribute> attributes = 
new ArrayList<>();
 
  140                     BlackboardAttribute setNameAttribute = 
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME, moduleName, filesSet.getName());
 
  141                     attributes.add(setNameAttribute);
 
  145                     BlackboardAttribute ruleNameAttribute = 
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY, moduleName, ruleSatisfied);
 
  146                     attributes.add(ruleNameAttribute);
 
  148                     org.
sleuthkit.datamodel.Blackboard tskBlackboard = currentCase.getSleuthkitCase().getBlackboard();
 
  150                     if (!tskBlackboard.artifactExists(file, BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT, attributes)) {
 
  151                         BlackboardArtifact artifact = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT);
 
  152                         artifact.addAttributes(attributes);
 
  156                             blackboard.indexArtifact(artifact);
 
  157                         } 
catch (Blackboard.BlackboardException ex) {
 
  158                             logger.log(Level.SEVERE, 
"Unable to index blackboard artifact " + artifact.getArtifactID(), ex); 
 
  159                             MessageNotifyUtil.Notify.error(Bundle.FilesIdentifierIngestModule_indexError_message(), artifact.getDisplayName());
 
  162                         services.fireModuleDataEvent(
new ModuleDataEvent(moduleName, BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT, Collections.singletonList(artifact)));
 
  165                         StringBuilder detailsSb = 
new StringBuilder();
 
  166                         detailsSb.append(
"File: " + file.getParentPath() + file.getName() + 
"<br/>\n");
 
  167                         detailsSb.append(
"Rule Set: " + filesSet.getName());
 
  169                         services.postMessage(IngestMessage.createDataMessage(InterestingItemsIngestModuleFactory.getModuleName(),
 
  170                                 "Interesting File Match: " + filesSet.getName() + 
"(" + file.getName() +
")",
 
  171                                 detailsSb.toString(),
 
  175                 } 
catch (TskCoreException ex) {
 
  176                     FilesIdentifierIngestModule.logger.log(Level.SEVERE, 
"Error posting to the blackboard", ex); 
 
  180         return ProcessResult.OK;
 
  187     public void shutDown() {
 
  188         if (context != null) {
 
  189             if (refCounter.decrementAndGet(
this.context.getJobId()) == 0) {
 
  193                 FilesIdentifierIngestModule.interestingFileSetsByJob.remove(this.context.getJobId());