19 package org.sleuthkit.autopsy.test;
 
   21 import java.util.ArrayList;
 
   22 import java.util.Collection;
 
   23 import java.util.logging.Level;
 
   25 import org.openide.util.Exceptions;
 
   26 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_ARTIFACT_HIT.getLabel();
 
   52     private static final String INT_ARTIFACT_DISPLAY_NAME = BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getDisplayName();
 
   53     private BlackboardArtifact.Type artifactType;
 
   56     public void startUp(IngestJobContext context) 
throws IngestModuleException {
 
   58             Blackboard blackboard = Case.getCurrentCaseThrows().getServices().getBlackboard();
 
   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().getBlackboard();
 
   81             BlackboardArtifact.Type artifactTypeBase = blackboard.getOrAddArtifactType(ARTIFACT_TYPE_NAMES[randomArtIndex], ARTIFACT_DISPLAY_NAMES[randomArtIndex]);
 
   82             BlackboardArtifact artifactBase = file.newArtifact(artifactTypeBase.getTypeID());
 
   83             Collection<BlackboardAttribute> baseAttributes = 
new ArrayList<>();
 
   85             BlackboardAttribute baseAttr;
 
   86             switch (artifactBase.getArtifactTypeID()) {
 
   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";
 
  115             artifactBase.addAttributes(baseAttributes);
 
  116             BlackboardArtifact artifact = file.newArtifact(artifactType.getTypeID());
 
  117             Collection<BlackboardAttribute> attributes = 
new ArrayList<>();
 
  118             BlackboardAttribute att = 
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME, MODULE_NAME, 
"ArtifactsAndTxt");
 
  120             BlackboardAttribute att2 = 
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT, MODULE_NAME, commentTxt);
 
  121             BlackboardAttribute att3 = 
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY, MODULE_NAME, 
"");
 
  123             attributes.add(att2);
 
  124             attributes.add(att3);
 
  125             attributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT, MODULE_NAME, artifactBase.getArtifactID()));
 
  126             artifact.addAttributes(attributes);
 
  127         } 
catch (TskCoreException | NoCurrentCaseException ex) {
 
  128             logger.log(Level.SEVERE, String.format(
"Failed to process file (obj_id = %d)", file.getId()), ex);
 
  129             return ProcessResult.ERROR;
 
  130         } 
catch (Blackboard.BlackboardException ex) {
 
  131             Exceptions.printStackTrace(ex);
 
  133         return ProcessResult.OK;