Autopsy  3.1
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 
20 
21 package org.sleuthkit.autopsy.modules.fileextmismatch;
22 
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.logging.Level;
29 import javax.swing.Action;
30 import org.openide.util.Lookup;
31 import org.openide.util.NbBundle;
32 import org.openide.util.Utilities;
33 import org.openide.util.lookup.ServiceProvider;
41 
46 @ServiceProvider(service = ContextMenuActionsProvider.class)
48  @Override
49  public List<Action> getActions() {
50  ArrayList<Action> actions = new ArrayList<>();
51 
52  // Ignore if file ingest is in progress.
54 
55  final Collection<? extends BlackboardArtifact> selectedArts = Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class);
56 
57  // Prevent multiselect
58  if (selectedArts.size() == 1) {
59 
60  for (BlackboardArtifact nodeArt : selectedArts) {
61 
62  // Only for mismatch results
63  if (nodeArt.getArtifactTypeName().equals("TSK_EXT_MISMATCH_DETECTED")) { //NON-NLS
64  String mimeTypeStr = "";
65  String extStr = "";
66 
67  AbstractFile af = null;
68  try {
69  af = nodeArt.getSleuthkitCase().getAbstractFileById(nodeArt.getObjectID());
70  } catch (TskCoreException ex) {
71  Logger.getLogger(FileExtMismatchContextMenuActionsProvider.class.getName()).log(Level.SEVERE, "Error getting file by id", ex); //NON-NLS
72  }
73 
74  if (af != null) {
75  try {
76  int i = af.getName().lastIndexOf(".");
77  if ((i > -1) && ((i + 1) < af.getName().length())) {
78  extStr = af.getName().substring(i + 1).toLowerCase();
79  }
80 
81  ArrayList<BlackboardArtifact> artList = af.getAllArtifacts();
82  for (BlackboardArtifact art : artList) {
83  List<BlackboardAttribute> atrList = art.getAttributes();
84  for (BlackboardAttribute att : atrList) {
85  if (att.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG.getTypeID()) {
86  mimeTypeStr = att.getValueString();
87  break;
88  }
89  }
90  if (!mimeTypeStr.isEmpty()) {
91  break;
92  }
93  }
94  } catch (TskCoreException ex) {
95  Logger.getLogger(FileExtMismatchContextMenuActionsProvider.class.getName()).log(Level.SEVERE, "Error looking up blackboard attributes", ex); //NON-NLS
96  }
97 
98  if (!extStr.isEmpty() && !mimeTypeStr.isEmpty()) {
99  // Limit max size so the context window doesn't get ridiculously wide
100  if (extStr.length() > 10) {
101  extStr = extStr.substring(0, 9);
102  }
103  if (mimeTypeStr.length() > 40) {
104  mimeTypeStr = mimeTypeStr.substring(0, 39);
105  }
106  String menuItemStr = NbBundle.getMessage(this.getClass(),
107  "FileExtMismatchContextMenuActionsProvider.menuItemStr",
108  extStr, mimeTypeStr);
109  actions.add(new AddFileExtensionAction(menuItemStr, extStr, mimeTypeStr));
110 
111  // Check if already added
112  HashMap<String, String[]> editableMap = FileExtMismatchXML.getDefault().load();
113  ArrayList<String> editedExtensions = new ArrayList<>(Arrays.asList(editableMap.get(mimeTypeStr)));
114  if (editedExtensions.contains(extStr)) {
115  // Informs the user that they have already added this extension to this MIME type
116  actions.get(0).setEnabled(false);
117  }
118 
119  }
120  }
121  }
122  }
123  }
124  }
125 
126  return actions;
127  }
128 }
static synchronized IngestManager getInstance()
ArrayList< BlackboardArtifact > getAllArtifacts()
AbstractFile getAbstractFileById(long id)
static Logger getLogger(String name)
Definition: Logger.java:131

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