19 package org.sleuthkit.autopsy.test;
 
   21 import java.util.ArrayList;
 
   22 import java.util.Collection;
 
   23 import java.util.Collections;
 
   24 import java.util.logging.Level;
 
   25 import org.openide.util.NbBundle;
 
   43     "InterestingArtifactCreatorIngestModule.exceptionMessage.errorCreatingCustomType=Error creating custom artifact type." 
   45 final class InterestingArtifactCreatorIngestModule extends FileIngestModuleAdapter {
 
   47     private static final Logger logger = Logger.getLogger(InterestingArtifactCreatorIngestModule.class.getName());
 
   48     private static final String MODULE_NAME = InterestingArtifactCreatorIngestModuleFactory.getModuleName();
 
   49     private static final String[] ARTIFACT_TYPE_NAMES = {
"TSK_WEB_BOOKMARK", 
"TSK_KEYWORD_HIT", 
"TSK_CALLLOG"};
 
   50     private static final String[] ARTIFACT_DISPLAY_NAMES = {
"Web Bookmarks", 
"Keyword Hits", 
"Call Logs"};
 
   51     private static final String INT_ARTIFACT_TYPE_NAME = BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ITEM.getLabel();
 
   52     private static final String INT_ARTIFACT_DISPLAY_NAME = BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ITEM.getDisplayName();
 
   53     private BlackboardArtifact.Type artifactType;
 
   56     public void startUp(IngestJobContext context) 
throws IngestModuleException {
 
   58             Blackboard blackboard = Case.getCurrentCaseThrows().getServices().getArtifactsBlackboard();
 
   59             artifactType = blackboard.getOrAddArtifactType(INT_ARTIFACT_TYPE_NAME, INT_ARTIFACT_DISPLAY_NAME);
 
   60          } 
catch (Blackboard.BlackboardException | NoCurrentCaseException ex) {
 
   61             throw new IngestModuleException(Bundle.InterestingArtifactCreatorIngestModule_exceptionMessage_errorCreatingCustomType(), ex);
 
   66     public ProcessResult process(AbstractFile file) {
 
   70         if (file.isDir() || file.isVirtual()) {
 
   71             return ProcessResult.OK;
 
   79             int randomArtIndex = (int) (Math.random() * 3);
 
   80             Blackboard blackboard = Case.getCurrentCaseThrows().getServices().getArtifactsBlackboard();
 
   81             BlackboardArtifact.Type artifactTypeBase = blackboard.getOrAddArtifactType(ARTIFACT_TYPE_NAMES[randomArtIndex], ARTIFACT_DISPLAY_NAMES[randomArtIndex]);
 
   83             Collection<BlackboardAttribute> baseAttributes = 
new ArrayList<>();
 
   85             BlackboardAttribute baseAttr;
 
   86             switch (artifactTypeBase.getTypeID()) {
 
   88                     commentTxt = 
"www.placeholderWebsiteDOTCOM";
 
   89                     baseAttr = 
new BlackboardAttribute(
 
   90                             BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, 
"Fake Web BookMark", 
"www.thisWebsiteIsStillFake.com");
 
   91                     baseAttributes.add(baseAttr);
 
   94                     commentTxt = 
"fakeKeyword";
 
   95                     baseAttr = 
new BlackboardAttribute(
 
   96                             BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_PREVIEW, 
"Fake Keyword Search", 
"Fake Keyword Preview Text");
 
   97                     BlackboardAttribute set = 
new BlackboardAttribute(
 
   98                             BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME, 
"Fake Keyword Search", 
"Fake");
 
   99                     BlackboardAttribute keyword = 
new BlackboardAttribute(
 
  100                             BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD, 
"Fake Keyword Search", 
"FakeKeyword");
 
  101                     baseAttributes.add(baseAttr);
 
  102                     baseAttributes.add(set);
 
  103                     baseAttributes.add(keyword);
 
  106                     commentTxt = 
"fake phone number from";
 
  107                     baseAttr = 
new BlackboardAttribute(
 
  108                             BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, 
"Fake Call Log Whatever", 
"555-555-5555");
 
  109                     baseAttributes.add(baseAttr);
 
  112                     commentTxt = 
"DEPENDENT ON ARTIFACT TYPE";
 
  116             BlackboardArtifact artifactBase;
 
  117             switch (artifactTypeBase.getCategory()) {
 
  119                     artifactBase = file.newDataArtifact(artifactTypeBase, baseAttributes);
 
  121                 case ANALYSIS_RESULT:
 
  122                     artifactBase = file.newAnalysisResult(artifactTypeBase, Score.SCORE_UNKNOWN, null, null, null, baseAttributes)
 
  123                             .getAnalysisResult();
 
  126                     throw new IllegalArgumentException(
"Unknown category type: " + artifactTypeBase.getCategory().getDisplayName());
 
  129             Collection<BlackboardAttribute> attributes = 
new ArrayList<>();
 
  130             BlackboardAttribute att = 
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME, MODULE_NAME, 
"ArtifactsAndTxt");
 
  132             BlackboardAttribute att2 = 
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT, MODULE_NAME, commentTxt);
 
  133             BlackboardAttribute att3 = 
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY, MODULE_NAME, 
"");
 
  135             attributes.add(att2);
 
  136             attributes.add(att3);
 
  137             attributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT, MODULE_NAME, artifactBase.getArtifactID()));
 
  139             switch (artifactType.getCategory()) {
 
  141                     file.newDataArtifact(artifactType, attributes);
 
  143                 case ANALYSIS_RESULT:
 
  144                     file.newAnalysisResult(artifactType, Score.SCORE_UNKNOWN, null, null, null, attributes)
 
  145                             .getAnalysisResult();
 
  148                     throw new IllegalArgumentException(
"Unknown category type: " + artifactType.getCategory().getDisplayName());
 
  151         } 
catch (TskCoreException | NoCurrentCaseException ex) {
 
  152             logger.log(Level.SEVERE, String.format(
"Failed to process file (obj_id = %d)", file.getId()), ex);
 
  153             return ProcessResult.ERROR;
 
  154         } 
catch (Blackboard.BlackboardException ex) {
 
  155             logger.log(Level.WARNING, 
"Blackboard Exception processing file with obj_id = " + file.getId(), ex);
 
  157         return ProcessResult.OK;