Autopsy  4.9.1
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-2018 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;
41 import org.sleuthkit.datamodel.AbstractFile;
42 import org.sleuthkit.datamodel.BlackboardArtifact;
43 import org.sleuthkit.datamodel.TskCoreException;
44 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
45 import org.sleuthkit.datamodel.TskData.TSK_FS_NAME_FLAG_ENUM;
46 
51 public class FileNode extends AbstractFsContentNode<AbstractFile> {
52 
53  private static final Logger logger = Logger.getLogger(FileNode.class.getName());
54 
63  static String getIconForFileType(AbstractFile file) {
64  String ext = file.getNameExtension();
65  if (StringUtils.isBlank(ext)) {
66  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
67  } else {
68  ext = "." + ext;
69  }
70  if (FileTypeExtensions.getImageExtensions().contains(ext)) {
71  return "org/sleuthkit/autopsy/images/image-file.png"; //NON-NLS
72  }
73  if (FileTypeExtensions.getVideoExtensions().contains(ext)) {
74  return "org/sleuthkit/autopsy/images/video-file.png"; //NON-NLS
75  }
76  if (FileTypeExtensions.getAudioExtensions().contains(ext)) {
77  return "org/sleuthkit/autopsy/images/audio-file.png"; //NON-NLS
78  }
79  if (FileTypeExtensions.getDocumentExtensions().contains(ext)) {
80  return "org/sleuthkit/autopsy/images/doc-file.png"; //NON-NLS
81  }
82  if (FileTypeExtensions.getExecutableExtensions().contains(ext)) {
83  return "org/sleuthkit/autopsy/images/exe-file.png"; //NON-NLS
84  }
85  if (FileTypeExtensions.getTextExtensions().contains(ext)) {
86  return "org/sleuthkit/autopsy/images/text-file.png"; //NON-NLS
87  }
88  if (FileTypeExtensions.getWebExtensions().contains(ext)) {
89  return "org/sleuthkit/autopsy/images/web-file.png"; //NON-NLS
90  }
91  if (FileTypeExtensions.getPDFExtensions().contains(ext)) {
92  return "org/sleuthkit/autopsy/images/pdf-file.png"; //NON-NLS
93  }
94  if (FileTypeExtensions.getArchiveExtensions().contains(ext)) {
95  return "org/sleuthkit/autopsy/images/archive-file.png"; //NON-NLS
96  }
97  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
98  }
99 
106  public FileNode(AbstractFile file) {
107  this(file, true);
108  setIcon(file);
109  }
110 
118  public FileNode(AbstractFile file, boolean directoryBrowseMode) {
119  super(file, directoryBrowseMode);
120  setIcon(file);
121  }
122 
123  /*
124  * Sets the icon for the node, based on properties of the AbstractFile.
125  */
126  private void setIcon(AbstractFile file) {
127  if (file.isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM.UNALLOC)) {
128  if (file.getType().equals(TSK_DB_FILES_TYPE_ENUM.CARVED)) {
129  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/carved-file-icon-16.png"); //NON-NLS
130  } else {
131  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/file-icon-deleted.png"); //NON-NLS
132  }
133  } else {
134  this.setIconBaseWithExtension(getIconForFileType(file));
135  }
136  }
137 
147  @Override
148  @NbBundle.Messages({
149  "FileNode.getActions.viewFileInDir.text=View File in Directory",
150  "FileNode.getActions.viewInNewWin.text=View in New Window",
151  "FileNode.getActions.openInExtViewer.text=Open in External Viewer",
152  "FileNode.getActions.searchFilesSameMD5.text=Search for files with the same MD5 hash"})
153  public Action[] getActions(boolean context) {
154  List<Action> actionsList = new ArrayList<>();
155  actionsList.addAll(Arrays.asList(super.getActions(true)));
156 
157  if (!this.getDirectoryBrowseMode()) {
158  actionsList.add(new ViewContextAction(Bundle.FileNode_getActions_viewFileInDir_text(), this));
159  actionsList.add(null); // Creates an item separator
160  }
161 
162  actionsList.add(new NewWindowViewAction(Bundle.FileNode_getActions_viewInNewWin_text(), this));
163  actionsList.add(new ExternalViewerAction(Bundle.FileNode_getActions_openInExtViewer_text(), this));
164  actionsList.add(ViewFileInTimelineAction.createViewFileAction(getContent()));
165  actionsList.add(null); // Creates an item separator
166 
167  actionsList.add(ExtractAction.getInstance());
168  actionsList.add(null); // Creates an item separator
169 
170  actionsList.add(AddContentTagAction.getInstance());
171  final Collection<AbstractFile> selectedFilesList = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
172  if (1 == selectedFilesList.size()) {
173  actionsList.add(DeleteFileContentTagAction.getInstance());
174  }
175  actionsList.addAll(ContextMenuExtensionPoint.getActions());
176  if (FileTypeExtensions.getArchiveExtensions().contains("." + this.content.getNameExtension().toLowerCase())) {
177  try {
178  if (this.content.getArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED).size() > 0) {
179  actionsList.add(new ExtractArchiveWithPasswordAction(this.getContent()));
180  }
181  } catch (TskCoreException ex) {
182  logger.log(Level.WARNING, "Unable to add unzip with password action to context menus", ex);
183  }
184  }
185  return actionsList.toArray(new Action[actionsList.size()]);
186  }
187 
196  @Override
197  public <T> T accept(ContentNodeVisitor<T> visitor) {
198  return visitor.visit(this);
199  }
200 
209  @Override
210  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
211  return visitor.visit(this);
212  }
213 
220  @Override
221  public boolean isLeafTypeNode() {
222  /*
223  * A FileNode may have FileNodes for derived files as children.
224  */
225  return false;
226  }
227 
233  @Override
234  public String getItemType() {
235  return getClass().getName();
236  }
237 }
static synchronized ExtractAction getInstance()
static synchronized DeleteFileContentTagAction getInstance()
FileNode(AbstractFile file, boolean directoryBrowseMode)
Definition: FileNode.java:118
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static ViewFileInTimelineAction createViewFileAction(AbstractFile file)
Action[] getActions(boolean context)
Definition: FileNode.java:153
static synchronized AddContentTagAction getInstance()

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