mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-14 17:06:16 +00:00
Remove optional parameters from MIME types
This commit is contained in:
parent
7a08914b6d
commit
e4f351bf8c
@ -1,11 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* Autopsy Forensic Browser
|
||||||
* To change this template file, choose Tools | Templates
|
*
|
||||||
* and open the template in the editor.
|
* Copyright 2011-2016 Basis Technology Corp.
|
||||||
|
* Contact: carrier <at> sleuthkit <dot> org
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.filesearch;
|
package org.sleuthkit.autopsy.filesearch;
|
||||||
|
|
||||||
import java.beans.PropertyChangeListener;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -14,18 +26,11 @@ import java.util.SortedSet;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import javax.swing.event.ListSelectionEvent;
|
import javax.swing.event.ListSelectionEvent;
|
||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
import org.apache.tika.mime.MediaType;
|
|
||||||
import org.apache.tika.mime.MimeTypes;
|
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector;
|
import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author oliver
|
|
||||||
*/
|
|
||||||
public class MimeTypePanel extends javax.swing.JPanel {
|
public class MimeTypePanel extends javax.swing.JPanel {
|
||||||
|
|
||||||
private static final SortedSet<MediaType> mediaTypes = MimeTypes.getDefaultMimeTypes().getMediaTypeRegistry().getTypes();
|
|
||||||
private static final Logger logger = Logger.getLogger(MimeTypePanel.class.getName());
|
private static final Logger logger = Logger.getLogger(MimeTypePanel.class.getName());
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@ -45,8 +50,8 @@ public class MimeTypePanel extends javax.swing.JPanel {
|
|||||||
|
|
||||||
private String[] getMimeTypeArray() {
|
private String[] getMimeTypeArray() {
|
||||||
Set<String> fileTypesCollated = new HashSet<>();
|
Set<String> fileTypesCollated = new HashSet<>();
|
||||||
for (MediaType mediaType : mediaTypes) {
|
for (String mediaType : FileTypeDetector.getDetectedTypes()) {
|
||||||
fileTypesCollated.add(mediaType.toString());
|
fileTypesCollated.add(mediaType);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileTypeDetector fileTypeDetector;
|
FileTypeDetector fileTypeDetector;
|
||||||
|
@ -19,11 +19,13 @@
|
|||||||
package org.sleuthkit.autopsy.modules.filetypeid;
|
package org.sleuthkit.autopsy.modules.filetypeid;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import org.apache.tika.Tika;
|
import org.apache.tika.Tika;
|
||||||
import org.apache.tika.mime.MediaType;
|
|
||||||
import org.apache.tika.mime.MimeTypes;
|
import org.apache.tika.mime.MimeTypes;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
import org.sleuthkit.autopsy.casemodule.Case;
|
import org.sleuthkit.autopsy.casemodule.Case;
|
||||||
@ -49,6 +51,7 @@ public class FileTypeDetector {
|
|||||||
private final byte buffer[] = new byte[BUFFER_SIZE];
|
private final byte buffer[] = new byte[BUFFER_SIZE];
|
||||||
private final List<FileType> userDefinedFileTypes;
|
private final List<FileType> userDefinedFileTypes;
|
||||||
private final List<FileType> autopsyDefinedFileTypes;
|
private final List<FileType> autopsyDefinedFileTypes;
|
||||||
|
private static SortedSet<String> detectedTypes; //no optional parameters
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an object that detects the MIME type of a file by an
|
* Constructs an object that detects the MIME type of a file by an
|
||||||
@ -100,6 +103,21 @@ public class FileTypeDetector {
|
|||||||
|| isDetectableByTika(mimeType);
|
|| isDetectableByTika(mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an unmodifiable list of MIME types that does not contain types
|
||||||
|
* with optional parameters. The list has no duplicate types and is in
|
||||||
|
* alphabetical order.
|
||||||
|
*
|
||||||
|
* @return an unmodifiable view of a set of MIME types
|
||||||
|
*/
|
||||||
|
public static synchronized SortedSet<String> getDetectedTypes() {
|
||||||
|
if (detectedTypes == null) {
|
||||||
|
detectedTypes = org.apache.tika.mime.MimeTypes.getDefaultMimeTypes().getMediaTypeRegistry().getTypes()
|
||||||
|
.stream().filter(t -> !t.hasParameters()).map(s -> s.toString()).collect(Collectors.toCollection(TreeSet::new));
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableSortedSet(detectedTypes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether or not a given MIME type is detectable as a
|
* Determines whether or not a given MIME type is detectable as a
|
||||||
* user-defined MIME type by this detector.
|
* user-defined MIME type by this detector.
|
||||||
@ -126,15 +144,7 @@ public class FileTypeDetector {
|
|||||||
* @return True or false.
|
* @return True or false.
|
||||||
*/
|
*/
|
||||||
private boolean isDetectableByTika(String mimeType) {
|
private boolean isDetectableByTika(String mimeType) {
|
||||||
String[] split = mimeType.split("/");
|
return this.getDetectedTypes().contains(removeOptionalParameter(mimeType));
|
||||||
if (split.length == 2) {
|
|
||||||
String type = split[0];
|
|
||||||
String subtype = split[1];
|
|
||||||
MediaType mediaType = new MediaType(type, subtype);
|
|
||||||
SortedSet<MediaType> m = MimeTypes.getDefaultMimeTypes().getMediaTypeRegistry().getTypes();
|
|
||||||
return m.contains(mediaType);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -196,7 +206,7 @@ public class FileTypeDetector {
|
|||||||
*/
|
*/
|
||||||
String mimeType = file.getMIMEType();
|
String mimeType = file.getMIMEType();
|
||||||
if (null != mimeType) {
|
if (null != mimeType) {
|
||||||
return mimeType;
|
return removeOptionalParameter(mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -248,6 +258,7 @@ public class FileTypeDetector {
|
|||||||
* Remove the Tika suffix from the MIME type name.
|
* Remove the Tika suffix from the MIME type name.
|
||||||
*/
|
*/
|
||||||
mimeType = tikaType.replace("tika-", ""); //NON-NLS
|
mimeType = tikaType.replace("tika-", ""); //NON-NLS
|
||||||
|
mimeType = removeOptionalParameter(mimeType);
|
||||||
|
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
/*
|
/*
|
||||||
@ -288,6 +299,20 @@ public class FileTypeDetector {
|
|||||||
return mimeType;
|
return mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the optional parameter from a MIME type string
|
||||||
|
* @param mimeType
|
||||||
|
* @return MIME type without the optional parameter
|
||||||
|
*/
|
||||||
|
private String removeOptionalParameter(String mimeType) {
|
||||||
|
int indexOfSemicolon = mimeType.indexOf(";");
|
||||||
|
if (indexOfSemicolon != -1 ) {
|
||||||
|
return mimeType.substring(0, indexOfSemicolon).trim();
|
||||||
|
} else {
|
||||||
|
return mimeType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether or not the a file matches a user-defined custom file
|
* Determines whether or not the a file matches a user-defined custom file
|
||||||
* type.
|
* type.
|
||||||
|
@ -24,9 +24,6 @@ import org.apache.tika.mime.MediaType;
|
|||||||
import org.apache.tika.mime.MimeTypes;
|
import org.apache.tika.mime.MimeTypes;
|
||||||
|
|
||||||
import org.sleuthkit.datamodel.AbstractFile;
|
import org.sleuthkit.datamodel.AbstractFile;
|
||||||
import org.sleuthkit.datamodel.BlackboardArtifact;
|
|
||||||
import org.sleuthkit.datamodel.BlackboardAttribute;
|
|
||||||
import org.sleuthkit.datamodel.TskCoreException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector
|
* @deprecated Use org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector
|
||||||
|
@ -31,8 +31,6 @@ import java.util.regex.PatternSyntaxException;
|
|||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import org.apache.tika.mime.MediaType;
|
|
||||||
import org.apache.tika.mime.MimeTypes;
|
|
||||||
import org.openide.DialogDisplayer;
|
import org.openide.DialogDisplayer;
|
||||||
import org.openide.NotifyDescriptor;
|
import org.openide.NotifyDescriptor;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
@ -58,7 +56,6 @@ final class FilesSetRulePanel extends javax.swing.JPanel {
|
|||||||
"FilesSetRulePanel.ZeroFileSizeError=File size condition value must not be 0 (Unless = is selected)."
|
"FilesSetRulePanel.ZeroFileSizeError=File size condition value must not be 0 (Unless = is selected)."
|
||||||
})
|
})
|
||||||
|
|
||||||
private static final SortedSet<MediaType> mediaTypes = MimeTypes.getDefaultMimeTypes().getMediaTypeRegistry().getTypes();
|
|
||||||
private static final Logger logger = Logger.getLogger(FilesSetRulePanel.class.getName());
|
private static final Logger logger = Logger.getLogger(FilesSetRulePanel.class.getName());
|
||||||
private static final String SLEUTHKIT_PATH_SEPARATOR = "/"; // NON-NLS
|
private static final String SLEUTHKIT_PATH_SEPARATOR = "/"; // NON-NLS
|
||||||
private static final List<String> ILLEGAL_FILE_NAME_CHARS = InterestingItemDefsManager.getIllegalFileNameChars();
|
private static final List<String> ILLEGAL_FILE_NAME_CHARS = InterestingItemDefsManager.getIllegalFileNameChars();
|
||||||
@ -106,8 +103,8 @@ final class FilesSetRulePanel extends javax.swing.JPanel {
|
|||||||
|
|
||||||
private void populateMimeTypesComboBox() {
|
private void populateMimeTypesComboBox() {
|
||||||
Set<String> fileTypesCollated = new HashSet<>();
|
Set<String> fileTypesCollated = new HashSet<>();
|
||||||
for (MediaType mediaType : mediaTypes) {
|
for (String mediaType : FileTypeDetector.getDetectedTypes()) {
|
||||||
fileTypesCollated.add(mediaType.toString());
|
fileTypesCollated.add(mediaType);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileTypeDetector fileTypeDetector;
|
FileTypeDetector fileTypeDetector;
|
||||||
|
@ -34,7 +34,6 @@ import javax.swing.JOptionPane;
|
|||||||
import javax.swing.event.ListSelectionEvent;
|
import javax.swing.event.ListSelectionEvent;
|
||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
import org.apache.tika.mime.MediaType;
|
import org.apache.tika.mime.MediaType;
|
||||||
import org.apache.tika.mime.MimeTypes;
|
|
||||||
import org.netbeans.spi.options.OptionsPanelController;
|
import org.netbeans.spi.options.OptionsPanelController;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
import org.sleuthkit.autopsy.corecomponents.OptionsPanel;
|
import org.sleuthkit.autopsy.corecomponents.OptionsPanel;
|
||||||
@ -57,12 +56,11 @@ final class InterestingItemDefsPanel extends IngestModuleGlobalSettingsPanel imp
|
|||||||
"InterestingItemsDefsPanel.saveError=Error saving interesting files sets to file."
|
"InterestingItemsDefsPanel.saveError=Error saving interesting files sets to file."
|
||||||
})
|
})
|
||||||
|
|
||||||
private static final SortedSet<MediaType> mediaTypes = MimeTypes.getDefaultMimeTypes().getMediaTypeRegistry().getTypes();
|
|
||||||
private final DefaultListModel<FilesSet> setsListModel = new DefaultListModel<>();
|
private final DefaultListModel<FilesSet> setsListModel = new DefaultListModel<>();
|
||||||
private final DefaultListModel<FilesSet.Rule> rulesListModel = new DefaultListModel<>();
|
private final DefaultListModel<FilesSet.Rule> rulesListModel = new DefaultListModel<>();
|
||||||
private final Logger logger = Logger.getLogger(InterestingItemDefsPanel.class.getName());
|
private final Logger logger = Logger.getLogger(InterestingItemDefsPanel.class.getName());
|
||||||
private JButton okButton = new JButton("OK");
|
private final JButton okButton = new JButton("OK");
|
||||||
private JButton cancelButton = new JButton("Cancel");
|
private final JButton cancelButton = new JButton("Cancel");
|
||||||
|
|
||||||
// The following is a map of interesting files set names to interesting
|
// The following is a map of interesting files set names to interesting
|
||||||
// files set definitions. It is a snapshot of the files set definitions
|
// files set definitions. It is a snapshot of the files set definitions
|
||||||
@ -90,8 +88,8 @@ final class InterestingItemDefsPanel extends IngestModuleGlobalSettingsPanel imp
|
|||||||
setName(Bundle.InterestingItemDefsPanel_Title());
|
setName(Bundle.InterestingItemDefsPanel_Title());
|
||||||
|
|
||||||
Set<String> fileTypesCollated = new HashSet<>();
|
Set<String> fileTypesCollated = new HashSet<>();
|
||||||
for (MediaType mediaType : mediaTypes) {
|
for (String mediaType : FileTypeDetector.getDetectedTypes()) {
|
||||||
fileTypesCollated.add(mediaType.toString());
|
fileTypesCollated.add(mediaType);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileTypeDetector fileTypeDetector;
|
FileTypeDetector fileTypeDetector;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user