19package org.sleuthkit.autopsy.contentviewers.contextviewer;
21import java.awt.Component;
22import java.awt.Insets;
23import java.util.ArrayList;
24import java.util.Collections;
25import java.util.Comparator;
26import java.util.HashMap;
29import java.util.logging.Level;
30import javax.swing.BoxLayout;
31import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
32import javax.swing.border.EmptyBorder;
33import org.apache.commons.lang.StringUtils;
34import org.openide.nodes.Node;
35import org.openide.util.NbBundle;
36import org.openide.util.lookup.ServiceProvider;
37import org.sleuthkit.autopsy.casemodule.Case;
38import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
39import org.sleuthkit.autopsy.contentviewers.layout.ContentViewerDefaults;
40import org.sleuthkit.autopsy.contentviewers.utils.ViewerPriority;
41import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer;
42import org.sleuthkit.autopsy.coreutils.Logger;
43import org.sleuthkit.datamodel.AbstractFile;
44import org.sleuthkit.datamodel.BlackboardArtifact;
45import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT;
46import org.sleuthkit.datamodel.BlackboardAttribute;
47import org.sleuthkit.datamodel.SleuthkitCase;
48import org.sleuthkit.datamodel.TskCoreException;
68 private static final List<BlackboardArtifact.ARTIFACT_TYPE>
CONTEXT_ARTIFACTS =
new ArrayList<>();
82 jScrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_AS_NEEDED);
90 @SuppressWarnings(
"unchecked")
95 javax.swing.JLabel jSourceLabel =
new javax.swing.JLabel();
97 javax.swing.JLabel jUsageLabel =
new javax.swing.JLabel();
99 javax.swing.JLabel jUnknownLabel =
new javax.swing.JLabel();
106 org.openide.awt.Mnemonics.setLocalizedText(jSourceLabel, org.openide.util.NbBundle.getMessage(
ContextViewer.class,
"ContextViewer.jSourceLabel.text"));
114 org.openide.awt.Mnemonics.setLocalizedText(jUsageLabel, org.openide.util.NbBundle.getMessage(
ContextViewer.class,
"ContextViewer.jUsageLabel.text"));
119 org.openide.awt.Mnemonics.setLocalizedText(jUnknownLabel, org.openide.util.NbBundle.getMessage(
ContextViewer.class,
"ContextViewer.jUnknownLabel.text"));
123 setPreferredSize(
new java.awt.Dimension(0, 0));
125 jScrollPane.setPreferredSize(
new java.awt.Dimension(16, 16));
127 javax.swing.GroupLayout
layout =
new javax.swing.GroupLayout(
this);
129 layout.setHorizontalGroup(
130 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
131 .addComponent(
jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 509, Short.MAX_VALUE)
134 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
135 .addComponent(
jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
141 if ((selectedNode ==
null) || (!
isSupported(selectedNode))) {
146 AbstractFile file = selectedNode.getLookup().lookup(AbstractFile.class);
150 logger.log(Level.SEVERE, String.format(
"Exception displaying context for file %s", file.getName()), ex);
155 "ContextViewer.title=Context",
156 "ContextViewer.toolTip=Displays context for selected file."
161 return Bundle.ContextViewer_title();
166 return Bundle.ContextViewer_toolTip();
189 if (node.getLookup().lookup(AbstractFile.class) !=
null) {
190 AbstractFile abstractFile = node.getLookup().lookup(AbstractFile.class);
192 List<BlackboardArtifact> artifactsList;
194 artifactsList = abstractFile.getArtifacts(artifactType);
195 if (!artifactsList.isEmpty()) {
198 }
catch (TskCoreException ex) {
199 logger.log(Level.SEVERE, String.format(
"Exception while looking up context artifacts for file %s", abstractFile), ex);
215 "ContextViewer.unknownSource=Unknown ",
231 boolean foundASource =
false;
233 List<BlackboardArtifact> artifactsList = tskCase.getBlackboardArtifacts(artifactType, sourceFile.getId());
235 foundASource = !artifactsList.isEmpty();
236 for (BlackboardArtifact contextArtifact : artifactsList) {
240 javax.swing.JPanel contextContainer =
new javax.swing.JPanel();
241 contextContainer.setLayout(
new BoxLayout(contextContainer, BoxLayout.Y_AXIS));
250 contextContainer.add(sourcePanel);
251 contextContainer.setAlignmentX(0);
259 contextContainer.add(usagePanel);
260 contextContainer.setAlignmentX(0);
265 contextContainer.setEnabled(foundASource);
266 contextContainer.setVisible(foundASource);
267 jScrollPane.getViewport().setView(contextContainer);
286 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getTypeID() == artifact.getArtifactTypeID()) {
287 BlackboardAttribute associatedArtifactAttribute = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
288 if (associatedArtifactAttribute !=
null) {
289 long artifactId = associatedArtifactAttribute.getValueLong();
290 BlackboardArtifact associatedArtifact = artifact.getSleuthkitCase().getBlackboardArtifact(artifactId);
305 "ContextViewer.attachmentSource=Attached to: ",
306 "ContextViewer.downloadSource=Downloaded from: ",
307 "ContextViewer.recentDocs=Recent Documents: ",
308 "ContextViewer.programExecution=Program Execution: "
312 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() == associatedArtifact.getArtifactTypeID()
313 || BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID() == associatedArtifact.getArtifactTypeID()) {
314 String sourceName = Bundle.ContextViewer_attachmentSource();
318 sourcePanel.setAlignmentX(0);
321 }
else if (BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() == associatedArtifact.getArtifactTypeID()
322 || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID() == associatedArtifact.getArtifactTypeID()) {
323 String sourceName = Bundle.ContextViewer_downloadSource();
327 sourcePanel.setAlignmentX(0);
330 }
else if (BlackboardArtifact.ARTIFACT_TYPE.TSK_RECENT_OBJECT.getTypeID() == associatedArtifact.getArtifactTypeID()) {
331 String sourceName = Bundle.ContextViewer_recentDocs();
335 usagePanel.setAlignmentX(0);
338 }
else if (BlackboardArtifact.ARTIFACT_TYPE.TSK_PROG_RUN.getTypeID() == associatedArtifact.getArtifactTypeID()) {
339 String sourceName = Bundle.ContextViewer_programExecution();
343 usagePanel.setAlignmentX(0);
362 "ContextViewer.downloadURL=URL",
363 "ContextViewer.downloadedOn=On"
367 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributesMap =
getAttributesMap(artifact);
369 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() == artifact.getArtifactTypeID()
370 || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID() == artifact.getArtifactTypeID()) {
371 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, attributesMap, Bundle.ContextViewer_downloadURL());
372 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, attributesMap, Bundle.ContextViewer_downloadedOn());
374 return sb.toString();
388 "ContextViewer.on=Opened at",
389 "ContextViewer.unknown=Opened at unknown time"
393 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributesMap =
getAttributesMap(artifact);
395 BlackboardAttribute attribute = attributesMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME);
397 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_RECENT_OBJECT.getTypeID() == artifact.getArtifactTypeID()) {
398 if (attribute !=
null && attribute.getValueLong() > 0) {
399 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, attributesMap, Bundle.ContextViewer_on());
401 sb.append(Bundle.ContextViewer_unknown());
404 return sb.toString();
418 "ContextViewer.runOn=Program Run On",
419 "ContextViewer.runUnknown= Program Run at unknown time"
423 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributesMap =
getAttributesMap(artifact);
425 BlackboardAttribute attribute = attributesMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME);
427 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_PROG_RUN.getTypeID() == artifact.getArtifactTypeID()) {
428 if (attribute !=
null && attribute.getValueLong() > 0) {
429 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, attributesMap, Bundle.ContextViewer_runOn());
431 sb.append(Bundle.ContextViewer_runUnknown());
434 return sb.toString();
447 "ContextViewer.message=Message",
448 "ContextViewer.email=Email",
449 "ContextViewer.messageFrom=From",
450 "ContextViewer.messageTo=To",
451 "ContextViewer.messageOn=On",})
455 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributesMap =
getAttributesMap(artifact);
457 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() == artifact.getArtifactTypeID()) {
458 sb.append(Bundle.ContextViewer_message()).append(
' ');
459 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, attributesMap, Bundle.ContextViewer_messageFrom());
460 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO, attributesMap, Bundle.ContextViewer_messageTo());
461 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, attributesMap, Bundle.ContextViewer_messageOn());
462 }
else if (BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID() == artifact.getArtifactTypeID()) {
463 sb.append(Bundle.ContextViewer_email()).append(
' ');
464 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_FROM, attributesMap, Bundle.ContextViewer_messageFrom());
465 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_TO, attributesMap, Bundle.ContextViewer_messageTo());
466 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT, attributesMap, Bundle.ContextViewer_messageOn());
468 return sb.toString();
482 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributesMap, String prependStr) {
484 BlackboardAttribute attribute = attributesMap.get(attribType);
485 if (attribute !=
null) {
486 String attrVal = attribute.getDisplayString();
487 if (!StringUtils.isEmpty(attrVal)) {
488 if (!StringUtils.isEmpty(prependStr)) {
489 sb.append(prependStr).append(
' ');
506 private Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute>
getAttributesMap(BlackboardArtifact artifact)
throws TskCoreException {
507 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributeMap =
new HashMap<>();
509 List<BlackboardAttribute> attributeList = artifact.getAttributes();
510 for (BlackboardAttribute attribute : attributeList) {
511 BlackboardAttribute.ATTRIBUTE_TYPE type = BlackboardAttribute.ATTRIBUTE_TYPE.fromID(attribute.getAttributeType().getTypeID());
512 attributeMap.put(type, attribute);
537 BlackboardAttribute attribute = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME));
539 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID() == artifact.getArtifactTypeID()) {
540 attribute = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT));
541 }
else if (BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() == artifact.getArtifactTypeID()
542 || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID() == artifact.getArtifactTypeID()) {
543 attribute = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED));
545 return (attribute !=
null ? attribute.getValueLong() :
null);
551 class SortByDateTime
implements Comparator<DateTimePanel> {
558 if(dateTime1 ==
null && dateTime2 ==
null) {
560 }
else if(dateTime1 ==
null) {
562 }
else if(dateTime2 ==
null) {
566 return dateTime1.compareTo(dateTime2);
SleuthkitCase getSleuthkitCase()
static Case getCurrentCaseThrows()
static final Logger logger
javax.swing.JPanel jUnknownPanel
final List< ContextSourcePanel > contextSourcePanels
static final int ATTRIBUTE_STR_MAX_LEN
String programExecArtifactToString(BlackboardArtifact artifact)
static final Insets FIRST_HEADER_INSETS
String msgArtifactToAbbreviatedString(BlackboardArtifact artifact)
static final int ARTIFACT_STR_MAX_LEN
static final long serialVersionUID
DataContentViewer createInstance()
javax.swing.JScrollPane jScrollPane
void populatePanels(AbstractFile sourceFile)
String recentDocArtifactToString(BlackboardArtifact artifact)
javax.swing.JPanel jSourcePanel
void appendAttributeString(StringBuilder sb, BlackboardAttribute.ATTRIBUTE_TYPE attribType, Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute > attributesMap, String prependStr)
String webDownloadArtifactToString(BlackboardArtifact artifact)
void addAssociatedArtifactToPanel(BlackboardArtifact artifact)
int isPreferred(Node node)
Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute > getAttributesMap(BlackboardArtifact artifact)
javax.swing.JPanel jUsagePanel
void addArtifactToPanels(BlackboardArtifact associatedArtifact)
static final Insets DATA_ROW_INSETS
void setNode(Node selectedNode)
Long getArtifactDateTime(BlackboardArtifact artifact)
boolean isSupported(Node node)
final List< ContextUsagePanel > contextUsagePanels
static final List< BlackboardArtifact.ARTIFACT_TYPE > CONTEXT_ARTIFACTS
static final Insets HEADER_INSETS
static Insets getPanelInsets()
static Font getHeaderFont()
static Color getPanelBackground()
static Integer getSectionIndent()
static Integer getSectionSpacing()
static Integer getLineSpacing()
synchronized static Logger getLogger(String name)