19 package org.sleuthkit.autopsy.modules.interestingitems;
 
   21 import java.util.ArrayList;
 
   22 import java.util.Arrays;
 
   23 import java.util.Collection;
 
   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;
 
   42 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT;
 
   44 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY;
 
   45 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME;
 
   53 @NbBundle.Messages({
"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 static final String MODULE_NAME = InterestingItemsIngestModuleFactory.getModuleName();
 
   62     private final FilesIdentifierIngestJobSettings settings;
 
   63     private final IngestServices services = IngestServices.getInstance();
 
   64     private IngestJobContext context;
 
   65     private Blackboard blackboard;
 
   73     FilesIdentifierIngestModule(FilesIdentifierIngestJobSettings settings) {
 
   74         this.settings = settings;
 
   78     public void startUp(IngestJobContext context) 
throws IngestModuleException {
 
   79         this.context = context;
 
   80         synchronized (FilesIdentifierIngestModule.sharedResourcesLock) {
 
   81             if (FilesIdentifierIngestModule.refCounter.incrementAndGet(context.getJobId()) == 1) {
 
   87                 List<FilesSet> filesSets = 
new ArrayList<>();
 
   89                     for (FilesSet set : FilesSetsManager.getInstance().getInterestingFilesSets().values()) {
 
   90                         if (settings.interestingFilesSetIsEnabled(set.getName())) {
 
   94                 } 
catch (FilesSetsManager.FilesSetsManagerException ex) {
 
   95                     throw new IngestModuleException(Bundle.FilesIdentifierIngestModule_getFilesError(), ex);
 
   97                 FilesIdentifierIngestModule.interestingFileSetsByJob.put(context.getJobId(), filesSets);
 
  103     @Messages({
"FilesIdentifierIngestModule.indexError.message=Failed to index interesting file hit artifact for keyword search."})
 
  104     public ProcessResult process(AbstractFile file) {
 
  106             blackboard = Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboard();
 
  107         } 
catch (NoCurrentCaseException ex) {
 
  108             logger.log(Level.SEVERE, 
"Exception while getting open case.", ex); 
 
  109             return ProcessResult.ERROR;
 
  113         if (file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
 
  114             return ProcessResult.OK;
 
  118         List<FilesSet> filesSets = FilesIdentifierIngestModule.interestingFileSetsByJob.get(this.context.getJobId());
 
  119         for (FilesSet filesSet : filesSets) {
 
  120             String ruleSatisfied = filesSet.fileIsMemberOf(file);
 
  121             if (ruleSatisfied != null) {
 
  124                     Collection<BlackboardAttribute> attributes = Arrays.asList(
 
  131                             new BlackboardAttribute(
 
  132                                     TSK_SET_NAME, MODULE_NAME,
 
  138                             new BlackboardAttribute(
 
  139                                     TSK_CATEGORY, MODULE_NAME,
 
  144                     if (!blackboard.artifactExists(file, TSK_INTERESTING_FILE_HIT, attributes)) {
 
  145                         BlackboardArtifact artifact = file.newArtifact(TSK_INTERESTING_FILE_HIT);
 
  146                         artifact.addAttributes(attributes);
 
  150                             blackboard.postArtifact(artifact, MODULE_NAME);
 
  151                         } 
catch (Blackboard.BlackboardException ex) {
 
  152                             logger.log(Level.SEVERE, 
"Unable to index blackboard artifact " + artifact.getArtifactID(), ex); 
 
  153                             MessageNotifyUtil.Notify.error(Bundle.FilesIdentifierIngestModule_indexError_message(), artifact.getDisplayName());
 
  157                         StringBuilder detailsSb = 
new StringBuilder();
 
  158                         detailsSb.append(
"File: ").append(file.getParentPath()).append(file.getName()).append(
"<br/>\n");
 
  159                         detailsSb.append(
"Rule Set: ").append(filesSet.getName());
 
  161                         services.postMessage(IngestMessage.createDataMessage(InterestingItemsIngestModuleFactory.getModuleName(),
 
  162                                 "Interesting File Match: " + filesSet.getName() + 
"(" + file.getName() + 
")",
 
  163                                 detailsSb.toString(),
 
  167                 } 
catch (TskCoreException ex) {
 
  168                     FilesIdentifierIngestModule.logger.log(Level.SEVERE, 
"Error posting to the blackboard", ex); 
 
  172         return ProcessResult.OK;
 
  176     public void shutDown() {
 
  177         if (context != null) {
 
  178             if (refCounter.decrementAndGet(
this.context.getJobId()) == 0) {
 
  182                 FilesIdentifierIngestModule.interestingFileSetsByJob.remove(this.context.getJobId());