Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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.util.NbBundle;
30 import org.openide.util.Utilities;
43 import org.sleuthkit.datamodel.AbstractFile;
44 import org.sleuthkit.datamodel.BlackboardArtifact;
45 import org.sleuthkit.datamodel.TskCoreException;
46 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
47 import org.sleuthkit.datamodel.TskData.TSK_FS_NAME_FLAG_ENUM;
48 
53 public class FileNode extends AbstractFsContentNode<AbstractFile> {
54 
55  private static final Logger logger = Logger.getLogger(FileNode.class.getName());
56 
65  static String getIconForFileType(AbstractFile file) {
66  String ext = file.getNameExtension();
67  if (StringUtils.isBlank(ext)) {
68  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
69  } else {
70  ext = "." + ext;
71  }
72  if (FileTypeExtensions.getImageExtensions().contains(ext)) {
73  return "org/sleuthkit/autopsy/images/image-file.png"; //NON-NLS
74  }
75  if (FileTypeExtensions.getVideoExtensions().contains(ext)) {
76  return "org/sleuthkit/autopsy/images/video-file.png"; //NON-NLS
77  }
78  if (FileTypeExtensions.getAudioExtensions().contains(ext)) {
79  return "org/sleuthkit/autopsy/images/audio-file.png"; //NON-NLS
80  }
81  if (FileTypeExtensions.getDocumentExtensions().contains(ext)) {
82  return "org/sleuthkit/autopsy/images/doc-file.png"; //NON-NLS
83  }
84  if (FileTypeExtensions.getExecutableExtensions().contains(ext)) {
85  return "org/sleuthkit/autopsy/images/exe-file.png"; //NON-NLS
86  }
87  if (FileTypeExtensions.getTextExtensions().contains(ext)) {
88  return "org/sleuthkit/autopsy/images/text-file.png"; //NON-NLS
89  }
90  if (FileTypeExtensions.getWebExtensions().contains(ext)) {
91  return "org/sleuthkit/autopsy/images/web-file.png"; //NON-NLS
92  }
93  if (FileTypeExtensions.getPDFExtensions().contains(ext)) {
94  return "org/sleuthkit/autopsy/images/pdf-file.png"; //NON-NLS
95  }
96  if (FileTypeExtensions.getArchiveExtensions().contains(ext)) {
97  return "org/sleuthkit/autopsy/images/archive-file.png"; //NON-NLS
98  }
99  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
100  }
101 
108  public FileNode(AbstractFile file) {
109  this(file, true);
110  setIcon(file);
111  }
112 
120  public FileNode(AbstractFile file, boolean directoryBrowseMode) {
121  super(file, directoryBrowseMode);
122  setIcon(file);
123  }
124 
125  /*
126  * Sets the icon for the node, based on properties of the AbstractFile.
127  */
128  private void setIcon(AbstractFile file) {
129  if (file.isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM.UNALLOC)) {
130  if (file.getType().equals(TSK_DB_FILES_TYPE_ENUM.CARVED)) {
131  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/carved-file-x-icon-16.png"); //NON-NLS
132  } else {
133  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/file-icon-deleted.png"); //NON-NLS
134  }
135  } else {
136  this.setIconBaseWithExtension(getIconForFileType(file));
137  }
138  }
139 
149  @Override
150  @NbBundle.Messages({
151  "FileNode.getActions.viewFileInDir.text=View File in Directory",
152  "FileNode.getActions.viewInNewWin.text=View in New Window",
153  "FileNode.getActions.openInExtViewer.text=Open in External Viewer Ctrl+E",
154  "FileNode.getActions.searchFilesSameMD5.text=Search for files with the same MD5 hash"})
155  public Action[] getActions(boolean context) {
156  List<Action> actionsList = new ArrayList<>();
157  actionsList.addAll(Arrays.asList(super.getActions(true)));
158 
159  if (!this.getDirectoryBrowseMode()) {
160  actionsList.add(new ViewContextAction(Bundle.FileNode_getActions_viewFileInDir_text(), this));
161  actionsList.add(null); // Creates an item separator
162  }
163 
164  actionsList.add(new NewWindowViewAction(Bundle.FileNode_getActions_viewInNewWin_text(), this));
165  final Collection<AbstractFile> selectedFilesList
166  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
167  if (selectedFilesList.size() == 1) {
168  actionsList.add(new ExternalViewerAction(
169  Bundle.FileNode_getActions_openInExtViewer_text(), this));
170  } else {
171  actionsList.add(ExternalViewerShortcutAction.getInstance());
172  }
173  actionsList.add(ViewFileInTimelineAction.createViewFileAction(getContent()));
174  actionsList.add(null); // Creates an item separator
175 
176  actionsList.add(ExtractAction.getInstance());
177  actionsList.add(ExportCSVAction.getInstance());
178  actionsList.add(null); // Creates an item separator
179 
180  actionsList.add(AddContentTagAction.getInstance());
181  if (1 == selectedFilesList.size()) {
182  actionsList.add(DeleteFileContentTagAction.getInstance());
183  }
184  actionsList.addAll(ContextMenuExtensionPoint.getActions());
185  if (FileTypeExtensions.getArchiveExtensions().contains("." + this.content.getNameExtension().toLowerCase())) {
186  try {
187  if (this.content.getArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED).size() > 0) {
188  actionsList.add(new ExtractArchiveWithPasswordAction(this.getContent()));
189  }
190  } catch (TskCoreException ex) {
191  logger.log(Level.WARNING, "Unable to add unzip with password action to context menus", ex);
192  }
193  }
194  return actionsList.toArray(new Action[actionsList.size()]);
195  }
196 
205  @Override
206  public <T> T accept(ContentNodeVisitor<T> visitor) {
207  return visitor.visit(this);
208  }
209 
218  @Override
219  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
220  return visitor.visit(this);
221  }
222 
229  @Override
230  public boolean isLeafTypeNode() {
231  /*
232  * A FileNode may have FileNodes for derived files as children.
233  */
234  return false;
235  }
236 
242  @Override
243  public String getItemType() {
244  return getClass().getName();
245  }
246 }
static synchronized ExportCSVAction getInstance()
static synchronized ExtractAction getInstance()
static synchronized DeleteFileContentTagAction getInstance()
FileNode(AbstractFile file, boolean directoryBrowseMode)
Definition: FileNode.java:120
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static ViewFileInTimelineAction createViewFileAction(AbstractFile file)
Action[] getActions(boolean context)
Definition: FileNode.java:155
static synchronized AddContentTagAction getInstance()

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