Autopsy  4.19.3
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 
100  // If there is an attachment file
101  if (this.attachmentFile != null) {
102  actionsList.add(new ViewContextAction(Bundle.AttachmentNode_getActions_viewFileInDir_text(), this.attachmentFile));
103  actionsList.add(ViewFileInTimelineAction.createViewFileAction(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(null); // Creates an item separator
116 
117  actionsList.add(ExtractAction.getInstance());
118  actionsList.add(ExportCSVAction.getInstance());
119  actionsList.add(null); // Creates an item separator
120 
121  actionsList.add(AddContentTagAction.getInstance());
122  if (1 == selectedFilesList.size()) {
123  actionsList.add(DeleteFileContentTagAction.getInstance());
124  }
125  actionsList.addAll(ContextMenuExtensionPoint.getActions());
126 
127  actionsList.add(null);
128  }
129  actionsList.addAll(Arrays.asList(super.getActions(true)));
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-2022 Basis Technology. Generated on: Tue Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.