Started updating to standardize using extension set.

This commit is contained in:
Oliver Spohngellert 2016-04-18 12:47:25 -04:00
parent 8cbbd00d15
commit 85b9694659
5 changed files with 37 additions and 43 deletions

View File

@ -19,9 +19,8 @@
package org.sleuthkit.autopsy.modules.fileextmismatch; package org.sleuthkit.autopsy.modules.fileextmismatch;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@ -51,13 +50,13 @@ class AddFileExtensionAction extends AbstractAction {
@Override @Override
@Messages({"AddFileExtensionAction.writeError.message=Could not write file extension settings."}) @Messages({"AddFileExtensionAction.writeError.message=Could not write file extension settings."})
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
HashMap<String, String[]> editableMap; HashMap<String, Set<String>> editableMap;
editableMap = settings.getMimeTypeToExtsMap(); editableMap = settings.getMimeTypeToExtsMap();
ArrayList<String> editedExtensions = new ArrayList<>(Arrays.asList(editableMap.get(mimeTypeStr))); Set<String> editedExtensions = editableMap.get(mimeTypeStr);
editedExtensions.add(extStr); editedExtensions.add(extStr);
// Old array will be replaced by new array for this key // Old array will be replaced by new array for this key
editableMap.put(mimeTypeStr, editedExtensions.toArray(new String[0])); editableMap.put(mimeTypeStr, editedExtensions);
try { try {
FileExtMismatchSettings.writeSettings(new FileExtMismatchSettings(editableMap)); FileExtMismatchSettings.writeSettings(new FileExtMismatchSettings(editableMap));

View File

@ -19,10 +19,10 @@
package org.sleuthkit.autopsy.modules.fileextmismatch; package org.sleuthkit.autopsy.modules.fileextmismatch;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@ -87,12 +87,12 @@ public class FileExtMismatchContextMenuActionsProvider implements ContextMenuAct
extStr, mimeTypeStr); extStr, mimeTypeStr);
// Check if already added // Check if already added
HashMap<String, String[]> editableMap; HashMap<String, Set<String>> editableMap;
try { try {
FileExtMismatchSettings settings = FileExtMismatchSettings.readSettings(); FileExtMismatchSettings settings = FileExtMismatchSettings.readSettings();
editableMap = settings.getMimeTypeToExtsMap(); editableMap = settings.getMimeTypeToExtsMap();
actions.add(new AddFileExtensionAction(menuItemStr, extStr, mimeTypeStr, settings)); actions.add(new AddFileExtensionAction(menuItemStr, extStr, mimeTypeStr, settings));
ArrayList<String> editedExtensions = new ArrayList<>(Arrays.asList(editableMap.get(mimeTypeStr))); Set<String> editedExtensions = editableMap.get(mimeTypeStr);
if (editedExtensions.contains(extStr)) { if (editedExtensions.contains(extStr)) {
// Informs the user that they have already added this extension to this MIME type // Informs the user that they have already added this extension to this MIME type
actions.get(0).setEnabled(false); actions.get(0).setEnabled(false);

View File

@ -18,10 +18,9 @@
*/ */
package org.sleuthkit.autopsy.modules.fileextmismatch; package org.sleuthkit.autopsy.modules.fileextmismatch;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages; import org.openide.util.NbBundle.Messages;
@ -52,7 +51,7 @@ public class FileExtMismatchIngestModule implements FileIngestModule {
private static final Logger logger = Logger.getLogger(FileExtMismatchIngestModule.class.getName()); private static final Logger logger = Logger.getLogger(FileExtMismatchIngestModule.class.getName());
private final IngestServices services = IngestServices.getInstance(); private final IngestServices services = IngestServices.getInstance();
private final FileExtMismatchDetectorModuleSettings settings; private final FileExtMismatchDetectorModuleSettings settings;
private HashMap<String, String[]> mimeTypeToExtsMap = new HashMap<>(); private HashMap<String, Set<String>> mimeTypeToExtsMap = new HashMap<>();
private long jobId; private long jobId;
private static final HashMap<Long, IngestJobTotals> totalsForIngestJobs = new HashMap<>(); private static final HashMap<Long, IngestJobTotals> totalsForIngestJobs = new HashMap<>();
private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter(); private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter();
@ -180,17 +179,13 @@ public class FileExtMismatchIngestModule implements FileIngestModule {
} }
//get known allowed values from the map for this type //get known allowed values from the map for this type
String[] allowedExtArray = mimeTypeToExtsMap.get(currActualSigType); Set<String> allowedExtSet = mimeTypeToExtsMap.get(currActualSigType);
if (allowedExtArray != null) { if (allowedExtSet != null) {
List<String> allowedExtList = Arrays.asList(allowedExtArray);
// see if the filename ext is in the allowed list // see if the filename ext is in the allowed list
if (allowedExtList != null) { for (String e : allowedExtSet) {
for (String e : allowedExtList) {
if (e.equals(currActualExt)) { if (e.equals(currActualExt)) {
return false; return false;
} }
}
return true; //potential mismatch return true; //potential mismatch
} }
} }

View File

@ -23,9 +23,9 @@ import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import org.openide.util.io.NbObjectInputStream; import org.openide.util.io.NbObjectInputStream;
import org.openide.util.io.NbObjectOutputStream; import org.openide.util.io.NbObjectOutputStream;
@ -44,7 +44,7 @@ import org.w3c.dom.NodeList;
class FileExtMismatchSettings implements Serializable { class FileExtMismatchSettings implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private HashMap<String, String[]> mimeTypeToExtsMap; private HashMap<String, Set<String>> mimeTypeToExtsMap;
private static final Logger logger = Logger.getLogger(FileExtMismatchSettings.class.getName()); private static final Logger logger = Logger.getLogger(FileExtMismatchSettings.class.getName());
private static final String SIG_EL = "signature"; //NON-NLS private static final String SIG_EL = "signature"; //NON-NLS
private static final String EXT_EL = "ext"; //NON-NLS private static final String EXT_EL = "ext"; //NON-NLS
@ -68,21 +68,21 @@ class FileExtMismatchSettings implements Serializable {
* *
* @param mimeTypeToExtsMap * @param mimeTypeToExtsMap
*/ */
FileExtMismatchSettings(HashMap<String, String[]> mimeTypeToExtsMap) { FileExtMismatchSettings(HashMap<String, Set<String>> mimeTypeToExtsMap) {
this.mimeTypeToExtsMap = mimeTypeToExtsMap; this.mimeTypeToExtsMap = mimeTypeToExtsMap;
} }
/** /**
* @return the mime type to extension map * @return the mime type to extension map
*/ */
HashMap<String, String[]> getMimeTypeToExtsMap() { HashMap<String, Set<String>> getMimeTypeToExtsMap() {
return mimeTypeToExtsMap; return mimeTypeToExtsMap;
} }
/** /**
* Sets the signature to extension map for this settings. * Sets the signature to extension map for this settings.
*/ */
public void setMimeTypeToExtsMap(HashMap<String, String[]> mimeTypeToExtsMap) { public void setMimeTypeToExtsMap(HashMap<String, Set<String>> mimeTypeToExtsMap) {
this.mimeTypeToExtsMap = mimeTypeToExtsMap; this.mimeTypeToExtsMap = mimeTypeToExtsMap;
} }
@ -113,7 +113,7 @@ class FileExtMismatchSettings implements Serializable {
} }
private static FileExtMismatchSettings readXmlSettings() throws FileExtMismatchSettingsException { private static FileExtMismatchSettings readXmlSettings() throws FileExtMismatchSettingsException {
HashMap<String, String[]> sigTypeToExtMap = new HashMap<>(); HashMap<String, Set<String>> sigTypeToExtMap = new HashMap<>();
//Next tries to read the xml file if the serialized file did not exist //Next tries to read the xml file if the serialized file did not exist
File xmlFile = new File(FILTER_CONFIG_FILE); File xmlFile = new File(FILTER_CONFIG_FILE);
if (xmlFile.exists()) { if (xmlFile.exists()) {
@ -143,13 +143,12 @@ class FileExtMismatchSettings implements Serializable {
final int numExts = extNList.getLength(); final int numExts = extNList.getLength();
if (numExts != 0) { if (numExts != 0) {
List<String> extStrings = new ArrayList<>(); Set<String> extStrings = new HashSet<>();
for (int extIndex = 0; extIndex < numExts; ++extIndex) { for (int extIndex = 0; extIndex < numExts; ++extIndex) {
Element extEl = (Element) extNList.item(extIndex); Element extEl = (Element) extNList.item(extIndex);
extStrings.add(extEl.getTextContent()); extStrings.add(extEl.getTextContent());
} }
String[] sarray = extStrings.toArray(new String[0]); sigTypeToExtMap.put(mimetype, extStrings);
sigTypeToExtMap.put(mimetype, sarray);
} else { } else {
sigTypeToExtMap.put(mimetype, null); //ok to have an empty type (the ingest module will not use it) sigTypeToExtMap.put(mimetype, null); //ok to have an empty type (the ingest module will not use it)
} }

View File

@ -20,19 +20,20 @@ package org.sleuthkit.autopsy.modules.fileextmismatch;
import java.awt.Color; import java.awt.Color;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
import org.sleuthkit.autopsy.ingest.IngestModuleGlobalSettingsPanel;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.corecomponents.OptionsPanel; import org.sleuthkit.autopsy.corecomponents.OptionsPanel;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.ingest.IngestModuleGlobalSettingsPanel;
import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector; import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector;
/** /**
@ -42,7 +43,7 @@ import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector;
final class FileExtMismatchSettingsPanel extends IngestModuleGlobalSettingsPanel implements OptionsPanel { final class FileExtMismatchSettingsPanel extends IngestModuleGlobalSettingsPanel implements OptionsPanel {
private static final Logger logger = Logger.getLogger(FileExtMismatchSettingsPanel.class.getName()); private static final Logger logger = Logger.getLogger(FileExtMismatchSettingsPanel.class.getName());
private HashMap<String, String[]> editableMap = new HashMap<>(); private HashMap<String, Set<String>> editableMap = new HashMap<>();
private ArrayList<String> mimeList = null; private ArrayList<String> mimeList = null;
private ArrayList<String> currentExtensions = null; private ArrayList<String> currentExtensions = null;
private MimeTableModel mimeTableModel; private MimeTableModel mimeTableModel;
@ -382,11 +383,11 @@ final class FileExtMismatchSettingsPanel extends IngestModuleGlobalSettingsPanel
return; return;
} }
ArrayList<String> editedExtensions = new ArrayList<>(Arrays.asList(editableMap.get(selectedMime))); Set<String> editedExtensions = editableMap.get(selectedMime);
editedExtensions.add(newExt); editedExtensions.add(newExt);
// Old array will be replaced by new array for this key // Old array will be replaced by new array for this key
editableMap.put(selectedMime, editedExtensions.toArray(new String[0])); editableMap.put(selectedMime, editedExtensions);
// Refresh table // Refresh table
updateExtList(); updateExtList();
@ -430,7 +431,7 @@ final class FileExtMismatchSettingsPanel extends IngestModuleGlobalSettingsPanel
return; return;
} }
editableMap.put(newMime, new String[0]); editableMap.put(newMime, new HashSet<String>());
// Refresh table // Refresh table
updateMimeList(); updateMimeList();
@ -491,12 +492,12 @@ final class FileExtMismatchSettingsPanel extends IngestModuleGlobalSettingsPanel
return; return;
} }
ArrayList<String> editedExtensions = new ArrayList<>(Arrays.asList(editableMap.get(selectedMime))); Set<String> editedExtensions = editableMap.get(selectedMime);
editedExtensions.remove(selectedExt); editedExtensions.remove(selectedExt);
String deadExt = selectedExt; String deadExt = selectedExt;
// Old array will be replaced by new array for this key // Old array will be replaced by new array for this key
editableMap.put(selectedMime, editedExtensions.toArray(new String[0])); editableMap.put(selectedMime, editedExtensions);
// Refresh tables // Refresh tables
updateExtList(); updateExtList();
@ -517,10 +518,10 @@ final class FileExtMismatchSettingsPanel extends IngestModuleGlobalSettingsPanel
} }
private void updateExtList() { private void updateExtList() {
String[] temp = editableMap.get(selectedMime); Set<String> temp = editableMap.get(selectedMime);
if (temp != null) { if (temp != null) {
currentExtensions = new ArrayList<>(Arrays.asList(temp)); currentExtensions = new ArrayList<>(temp);
if (temp.length > 0) { if (temp.size() > 0) {
Collections.sort(currentExtensions); Collections.sort(currentExtensions);
} }
} else { } else {