Merge pull request #2707 from wschaeferB/2431-WellFormedCustomTypes-4.4.0

2431 well formed custom types 4.4.0
This commit is contained in:
Richard Cordovano 2017-04-18 09:29:42 -04:00 committed by GitHub
commit f44da3d1bb
4 changed files with 61 additions and 23 deletions

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2016 Basis Technology Corp.
* Copyright 2011-2017 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -29,6 +29,8 @@ import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children;
@ -147,13 +149,13 @@ public final class FileTypesByMimeType extends Observable implements AutopsyVisi
final String mime_type = resultSet.getString("mime_type"); //NON-NLS
if (!mime_type.isEmpty()) {
String mimeType[] = mime_type.split("/");
//Note: Users are able to define custom mime types in Autopsy that do not
//contain a "/" or possibly have multiple slashes
if (mimeType.length > 1 && !mimeType[0].isEmpty() && !mimeType[1].isEmpty()) {
//if the mime_type contained multiple slashes then everything after the first slash will become the subtype
final String mimeMediaSubType = StringUtils.join(ArrayUtils.subarray(mimeType, 1, mimeType.length), "/");
if (mimeType.length > 1 && !mimeType[0].isEmpty() && !mimeMediaSubType.isEmpty()) {
if (!existingMimeTypes.containsKey(mimeType[0])) {
existingMimeTypes.put(mimeType[0], new ArrayList<>());
}
existingMimeTypes.get(mimeType[0]).add(mimeType[1]);
existingMimeTypes.get(mimeType[0]).add(mimeMediaSubType);
}
}
}
@ -356,10 +358,10 @@ public final class FileTypesByMimeType extends Observable implements AutopsyVisi
* results
*/
private void updateDisplayName(String mimeType) {
final long count = new MediaSubTypeNodeChildren(mimeType).calculateItems(skCase, mimeType);
super.setDisplayName(mimeType.split("/")[1] + " (" + count + ")");
String[] mimeTypeParts = mimeType.split("/");
//joins up all remaining parts of the mimeType into one sub-type string
super.setDisplayName(StringUtils.join(ArrayUtils.subarray(mimeTypeParts, 1, mimeTypeParts.length), "/") + " (" + count + ")");
}
/**

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2016 Basis Technology Corp.
* Copyright 2011-2017 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -170,9 +170,9 @@ class AddFileTypeDialog extends JDialog {
*/
private void doButtonAction(boolean okPressed) {
if (okPressed) {
FileType fileType = addMimeTypePanel.getFileType();
if (fileType != null) {
this.fileType = fileType;
FileType fType = addMimeTypePanel.getFileType();
if (fType != null) {
this.fileType = fType;
this.result = BUTTON_PRESSED.OK;
setVisible(false);
}

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2016 Basis Technology Corp.
* Copyright 2011-2017 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -24,11 +24,14 @@ import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
import static org.sleuthkit.autopsy.modules.filetypeid.AddFileTypePanel.EVENT.SIG_LIST_CHANGED;
import org.sleuthkit.autopsy.modules.filetypeid.AddFileTypeSignatureDialog.BUTTON_PRESSED;
import org.sleuthkit.autopsy.modules.filetypeid.FileType.Signature;
@Messages("AddFileTypePanel.mimeFormatLabel.text=Form of MIME type should be: media type/media subtype")
/**
@ -89,11 +92,18 @@ class AddFileTypePanel extends javax.swing.JPanel {
"AddMimeTypePanel.emptySigList.title=Invalid Signature List",
"AddMimeTypePanel.emptySetName.message=Interesting files set name is required if alert is requested.",
"AddMimeTypePanel.emptySetName.title=Missing Interesting Files Set Name",
"# {0} - media subtype",
"AddFileTypePanel.nonStandardMIMEType.message="
+ "Files of this MIME type will not appear under the Views, File Types, By MIME Type tree because it is not in the format of: media type/media subtype",
+ "MIME type must be of form: media type/media subtype. Custom/{0} has been suggested instead.",
"# {0} - type name",
"AddFileTypePanel.containsIllegalCharacter.message=Invalid character in MIME type, {0} has been suggested instead",
"AddFileTypePanel.containsIllegalCharacter.title=Invalid Character in MIME Type",
"AddFileTypePanel.nonStandardMIMEType.title=Non-standard MIME Type"})
FileType getFileType() {
String typeName = mimeTypeTextField.getText();
//if typeName does not equal sanitized typeName display message saying this name will be used instead
if (typeName.isEmpty()) {
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "FileTypeIdGlobalSettingsPanel.JOptionPane.invalidMIMEType.message"),
@ -101,18 +111,44 @@ class AddFileTypePanel extends javax.swing.JPanel {
JOptionPane.ERROR_MESSAGE);
return null;
}
if (typeName.split("/").length != 2) {
//if we need to remove more characters could use matches instead of contains and regex "[^\\w\s\\-\\/] to remove everything that isnt a letter, number, underscore, whitespace, dash, or forward slash.
if (typeName.contains("\'")) { //remove single apostraphes as they are an easy way to accidently screw up PostgreSQL
typeName = typeName.replaceAll("[\\']", "");
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "AddFileTypePanel.nonStandardMIMEType.message"),
NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "AddFileTypePanel.containsIllegalCharacter.message", typeName),
NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "AddFileTypePanel.containsIllegalCharacter.title"),
JOptionPane.WARNING_MESSAGE);
mimeTypeTextField.setText(typeName);
return null;
}
//if the MIME type is lacking two parts or the first part is empty ask if they want to use 'custom' as the first part
//if the MIME type has more than 2 parts the first part will be used as a media type and the remainder of the string as the sub-type
String[] splitName = typeName.split("/");
if (splitName.length < 2 || splitName[0].isEmpty()) {
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "AddFileTypePanel.nonStandardMIMEType.message", typeName),
NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "AddFileTypePanel.nonStandardMIMEType.title"),
JOptionPane.WARNING_MESSAGE);
mimeTypeTextField.setText("custom/" + typeName);
return null;
}
//Make sure the mimetype will piece back together to be the same string it was entered
//trailing forward slashes will cause this mismatch to happen
//suggests a mime_type that will be the same after it is split appart and rejoined
if (!StringUtils.join(ArrayUtils.subarray(splitName, 0, splitName.length), "/").equals(typeName)) {
String rejoinedMimeType = StringUtils.join(ArrayUtils.subarray(splitName, 0, splitName.length), "/");
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "AddFileTypePanel.nonStandardMIMEType.message", rejoinedMimeType),
NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "AddFileTypePanel.nonStandardMIMEType.title"),
JOptionPane.WARNING_MESSAGE);
mimeTypeTextField.setText(rejoinedMimeType);
return null;
}
if (this.signaturesListModel.isEmpty()) {
JOptionPane.showMessageDialog(null,
Bundle.AddMimeTypePanel_emptySigList_message(),
Bundle.AddMimeTypePanel_emptySigList_title(),
JOptionPane.ERROR_MESSAGE);
return null;
}
List<Signature> sigList = new ArrayList<>();

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2014 Basis Technology Corp.
* Copyright 2011-2017 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");