19 package org.sleuthkit.autopsy.datamodel;
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.text.MessageFormat;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.LinkedHashMap;
27 import java.util.List;
29 import java.util.logging.Level;
30 import java.util.stream.Collectors;
31 import javax.swing.Action;
32 import org.apache.commons.lang3.StringUtils;
33 import org.openide.nodes.Children;
34 import org.openide.nodes.Sheet;
35 import org.openide.util.Lookup;
36 import org.openide.util.NbBundle;
37 import org.openide.util.lookup.Lookups;
49 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
51 import org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
71 BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID(),
72 BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID(),
73 BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT.getTypeID(),};
79 BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT.getTypeID(),};
81 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
83 public void propertyChange(PropertyChangeEvent evt) {
84 String eventType = evt.getPropertyName();
87 if (event.getAddedTag().getArtifact().equals(artifact)) {
92 if (event.getDeletedTagInfo().getArtifactID() == artifact.getArtifactID()) {
97 if (event.getAddedTag().getContent().equals(associated)) {
102 if (event.getDeletedTagInfo().getContentID()== associated.getId()) {
106 if (evt.getNewValue() == null) {
126 this.associated = this.getLookup().lookup(Content.class);
127 this.setName(Long.toString(artifact.getArtifactID()));
129 this.setIconBaseWithExtension(iconPath);
144 this.associated = this.getLookup().lookup(Content.class);
145 this.setName(Long.toString(artifact.getArtifactID()));
147 this.setIconBaseWithExtension(
ExtractedContent.getIconFilePath(artifact.getArtifactTypeID()));
157 "BlackboardArtifactNode.getAction.errorTitle=Error getting actions",
158 "BlackboardArtifactNode.getAction.resultErrorMessage=There was a problem getting actions for the selected result."
159 +
" The 'View Result in Timeline' action will not be available.",
160 "BlackboardArtifactNode.getAction.linkedFileMessage=There was a problem getting actions for the selected result. "
161 +
" The 'View File in Timeline' action will not be available."})
163 List<Action> actionsList =
new ArrayList<>();
164 actionsList.addAll(Arrays.asList(super.getActions(context)));
171 }
catch (TskCoreException ex) {
172 LOGGER.log(Level.SEVERE, MessageFormat.format(
"Error getting arttribute(s) from blackboard artifact{0}.", artifact.getArtifactID()), ex);
173 MessageNotifyUtil.
Notify.
error(Bundle.BlackboardArtifactNode_getAction_errorTitle(), Bundle.BlackboardArtifactNode_getAction_resultErrorMessage());
178 AbstractFile c = findLinked(artifact);
182 }
catch (TskCoreException ex) {
183 LOGGER.log(Level.SEVERE, MessageFormat.format(
"Error getting linked file from blackboard artifact{0}.", artifact.getArtifactID()), ex);
184 MessageNotifyUtil.
Notify.
error(Bundle.BlackboardArtifactNode_getAction_errorTitle(), Bundle.BlackboardArtifactNode_getAction_linkedFileMessage());
188 AbstractFile file = getLookup().lookup(AbstractFile.class);
193 return actionsList.toArray(
new Action[actionsList.size()]);
202 String displayName =
"";
203 if (associated != null) {
204 displayName = associated.getName();
210 if (artifact != null && artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
212 for (BlackboardAttribute attribute : artifact.getAttributes()) {
213 if (attribute.getAttributeType().getTypeID() == ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT.getTypeID()) {
215 if (associatedArtifact != null) {
216 displayName = associatedArtifact.getDisplayName() +
" Artifact";
220 }
catch (TskCoreException ex) {
229 Sheet s = super.createSheet();
230 Sheet.Set ss = s.get(Sheet.PROPERTIES);
232 ss = Sheet.createPropertiesSet();
235 final String NO_DESCR = NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.noDesc.text");
237 Map<String, Object> map =
new LinkedHashMap<>();
241 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.srcFile.displayName"),
243 this.getDisplayName()));
245 for (Map.Entry<String, Object> entry : map.entrySet()) {
253 if (customProperties != null) {
259 final int artifactTypeId = artifact.getArtifactTypeID();
262 if (artifactTypeId == BlackboardArtifact.ARTIFACT_TYPE.TSK_EXT_MISMATCH_DETECTED.getTypeID()) {
264 String actualMimeType =
"";
265 if (associated instanceof AbstractFile) {
266 AbstractFile af = (AbstractFile) associated;
267 ext = af.getNameExtension();
268 actualMimeType = af.getMIMEType();
269 if (actualMimeType == null) {
279 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.mimeType.displayName"),
284 if (Arrays.asList(SHOW_UNIQUE_PATH).contains(artifactTypeId)) {
285 String sourcePath =
"";
287 sourcePath = associated.getUniquePath();
288 }
catch (TskCoreException ex) {
289 LOGGER.log(Level.WARNING,
"Failed to get unique path from: {0}", associated.getName());
292 if (sourcePath.isEmpty() ==
false) {
295 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.filePath.displayName"),
300 if (Arrays.asList(SHOW_FILE_METADATA).contains(artifactTypeId)) {
301 AbstractFile file = associated instanceof AbstractFile ? (AbstractFile) associated : null;
303 NbBundle.getMessage(
BlackboardArtifactNode.class,
"ContentTagNode.createSheet.fileModifiedTime.displayName"),
307 NbBundle.getMessage(
BlackboardArtifactNode.class,
"ContentTagNode.createSheet.fileChangedTime.displayName"),
311 NbBundle.getMessage(
BlackboardArtifactNode.class,
"ContentTagNode.createSheet.fileAccessedTime.displayName"),
315 NbBundle.getMessage(
BlackboardArtifactNode.class,
"ContentTagNode.createSheet.fileCreatedTime.displayName"),
321 associated.getSize()));
324 String dataSourceStr =
"";
326 Content dataSource = associated.getDataSource();
327 if (dataSource != null) {
328 dataSourceStr = dataSource.getName();
332 }
catch (TskCoreException ex) {
333 LOGGER.log(Level.WARNING,
"Failed to get image name from {0}", associated.getName());
336 if (dataSourceStr.isEmpty() ==
false) {
339 NbBundle.getMessage(
BlackboardArtifactNode.class,
"BlackboardArtifactNode.createSheet.dataSrc.displayName"),
346 List<Tag> tags =
new ArrayList<>();
350 }
catch (TskCoreException ex) {
351 LOGGER.log(Level.SEVERE,
"Failed to get tags for artifact " + artifact.getDisplayName(), ex);
354 NO_DESCR, tags.stream().map(t -> t.getName().getDisplayName()).collect(Collectors.joining(
", "))));
364 String parentName = associated.getName();
367 while ((parent = parent.getParent()) != null) {
368 parentName = parent.getName();
370 }
catch (TskCoreException ex) {
371 LOGGER.log(Level.WARNING,
"Failed to get parent name from {0}", associated.getName());
384 if (null == customProperties) {
386 customProperties =
new ArrayList<>();
388 customProperties.add(np);
398 @SuppressWarnings(
"deprecation")
401 for (BlackboardAttribute attribute : artifact.getAttributes()) {
402 final int attributeTypeID = attribute.getAttributeType().getTypeID();
404 if (attributeTypeID == ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()
405 || attributeTypeID == ATTRIBUTE_TYPE.TSK_TAGGED_ARTIFACT.getTypeID()
406 || attributeTypeID == ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT.getTypeID()
407 || attributeTypeID == ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID()) {
408 }
else if (attribute.getAttributeType().getValueType() == BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME) {
410 }
else if (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getTypeID()
411 && attributeTypeID == ATTRIBUTE_TYPE.TSK_TEXT.getTypeID()) {
419 String value = attribute.getDisplayString();
420 if (value.length() > 512) {
421 value = value.substring(0, 512);
423 map.put(attribute.getAttributeType().getDisplayName(), value);
425 map.put(attribute.getAttributeType().getDisplayName(), attribute.getDisplayString());
428 }
catch (TskCoreException ex) {
429 LOGGER.log(Level.SEVERE,
"Getting attributes failed", ex);
435 return v.
visit(
this);
446 List<Object> forLookup =
new ArrayList<>();
447 forLookup.add(artifact);
451 if (content != null) {
452 forLookup.add(content);
458 if (highlight != null) {
459 forLookup.add(highlight);
462 return Lookups.fixed(forLookup.toArray(
new Object[forLookup.size()]));
467 return artifact.getSleuthkitCase().getContentById(artifact.getObjectID());
468 }
catch (TskCoreException ex) {
469 LOGGER.log(Level.WARNING,
"Getting file failed", ex);
471 throw new IllegalArgumentException(
476 if (artifact.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
480 long objectId = content.getId();
482 Lookup lookup = Lookup.getDefault();
485 List<BlackboardAttribute> attributes = artifact.getAttributes();
486 String keyword = null;
487 String regexp = null;
488 for (BlackboardAttribute att : attributes) {
489 final int attributeTypeID = att.getAttributeType().getTypeID();
490 if (attributeTypeID == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD.getTypeID()) {
491 keyword = att.getValueString();
492 }
else if (attributeTypeID == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_REGEXP.getTypeID()) {
493 regexp = att.getValueString();
494 }
else if (attributeTypeID == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT.getTypeID()) {
495 objectId = att.getValueLong();
498 if (keyword != null) {
499 boolean isRegexp = StringUtils.isNotBlank(regexp);
500 String origQuery = isRegexp ? regexp : keyword;
501 return highlightFactory.
createInstance(objectId, keyword, isRegexp, origQuery);
503 }
catch (TskCoreException ex) {
504 LOGGER.log(Level.WARNING,
"Failed to retrieve Blackboard Attributes", ex);
516 return getClass().getName();
void fillPropertyMap(Map< String, Object > map, BlackboardArtifact artifact)
static String getStringTime(long epochSeconds, TimeZone tzone)
static boolean hasSupportedTimeStamp(BlackboardArtifact artifact)
final PropertyChangeListener pcl
static void removePropertyChangeListener(PropertyChangeListener listener)
BlackboardArtifactNode(BlackboardArtifact artifact, String iconPath)
static Lookup createLookup(BlackboardArtifact artifact)
static final Integer[] SHOW_FILE_METADATA
TextMarkupLookup createInstance(long objectId, String keyword, boolean isRegex, String originalQuery)
T visit(DataSourcesNode in)
Action[] getActions(boolean context)
static Content getAssociatedContent(BlackboardArtifact artifact)
static ViewFileInTimelineAction createViewSourceFileAction(AbstractFile file)
TagsManager getTagsManager()
List< NodeProperty<?extends Object > > customProperties
static final Logger LOGGER
String getRootParentName()
final BlackboardArtifact artifact
SleuthkitCase getSleuthkitCase()
static void addPropertyChangeListener(PropertyChangeListener listener)
static TextMarkupLookup getHighlightLookup(BlackboardArtifact artifact, Content content)
BLACKBOARD_ARTIFACT_TAG_ADDED
static void error(String title, String message)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
void addNodeProperty(NodeProperty<?> np)
BlackboardArtifactNode(BlackboardArtifact artifact)
static final Integer[] SHOW_UNIQUE_PATH
static ViewFileInTimelineAction createViewFileAction(AbstractFile file)
BLACKBOARD_ARTIFACT_TAG_DELETED