Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileExtMismatchContextMenuActionsProvider.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 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.modules.fileextmismatch;
20 
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.Action;
28 import org.openide.util.Lookup;
29 import org.openide.util.NbBundle;
30 import org.openide.util.Utilities;
31 import org.openide.util.lookup.ServiceProvider;
35 import org.sleuthkit.datamodel.AbstractFile;
36 import org.sleuthkit.datamodel.BlackboardArtifact;
37 import org.sleuthkit.datamodel.BlackboardAttribute;
38 import org.sleuthkit.datamodel.TskCoreException;
39 
44 @ServiceProvider(service = ContextMenuActionsProvider.class)
46 
47  @Override
48  public List<Action> getActions() {
49  ArrayList<Action> actions = new ArrayList<>();
50 
51  // Ignore if file ingest is in progress.
53 
54  final Collection<? extends BlackboardArtifact> selectedArts = Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class);
55 
56  // Prevent multiselect
57  if (selectedArts.size() == 1) {
58 
59  for (BlackboardArtifact nodeArt : selectedArts) {
60 
61  // Only for mismatch results
62  if (nodeArt.getArtifactTypeName().equals("TSK_EXT_MISMATCH_DETECTED")) { //NON-NLS
63  String mimeTypeStr = "";
64  String extStr = "";
65 
66  AbstractFile af = null;
67  try {
68  af = nodeArt.getSleuthkitCase().getAbstractFileById(nodeArt.getObjectID());
69  } catch (TskCoreException ex) {
70  Logger.getLogger(FileExtMismatchContextMenuActionsProvider.class.getName()).log(Level.SEVERE, "Error getting file by id", ex); //NON-NLS
71  }
72 
73  if (af != null) {
74  int i = af.getName().lastIndexOf(".");
75  if ((i > -1) && ((i + 1) < af.getName().length())) {
76  extStr = af.getName().substring(i + 1).toLowerCase();
77  }
78  mimeTypeStr = af.getMIMEType();
79  if(mimeTypeStr == null) {
80  mimeTypeStr = "";
81  }
82 
83  if (!extStr.isEmpty() && !mimeTypeStr.isEmpty()) {
84  // Limit max size so the context window doesn't get ridiculously wide
85  if (extStr.length() > 10) {
86  extStr = extStr.substring(0, 9);
87  }
88  if (mimeTypeStr.length() > 40) {
89  mimeTypeStr = mimeTypeStr.substring(0, 39);
90  }
91  String menuItemStr = NbBundle.getMessage(this.getClass(),
92  "FileExtMismatchContextMenuActionsProvider.menuItemStr",
93  extStr, mimeTypeStr);
94  actions.add(new AddFileExtensionAction(menuItemStr, extStr, mimeTypeStr));
95 
96  // Check if already added
97  HashMap<String, String[]> editableMap = FileExtMismatchXML.getDefault().load();
98  ArrayList<String> editedExtensions = new ArrayList<>(Arrays.asList(editableMap.get(mimeTypeStr)));
99  if (editedExtensions.contains(extStr)) {
100  // Informs the user that they have already added this extension to this MIME type
101  actions.get(0).setEnabled(false);
102  }
103 
104  }
105  }
106  }
107  }
108  }
109  }
110 
111  return actions;
112  }
113 }
static synchronized IngestManager getInstance()
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.