Autopsy 4.22.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-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 */
19package org.sleuthkit.autopsy.datamodel;
20
21import java.util.ArrayList;
22import java.util.Arrays;
23import java.util.Collection;
24import java.util.HashSet;
25import java.util.List;
26import java.util.logging.Level;
27import javax.swing.Action;
28import org.apache.commons.lang3.StringUtils;
29import org.openide.util.NbBundle;
30import org.openide.util.Utilities;
31import org.sleuthkit.autopsy.actions.AddContentTagAction;
32import org.sleuthkit.autopsy.actions.DeleteFileContentTagAction;
33import org.sleuthkit.autopsy.coreutils.ContextMenuExtensionPoint;
34import org.sleuthkit.autopsy.coreutils.Logger;
35import org.sleuthkit.autopsy.directorytree.ExportCSVAction;
36import org.sleuthkit.autopsy.directorytree.ExternalViewerAction;
37import org.sleuthkit.autopsy.directorytree.ExternalViewerShortcutAction;
38import org.sleuthkit.autopsy.directorytree.ExtractAction;
39import org.sleuthkit.autopsy.directorytree.NewWindowViewAction;
40import org.sleuthkit.autopsy.directorytree.ViewContextAction;
41import org.sleuthkit.autopsy.modules.embeddedfileextractor.ExtractArchiveWithPasswordAction;
42import org.sleuthkit.autopsy.timeline.actions.ViewFileInTimelineAction;
43import org.sleuthkit.datamodel.AbstractFile;
44import org.sleuthkit.datamodel.BlackboardArtifact;
45import org.sleuthkit.datamodel.TskCoreException;
46import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
47import org.sleuthkit.datamodel.TskData.TSK_FS_NAME_FLAG_ENUM;
48
53public 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 Item 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
158 if (!this.getDirectoryBrowseMode()) {
159 actionsList.add(new ViewContextAction(Bundle.FileNode_getActions_viewFileInDir_text(), this));
160 }
162 actionsList.add(null); // Creates an item separator
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
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
195 actionsList.add(null);
196 actionsList.addAll(Arrays.asList(super.getActions(true)));
197
198 return actionsList.toArray(new Action[actionsList.size()]);
199 }
200
209 @Override
210 public <T> T accept(ContentNodeVisitor<T> visitor) {
211 return visitor.visit(this);
212 }
213
222 @Override
223 public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
224 return visitor.visit(this);
225 }
226
233 @Override
234 public boolean isLeafTypeNode() {
235 /*
236 * A FileNode may have FileNodes for derived files as children.
237 */
238 return false;
239 }
240
246 @Override
247 public String getItemType() {
248 return getClass().getName();
249 }
250}
static synchronized AddContentTagAction getInstance()
static synchronized DeleteFileContentTagAction getInstance()
synchronized static Logger getLogger(String name)
Definition Logger.java:124
FileNode(AbstractFile file, boolean directoryBrowseMode)
Action[] getActions(boolean context)
static synchronized ExportCSVAction getInstance()
static synchronized ExtractAction getInstance()
static ViewFileInTimelineAction createViewFileAction(AbstractFile file)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.