Autopsy  4.21.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 java.util.Arrays;
22 import java.util.Collection;
23 import java.util.HashSet;
24 import java.util.Set;
25 import java.util.TreeSet;
26 import java.util.function.Consumer;
27 import java.util.logging.Level;
28 import org.openide.nodes.Children;
29 import org.openide.nodes.Node;
30 import org.openide.nodes.Sheet;
31 import org.openide.util.NbBundle;
35 import org.sleuthkit.datamodel.AbstractFile;
36 import org.sleuthkit.datamodel.BlackboardArtifact;
37 import org.sleuthkit.datamodel.BlackboardAttribute;
38 import org.sleuthkit.datamodel.Content;
39 import org.sleuthkit.datamodel.TskCoreException;
40 import org.sleuthkit.datamodel.blackboardutils.attributes.BlackboardJsonAttrUtil;
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  try {
93  MessageAttachments msgAttachments = BlackboardJsonAttrUtil.fromAttribute(attachmentsAttr, MessageAttachments.class);
94  Collection<FileAttachment> fileAttachments = msgAttachments.getFileAttachments();
95  for (FileAttachment fileAttachment : fileAttachments) {
96  long attachedFileObjId = fileAttachment.getObjectId();
97  if (attachedFileObjId >= 0) {
98  AbstractFile attachedFile = bba.getSleuthkitCase().getAbstractFileById(attachedFileObjId);
99  thumbnails.add(attachedFile);
100  }
101  }
102  }
103  catch (BlackboardJsonAttrUtil.InvalidJsonException ex) {
104  LOGGER.log(Level.WARNING, String.format("Unable to parse json for MessageAttachments object in artifact: %s", bba.getName()), ex);
105  }
106  } else { // backward compatibility - email message attachments are derived files, children of the message.
107  for (Content childContent : bba.getChildren()) {
108  if (childContent instanceof AbstractFile) {
109  thumbnails.add((AbstractFile) childContent);
110  }
111  }
112  }
113 
114  } catch (TskCoreException ex) {
115  LOGGER.log(Level.WARNING, "Unable to get children from artifact.", ex); //NON-NLS
116  }
117  }
118  });
119 
120  setKeys(thumbnails);
121  }
122 
126  static class AttachementThumbnailNode extends FileNode {
127 
128  AttachementThumbnailNode(AbstractFile file) {
129  super(file, false);
130  }
131 
132  @Override
133  protected Sheet createSheet() {
134  Sheet sheet = super.createSheet();
135  Set<String> keepProps = new HashSet<>(Arrays.asList(
136  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.nameColLbl"),
137  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.score.name"),
138  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.comment.name"),
139  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.count.name"),
140  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.sizeColLbl"),
141  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.mimeType"),
142  NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.knownColLbl")));
143 
144  //Remove all other props except for the ones above
145  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
146  for (Node.Property<?> p : sheetSet.getProperties()) {
147  if (!keepProps.contains(p.getName())) {
148  sheetSet.remove(p.getName());
149  }
150  }
151 
152  return sheet;
153  }
154  }
155 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.