19 package org.sleuthkit.autopsy.datamodel;
21 import com.google.common.cache.Cache;
22 import com.google.common.cache.CacheBuilder;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.text.MessageFormat;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.EnumSet;
29 import java.util.LinkedHashMap;
30 import java.util.List;
32 import java.util.MissingResourceException;
34 import java.util.concurrent.ExecutionException;
35 import java.util.concurrent.TimeUnit;
36 import java.util.logging.Level;
37 import java.util.stream.Collectors;
38 import javax.swing.Action;
39 import org.apache.commons.lang3.StringUtils;
40 import org.openide.nodes.Sheet;
41 import org.openide.util.Lookup;
42 import org.openide.util.NbBundle;
43 import org.openide.util.WeakListeners;
44 import org.openide.util.lookup.Lookups;
68 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
70 import org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
90 private static Cache<Long, Content>
contentCache = CacheBuilder.newBuilder()
91 .expireAfterWrite(1, TimeUnit.MINUTES).
107 BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID(),
108 BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID(),
109 BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT.getTypeID(),
110 BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID(),};
116 BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT.getTypeID(),};
118 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
120 public void propertyChange(PropertyChangeEvent evt) {
121 String eventType = evt.getPropertyName();
124 if (event.getAddedTag().getArtifact().equals(artifact)) {
129 if (event.getDeletedTagInfo().getArtifactID() == artifact.getArtifactID()) {
134 if (event.getAddedTag().getContent().equals(associated)) {
139 if (event.getDeletedTagInfo().getContentID() == associated.getId()) {
144 if (event.getContentID() == associated.getId()) {
148 if (evt.getNewValue() == null) {
151 contentCache.invalidateAll();
165 private final PropertyChangeListener
weakPcl = WeakListeners.propertyChange(pcl, null);
181 for (Content lookupContent : this.getLookup().lookupAll(Content.class)) {
182 if ((lookupContent != null) && (!(lookupContent instanceof BlackboardArtifact))) {
183 this.associated = lookupContent;
188 this.
setName(Long.toString(artifact.getArtifactID()));
190 this.setIconBaseWithExtension(iconPath);
229 "BlackboardArtifactNode.getAction.errorTitle=Error getting actions",
230 "BlackboardArtifactNode.getAction.resultErrorMessage=There was a problem getting actions for the selected result."
231 +
" The 'View Result in Timeline' action will not be available.",
232 "BlackboardArtifactNode.getAction.linkedFileMessage=There was a problem getting actions for the selected result. "
233 +
" The 'View File in Timeline' action will not be available."})
235 List<Action> actionsList =
new ArrayList<>();
236 actionsList.addAll(Arrays.asList(super.getActions(context)));
237 AbstractFile file = getLookup().lookup(AbstractFile.class);
244 }
catch (TskCoreException ex) {
245 logger.log(Level.SEVERE, MessageFormat.format(
"Error getting arttribute(s) from blackboard artifact{0}.", artifact.getArtifactID()), ex);
246 MessageNotifyUtil.
Notify.
error(Bundle.BlackboardArtifactNode_getAction_errorTitle(), Bundle.BlackboardArtifactNode_getAction_resultErrorMessage());
251 AbstractFile c = findLinked(artifact);
255 }
catch (TskCoreException ex) {
256 logger.log(Level.SEVERE, MessageFormat.format(
"Error getting linked file from blackboard artifact{0}.", artifact.getArtifactID()), ex);
257 MessageNotifyUtil.
Notify.
error(Bundle.BlackboardArtifactNode_getAction_errorTitle(), Bundle.BlackboardArtifactNode_getAction_linkedFileMessage());
265 return actionsList.toArray(
new Action[actionsList.size()]);
268 @NbBundle.Messages({
"# {0} - artifactDisplayName",
"BlackboardArtifactNode.displayName.artifact={0} Artifact"})
275 String displayName =
"";
281 && (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()
282 || artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID())) {
284 for (BlackboardAttribute attribute : artifact.getAttributes()) {
285 if (attribute.getAttributeType().getTypeID() == ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT.getTypeID()) {
287 if (associatedArtifact != null) {
288 if (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID()) {
289 artifact.getDisplayName();
291 displayName = NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.displayName.artifact", associatedArtifact.getDisplayName());
301 if (displayName.isEmpty() && artifact != null) {
302 displayName = artifact.getName();
317 if (associated != null) {
318 srcName = associated.getName();
324 "BlackboardArtifactNode.createSheet.artifactType.displayName=Result Type",
325 "BlackboardArtifactNode.createSheet.artifactType.name=Result Type",
326 "BlackboardArtifactNode.createSheet.artifactDetails.displayName=Result Details",
327 "BlackboardArtifactNode.createSheet.artifactDetails.name=Result Details",
328 "BlackboardArtifactNode.createSheet.artifactMD5.displayName=MD5 Hash",
329 "BlackboardArtifactNode.createSheet.artifactMD5.name=MD5 Hash",
330 "BlackboardArtifactNode.createSheet.fileSize.name=Size",
331 "BlackboardArtifactNode.createSheet.fileSize.displayName=Size",
332 "BlackboardArtifactNode.createSheet.path.displayName=Path",
333 "BlackboardArtifactNode.createSheet.path.name=Path"})
337 Sheet sheet = super.createSheet();
340 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
341 if (sheetSet == null) {
342 sheetSet = Sheet.createPropertiesSet();
346 Map<String, Object> map =
new LinkedHashMap<>();
350 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.srcFile.displayName"),
365 if (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID()) {
367 BlackboardAttribute attribute = artifact.getAttribute(
new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
368 if (attribute != null) {
371 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.artifactType.displayName"),
373 associatedArtifact.getDisplayName()));
375 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.artifactDetails.displayName"),
377 associatedArtifact.getShortDescription()));
384 for (Map.Entry<String, Object> entry : map.entrySet()) {
392 if (customProperties != null) {
398 final int artifactTypeId = artifact.getArtifactTypeID();
401 if (artifactTypeId == BlackboardArtifact.ARTIFACT_TYPE.TSK_EXT_MISMATCH_DETECTED.getTypeID()) {
403 String actualMimeType =
"";
404 if (associated instanceof AbstractFile) {
405 AbstractFile af = (AbstractFile) associated;
406 ext = af.getNameExtension();
407 actualMimeType = af.getMIMEType();
408 if (actualMimeType == null) {
418 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.mimeType.displayName"),
423 if (Arrays.asList(SHOW_UNIQUE_PATH).contains(artifactTypeId)) {
424 String sourcePath =
"";
426 sourcePath = associated.getUniquePath();
427 }
catch (TskCoreException ex) {
428 logger.log(Level.WARNING,
"Failed to get unique path from: {0}", associated.getName());
431 if (sourcePath.isEmpty() ==
false) {
434 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.filePath.displayName"),
439 if (Arrays.asList(SHOW_FILE_METADATA).contains(artifactTypeId)) {
440 AbstractFile file = associated instanceof AbstractFile ? (AbstractFile) associated : null;
442 NbBundle.getMessage(
BlackboardArtifactNode.class,
"ContentTagNode.createSheet.fileModifiedTime.displayName"),
446 NbBundle.getMessage(
BlackboardArtifactNode.class,
"ContentTagNode.createSheet.fileChangedTime.displayName"),
450 NbBundle.getMessage(
BlackboardArtifactNode.class,
"ContentTagNode.createSheet.fileAccessedTime.displayName"),
454 NbBundle.getMessage(
BlackboardArtifactNode.class,
"ContentTagNode.createSheet.fileCreatedTime.displayName"),
460 associated.getSize()));
461 sheetSet.put(
new NodeProperty<>(Bundle.BlackboardArtifactNode_createSheet_artifactMD5_name(),
462 Bundle.BlackboardArtifactNode_createSheet_artifactMD5_displayName(),
464 file == null ?
"" : StringUtils.defaultString(file.getMd5Hash())));
467 String dataSourceStr =
"";
469 Content dataSource = associated.getDataSource();
470 if (dataSource != null) {
471 dataSourceStr = dataSource.getName();
475 }
catch (TskCoreException ex) {
476 logger.log(Level.WARNING,
"Failed to get image name from {0}", associated.getName());
479 if (dataSourceStr.isEmpty() ==
false) {
482 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.dataSrc.displayName"),
489 if (artifactTypeId == BlackboardArtifact.ARTIFACT_TYPE.TSK_METADATA_EXIF.getTypeID()) {
493 if (associated instanceof AbstractFile) {
494 AbstractFile af = (AbstractFile) associated;
497 path = af.getUniquePath();
498 }
catch (TskCoreException ex) {
499 path = af.getParentPath();
503 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.fileSize.displayName"),
524 List<Tag> tags =
new ArrayList<>();
529 logger.log(Level.SEVERE,
"Failed to get tags for artifact " + artifact.getDisplayName(), ex);
542 "BlackboardArtifactNode.createSheet.tags.displayName=Tags"})
544 protected void addTagProperty(Sheet.Set sheetSet)
throws MissingResourceException {
546 List<Tag> tags =
new ArrayList<>();
551 logger.log(Level.SEVERE,
"Failed to get tags for artifact " + artifact.getDisplayName(), ex);
553 sheetSet.put(
new NodeProperty<>(
"Tags", Bundle.BlackboardArtifactNode_createSheet_tags_displayName(),
554 NO_DESCR, tags.stream().map(t -> t.getName().getDisplayName()).collect(Collectors.joining(
", "))));
568 sheetSet.put(
new NodeProperty<>(
"Tags", Bundle.BlackboardArtifactNode_createSheet_tags_displayName(),
569 NO_DESCR, tags.stream().map(t -> t.getName().getDisplayName()).collect(Collectors.joining(
", "))));
577 return correlationAttribute;
591 @NbBundle.Messages({
"BlackboardArtifactNode.createSheet.comment.name=C",
592 "BlackboardArtifactNode.createSheet.comment.displayName=C"})
595 for (Tag tag : tags) {
596 if (!StringUtils.isBlank(tag.getComment())) {
605 if (attribute != null && !StringUtils.isBlank(attribute.
getComment())) {
612 sheetSet.put(
new NodeProperty<>(Bundle.BlackboardArtifactNode_createSheet_comment_name(), Bundle.BlackboardArtifactNode_createSheet_comment_displayName(),
NO_DESCR,
624 @NbBundle.Messages({
"BlackboardArtifactNode.createSheet.score.name=S",
625 "BlackboardArtifactNode.createSheet.score.displayName=S",
626 "BlackboardArtifactNode.createSheet.notableFile.description=Associated file recognized as notable.",
627 "BlackboardArtifactNode.createSheet.interestingResult.description=Result has an interesting result associated with it.",
628 "BlackboardArtifactNode.createSheet.taggedItem.description=Result or associated file has been tagged.",
629 "BlackboardArtifactNode.createSheet.notableTaggedItem.description=Result or associated file tagged with notable tag.",
630 "BlackboardArtifactNode.createSheet.noScore.description=No score"})
633 String description = Bundle.BlackboardArtifactNode_createSheet_noScore_description();
634 if (associated instanceof AbstractFile) {
635 if (((AbstractFile) associated).getKnown() == TskData.FileKnown.BAD) {
637 description = Bundle.BlackboardArtifactNode_createSheet_notableFile_description();
643 BlackboardAttribute attr = content.getAttribute(
new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_SET_NAME));
646 if (hashDb.getHashSetName().equals(attr.getValueString())) {
648 description = Bundle.BlackboardArtifactNode_createSheet_notableFile_description();
652 }
catch (TskCoreException ex) {
654 logger.log(Level.WARNING,
"Unable to get TSK_SET_NAME attribute for artifact of type TSK_HASHSET_HIT with artifact ID " + content.getArtifactID(), ex);
658 if (score ==
Score.
NO_SCORE && !content.getArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT).isEmpty()) {
660 description = Bundle.BlackboardArtifactNode_createSheet_interestingResult_description();
662 }
catch (TskCoreException ex) {
663 logger.log(Level.WARNING,
"Error getting artifacts for artifact: " + content.getName(), ex);
667 description = Bundle.BlackboardArtifactNode_createSheet_taggedItem_description();
668 for (Tag tag : tags) {
669 if (tag.getName().getKnownStatus() == TskData.FileKnown.BAD) {
671 description = Bundle.BlackboardArtifactNode_createSheet_notableTaggedItem_description();
676 sheetSet.put(
new NodeProperty<>(Bundle.BlackboardArtifactNode_createSheet_score_name(), Bundle.BlackboardArtifactNode_createSheet_score_displayName(), description, score));
679 @NbBundle.Messages({
"BlackboardArtifactNode.createSheet.count.name=O",
680 "BlackboardArtifactNode.createSheet.count.displayName=O",
681 "BlackboardArtifactNode.createSheet.count.noCentralRepo.description=Central repository was not enabled when this column was populated",
682 "BlackboardArtifactNode.createSheet.count.hashLookupNotRun.description=Hash lookup had not been run on this artifact's associated file when the column was populated",
683 "# {0} - occuranceCount",
684 "BlackboardArtifactNode.createSheet.count.description=There were {0} datasource(s) found with occurances of the correlation value"})
688 String description = Bundle.BlackboardArtifactNode_createSheet_count_noCentralRepo_description();
693 description = Bundle.BlackboardArtifactNode_createSheet_count_description(count);
694 }
else if (attribute != null) {
695 description = Bundle.BlackboardArtifactNode_createSheet_count_hashLookupNotRun_description();
698 logger.log(Level.WARNING,
"Error getting count of datasources with correlation attribute", ex);
700 logger.log(Level.WARNING,
"Unable to normalize data to get count of datasources with correlation attribute", ex);
703 new NodeProperty<>(Bundle.BlackboardArtifactNode_createSheet_count_name(), Bundle.BlackboardArtifactNode_createSheet_count_displayName(), description, count));
711 String parentName = associated.getName();
714 while ((parent = parent.getParent()) != null) {
715 parentName = parent.getName();
717 }
catch (TskCoreException ex) {
718 logger.log(Level.WARNING,
"Failed to get parent name from {0}", associated.getName());
731 if (null == customProperties) {
733 customProperties =
new ArrayList<>();
735 customProperties.add(np);
745 @SuppressWarnings(
"deprecation")
748 for (BlackboardAttribute attribute : artifact.getAttributes()) {
749 final int attributeTypeID = attribute.getAttributeType().getTypeID();
751 if (attributeTypeID == ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()
752 || attributeTypeID == ATTRIBUTE_TYPE.TSK_TAGGED_ARTIFACT.getTypeID()
753 || attributeTypeID == ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT.getTypeID()
754 || attributeTypeID == ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID()
755 || attributeTypeID == ATTRIBUTE_TYPE.TSK_KEYWORD_SEARCH_TYPE.getTypeID()) {
756 }
else if (artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()) {
758 }
else if (attribute.getAttributeType().getValueType() == BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME) {
760 }
else if (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getTypeID()
761 && attributeTypeID == ATTRIBUTE_TYPE.TSK_TEXT.getTypeID()) {
769 String value = attribute.getDisplayString();
770 if (value.length() > 512) {
771 value = value.substring(0, 512);
773 map.put(attribute.getAttributeType().getDisplayName(), value);
775 map.put(attribute.getAttributeType().getDisplayName(), attribute.getDisplayString());
778 }
catch (TskCoreException ex) {
779 logger.log(Level.SEVERE,
"Getting attributes failed", ex);
792 final int attributeTypeID = attribute.getAttributeType().getTypeID();
795 if (attributeTypeID == ATTRIBUTE_TYPE.TSK_DATETIME_SENT.getTypeID()
796 || attributeTypeID == ATTRIBUTE_TYPE.TSK_EMAIL_CONTENT_HTML.getTypeID()
797 || attributeTypeID == ATTRIBUTE_TYPE.TSK_EMAIL_CONTENT_RTF.getTypeID()
798 || attributeTypeID == ATTRIBUTE_TYPE.TSK_EMAIL_BCC.getTypeID()
799 || attributeTypeID == ATTRIBUTE_TYPE.TSK_EMAIL_CC.getTypeID()
800 || attributeTypeID == ATTRIBUTE_TYPE.TSK_HEADERS.getTypeID()) {
803 }
else if (attributeTypeID == ATTRIBUTE_TYPE.TSK_EMAIL_CONTENT_PLAIN.getTypeID()) {
805 String value = attribute.getDisplayString();
806 if (value.length() > 160) {
807 value = value.substring(0, 160) +
"...";
809 map.put(attribute.getAttributeType().getDisplayName(), value);
810 }
else if (attribute.getAttributeType().getValueType() == BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME) {
813 map.put(attribute.getAttributeType().getDisplayName(), attribute.getDisplayString());
820 return visitor.
visit(
this);
833 final long objectID = artifact.getObjectID();
835 Content content = contentCache.get(objectID, () -> artifact.getSleuthkitCase().getContentById(objectID));
836 if (content == null) {
837 return Lookups.fixed(artifact);
839 return Lookups.fixed(artifact, content);
841 }
catch (ExecutionException ex) {
842 logger.log(Level.WARNING,
"Getting associated content for artifact failed", ex);
843 return Lookups.fixed(artifact);
854 return getClass().getName();
858 public <T> T accept(ContentNodeVisitor<T> visitor) {
859 return visitor.visit(
this);
final void addTagProperty(Sheet.Set sheetSet, List< Tag > tags)
void addTagProperty(Sheet.Set sheetSet)
void fillPropertyMap(Map< String, Object > map, BlackboardArtifact artifact)
static String getStringTime(long epochSeconds, TimeZone tzone)
static boolean hasSupportedTimeStamp(BlackboardArtifact artifact)
final PropertyChangeListener weakPcl
static Cache< Long, Content > contentCache
void setName(String name)
final PropertyChangeListener pcl
BlackboardArtifactNode(BlackboardArtifact artifact, String iconPath)
static Lookup createLookup(BlackboardArtifact artifact)
static final String NO_DESCR
static final Integer[] SHOW_FILE_METADATA
String getCorrelationValue()
T visit(DataSourcesNode in)
Action[] getActions(boolean context)
final void addScoreProperty(Sheet.Set sheetSet, List< Tag > tags)
Type getCorrelationType()
static ViewFileInTimelineAction createViewSourceFileAction(AbstractFile file)
static final Set< Case.Events > CASE_EVENTS_OF_INTEREST
Long getCountUniqueCaseDataSourceTuplesHavingTypeValue(CorrelationAttributeInstance.Type aType, String value)
TagsManager getTagsManager()
synchronized List< HashDb > getKnownBadFileHashSets()
static EamDb getInstance()
List< NodeProperty<?extends Object > > customProperties
static synchronized HashDbManager getInstance()
static CorrelationAttributeInstance getInstanceFromContent(Content content)
final List< Tag > getAllTagsFromDatabase()
String getRootParentName()
final BlackboardArtifact artifact
void addEmailMsgProperty(Map< String, Object > map, BlackboardAttribute attribute)
final void addCommentProperty(Sheet.Set sheetSet, List< Tag > tags, CorrelationAttributeInstance attribute)
final CorrelationAttributeInstance getCorrelationAttributeInstance()
static boolean isEnabled()
SleuthkitCase getSleuthkitCase()
final void addCountProperty(Sheet.Set sheetSet, CorrelationAttributeInstance attribute)
BLACKBOARD_ARTIFACT_TAG_ADDED
static final Logger logger
static void error(String title, String message)
BlackboardArtifact getArtifact()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
static boolean hideCentralRepoCommentsAndOccurrences()
void addNodeProperty(NodeProperty<?> np)
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
BlackboardArtifactNode(BlackboardArtifact artifact)
static final Integer[] SHOW_UNIQUE_PATH
static ViewFileInTimelineAction createViewFileAction(AbstractFile file)
BLACKBOARD_ARTIFACT_TAG_DELETED