19 package org.sleuthkit.autopsy.contentviewers.contextviewer;
21 import java.awt.Component;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.BoxLayout;
28 import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
29 import org.apache.commons.lang.StringUtils;
30 import org.openide.nodes.Node;
31 import org.openide.util.NbBundle;
32 import org.openide.util.lookup.ServiceProvider;
39 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT;
49 @ServiceProvider(service = DataContentViewer.class, position = 7)
52 private static final long serialVersionUID = 1L;
54 private static final int ARTIFACT_STR_MAX_LEN = 1024;
55 private static final int ATTRIBUTE_STR_MAX_LEN = 200;
58 private static final List<BlackboardArtifact.ARTIFACT_TYPE> SOURCE_CONTEXT_ARTIFACTS =
new ArrayList<>();
59 private final List<javax.swing.JPanel> contextSourcePanels =
new ArrayList<>();
60 private final List<javax.swing.JPanel> contextUsagePanels =
new ArrayList<>();
63 SOURCE_CONTEXT_ARTIFACTS.add(TSK_ASSOCIATED_OBJECT);
72 jScrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_AS_NEEDED);
80 @SuppressWarnings(
"unchecked")
82 private
void initComponents() {
84 jSourcePanel =
new javax.swing.JPanel();
85 javax.swing.JLabel jSourceLabel =
new javax.swing.JLabel();
86 jUsagePanel =
new javax.swing.JPanel();
87 javax.swing.JLabel jUsageLabel =
new javax.swing.JLabel();
88 jUnknownPanel =
new javax.swing.JPanel();
89 javax.swing.JLabel jUnknownLabel =
new javax.swing.JLabel();
90 jScrollPane =
new javax.swing.JScrollPane();
92 jSourcePanel.setBackground(javax.swing.UIManager.getDefaults().getColor(
"window"));
94 jSourceLabel.setFont(jSourceLabel.getFont().deriveFont(jSourceLabel.getFont().getStyle() | java.awt.Font.BOLD, jSourceLabel.getFont().getSize()+1));
95 org.openide.awt.Mnemonics.setLocalizedText(jSourceLabel,
org.openide.util.NbBundle.getMessage(
ContextViewer.class,
"ContextViewer.jSourceLabel.text"));
97 javax.swing.GroupLayout jSourcePanelLayout =
new javax.swing.GroupLayout(jSourcePanel);
98 jSourcePanel.setLayout(jSourcePanelLayout);
99 jSourcePanelLayout.setHorizontalGroup(
100 jSourcePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
101 .addGroup(jSourcePanelLayout.createSequentialGroup()
103 .addComponent(jSourceLabel)
104 .addContainerGap(304, Short.MAX_VALUE))
106 jSourcePanelLayout.setVerticalGroup(
107 jSourcePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
108 .addGroup(jSourcePanelLayout.createSequentialGroup()
110 .addComponent(jSourceLabel)
114 jUsagePanel.setBackground(javax.swing.UIManager.getDefaults().getColor(
"window"));
116 jUsageLabel.setFont(jUsageLabel.getFont().deriveFont(jUsageLabel.getFont().getStyle() | java.awt.Font.BOLD, jUsageLabel.getFont().getSize()+1));
117 org.openide.awt.Mnemonics.setLocalizedText(jUsageLabel,
org.openide.util.NbBundle.getMessage(
ContextViewer.class,
"ContextViewer.jUsageLabel.text"));
119 javax.swing.GroupLayout jUsagePanelLayout =
new javax.swing.GroupLayout(jUsagePanel);
120 jUsagePanel.setLayout(jUsagePanelLayout);
121 jUsagePanelLayout.setHorizontalGroup(
122 jUsagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
123 .addGroup(jUsagePanelLayout.createSequentialGroup()
125 .addComponent(jUsageLabel)
126 .addContainerGap(298, Short.MAX_VALUE))
128 jUsagePanelLayout.setVerticalGroup(
129 jUsagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
130 .addGroup(jUsagePanelLayout.createSequentialGroup()
132 .addComponent(jUsageLabel)
136 jUnknownPanel.setBackground(
new java.awt.Color(255, 255, 255));
138 org.openide.awt.Mnemonics.setLocalizedText(jUnknownLabel,
org.openide.util.NbBundle.getMessage(
ContextViewer.class,
"ContextViewer.jUnknownLabel.text"));
140 javax.swing.GroupLayout jUnknownPanelLayout =
new javax.swing.GroupLayout(jUnknownPanel);
141 jUnknownPanel.setLayout(jUnknownPanelLayout);
142 jUnknownPanelLayout.setHorizontalGroup(
143 jUnknownPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144 .addGroup(jUnknownPanelLayout.createSequentialGroup()
146 .addComponent(jUnknownLabel)
147 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
149 jUnknownPanelLayout.setVerticalGroup(
150 jUnknownPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
151 .addGroup(jUnknownPanelLayout.createSequentialGroup()
153 .addComponent(jUnknownLabel)
157 setBackground(
new java.awt.Color(255, 255, 255));
158 setPreferredSize(
new java.awt.Dimension(495, 358));
160 jScrollPane.setBackground(
new java.awt.Color(255, 255, 255));
162 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
163 this.setLayout(layout);
164 layout.setHorizontalGroup(
165 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166 .addComponent(jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 509, Short.MAX_VALUE)
168 layout.setVerticalGroup(
169 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
170 .addComponent(jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
176 if ((selectedNode == null) || (!isSupported(selectedNode))) {
181 AbstractFile file = selectedNode.getLookup().lookup(AbstractFile.class);
183 populateSourceContextData(file);
185 logger.log(Level.SEVERE, String.format(
"Exception displaying context for file %s", file.getName()), ex);
190 "ContextViewer.title=Context",
191 "ContextViewer.toolTip=Displays context for selected file."
196 return Bundle.ContextViewer_title();
201 return Bundle.ContextViewer_toolTip();
216 contextSourcePanels.clear();
217 contextUsagePanels.clear();
224 if (node.getLookup().lookup(AbstractFile.class) != null) {
225 AbstractFile abstractFile = node.getLookup().lookup(AbstractFile.class);
226 for (BlackboardArtifact.ARTIFACT_TYPE artifactType : SOURCE_CONTEXT_ARTIFACTS) {
227 List<BlackboardArtifact> artifactsList;
229 artifactsList = abstractFile.getArtifacts(artifactType);
230 if (!artifactsList.isEmpty()) {
233 }
catch (TskCoreException ex) {
234 logger.log(Level.SEVERE, String.format(
"Exception while looking up context artifacts for file %s", abstractFile), ex);
250 "ContextViewer.unknownSource=Unknown ",
266 boolean foundASource =
false;
267 for (BlackboardArtifact.ARTIFACT_TYPE artifactType : SOURCE_CONTEXT_ARTIFACTS) {
268 List<BlackboardArtifact> artifactsList = tskCase.getBlackboardArtifacts(artifactType, sourceFile.getId());
270 foundASource = !artifactsList.isEmpty();
271 for (BlackboardArtifact contextArtifact : artifactsList) {
272 addSourceEntry(contextArtifact);
275 javax.swing.JPanel contextContainer =
new javax.swing.JPanel();
276 contextContainer.add(jSourcePanel);
277 contextContainer.setLayout(
new BoxLayout(contextContainer, BoxLayout.Y_AXIS));
278 if (contextSourcePanels.isEmpty()) {
279 contextContainer.add(jUnknownPanel);
281 for (javax.swing.JPanel sourcePanel : contextSourcePanels) {
282 contextContainer.add(sourcePanel);
285 contextContainer.add(jUsagePanel);
286 if (contextUsagePanels.isEmpty()) {
287 contextContainer.add(jUnknownPanel);
289 for (javax.swing.JPanel usagePanel : contextUsagePanels) {
290 contextContainer.add(usagePanel);
293 contextContainer.setEnabled(foundASource);
294 contextContainer.setVisible(foundASource);
295 jScrollPane.getViewport().setView(contextContainer);
296 jScrollPane.setEnabled(foundASource);
297 jScrollPane.setVisible(foundASource);
298 jScrollPane.repaint();
299 jScrollPane.revalidate();
313 private void addSourceEntry(BlackboardArtifact artifact)
throws TskCoreException {
315 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getTypeID() == artifact.getArtifactTypeID()) {
316 BlackboardAttribute associatedArtifactAttribute = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
317 if (associatedArtifactAttribute != null) {
318 long artifactId = associatedArtifactAttribute.getValueLong();
319 BlackboardArtifact associatedArtifact = artifact.getSleuthkitCase().getBlackboardArtifact(artifactId);
321 setSourceFields(associatedArtifact);
335 "ContextViewer.attachmentSource=Attached to: ",
336 "ContextViewer.downloadSource=Downloaded from: ",
337 "ContextViewer.recentDocs=Recent Documents: "
339 private void setSourceFields(BlackboardArtifact associatedArtifact)
throws TskCoreException {
340 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() == associatedArtifact.getArtifactTypeID()
341 || BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID() == associatedArtifact.getArtifactTypeID()) {
342 String sourceName = Bundle.ContextViewer_attachmentSource();
343 String sourceText = msgArtifactToAbbreviatedString(associatedArtifact);
344 javax.swing.JPanel sourcePanel =
new ContextSourcePanel(sourceName, sourceText, associatedArtifact);
345 contextSourcePanels.add(sourcePanel);
347 }
else if (BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() == associatedArtifact.getArtifactTypeID()
348 || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID() == associatedArtifact.getArtifactTypeID()) {
349 String sourceName = Bundle.ContextViewer_downloadSource();
350 String sourceText = webDownloadArtifactToString(associatedArtifact);
351 javax.swing.JPanel sourcePanel =
new ContextSourcePanel(sourceName, sourceText, associatedArtifact);
352 contextSourcePanels.add(sourcePanel);
354 }
else if (BlackboardArtifact.ARTIFACT_TYPE.TSK_RECENT_OBJECT.getTypeID() == associatedArtifact.getArtifactTypeID()) {
355 String sourceName = Bundle.ContextViewer_recentDocs();
356 String sourceText = recentDocArtifactToString(associatedArtifact);
357 javax.swing.JPanel usagePanel =
new ContextUsagePanel(sourceName, sourceText, associatedArtifact);
358 contextUsagePanels.add(usagePanel);
374 "ContextViewer.downloadURL=URL",
375 "ContextViewer.downloadedOn=On"
378 StringBuilder sb =
new StringBuilder(ARTIFACT_STR_MAX_LEN);
379 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributesMap = getAttributesMap(artifact);
381 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() == artifact.getArtifactTypeID()
382 || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID() == artifact.getArtifactTypeID()) {
383 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, attributesMap, Bundle.ContextViewer_downloadURL());
384 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, attributesMap, Bundle.ContextViewer_downloadedOn());
386 return sb.toString();
400 "ContextViewer.on=Opened at",
401 "ContextViewer.unknown=Opened at unknown time"
404 StringBuilder sb =
new StringBuilder(ARTIFACT_STR_MAX_LEN);
405 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributesMap = getAttributesMap(artifact);
407 BlackboardAttribute attribute = attributesMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME);
409 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_RECENT_OBJECT.getTypeID() == artifact.getArtifactTypeID()) {
410 if (attribute != null && attribute.getValueLong() > 0) {
411 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, attributesMap, Bundle.ContextViewer_on());
413 sb.append(Bundle.ContextViewer_unknown());
416 return sb.toString();
429 "ContextViewer.message=Message",
430 "ContextViewer.email=Email",
431 "ContextViewer.messageFrom=From",
432 "ContextViewer.messageTo=To",
433 "ContextViewer.messageOn=On",})
436 StringBuilder sb =
new StringBuilder(ARTIFACT_STR_MAX_LEN);
437 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributesMap = getAttributesMap(artifact);
439 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() == artifact.getArtifactTypeID()) {
440 sb.append(Bundle.ContextViewer_message()).append(
' ');
441 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, attributesMap, Bundle.ContextViewer_messageFrom());
442 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO, attributesMap, Bundle.ContextViewer_messageTo());
443 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, attributesMap, Bundle.ContextViewer_messageOn());
444 }
else if (BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID() == artifact.getArtifactTypeID()) {
445 sb.append(Bundle.ContextViewer_email()).append(
' ');
446 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_FROM, attributesMap, Bundle.ContextViewer_messageFrom());
447 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_TO, attributesMap, Bundle.ContextViewer_messageTo());
448 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT, attributesMap, Bundle.ContextViewer_messageOn());
450 return sb.toString();
464 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributesMap, String prependStr) {
466 BlackboardAttribute attribute = attributesMap.get(attribType);
467 if (attribute != null) {
468 String attrVal = attribute.getDisplayString();
469 if (!StringUtils.isEmpty(attrVal)) {
470 if (!StringUtils.isEmpty(prependStr)) {
471 sb.append(prependStr).append(
' ');
473 sb.append(StringUtils.abbreviate(attrVal, ATTRIBUTE_STR_MAX_LEN)).append(
' ');
488 private Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute>
getAttributesMap(BlackboardArtifact artifact)
throws TskCoreException {
489 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributeMap =
new HashMap<>();
491 List<BlackboardAttribute> attributeList = artifact.getAttributes();
492 for (BlackboardAttribute attribute : attributeList) {
493 BlackboardAttribute.ATTRIBUTE_TYPE type = BlackboardAttribute.ATTRIBUTE_TYPE.fromID(attribute.getAttributeType().getTypeID());
494 attributeMap.put(type, attribute);
javax.swing.JPanel jSourcePanel
void addSourceEntry(BlackboardArtifact artifact)
String webDownloadArtifactToString(BlackboardArtifact artifact)
javax.swing.JPanel jUnknownPanel
String recentDocArtifactToString(BlackboardArtifact artifact)
Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute > getAttributesMap(BlackboardArtifact artifact)
void appendAttributeString(StringBuilder sb, BlackboardAttribute.ATTRIBUTE_TYPE attribType, Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute > attributesMap, String prependStr)
void setNode(Node selectedNode)
void populateSourceContextData(AbstractFile sourceFile)
javax.swing.JPanel jUsagePanel
int isPreferred(Node node)
SleuthkitCase getSleuthkitCase()
boolean isSupported(Node node)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
String msgArtifactToAbbreviatedString(BlackboardArtifact artifact)
DataContentViewer createInstance()
void setSourceFields(BlackboardArtifact associatedArtifact)
javax.swing.JScrollPane jScrollPane