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