Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AttachmentThumbnailsChildren.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019-2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obt ain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.communications.relationships;
20 
21 import com.google.gson.Gson;
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.HashSet;
25 import java.util.Set;
26 import java.util.TreeSet;
27 import java.util.function.Consumer;
28 import java.util.logging.Level;
29 import org.openide.nodes.Children;
30 import org.openide.nodes.Node;
31 import org.openide.nodes.Sheet;
32 import org.openide.util.NbBundle;
36 import org.sleuthkit.datamodel.AbstractFile;
37 import org.sleuthkit.datamodel.BlackboardArtifact;
38 import org.sleuthkit.datamodel.BlackboardAttribute;
39 import org.sleuthkit.datamodel.Content;
40 import org.sleuthkit.datamodel.TskCoreException;
41 import org.sleuthkit.datamodel.blackboardutils.attributes.MessageAttachments.FileAttachment;
42 import org.sleuthkit.datamodel.blackboardutils.attributes.MessageAttachments;
43 
47 final class AttachmentThumbnailsChildren extends Children.Keys<AbstractFile> {
48 
49  private static final Logger LOGGER = Logger.getLogger(AttachmentThumbnailsChildren.class.getName());
50 
51  private final Set<BlackboardArtifact> artifacts;
52 
53  /*
54  * Creates the list of thumbnails from the given list of
55  * BlackboardArtifacts.
56  *
57  * The thumbnails will be initialls sorted by size, then name so that they
58  * appear sorted by size by default.
59  */
60  AttachmentThumbnailsChildren(Set<BlackboardArtifact> artifacts) {
61  super(false);
62 
63  this.artifacts = artifacts;
64 
65  }
66 
67  @Override
68  protected Node[] createNodes(AbstractFile t) {
69  return new Node[]{new AttachementThumbnailNode(t)};
70  }
71 
72  @Override
73  protected void addNotify() {
74  super.addNotify();
75 
76  Set<AbstractFile> thumbnails = new TreeSet<>((AbstractFile file1, AbstractFile file2) -> {
77  int result = Long.compare(file1.getSize(), file2.getSize());
78  if (result == 0) {
79  result = file1.getName().compareTo(file2.getName());
80  }
81 
82  return result;
83  });
84 
85  artifacts.forEach(new Consumer<BlackboardArtifact>() {
86  @Override
87  public void accept(BlackboardArtifact bba) {
88  try {
89  // Get the attachments from TSK_ATTACHMENTS attribute.
90  BlackboardAttribute attachmentsAttr = bba.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ATTACHMENTS));
91  if (attachmentsAttr != null) {
92 
93  String jsonVal = attachmentsAttr.getValueString();
94  MessageAttachments msgAttachments = new Gson().fromJson(jsonVal, MessageAttachments.class);
95 
96  Collection<FileAttachment> fileAttachments = msgAttachments.getFileAttachments();
97  for (FileAttachment fileAttachment : fileAttachments) {
98  long attachedFileObjId = fileAttachment.getObjectId();
99  if (attachedFileObjId >= 0) {
100  AbstractFile attachedFile = bba.getSleuthkitCase().getAbstractFileById(attachedFileObjId);
101  thumbnails.add(attachedFile);
102  }
103  }
104  } else { // backward compatibility - email message attachments are derived files, children of the message.
105  for (Content childContent : bba.getChildren()) {
106  if (childContent instanceof AbstractFile) {
107  thumbnails.add((AbstractFile) childContent);
108  }
109  }
110  }
111 
112  } catch (TskCoreException ex) {
113  LOGGER.log(Level.WARNING, "Unable to get children from artifact.", ex); //NON-NLS
114  }
115  }
116  });
117 
118  setKeys(thumbnails);
119  }
120 
124  static class AttachementThumbnailNode extends FileNode {
125 
126  AttachementThumbnailNode(AbstractFile file) {
127  super(file, false);
128  }
129 
130  @Override
131  protected Sheet createSheet() {
132  Sheet sheet = super.createSheet();
133  Set<String> keepProps = new HashSet<>(Arrays.asList(
134  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.nameColLbl"),
135  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.score.name"),
136  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.comment.name"),
137  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.count.name"),
138  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.sizeColLbl"),
139  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.mimeType"),
140  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.knownColLbl")));
141 
142  //Remove all other props except for the ones above
143  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
144  for (Node.Property<?> p : sheetSet.getProperties()) {
145  if (!keepProps.contains(p.getName())) {
146  sheetSet.remove(p.getName());
147  }
148  }
149 
150  return sheet;
151  }
152  }
153 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.