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;
 
   54 @NbBundle.Messages({
"FilesIdentifierIngestModule.getFilesError=Error getting interesting files sets from file."})
 
   55 final class FilesIdentifierIngestModule implements FileIngestModule {
 
   57     private static final Object sharedResourcesLock = 
new Object();
 
   58     private static final Logger logger = Logger.getLogger(FilesIdentifierIngestModule.class.getName());
 
   59     private static final IngestModuleReferenceCounter refCounter = 
new IngestModuleReferenceCounter();
 
   60     private static final Map<Long, List<FilesSet>> interestingFileSetsByJob = 
new ConcurrentHashMap<>();
 
   61     private static final String MODULE_NAME = InterestingItemsIngestModuleFactory.getModuleName();
 
   63     private final FilesIdentifierIngestJobSettings settings;
 
   64     private final IngestServices services = IngestServices.getInstance();
 
   65     private IngestJobContext context;
 
   66     private Blackboard blackboard;
 
   74     FilesIdentifierIngestModule(FilesIdentifierIngestJobSettings settings) {
 
   75         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);
 
  104     @Messages({
"FilesIdentifierIngestModule.indexError.message=Failed to index interesting file hit artifact for keyword search."})
 
  105     public ProcessResult process(AbstractFile file) {
 
  107             blackboard = Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboard();
 
  108         } 
catch (NoCurrentCaseException ex) {
 
  109             logger.log(Level.SEVERE, 
"Exception while getting open case.", ex); 
 
  110             return ProcessResult.ERROR;
 
  114         if (file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
 
  115             return ProcessResult.OK;
 
  119         List<FilesSet> filesSets = FilesIdentifierIngestModule.interestingFileSetsByJob.get(this.context.getJobId());
 
  120         for (FilesSet filesSet : filesSets) {
 
  121             String ruleSatisfied = filesSet.fileIsMemberOf(file);
 
  122             if (ruleSatisfied != null) {
 
  125                     Collection<BlackboardAttribute> attributes = Arrays.asList(
 
  132                             new BlackboardAttribute(
 
  133                                     TSK_SET_NAME, MODULE_NAME,
 
  139                             new BlackboardAttribute(
 
  140                                     TSK_CATEGORY, MODULE_NAME,
 
  145                     if (!blackboard.artifactExists(file, TSK_INTERESTING_FILE_HIT, attributes)) {
 
  146                         BlackboardArtifact artifact = file.newAnalysisResult(
 
  147                                 BlackboardArtifact.Type.TSK_INTERESTING_FILE_HIT, Score.SCORE_LIKELY_NOTABLE, 
 
  148                                 null, filesSet.getName(), null, 
 
  150                                 .getAnalysisResult();
 
  154                             blackboard.postArtifact(artifact, MODULE_NAME);
 
  155                         } 
catch (Blackboard.BlackboardException ex) {
 
  156                             logger.log(Level.SEVERE, 
"Unable to index blackboard artifact " + artifact.getArtifactID(), ex); 
 
  157                             MessageNotifyUtil.Notify.error(Bundle.FilesIdentifierIngestModule_indexError_message(), artifact.getDisplayName());
 
  161                         StringBuilder detailsSb = 
new StringBuilder();
 
  162                         detailsSb.append(
"File: ").append(file.getParentPath()).append(file.getName()).append(
"<br/>\n");
 
  163                         detailsSb.append(
"Rule Set: ").append(filesSet.getName());
 
  165                         services.postMessage(IngestMessage.createDataMessage(InterestingItemsIngestModuleFactory.getModuleName(),
 
  166                                 "Interesting File Match: " + filesSet.getName() + 
"(" + file.getName() + 
")",
 
  167                                 detailsSb.toString(),
 
  171                 } 
catch (TskCoreException ex) {
 
  172                     FilesIdentifierIngestModule.logger.log(Level.SEVERE, 
"Error posting to the blackboard", ex); 
 
  176         return ProcessResult.OK;
 
  180     public void shutDown() {
 
  181         if (context != null) {
 
  182             if (refCounter.decrementAndGet(
this.context.getJobId()) == 0) {
 
  186                 FilesIdentifierIngestModule.interestingFileSetsByJob.remove(this.context.getJobId());