Autopsy  4.16.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 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.modules.fileextmismatch;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Set;
26 import java.util.logging.Level;
27 import javax.swing.Action;
28 import javax.swing.JOptionPane;
29 import org.openide.util.NbBundle;
30 import org.openide.util.Utilities;
31 import org.openide.util.lookup.ServiceProvider;
32 import org.openide.windows.WindowManager;
36 import org.sleuthkit.datamodel.AbstractFile;
37 import org.sleuthkit.datamodel.BlackboardArtifact;
38 
43 @ServiceProvider(service = ContextMenuActionsProvider.class)
45  private static final Logger logger = Logger.getLogger(FileExtMismatchContextMenuActionsProvider.class.getName());
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 = Utilities.actionsGlobalContext().lookup(AbstractFile.class);
67 
68  if (af != null) {
69  int i = af.getName().lastIndexOf(".");
70  if ((i > -1) && ((i + 1) < af.getName().length())) {
71  extStr = af.getName().substring(i + 1).toLowerCase();
72  }
73  mimeTypeStr = af.getMIMEType();
74  if (mimeTypeStr == null) {
75  mimeTypeStr = "";
76  }
77 
78  if (!extStr.isEmpty() && !mimeTypeStr.isEmpty()) {
79  // Limit max size so the context window doesn't get ridiculously wide
80  if (extStr.length() > 10) {
81  extStr = extStr.substring(0, 9);
82  }
83  if (mimeTypeStr.length() > 40) {
84  mimeTypeStr = mimeTypeStr.substring(0, 39);
85  }
86  String menuItemStr = NbBundle.getMessage(this.getClass(),
87  "FileExtMismatchContextMenuActionsProvider.menuItemStr",
88  extStr, mimeTypeStr);
89 
90  // Check if already added
91  HashMap<String, Set<String>> editableMap;
92  try {
93  FileExtMismatchSettings settings = FileExtMismatchSettings.readSettings();
94  editableMap = settings.getMimeTypeToExtsMap();
95  actions.add(new AddFileExtensionAction(menuItemStr, extStr, mimeTypeStr, settings));
96  Set<String> editedExtensions = editableMap.get(mimeTypeStr);
97  if (editedExtensions.contains(extStr)) {
98  // Informs the user that they have already added this extension to this MIME type
99  actions.get(0).setEnabled(false);
100  }
101  } catch (FileExtMismatchSettings.FileExtMismatchSettingsException ex) {
102  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
103  NbBundle.getMessage(this.getClass(), "AddFileExtensionAction.msgDlg.msg2"),
104  NbBundle.getMessage(this.getClass(), "AddFileExtensionAction.msgDlg.title"),
105  JOptionPane.ERROR_MESSAGE);
106  logger.log(Level.WARNING, "File extension mismatch settings could not be read, extensions update not available.", ex);
107  }
108  }
109  }
110  }
111  }
112  }
113  }
114 
115  return actions;
116  }
117 }
static synchronized IngestManager getInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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