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;
33 import java.util.concurrent.ExecutionException;
34 import java.util.concurrent.TimeUnit;
35 import java.util.logging.Level;
36 import java.util.stream.Collectors;
37 import javax.swing.Action;
38 import org.openide.nodes.Sheet;
39 import org.openide.util.Lookup;
40 import org.openide.util.NbBundle;
41 import org.openide.util.WeakListeners;
42 import org.openide.util.lookup.Lookups;
55 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
57 import org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
75 private static Cache<Long, Content>
contentCache = CacheBuilder.newBuilder()
76 .expireAfterWrite(1, TimeUnit.MINUTES).
88 BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID(),
89 BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID(),
90 BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT.getTypeID(),
91 BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID(),};
97 BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT.getTypeID(),};
99 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
101 public void propertyChange(PropertyChangeEvent evt) {
102 String eventType = evt.getPropertyName();
105 if (event.getAddedTag().getArtifact().equals(artifact)) {
110 if (event.getDeletedTagInfo().getArtifactID() == artifact.getArtifactID()) {
115 if (event.getAddedTag().getContent().equals(associated)) {
120 if (event.getDeletedTagInfo().getContentID() == associated.getId()) {
124 if (evt.getNewValue() == null) {
127 contentCache.invalidateAll();
141 private final PropertyChangeListener
weakPcl = WeakListeners.propertyChange(pcl, null);
157 for (Content lookupContent : this.getLookup().lookupAll(Content.class)) {
158 if ((lookupContent != null) && (!(lookupContent instanceof BlackboardArtifact))) {
159 this.associated = lookupContent;
164 this.
setName(Long.toString(artifact.getArtifactID()));
166 this.setIconBaseWithExtension(iconPath);
204 "BlackboardArtifactNode.getAction.errorTitle=Error getting actions",
205 "BlackboardArtifactNode.getAction.resultErrorMessage=There was a problem getting actions for the selected result."
206 +
" The 'View Result in Timeline' action will not be available.",
207 "BlackboardArtifactNode.getAction.linkedFileMessage=There was a problem getting actions for the selected result. "
208 +
" The 'View File in Timeline' action will not be available."})
210 List<Action> actionsList =
new ArrayList<>();
211 actionsList.addAll(Arrays.asList(super.getActions(context)));
218 }
catch (TskCoreException ex) {
219 LOGGER.log(Level.SEVERE, MessageFormat.format(
"Error getting arttribute(s) from blackboard artifact{0}.", artifact.getArtifactID()), ex);
220 MessageNotifyUtil.
Notify.
error(Bundle.BlackboardArtifactNode_getAction_errorTitle(), Bundle.BlackboardArtifactNode_getAction_resultErrorMessage());
225 AbstractFile c = findLinked(artifact);
229 }
catch (TskCoreException ex) {
230 LOGGER.log(Level.SEVERE, MessageFormat.format(
"Error getting linked file from blackboard artifact{0}.", artifact.getArtifactID()), ex);
231 MessageNotifyUtil.
Notify.
error(Bundle.BlackboardArtifactNode_getAction_errorTitle(), Bundle.BlackboardArtifactNode_getAction_linkedFileMessage());
235 AbstractFile file = getLookup().lookup(AbstractFile.class);
240 return actionsList.toArray(
new Action[actionsList.size()]);
243 @NbBundle.Messages({
"# {0} - artifactDisplayName",
"BlackboardArtifactNode.displayName.artifact={0} Artifact"})
250 String displayName =
"";
256 && (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()
257 || artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID())) {
259 for (BlackboardAttribute attribute : artifact.getAttributes()) {
260 if (attribute.getAttributeType().getTypeID() == ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT.getTypeID()) {
262 if (associatedArtifact != null) {
263 if (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID()) {
264 artifact.getDisplayName();
266 displayName = NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.displayName.artifact", associatedArtifact.getDisplayName());
271 }
catch (TskCoreException ex) {
276 if (displayName.isEmpty() && artifact != null) {
277 displayName = artifact.getName();
292 if (associated != null) {
293 srcName = associated.getName();
299 "BlackboardArtifactNode.createSheet.artifactType.displayName=Artifact Type",
300 "BlackboardArtifactNode.createSheet.artifactType.name=Artifact Type",
301 "BlackboardArtifactNode.createSheet.artifactDetails.displayName=Artifact Details",
302 "BlackboardArtifactNode.createSheet.artifactDetails.name=Artifact Details",
303 "BlackboardArtifactNode.artifact.displayName=Artifact"})
307 Sheet s = super.createSheet();
308 Sheet.Set ss = s.get(Sheet.PROPERTIES);
310 ss = Sheet.createPropertiesSet();
313 final String NO_DESCR = NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.noDesc.text");
315 Map<String, Object> map =
new LinkedHashMap<>();
319 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.srcFile.displayName"),
322 if (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID()) {
324 BlackboardAttribute attribute = artifact.getAttribute(
new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
325 if (attribute != null) {
328 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.artifactType.displayName"),
330 associatedArtifact.getDisplayName() +
" " + NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.artifact.displayName")));
332 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.artifactDetails.displayName"),
334 associatedArtifact.getShortDescription()));
336 }
catch (TskCoreException ex) {
341 for (Map.Entry<String, Object> entry : map.entrySet()) {
349 if (customProperties != null) {
355 final int artifactTypeId = artifact.getArtifactTypeID();
358 if (artifactTypeId == BlackboardArtifact.ARTIFACT_TYPE.TSK_EXT_MISMATCH_DETECTED.getTypeID()) {
360 String actualMimeType =
"";
361 if (associated instanceof AbstractFile) {
362 AbstractFile af = (AbstractFile) associated;
363 ext = af.getNameExtension();
364 actualMimeType = af.getMIMEType();
365 if (actualMimeType == null) {
375 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.mimeType.displayName"),
380 if (Arrays.asList(SHOW_UNIQUE_PATH).contains(artifactTypeId)) {
381 String sourcePath =
"";
383 sourcePath = associated.getUniquePath();
384 }
catch (TskCoreException ex) {
385 LOGGER.log(Level.WARNING,
"Failed to get unique path from: {0}", associated.getName());
388 if (sourcePath.isEmpty() ==
false) {
391 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.filePath.displayName"),
396 if (Arrays.asList(SHOW_FILE_METADATA).contains(artifactTypeId)) {
397 AbstractFile file = associated instanceof AbstractFile ? (AbstractFile) associated : null;
399 NbBundle.getMessage(
BlackboardArtifactNode.class,
"ContentTagNode.createSheet.fileModifiedTime.displayName"),
403 NbBundle.getMessage(
BlackboardArtifactNode.class,
"ContentTagNode.createSheet.fileChangedTime.displayName"),
407 NbBundle.getMessage(
BlackboardArtifactNode.class,
"ContentTagNode.createSheet.fileAccessedTime.displayName"),
411 NbBundle.getMessage(
BlackboardArtifactNode.class,
"ContentTagNode.createSheet.fileCreatedTime.displayName"),
417 associated.getSize()));
420 String dataSourceStr =
"";
422 Content dataSource = associated.getDataSource();
423 if (dataSource != null) {
424 dataSourceStr = dataSource.getName();
428 }
catch (TskCoreException ex) {
429 LOGGER.log(Level.WARNING,
"Failed to get image name from {0}", associated.getName());
432 if (dataSourceStr.isEmpty() ==
false) {
435 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.dataSrc.displayName"),
442 List<Tag> tags =
new ArrayList<>();
446 }
catch (TskCoreException ex) {
447 LOGGER.log(Level.SEVERE,
"Failed to get tags for artifact " + artifact.getDisplayName(), ex);
450 NO_DESCR, tags.stream().map(t -> t.getName().getDisplayName()).collect(Collectors.joining(
", "))));
460 String parentName = associated.getName();
463 while ((parent = parent.getParent()) != null) {
464 parentName = parent.getName();
466 }
catch (TskCoreException ex) {
467 LOGGER.log(Level.WARNING,
"Failed to get parent name from {0}", associated.getName());
480 if (null == customProperties) {
482 customProperties =
new ArrayList<>();
484 customProperties.add(np);
494 @SuppressWarnings(
"deprecation")
497 for (BlackboardAttribute attribute : artifact.getAttributes()) {
498 final int attributeTypeID = attribute.getAttributeType().getTypeID();
500 if (attributeTypeID == ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()
501 || attributeTypeID == ATTRIBUTE_TYPE.TSK_TAGGED_ARTIFACT.getTypeID()
502 || attributeTypeID == ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT.getTypeID()
503 || attributeTypeID == ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID()
504 || attributeTypeID == ATTRIBUTE_TYPE.TSK_KEYWORD_SEARCH_TYPE.getTypeID()) {
505 }
else if (artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()) {
507 }
else if (attribute.getAttributeType().getValueType() == BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME) {
509 }
else if (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getTypeID()
510 && attributeTypeID == ATTRIBUTE_TYPE.TSK_TEXT.getTypeID()) {
518 String value = attribute.getDisplayString();
519 if (value.length() > 512) {
520 value = value.substring(0, 512);
522 map.put(attribute.getAttributeType().getDisplayName(), value);
524 map.put(attribute.getAttributeType().getDisplayName(), attribute.getDisplayString());
527 }
catch (TskCoreException ex) {
528 LOGGER.log(Level.SEVERE,
"Getting attributes failed", ex);
541 final int attributeTypeID = attribute.getAttributeType().getTypeID();
544 if (attributeTypeID == ATTRIBUTE_TYPE.TSK_DATETIME_SENT.getTypeID()
545 || attributeTypeID == ATTRIBUTE_TYPE.TSK_EMAIL_CONTENT_HTML.getTypeID()
546 || attributeTypeID == ATTRIBUTE_TYPE.TSK_EMAIL_CONTENT_RTF.getTypeID()
547 || attributeTypeID == ATTRIBUTE_TYPE.TSK_EMAIL_BCC.getTypeID()
548 || attributeTypeID == ATTRIBUTE_TYPE.TSK_EMAIL_CC.getTypeID()
549 || attributeTypeID == ATTRIBUTE_TYPE.TSK_HEADERS.getTypeID()) {
552 }
else if (attributeTypeID == ATTRIBUTE_TYPE.TSK_EMAIL_CONTENT_PLAIN.getTypeID()) {
554 String value = attribute.getDisplayString();
555 if (value.length() > 160) {
556 value = value.substring(0, 160) +
"...";
558 map.put(attribute.getAttributeType().getDisplayName(), value);
559 }
else if (attribute.getAttributeType().getValueType() == BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME) {
562 map.put(attribute.getAttributeType().getDisplayName(), attribute.getDisplayString());
569 return v.
visit(
this);
582 final long objectID = artifact.getObjectID();
584 Content content = contentCache.get(objectID, () -> artifact.getSleuthkitCase().getContentById(objectID));
585 if (content == null) {
586 return Lookups.fixed(artifact);
588 return Lookups.fixed(artifact, content);
590 }
catch (ExecutionException ex) {
591 LOGGER.log(Level.WARNING,
"Getting associated content for artifact failed", ex);
592 return Lookups.fixed(artifact);
603 return getClass().getName();
607 public <T> T accept(ContentNodeVisitor<T> v) {
608 return v.visit(
this);
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 Integer[] SHOW_FILE_METADATA
T visit(DataSourcesNode in)
Action[] getActions(boolean context)
static ViewFileInTimelineAction createViewSourceFileAction(AbstractFile file)
static final Set< Case.Events > CASE_EVENTS_OF_INTEREST
TagsManager getTagsManager()
List< NodeProperty<?extends Object > > customProperties
static final Logger LOGGER
String getRootParentName()
final BlackboardArtifact artifact
void addEmailMsgProperty(Map< String, Object > map, BlackboardAttribute attribute)
SleuthkitCase getSleuthkitCase()
BLACKBOARD_ARTIFACT_TAG_ADDED
static void error(String title, String message)
BlackboardArtifact getArtifact()
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
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