Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExternalViewerAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2014 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.directorytree;
20 
21 import java.awt.Desktop;
22 import java.awt.event.ActionEvent;
23 import java.io.File;
24 import java.io.IOException;
25 import java.util.logging.Level;
26 import javax.swing.AbstractAction;
27 import org.openide.nodes.Node;
31 
37 public class ExternalViewerAction extends AbstractAction {
38 
39  private final static Logger logger = Logger.getLogger(ExternalViewerAction.class.getName());
40  private org.sleuthkit.datamodel.AbstractFile fileObject;
41  final static String[] EXECUTABLE_EXT = {".exe", ".dll", ".com", ".bat", ".msi", ".reg", ".scr"}; //NON-NLS
42 
43  public ExternalViewerAction(String title, Node fileNode) {
44  super(title);
45  this.fileObject = fileNode.getLookup().lookup(org.sleuthkit.datamodel.AbstractFile.class);
46 
47  long size = fileObject.getSize();
48  String fileName = fileObject.getName();
49  int extPos = fileName.lastIndexOf('.');
50 
51  boolean isExecutable = false;
52  if (extPos != -1) {
53  String extension = fileName.substring(extPos, fileName.length()).toLowerCase();
54  for (int i = 0; i < EXECUTABLE_EXT.length; ++i) {
55  if (EXECUTABLE_EXT[i].equals(extension)) {
56  isExecutable = true;
57  break;
58  }
59  }
60  }
61 
62  // no point opening a file if it's empty, and java doesn't know how to
63  // find an application for files without an extension
64  // or if file is executable (for security reasons)
65  if (!(size > 0) || extPos == -1 || isExecutable) {
66  this.setEnabled(false);
67  }
68  }
69 
70  @Override
71  public void actionPerformed(ActionEvent e) {
72  // Get the temp folder path of the case
73  String tempPath = Case.getCurrentCase().getTempDirectory();
74  tempPath = tempPath + File.separator + this.fileObject.getName();
75 
76  // create the temporary file
77  File tempFile = new File(tempPath);
78  if (tempFile.exists()) {
79  tempFile.delete();
80  }
81  try {
82  tempFile.createNewFile();
84  } catch (IOException ex) {
85  // throw an error here
86  logger.log(Level.WARNING, "Can't save to temporary file.", ex); //NON-NLS
87  }
88 
89  try {
90  Desktop.getDesktop().open(tempFile);
91  } catch (IOException ex) {
92  // if can't open the file, throw the error saying: "File type not supported."
93  logger.log(Level.WARNING, "File type not supported.", ex); //NON-NLS
94  }
95 
96  // delete the file on exit
97  tempFile.deleteOnExit();
98  }
99 }
static< T > long writeToFile(Content content, java.io.File outputFile, ProgressHandle progress, Future< T > worker, boolean source)
synchronized static Logger getLogger(String name)
Definition: Logger.java:166

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.