19 package org.sleuthkit.autopsy.contentviewers.artifactviewers;
21 import java.util.Collection;
22 import java.util.HashMap;
23 import java.util.HashSet;
25 import java.util.Optional;
27 import java.util.logging.Level;
28 import javax.swing.SwingWorker;
32 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT;
34 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT;
37 import org.
sleuthkit.datamodel.blackboardutils.attributes.BlackboardJsonAttrUtil;
38 import org.
sleuthkit.datamodel.blackboardutils.attributes.MessageAttachments;
44 class MessageArtifactWorker
extends SwingWorker<MessageArtifactWorker.MesssageArtifactData, Void> {
46 private BlackboardArtifact artifact;
47 private static final Logger logger = Logger.getLogger(MessageArtifactWorker.class.getName());
49 private static final BlackboardAttribute.Type TSK_ASSOCIATED_TYPE =
new BlackboardAttribute.Type(TSK_ASSOCIATED_ARTIFACT);
51 MessageArtifactWorker(BlackboardArtifact artifact) {
52 this.artifact = artifact;
56 protected MesssageArtifactData doInBackground() throws Exception {
61 if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()) {
63 getAssociatedArtifact(artifact).ifPresent(associatedArtifact -> {
64 this.artifact = associatedArtifact;
66 }
catch (TskCoreException ex) {
67 logger.log(Level.SEVERE,
"error getting associated artifact", ex);
71 Map<BlackboardAttribute.Type, BlackboardAttribute> map = getAttributesForArtifact(artifact);
72 Set<MessageAttachments.Attachment> attachements = getAttachments(artifact);
78 return new MesssageArtifactData(artifact, map, attachements);
90 static private Map<BlackboardAttribute.Type, BlackboardAttribute> getAttributesForArtifact(BlackboardArtifact artifact)
throws TskCoreException {
91 Map<BlackboardAttribute.Type, BlackboardAttribute> attributeMap =
new HashMap<>();
92 for (BlackboardAttribute attribute : artifact.getAttributes()) {
93 attributeMap.put(attribute.getAttributeType(), attribute);
108 private Set<MessageAttachments.Attachment> getAttachments(BlackboardArtifact art)
throws TskCoreException {
110 final Set<MessageAttachments.Attachment> attachments =
new HashSet<>();
113 BlackboardAttribute attachmentsAttr = art.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ATTACHMENTS));
114 if (attachmentsAttr != null) {
116 MessageAttachments msgAttachments = BlackboardJsonAttrUtil.fromAttribute(attachmentsAttr, MessageAttachments.class);
117 Collection<MessageAttachments.FileAttachment> fileAttachments = msgAttachments.getFileAttachments();
118 for (MessageAttachments.FileAttachment fileAttachment : fileAttachments) {
119 attachments.add(fileAttachment);
121 Collection<MessageAttachments.URLAttachment> urlAttachments = msgAttachments.getUrlAttachments();
122 for (MessageAttachments.URLAttachment urlAttachment : urlAttachments) {
123 attachments.add(urlAttachment);
125 }
catch (BlackboardJsonAttrUtil.InvalidJsonException ex) {
126 logger.log(Level.WARNING, String.format(
"Unable to parse json for MessageAttachments object in artifact: %s", art.getName()), ex);
129 for (Content child : art.getChildren()) {
130 if (child instanceof AbstractFile) {
131 attachments.add(
new MessageAttachments.FileAttachment((AbstractFile) child));
149 static Optional<BlackboardArtifact> getAssociatedArtifact(
final BlackboardArtifact artifact)
throws TskCoreException {
150 BlackboardAttribute attribute = artifact.getAttribute(TSK_ASSOCIATED_TYPE);
151 if (attribute != null) {
152 return Optional.of(artifact.getSleuthkitCase().getArtifactByArtifactId(attribute.getValueLong()));
154 return Optional.empty();
160 static class MesssageArtifactData {
162 private final BlackboardArtifact artifact;
163 private final Map<BlackboardAttribute.Type, BlackboardAttribute> attributeMap;
164 private final Set<MessageAttachments.Attachment> attachements;
166 MesssageArtifactData(BlackboardArtifact artifact, Map<BlackboardAttribute.Type, BlackboardAttribute> attributeMap, Set<MessageAttachments.Attachment> attachements) {
167 this.artifact = artifact;
168 this.attributeMap = attributeMap;
169 this.attachements = attachements;
172 BlackboardArtifact getArtifact() {
176 Map<BlackboardAttribute.Type, BlackboardAttribute> getAttributeMap() {
180 Set<MessageAttachments.Attachment> getAttachements() {
192 String getAttributeDisplayString(BlackboardAttribute.ATTRIBUTE_TYPE attributeType) {
193 BlackboardAttribute attribute = attributeMap.get(
new BlackboardAttribute.Type(attributeType));
194 if (attribute != null) {
195 return attribute.getDisplayString();