Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AttachmentNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017-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 obtain 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.datamodel;
20 
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.Action;
28 import org.apache.commons.lang3.StringUtils;
29 import org.openide.nodes.Children;
30 import org.openide.nodes.Sheet;
31 import org.openide.util.Lookup;
32 import org.openide.util.NbBundle;
33 import org.openide.util.Utilities;
34 import org.openide.util.lookup.Lookups;
41 import static org.sleuthkit.autopsy.datamodel.FileNode.getIconForFileType;
49 import org.sleuthkit.datamodel.AbstractFile;
50 import org.sleuthkit.datamodel.TskException;
51 import org.sleuthkit.datamodel.blackboardutils.attributes.MessageAttachments.Attachment;
52 import org.sleuthkit.datamodel.blackboardutils.attributes.MessageAttachments.FileAttachment;
53 import org.sleuthkit.datamodel.blackboardutils.attributes.MessageAttachments.URLAttachment;
54 
59 public final class AttachmentNode extends DisplayableItemNode {
60 
61  private static final Logger LOGGER = Logger.getLogger(AttachmentNode.class.getName());
62 
63  private final Attachment attachment;
64  private final AbstractFile attachmentFile;
65 
66  public AttachmentNode(Attachment attachment) {
67 
68  super(Children.LEAF, createLookup(attachment));
69 
70  super.setName(attachment.getLocation());
71  super.setDisplayName(attachment.getLocation()); // SET NODE DISPLAY NAME, I.E., TEXT IN FIRST TABLE CELL
72 
73  this.attachment = attachment;
74  Long attachmentObjId = attachment.getObjId();
75  AbstractFile attchmentAbstractFile = null;
76 
77  if (attachmentObjId != null && attachmentObjId > 0) {
78  try {
79  attchmentAbstractFile = Case.getCurrentCaseThrows().getSleuthkitCase().getAbstractFileById(attachmentObjId);
80  } catch (TskException | NoCurrentCaseException ex) {
81  LOGGER.log(Level.WARNING, "Error loading attachment file with object id " + attachmentObjId, ex); //NON-NLS
82  }
83  }
84  attachmentFile = attchmentAbstractFile;
85 
86  // set the icon for node
87  setIcon();
88  }
89 
90  @Override
91  @NbBundle.Messages({
92  "AttachmentNode.getActions.viewFileInDir.text=View File in Directory",
93  "AttachmentNode.getActions.viewInNewWin.text=View in New Window",
94  "AttachmentNode.getActions.openInExtViewer.text=Open in External Viewer Ctrl+E",
95  "AttachmentNode.getActions.searchFilesSameMD5.text=Search for files with the same MD5 hash"})
96  public Action[] getActions(boolean context) {
97 
98  List<Action> actionsList = new ArrayList<>();
99  actionsList.addAll(Arrays.asList(super.getActions(true)));
100 
101  // If there is an attachment file
102  if (this.attachmentFile != null) {
103  actionsList.add(new ViewContextAction(Bundle.AttachmentNode_getActions_viewFileInDir_text(), this.attachmentFile));
104  actionsList.add(null); // Creates an item separator
105 
106  actionsList.add(new NewWindowViewAction(Bundle.AttachmentNode_getActions_viewInNewWin_text(), this));
107  final Collection<AbstractFile> selectedFilesList
108  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
109  if (selectedFilesList.size() == 1) {
110  actionsList.add(new ExternalViewerAction(
111  Bundle.AttachmentNode_getActions_openInExtViewer_text(), this));
112  } else {
113  actionsList.add(ExternalViewerShortcutAction.getInstance());
114  }
115  actionsList.add(ViewFileInTimelineAction.createViewFileAction(this.attachmentFile));
116  actionsList.add(null); // Creates an item separator
117 
118  actionsList.add(ExtractAction.getInstance());
119  actionsList.add(ExportCSVAction.getInstance());
120  actionsList.add(null); // Creates an item separator
121 
122  actionsList.add(AddContentTagAction.getInstance());
123  if (1 == selectedFilesList.size()) {
124  actionsList.add(DeleteFileContentTagAction.getInstance());
125  }
126  actionsList.addAll(ContextMenuExtensionPoint.getActions());
127 
128  }
129  return actionsList.toArray(new Action[0]);
130  }
131 
132  @Override
133  protected Sheet createSheet() {
134 
135  // Create a new property sheet.
136  Sheet sheet = new Sheet();
137  Sheet.Set sheetSet = Sheet.createPropertiesSet();
138  sheet.put(sheetSet);
139 
140  sheetSet.put(new NodeProperty<>("Location", "Location", "", this.attachment.getLocation()));
141 
142  if (attachmentFile != null) {
143  long size = attachmentFile.getSize();
144  String mimeType = attachmentFile.getMIMEType();
145 
146  // @TODO Vik-5762: get SCO Columns
147 
148  sheetSet.put(new NodeProperty<>("Size", "Size", "", size));
149  if (StringUtils.isNotEmpty(mimeType)) {
150  sheetSet.put(new NodeProperty<>("Mime type", "Mime type", "", mimeType));
151  }
152  sheetSet.put(new NodeProperty<>("Known", "Known", "", attachmentFile.getKnown().getName()));
153  }
154 
155  return sheet;
156  }
157 
158  @Override
159  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
160  return visitor.visit(this);
161  }
162 
163  @Override
164  public boolean isLeafTypeNode() {
165  return true;
166  }
167 
168  @Override
169  public String getItemType() {
170  return getClass().getName();
171  }
172 
173  private static Lookup createLookup(Attachment attachment) {
174  Long attachmentObjId = attachment.getObjId();
175  if (attachmentObjId != null && attachmentObjId > 0) {
176  AbstractFile attachmentFile = null;
177  try {
178  attachmentFile = Case.getCurrentCaseThrows().getSleuthkitCase().getAbstractFileById(attachmentObjId);
179  if (attachmentFile != null) {
180  return Lookups.fixed(attachment, attachmentFile);
181  } else {
182  return Lookups.fixed(attachment);
183  }
184  } catch (TskException | NoCurrentCaseException ex) {
185  return Lookups.fixed(attachment);
186  }
187  }
188  return Lookups.fixed(attachment);
189  }
190 
194  private void setIcon() {
195  if (attachmentFile != null) {
196  this.setIconBaseWithExtension(getIconForFileType(attachmentFile));
197  } else if (attachment instanceof FileAttachment) {
198  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/document-question-16.png");
199  } else if (attachment instanceof URLAttachment) {
200  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/url-16.png");
201  } else {
202  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/file-icon-deleted.png");
203  }
204 
205  }
206 }
static Lookup createLookup(Attachment attachment)
static synchronized ExportCSVAction getInstance()
static synchronized ExtractAction getInstance()
static synchronized DeleteFileContentTagAction getInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static ViewFileInTimelineAction createViewFileAction(AbstractFile file)
static synchronized AddContentTagAction getInstance()

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.