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 org.apache.commons.lang.StringUtils;
28 import org.openide.nodes.Node;
29 import org.openide.util.NbBundle;
30 import org.openide.util.lookup.ServiceProvider;
38 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT;
51 private static final long serialVersionUID = 1L;
53 private static final int ARTIFACT_STR_MAX_LEN = 1024;
54 private static final int ATTRIBUTE_STR_MAX_LEN = 200;
57 private static final List<BlackboardArtifact.ARTIFACT_TYPE> SOURCE_CONTEXT_ARTIFACTS =
new ArrayList<>();
60 SOURCE_CONTEXT_ARTIFACTS.add(TSK_ASSOCIATED_OBJECT);
78 @SuppressWarnings(
"unchecked")
80 private
void initComponents() {
82 jSourceGoToResultButton =
new javax.swing.JButton();
83 jSourceLabel =
new javax.swing.JLabel();
84 jSourceNameLabel =
new javax.swing.JLabel();
85 jSourceTextLabel =
new javax.swing.JLabel();
87 setBackground(
new java.awt.Color(255, 255, 255));
89 org.openide.awt.Mnemonics.setLocalizedText(jSourceGoToResultButton,
org.openide.util.NbBundle.getMessage(
ContextViewer.class,
"ContextViewer.jSourceGoToResultButton.text"));
90 jSourceGoToResultButton.addActionListener(
new java.awt.event.ActionListener() {
91 public void actionPerformed(java.awt.event.ActionEvent evt) {
92 jSourceGoToResultButtonActionPerformed(evt);
96 jSourceLabel.setFont(
new java.awt.Font(
"Dialog", 1, 14));
97 org.openide.awt.Mnemonics.setLocalizedText(jSourceLabel,
org.openide.util.NbBundle.getMessage(
ContextViewer.class,
"ContextViewer.jSourceLabel.text"));
99 org.openide.awt.Mnemonics.setLocalizedText(jSourceNameLabel,
org.openide.util.NbBundle.getMessage(
ContextViewer.class,
"ContextViewer.jSourceNameLabel.text"));
101 org.openide.awt.Mnemonics.setLocalizedText(jSourceTextLabel,
org.openide.util.NbBundle.getMessage(
ContextViewer.class,
"ContextViewer.jSourceTextLabel.text"));
103 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
104 this.setLayout(layout);
105 layout.setHorizontalGroup(
106 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
107 .addGroup(layout.createSequentialGroup()
109 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
110 .addGroup(layout.createSequentialGroup()
111 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
112 .addComponent(jSourceLabel)
113 .addGroup(layout.createSequentialGroup()
115 .addComponent(jSourceNameLabel)
116 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
117 .addComponent(jSourceTextLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)))
119 .addGroup(layout.createSequentialGroup()
120 .addComponent(jSourceGoToResultButton)
121 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
123 layout.setVerticalGroup(
124 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
125 .addGroup(layout.createSequentialGroup()
127 .addComponent(jSourceLabel)
128 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
129 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
130 .addComponent(jSourceNameLabel)
131 .addComponent(jSourceTextLabel))
133 .addComponent(jSourceGoToResultButton)
134 .addGap(0, 203, Short.MAX_VALUE))
143 if (sourceContextArtifact != null) {
151 if ((selectedNode == null) || (!isSupported(selectedNode))) {
156 AbstractFile file = selectedNode.getLookup().lookup(AbstractFile.class);
158 populateSourceContextData(file);
160 logger.log(Level.SEVERE, String.format(
"Exception displaying context for file %s", file.getName()), ex);
165 "ContextViewer.title=Context",
166 "ContextViewer.toolTip=Displays context for selected file."
171 return Bundle.ContextViewer_title();
176 return Bundle.ContextViewer_toolTip();
191 jSourceGoToResultButton.setVisible(
false);
200 if (node.getLookup().lookup(AbstractFile.class) != null) {
201 AbstractFile abstractFile = node.getLookup().lookup(AbstractFile.class);
202 for (BlackboardArtifact.ARTIFACT_TYPE artifactType : SOURCE_CONTEXT_ARTIFACTS) {
203 List<BlackboardArtifact> artifactsList;
205 artifactsList = abstractFile.getArtifacts(artifactType);
206 if (!artifactsList.isEmpty()) {
209 }
catch (TskCoreException ex) {
210 logger.log(Level.SEVERE, String.format(
"Exception while looking up context artifacts for file %s", abstractFile), ex);
239 boolean foundASource =
false;
240 for (BlackboardArtifact.ARTIFACT_TYPE artifactType : SOURCE_CONTEXT_ARTIFACTS) {
241 List<BlackboardArtifact> artifactsList = tskCase.getBlackboardArtifacts(artifactType, sourceFile.getId());
243 foundASource = !artifactsList.isEmpty();
244 for (BlackboardArtifact contextArtifact : artifactsList) {
245 addSourceEntry(contextArtifact);
248 jSourceGoToResultButton.setVisible(
true);
249 if (foundASource ==
false) {
250 setSourceName(
"Unknown");
251 showSourceText(
false);
265 private void addSourceEntry(BlackboardArtifact artifact)
throws TskCoreException {
266 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getTypeID() == artifact.getArtifactTypeID()) {
267 BlackboardAttribute associatedArtifactAttribute = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
268 if (associatedArtifactAttribute != null) {
269 long artifactId = associatedArtifactAttribute.getValueLong();
270 BlackboardArtifact associatedArtifact = artifact.getSleuthkitCase().getBlackboardArtifact(artifactId);
273 sourceContextArtifact = associatedArtifact;
275 setSourceFields(associatedArtifact);
289 "ContextViewer.attachmentSource=Attached to: ",
290 "ContextViewer.downloadSource=Downloaded from: "
292 private void setSourceFields(BlackboardArtifact associatedArtifact)
throws TskCoreException {
293 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() == associatedArtifact.getArtifactTypeID()
294 || BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID() == associatedArtifact.getArtifactTypeID()) {
296 setSourceName(Bundle.ContextViewer_attachmentSource());
297 setSourceText(msgArtifactToAbbreviatedString(associatedArtifact));
299 }
else if (BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() == associatedArtifact.getArtifactTypeID()
300 || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID() == associatedArtifact.getArtifactTypeID()) {
302 setSourceName(Bundle.ContextViewer_downloadSource());
303 setSourceText(webDownloadArtifactToString(associatedArtifact));
313 jSourceNameLabel.setText(nameLabel);
322 jSourceTextLabel.setText(text);
323 showSourceText(!text.isEmpty());
327 jSourceTextLabel.setVisible(show);
328 jSourceGoToResultButton.setEnabled(show);
329 jSourceLabel.setVisible(show);
343 "ContextViewer.downloadURL=URL",
344 "ContextViewer.downloadedOn=On"
347 StringBuilder sb =
new StringBuilder(ARTIFACT_STR_MAX_LEN);
348 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributesMap = getAttributesMap(artifact);
350 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() == artifact.getArtifactTypeID()
351 || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID() == artifact.getArtifactTypeID()) {
352 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, attributesMap, Bundle.ContextViewer_downloadURL());
353 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, attributesMap, Bundle.ContextViewer_downloadedOn());
355 return sb.toString();
368 "ContextViewer.message=Message",
369 "ContextViewer.email=Email",
370 "ContextViewer.messageFrom=From",
371 "ContextViewer.messageTo=To",
372 "ContextViewer.messageOn=On",})
375 StringBuilder sb =
new StringBuilder(ARTIFACT_STR_MAX_LEN);
376 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributesMap = getAttributesMap(artifact);
378 if (BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() == artifact.getArtifactTypeID()) {
379 sb.append(Bundle.ContextViewer_message()).append(
' ');
380 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, attributesMap, Bundle.ContextViewer_messageFrom());
381 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO, attributesMap, Bundle.ContextViewer_messageTo());
382 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, attributesMap, Bundle.ContextViewer_messageOn());
383 }
else if (BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID() == artifact.getArtifactTypeID()) {
384 sb.append(Bundle.ContextViewer_email()).append(
' ');
385 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_FROM, attributesMap, Bundle.ContextViewer_messageFrom());
386 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_TO, attributesMap, Bundle.ContextViewer_messageTo());
387 appendAttributeString(sb, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT, attributesMap, Bundle.ContextViewer_messageOn());
389 return sb.toString();
403 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributesMap, String prependStr) {
405 BlackboardAttribute attribute = attributesMap.get(attribType);
406 if (attribute != null) {
407 String attrVal = attribute.getDisplayString();
408 if (!StringUtils.isEmpty(attrVal)) {
409 if (!StringUtils.isEmpty(prependStr)) {
410 sb.append(prependStr).append(
' ');
412 sb.append(StringUtils.abbreviate(attrVal, ATTRIBUTE_STR_MAX_LEN)).append(
' ');
427 private Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute>
getAttributesMap(BlackboardArtifact artifact)
throws TskCoreException {
428 Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attributeMap =
new HashMap<>();
430 List<BlackboardAttribute> attributeList = artifact.getAttributes();
431 for (BlackboardAttribute attribute : attributeList) {
432 BlackboardAttribute.ATTRIBUTE_TYPE type = BlackboardAttribute.ATTRIBUTE_TYPE.fromID(attribute.getAttributeType().getTypeID());
433 attributeMap.put(type, attribute);
void viewArtifact(final BlackboardArtifact art)
javax.swing.JButton jSourceGoToResultButton
void addSourceEntry(BlackboardArtifact artifact)
String webDownloadArtifactToString(BlackboardArtifact artifact)
javax.swing.JLabel jSourceNameLabel
BlackboardArtifact sourceContextArtifact
Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute > getAttributesMap(BlackboardArtifact artifact)
javax.swing.JLabel jSourceLabel
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.JLabel jSourceTextLabel
int isPreferred(Node node)
void showSourceText(boolean show)
SleuthkitCase getSleuthkitCase()
boolean isSupported(Node node)
void jSourceGoToResultButtonActionPerformed(java.awt.event.ActionEvent evt)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
String msgArtifactToAbbreviatedString(BlackboardArtifact artifact)
static synchronized DirectoryTreeTopComponent findInstance()
DataContentViewer createInstance()
void setSourceText(String text)
void setSourceFields(BlackboardArtifact associatedArtifact)
void setSourceName(String nameLabel)