mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 18:17:43 +00:00
Improve user-defined file types (incomplete)
This commit is contained in:
parent
c413aae377
commit
552d1039fb
@ -25,6 +25,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.logging.Level;
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
@ -155,6 +156,7 @@ public class XMLUtil {
|
||||
* @param xmlPath the full path to the file to load
|
||||
* @param xsdPath the full path to the file to validate against
|
||||
*/
|
||||
// RJCTODO: Deprecate
|
||||
public static <T> Document loadDoc(Class<T> clazz, String xmlPath, String xsdPath) {
|
||||
Document ret = loadDoc(clazz, xmlPath);
|
||||
if (!XMLUtil.xmlIsValid(ret, clazz, xsdPath)) {
|
||||
@ -163,6 +165,51 @@ public class XMLUtil {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to consolidate more specific exception types.
|
||||
*/
|
||||
public static class XmlUtilException extends Exception {
|
||||
|
||||
XmlUtilException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and validates an XML document.
|
||||
*
|
||||
* @param docPath The full path to the file to load.
|
||||
* @param schemaPath The full path to the file to validate against.
|
||||
*/
|
||||
/**
|
||||
* Loads and XML document and validates against a schema packaged as a
|
||||
* class resource.
|
||||
*
|
||||
* @param <T> The name of the class associated with the resource.
|
||||
* @param clazz The class associated with the resource.
|
||||
* @param docPath The full path to the XML document.
|
||||
* @param schemaResourceName The name of the schema resource
|
||||
* @return A WC3 DOM representation of the document
|
||||
* @throws IOException
|
||||
* @throws org.sleuthkit.autopsy.coreutils.XMLUtil.XmlUtilException
|
||||
*/
|
||||
public static <T> Document loadAndValidateDoc(Class<T> clazz, String docPath, String schemaResourceName) throws IOException, XmlUtilException {
|
||||
try {
|
||||
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = builderFactory.newDocumentBuilder();
|
||||
Document doc = builder.parse(new FileInputStream(docPath));
|
||||
PlatformUtil.extractResourceToUserConfigDir(clazz, schemaResourceName, false);
|
||||
File schemaFile = new File(Paths.get(PlatformUtil.getUserConfigDirectory(), schemaResourceName).toAbsolutePath().toString());
|
||||
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
Schema schema = schemaFactory.newSchema(schemaFile);
|
||||
Validator validator = schema.newValidator();
|
||||
validator.validate(new DOMSource(doc), new DOMResult());
|
||||
return doc;
|
||||
} catch (ParserConfigurationException | SAXException ex) {
|
||||
throw new XmlUtilException(ex.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves XML files to disk
|
||||
*
|
||||
@ -203,4 +250,5 @@ public class XMLUtil {
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ FileTypeIdGlobalSettingsPanel.jTextArea1.text=Enter a MIME type and signature to
|
||||
FileTypeIdGlobalSettingsPanel.signatureTypeLabel.text=Signature Type
|
||||
FileTypeIdGlobalSettingsPanel.mimeTypeTextField.text=
|
||||
FileTypeIdGlobalSettingsPanel.signatureLabel.text=Signature
|
||||
FileTypeIdGlobalSettingsPanel.mimeTypeLabel.text=Mime Type
|
||||
FileTypeIdGlobalSettingsPanel.mimeTypeLabel.text=MIME Type
|
||||
FileTypeIdGlobalSettingsPanel.saveTypeButton.text=Save Type
|
||||
FileTypeIdGlobalSettingsPanel.signatureComboBox.rawItem=Bytes (Hex)
|
||||
FileTypeIdGlobalSettingsPanel.signatureComboBox.asciiItem=String (ASCII)
|
||||
@ -30,4 +30,6 @@ FileTypeIdGlobalSettingsPanel.JOptionPane.invalidSignature.title=Missing Signatu
|
||||
FileTypeIdGlobalSettingsPanel.JOptionPane.invalidOffset.message=Offset must be a positive integer.
|
||||
FileTypeIdGlobalSettingsPanel.JOptionPane.invalidOffset.title=Invalid Offset
|
||||
FileTypeIdGlobalSettingsPanel.JOptionPane.invalidSignatureBytes.message=The signature must be able to be converted to UTF-8 bytes.
|
||||
FileTypeIdGlobalSettingsPanel.JOptionPane.invalidSignatureBytes.title=Invalid Signature
|
||||
FileTypeIdGlobalSettingsPanel.JOptionPane.invalidSignatureBytes.title=Invalid Signature
|
||||
FileTypeIdGlobalSettingsPanel.filesSetNameLabel.text=Files Set Name
|
||||
FileTypeIdGlobalSettingsPanel.filesSetNameTextField.text=
|
||||
|
@ -29,32 +29,35 @@ import org.sleuthkit.datamodel.TskCoreException;
|
||||
*/
|
||||
final class FileType {
|
||||
|
||||
private final String typeName;
|
||||
private final String mimeType;
|
||||
private final Signature signature;
|
||||
private final String filesSetName;
|
||||
private final boolean alert;
|
||||
|
||||
/**
|
||||
* Creates a representation of a named file type characterized by a file
|
||||
* signature.
|
||||
*
|
||||
* @param typeName The name of the file type.
|
||||
* @param mimeType The mime type to associate with this file type.
|
||||
* @param signature The signature that characterizes the file type.
|
||||
* @param filesSetName The interesting files set name
|
||||
* @param alert A flag indicating whether the user wishes to be alerted when
|
||||
* a file matching this type is encountered.
|
||||
*/
|
||||
FileType(String typeName, final Signature signature, boolean alert) {
|
||||
this.typeName = typeName;
|
||||
FileType(String mimeType, final Signature signature, String filesSetName, boolean alert) {
|
||||
this.mimeType = mimeType;
|
||||
this.signature = new Signature(signature.getSignatureBytes(), signature.getOffset(), signature.getType());
|
||||
this.filesSetName = filesSetName;
|
||||
this.alert = alert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name associated with this file type.
|
||||
* Gets the MIME type associated with this file type.
|
||||
*
|
||||
* @return The type name.
|
||||
*/
|
||||
String getTypeName() {
|
||||
return this.typeName;
|
||||
String getMimeType() {
|
||||
return this.mimeType;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,6 +88,14 @@ final class FileType {
|
||||
boolean alertOnMatch() {
|
||||
return this.alert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the interesting files set name assigned to this file type
|
||||
* @return
|
||||
*/
|
||||
String getFilesSetName() {
|
||||
return this.filesSetName;
|
||||
}
|
||||
|
||||
/**
|
||||
* A file signature consisting of a sequence of bytes at a specific offset
|
||||
|
@ -20,115 +20,107 @@
|
||||
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace min="-2" pref="10" max="-2" attributes="0"/>
|
||||
<Component id="typesScrollPane" pref="0" max="32767" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
<Component id="newTypeButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="deleteTypeButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="9" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="typesScrollPane" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="jSeparator1" min="-2" pref="13" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="37" max="-2" attributes="0"/>
|
||||
<Component id="saveTypeButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="18" max="-2" attributes="0"/>
|
||||
<Component id="jSeparator1" min="-2" pref="13" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" max="-2" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="signatureTypeLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="signatureTypeComboBox" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="signatureLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="hexPrefixLabel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="offsetLabel" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="16" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="offsetTextField" min="-2" pref="84" max="-2" attributes="0"/>
|
||||
<Component id="signatureTextField" min="-2" pref="178" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="2" max="-2" attributes="0"/>
|
||||
<Component id="mimeTypeLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="mimeTypeTextField" min="-2" pref="181" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="103" alignment="0" groupAlignment="1" max="-2" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="signatureTypeLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="signatureTypeComboBox" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="offsetLabel" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="filesSetNameLabel" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="signatureLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="hexPrefixLabel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane2" min="-2" pref="260" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="postHitCheckBox" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="5" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="offsetTextField" min="-2" pref="84" max="-2" attributes="0"/>
|
||||
<Component id="signatureTextField" min="-2" pref="178" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="2" max="-2" attributes="0"/>
|
||||
<Component id="mimeTypeLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="mimeTypeTextField" min="-2" pref="181" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="filesSetNameTextField" alignment="1" min="-2" pref="179" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="jScrollPane2" alignment="0" min="-2" pref="260" max="-2" attributes="0"/>
|
||||
<Component id="postHitCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="saveTypeButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<EmptySpace pref="29" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="16" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="16" pref="16" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Component id="jSeparator1" min="-2" pref="281" max="-2" attributes="0"/>
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="typesScrollPane" min="-2" pref="219" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jScrollPane2" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="mimeTypeLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="mimeTypeTextField" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="signatureTypeLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="signatureTypeComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="signatureTextField" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="hexPrefixLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="signatureLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="offsetTextField" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="offsetLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="postHitCheckBox" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Component id="jScrollPane2" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="newTypeButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="deleteTypeButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="saveTypeButton" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="mimeTypeLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="mimeTypeTextField" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="signatureTypeLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="signatureTypeComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="signatureTextField" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="hexPrefixLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="signatureLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="offsetTextField" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="offsetLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="postHitCheckBox" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="8" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="filesSetNameLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="filesSetNameTextField" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="saveTypeButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="typesScrollPane" min="-2" pref="249" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="deleteTypeButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="newTypeButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Component id="jSeparator1" min="-2" pref="260" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
@ -284,6 +276,23 @@
|
||||
<ResourceString bundle="org/sleuthkit/autopsy/modules/filetypeid/Bundle.properties" key="FileTypeIdGlobalSettingsPanel.postHitCheckBox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="postHitCheckBoxActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="filesSetNameLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
|
||||
<ResourceString bundle="org/sleuthkit/autopsy/modules/filetypeid/Bundle.properties" key="FileTypeIdGlobalSettingsPanel.filesSetNameLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="filesSetNameTextField">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
|
||||
<ResourceString bundle="org/sleuthkit/autopsy/modules/filetypeid/Bundle.properties" key="FileTypeIdGlobalSettingsPanel.filesSetNameTextField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -87,6 +87,8 @@ final class FileTypeIdGlobalSettingsPanel extends IngestModuleGlobalSettingsPane
|
||||
sigTypeComboBoxModel.addElement(FileTypeIdGlobalSettingsPanel.RAW_SIGNATURE_TYPE_COMBO_BOX_ITEM);
|
||||
sigTypeComboBoxModel.addElement(FileTypeIdGlobalSettingsPanel.ASCII_SIGNATURE_TYPE_COMBO_BOX_ITEM);
|
||||
this.signatureTypeComboBox.setModel(sigTypeComboBoxModel);
|
||||
|
||||
this.filesSetNameTextField.setEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,6 +216,8 @@ final class FileTypeIdGlobalSettingsPanel extends IngestModuleGlobalSettingsPane
|
||||
jScrollPane2 = new javax.swing.JScrollPane();
|
||||
jTextArea1 = new javax.swing.JTextArea();
|
||||
postHitCheckBox = new javax.swing.JCheckBox();
|
||||
filesSetNameLabel = new javax.swing.JLabel();
|
||||
filesSetNameTextField = new javax.swing.JTextField();
|
||||
|
||||
typesScrollPane.setViewportView(typesList);
|
||||
|
||||
@ -266,6 +270,15 @@ final class FileTypeIdGlobalSettingsPanel extends IngestModuleGlobalSettingsPane
|
||||
jScrollPane2.setViewportView(jTextArea1);
|
||||
|
||||
org.openide.awt.Mnemonics.setLocalizedText(postHitCheckBox, org.openide.util.NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "FileTypeIdGlobalSettingsPanel.postHitCheckBox.text")); // NOI18N
|
||||
postHitCheckBox.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
postHitCheckBoxActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
org.openide.awt.Mnemonics.setLocalizedText(filesSetNameLabel, org.openide.util.NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "FileTypeIdGlobalSettingsPanel.filesSetNameLabel.text")); // NOI18N
|
||||
|
||||
filesSetNameTextField.setText(org.openide.util.NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "FileTypeIdGlobalSettingsPanel.filesSetNameTextField.text")); // NOI18N
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
@ -275,93 +288,85 @@ final class FileTypeIdGlobalSettingsPanel extends IngestModuleGlobalSettingsPane
|
||||
.addGap(26, 26, 26)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(10, 10, 10)
|
||||
.addComponent(typesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addComponent(newTypeButton)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(deleteTypeButton))
|
||||
.addComponent(typesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
|
||||
.addComponent(deleteTypeButton)
|
||||
.addGap(9, 9, 9)))
|
||||
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(37, 37, 37)
|
||||
.addComponent(saveTypeButton))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
|
||||
.addComponent(signatureTypeLabel)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(signatureTypeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(signatureLabel)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(hexPrefixLabel)
|
||||
.addGap(2, 2, 2))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(offsetLabel)
|
||||
.addGap(44, 44, 44)))
|
||||
.addGap(5, 5, 5)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(offsetTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(signatureTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
|
||||
.addGap(2, 2, 2)
|
||||
.addComponent(mimeTypeLabel)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(mimeTypeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(6, 6, 6)
|
||||
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(postHitCheckBox)))))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
|
||||
.addComponent(signatureTypeLabel)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(signatureTypeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(offsetLabel)
|
||||
.addComponent(filesSetNameLabel)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(signatureLabel)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(hexPrefixLabel)))
|
||||
.addGap(5, 5, 5)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(offsetTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(signatureTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
|
||||
.addGap(2, 2, 2)
|
||||
.addComponent(mimeTypeLabel)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(mimeTypeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(filesSetNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(postHitCheckBox)
|
||||
.addComponent(saveTypeButton))
|
||||
.addContainerGap(29, Short.MAX_VALUE))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(16, 16, 16)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(typesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
|
||||
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(mimeTypeLabel)
|
||||
.addComponent(mimeTypeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(signatureTypeLabel)
|
||||
.addComponent(signatureTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(signatureTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(hexPrefixLabel)
|
||||
.addComponent(signatureLabel))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(offsetTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(offsetLabel))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(postHitCheckBox)))
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(newTypeButton)
|
||||
.addComponent(deleteTypeButton)))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(saveTypeButton))))
|
||||
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap())
|
||||
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(mimeTypeLabel)
|
||||
.addComponent(mimeTypeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(signatureTypeLabel)
|
||||
.addComponent(signatureTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(signatureTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(hexPrefixLabel)
|
||||
.addComponent(signatureLabel))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(offsetTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(offsetLabel))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(postHitCheckBox)
|
||||
.addGap(8, 8, 8)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(filesSetNameLabel)
|
||||
.addComponent(filesSetNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(saveTypeButton))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(typesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(deleteTypeButton)
|
||||
.addComponent(newTypeButton))))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
@ -419,14 +424,25 @@ final class FileTypeIdGlobalSettingsPanel extends IngestModuleGlobalSettingsPane
|
||||
*/
|
||||
long offset = Long.parseUnsignedLong(this.offsetTextField.getText());
|
||||
|
||||
/**
|
||||
* Get the interesting files set details.
|
||||
*/
|
||||
String filesSetName = this.filesSetNameTextField.getText();
|
||||
if (this.postHitCheckBox.isSelected() && filesSetName.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "FileTypeIdGlobalSettingsPanel.JOptionPane.invalidOffset.message"),
|
||||
NbBundle.getMessage(FileTypeIdGlobalSettingsPanel.class, "FileTypeIdGlobalSettingsPanel.JOptionPane.invalidOffset.title"),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put it all together and reset the file types list component.
|
||||
*/
|
||||
FileType.Signature signature = new FileType.Signature(signatureBytes, offset, sigType); // RJCTODO:
|
||||
FileType fileType = new FileType(typeName, signature, this.postHitCheckBox.isSelected());
|
||||
FileType fileType = new FileType(typeName, signature, filesSetName, this.postHitCheckBox.isSelected());
|
||||
this.fileTypes.put(typeName, fileType);
|
||||
this.setFileTypesListModel();
|
||||
this.typesList.setSelectedValue(fileType.getTypeName(), true);
|
||||
this.typesList.setSelectedValue(fileType.getMimeType(), true);
|
||||
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
@ -441,9 +457,15 @@ final class FileTypeIdGlobalSettingsPanel extends IngestModuleGlobalSettingsPane
|
||||
}
|
||||
}//GEN-LAST:event_saveTypeButtonActionPerformed
|
||||
|
||||
private void postHitCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_postHitCheckBoxActionPerformed
|
||||
this.filesSetNameTextField.setEnabled(this.postHitCheckBox.isSelected());
|
||||
}//GEN-LAST:event_postHitCheckBoxActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton deleteTypeButton;
|
||||
private javax.swing.JLabel filesSetNameLabel;
|
||||
private javax.swing.JTextField filesSetNameTextField;
|
||||
private javax.swing.JLabel hexPrefixLabel;
|
||||
private javax.swing.JScrollPane jScrollPane2;
|
||||
private javax.swing.JSeparator jSeparator1;
|
||||
|
@ -30,11 +30,18 @@
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="filesSetType">
|
||||
<xs:sequence>
|
||||
<xs:element name="name" type="xs:string"/>
|
||||
<xs:attribute name="alert" type="xs:boolean"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="fileType">
|
||||
<xs:sequence>
|
||||
<xs:element name="typename" type="verbatimStringType"/>
|
||||
<xs:element name="mimetype" type="verbatimStringType"/>
|
||||
<xs:element name="signature" type="signatureType"/>
|
||||
<xs:attribute name="alert" type="xs:boolean"/>
|
||||
<xs:element name="filesset" type="filesSetType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
|
@ -41,8 +41,8 @@ import org.sleuthkit.autopsy.modules.filetypeid.FileType.Signature;
|
||||
import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager;
|
||||
|
||||
/**
|
||||
* Manages user-defined file types characterized by type names (e.g., MIME type)
|
||||
* and signatures.
|
||||
* Manages user-defined file types characterized by MIME type, signature, and
|
||||
* optional membership in an interesting files set.
|
||||
*/
|
||||
final class UserDefinedFileTypesManager {
|
||||
|
||||
@ -51,19 +51,20 @@ final class UserDefinedFileTypesManager {
|
||||
private static final String USER_DEFINED_TYPE_DEFINITIONS_FILE = "UserFileTypeDefinitions.xml"; //NON-NLS
|
||||
private static final String FILE_TYPES_TAG_NAME = "filetypes"; //NON-NLS
|
||||
private static final String FILE_TYPE_TAG_NAME = "filetype"; //NON-NLS
|
||||
private static final String ALERT_ATTRIBUTE = "alert"; //NON-NLS
|
||||
private static final String TYPE_NAME_TAG_NAME = "typename"; //NON-NLS
|
||||
private static final String MIME_TYPE_TAG_NAME = "mimetype"; //NON-NLS
|
||||
private static final String SIGNATURE_TAG_NAME = "signature"; //NON-NLS
|
||||
private static final String SIGNATURE_TYPE_ATTRIBUTE = "type"; //NON-NLS
|
||||
private static final String BYTES_TAG_NAME = "bytes"; //NON-NLS
|
||||
private static final String OFFSET_TAG_NAME = "offset"; //NON-NLS
|
||||
private static final String INTERESTING_FILES_SET_TAG_NAME = "filesset"; //NON-NLS
|
||||
private static final String ALERT_ATTRIBUTE = "alert"; //NON-NLS
|
||||
private static final String ENCODING_FOR_XML_FILE = "UTF-8"; //NON-NLS
|
||||
private static final String ASCII_ENCODING = "US-ASCII"; //NON-NLS
|
||||
private static UserDefinedFileTypesManager instance;
|
||||
|
||||
/**
|
||||
* Predefined file types are stored in this mapping of file type names to
|
||||
* file types. Access to this map is guarded by the intrinsic lock of the
|
||||
* Predefined file types are stored in this mapping of MIME types to file
|
||||
* types. Access to this map is guarded by the intrinsic lock of the
|
||||
* user-defined file types manager for thread-safety.
|
||||
*/
|
||||
private final Map<String, FileType> predefinedFileTypes = new HashMap<>();
|
||||
@ -78,17 +79,18 @@ final class UserDefinedFileTypesManager {
|
||||
|
||||
/**
|
||||
* The combined set of user-defined file types and file types predefined by
|
||||
* Autopsy are stored in this mapping of file type names to file types. This
|
||||
* is the current working set of file types. Access to this map is guarded
|
||||
* by the intrinsic lock of the user-defined file types manager for
|
||||
* Autopsy are stored in this mapping of MIME types to file types. This is
|
||||
* the current working set of file types. Access to this map is guarded by
|
||||
* the intrinsic lock of the user-defined file types manager for
|
||||
* thread-safety.
|
||||
*/
|
||||
private final Map<String, FileType> fileTypes = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Gets the user-defined file types manager.
|
||||
* Gets the manager of user-defined file types characterized by MIME type,
|
||||
* signature, and optional membership in an interesting files set.
|
||||
*
|
||||
* @return A singleton user-defined file types manager.
|
||||
* @return The user-defined file types manager singleton.
|
||||
*/
|
||||
synchronized static UserDefinedFileTypesManager getInstance() {
|
||||
if (UserDefinedFileTypesManager.instance == null) {
|
||||
@ -98,8 +100,8 @@ final class UserDefinedFileTypesManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a manager of user-defined file types characterized by type names
|
||||
* (e.g., MIME type) and signatures.
|
||||
* Creates a manager of user-defined file types characterized by MIME type,
|
||||
* signature, and optional membership in an interesting files set.
|
||||
*/
|
||||
private UserDefinedFileTypesManager() {
|
||||
/**
|
||||
@ -111,30 +113,30 @@ final class UserDefinedFileTypesManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds standard predefined file types to the in-memory mapping of file type
|
||||
* names to predefined file types.
|
||||
* Adds the predefined file types to the in-memory mappings of MIME types to
|
||||
* file types.
|
||||
*/
|
||||
private void loadPredefinedFileTypes() {
|
||||
// RJCTODO: Remove test type
|
||||
// RJCTODO: Remove test file type.
|
||||
/**
|
||||
* Create a file type that should match $MBR in Small2 image.
|
||||
*/
|
||||
FileType fileType = new FileType("predefinedRAW", new Signature(new byte[]{(byte) 0x66, (byte) 0x73, (byte) 0x00}, 8L, FileType.Signature.Type.RAW), true);
|
||||
FileType fileType = new FileType("predefinedRAW", new Signature(new byte[]{(byte) 0x66, (byte) 0x73, (byte) 0x00}, 8L, FileType.Signature.Type.RAW), "predefinedRAW", true);
|
||||
this.addPredefinedFileType(fileType);
|
||||
|
||||
/**
|
||||
* Create a file type that should match test.txt in the Small2 image.
|
||||
*/
|
||||
// RJCTODO: Remove test type
|
||||
// RJCTODO: Remove test file type.
|
||||
try {
|
||||
fileType = new FileType("predefinedASCII", new Signature("hello".getBytes(UserDefinedFileTypesManager.ASCII_ENCODING), 0L, FileType.Signature.Type.ASCII), true);
|
||||
fileType = new FileType("predefinedASCII", new Signature("hello".getBytes(UserDefinedFileTypesManager.ASCII_ENCODING), 0L, FileType.Signature.Type.ASCII), "predefinedASCII", true);
|
||||
this.addPredefinedFileType(fileType);
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
UserDefinedFileTypesManager.logger.log(Level.SEVERE, "Unable to create 'predefinedASCII' predefined file type definition", ex); //NON-NLS
|
||||
}
|
||||
|
||||
try {
|
||||
// RJCTODO: Remove this code from TikaFileTypeDetector.java
|
||||
// RJCTODO: Remove this code from TikaFileTypeDetector.java.
|
||||
// try {
|
||||
// byte buf[];
|
||||
// int len = abstractFile.read(buffer, 0, BUFFER_SIZE);
|
||||
@ -156,7 +158,7 @@ final class UserDefinedFileTypesManager {
|
||||
// catch (IndexOutOfBoundsException e) {
|
||||
// // do nothing
|
||||
// }
|
||||
fileType = new FileType("text/xml", new Signature("<?xml".getBytes(UserDefinedFileTypesManager.ASCII_ENCODING), 0L, FileType.Signature.Type.ASCII), false);
|
||||
fileType = new FileType("text/xml", new Signature("<?xml".getBytes(UserDefinedFileTypesManager.ASCII_ENCODING), 0L, FileType.Signature.Type.ASCII), "", false);
|
||||
this.addPredefinedFileType(fileType);
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
/**
|
||||
@ -174,13 +176,13 @@ final class UserDefinedFileTypesManager {
|
||||
* @param fileType The file type to add.
|
||||
*/
|
||||
private void addPredefinedFileType(FileType fileType) {
|
||||
this.predefinedFileTypes.put(fileType.getTypeName(), fileType);
|
||||
this.fileTypes.put(fileType.getTypeName(), fileType);
|
||||
this.predefinedFileTypes.put(fileType.getMimeType(), fileType);
|
||||
this.fileTypes.put(fileType.getMimeType(), fileType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads user-defined file types into an in-memory mapping of file type
|
||||
* names to file types.
|
||||
* Adds the user-defined file types to the in-memory mappings of MIME types
|
||||
* to file types.
|
||||
*/
|
||||
private void loadUserDefinedFileTypes() {
|
||||
try {
|
||||
@ -209,8 +211,8 @@ final class UserDefinedFileTypesManager {
|
||||
* @param fileType The file type to add.
|
||||
*/
|
||||
private void addUserDefinedFileType(FileType fileType) {
|
||||
this.userDefinedFileTypes.put(fileType.getTypeName(), fileType);
|
||||
this.fileTypes.put(fileType.getTypeName(), fileType);
|
||||
this.userDefinedFileTypes.put(fileType.getMimeType(), fileType);
|
||||
this.fileTypes.put(fileType.getMimeType(), fileType);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,8 +244,8 @@ final class UserDefinedFileTypesManager {
|
||||
/**
|
||||
* Sets the user-defined file types.
|
||||
*
|
||||
* @param newFileTypes A mapping of file type names to user-defined
|
||||
* file types.
|
||||
* @param newFileTypes A mapping of file type names to user-defined file
|
||||
* types.
|
||||
* @throws
|
||||
* org.sleuthkit.autopsy.modules.filetypeid.UserDefinedFileTypesManager.UserDefinedFileTypesException
|
||||
*/
|
||||
@ -324,16 +326,15 @@ final class UserDefinedFileTypesManager {
|
||||
*/
|
||||
private static Element createFileTypeElement(FileType fileType, Document doc) {
|
||||
/**
|
||||
* Create a file type element with an alert attribute.
|
||||
* Create a file type element.
|
||||
*/
|
||||
Element fileTypeElem = doc.createElement(UserDefinedFileTypesManager.FILE_TYPE_TAG_NAME);
|
||||
fileTypeElem.setAttribute(UserDefinedFileTypesManager.ALERT_ATTRIBUTE, Boolean.toString(fileType.alertOnMatch()));
|
||||
|
||||
/**
|
||||
* Add a type name child element.
|
||||
* Add a MIME type name child element.
|
||||
*/
|
||||
Element typeNameElem = doc.createElement(UserDefinedFileTypesManager.TYPE_NAME_TAG_NAME);
|
||||
typeNameElem.setTextContent(fileType.getTypeName());
|
||||
Element typeNameElem = doc.createElement(UserDefinedFileTypesManager.MIME_TYPE_TAG_NAME);
|
||||
typeNameElem.setTextContent(fileType.getMimeType());
|
||||
fileTypeElem.appendChild(typeNameElem);
|
||||
|
||||
/**
|
||||
@ -358,6 +359,14 @@ final class UserDefinedFileTypesManager {
|
||||
offsetElem.setTextContent(DatatypeConverter.printLong(signature.getOffset()));
|
||||
signatureElem.appendChild(offsetElem);
|
||||
|
||||
/**
|
||||
* Add a files set child element with an alert attribute.
|
||||
*/
|
||||
Element filesSetElem = doc.createElement(UserDefinedFileTypesManager.INTERESTING_FILES_SET_TAG_NAME);
|
||||
filesSetElem.setTextContent(fileType.getFilesSetName());
|
||||
filesSetElem.setAttribute(UserDefinedFileTypesManager.ALERT_ATTRIBUTE, Boolean.toString(fileType.alertOnMatch()));
|
||||
fileTypeElem.appendChild(filesSetElem);
|
||||
|
||||
return fileTypeElem;
|
||||
}
|
||||
}
|
||||
@ -380,7 +389,7 @@ final class UserDefinedFileTypesManager {
|
||||
String xsdPathString = xsdPath.toAbsolutePath().toString();
|
||||
File file = new File(xsdPathString);
|
||||
if (file.exists() && file.canRead()) {
|
||||
Document doc = XMLUtil.loadDoc(UserDefinedFileTypesManager.XMLReader.class, filePath, xsdPathString);
|
||||
Document doc = XMLUtil.loadAndValidateDoc(UserDefinedFileTypesManager.XMLReader.class, filePath, xsdPathString);
|
||||
if (doc != null) {
|
||||
Element fileTypesElem = doc.getDocumentElement();
|
||||
if (fileTypesElem != null && fileTypesElem.getNodeName().equals(UserDefinedFileTypesManager.FILE_TYPES_TAG_NAME)) {
|
||||
@ -401,26 +410,26 @@ final class UserDefinedFileTypesManager {
|
||||
*
|
||||
* @param fileTypeElem The XML element.
|
||||
* @return A file type object.
|
||||
* @throws UserDefinedFileTypesException
|
||||
* @throws
|
||||
* org.sleuthkit.autopsy.modules.filetypeid.UserDefinedFileTypesManager.InvalidXMLException
|
||||
*/
|
||||
private static FileType parseFileType(Element fileTypeElem) throws InvalidXMLException {
|
||||
private static FileType parseFileType(Element fileTypeElem) throws InvalidXMLException, IllegalArgumentException, NumberFormatException {
|
||||
/**
|
||||
* Get the alert attribute.
|
||||
* Get the mime type child element.
|
||||
*/
|
||||
String alertAttribute = fileTypeElem.getAttribute(UserDefinedFileTypesManager.ALERT_ATTRIBUTE);
|
||||
boolean alert = Boolean.parseBoolean(alertAttribute);
|
||||
String mimeType = UserDefinedFileTypesManager.getChildElementTextContent(fileTypeElem, UserDefinedFileTypesManager.MIME_TYPE_TAG_NAME);
|
||||
|
||||
/**
|
||||
* Get the type name child element.
|
||||
* Get the signature child element. The check here is essentially a
|
||||
* "sanity check" since the XML was already validated using the XSD
|
||||
* file.
|
||||
*/
|
||||
String typeName = UserDefinedFileTypesManager.getChildElementTextContent(fileTypeElem, UserDefinedFileTypesManager.TYPE_NAME_TAG_NAME);
|
||||
|
||||
/**
|
||||
* Get the signature child element.
|
||||
*/
|
||||
Element signatureElem;
|
||||
NodeList signatureElems = fileTypeElem.getElementsByTagName(UserDefinedFileTypesManager.SIGNATURE_TAG_NAME);
|
||||
signatureElem = (Element) signatureElems.item(0);
|
||||
if (signatureElems.getLength() < 1) {
|
||||
} else {
|
||||
throw new InvalidXMLException("Missing " + UserDefinedFileTypesManager.SIGNATURE_TAG_NAME + " child element"); //NON-NLS
|
||||
}
|
||||
Element signatureElem = (Element) signatureElems.item(0);
|
||||
|
||||
/**
|
||||
* Get the signature (interpretation) type attribute from the
|
||||
@ -432,7 +441,7 @@ final class UserDefinedFileTypesManager {
|
||||
/**
|
||||
* Get the signature bytes.
|
||||
*/
|
||||
String sigBytesString = UserDefinedFileTypesManager.getChildElementTextContent(signatureElem, UserDefinedFileTypesManager.TYPE_NAME_TAG_NAME);
|
||||
String sigBytesString = UserDefinedFileTypesManager.getChildElementTextContent(signatureElem, UserDefinedFileTypesManager.BYTES_TAG_NAME);
|
||||
byte[] signatureBytes = DatatypeConverter.parseHexBinary(sigBytesString);
|
||||
|
||||
/**
|
||||
@ -441,11 +450,24 @@ final class UserDefinedFileTypesManager {
|
||||
String offsetString = UserDefinedFileTypesManager.getChildElementTextContent(signatureElem, UserDefinedFileTypesManager.OFFSET_TAG_NAME);
|
||||
long offset = DatatypeConverter.parseLong(offsetString);
|
||||
|
||||
/**
|
||||
* Get the interesting files set element.
|
||||
*/
|
||||
NodeList filesSetElems = fileTypeElem.getElementsByTagName(UserDefinedFileTypesManager.INTERESTING_FILES_SET_TAG_NAME);
|
||||
Element filesSetElem = (Element) filesSetElems.item(0);
|
||||
String filesSetName = filesSetElem.getTextContent();
|
||||
|
||||
/**
|
||||
* Get the alert attribute from the interesting files set element.
|
||||
*/
|
||||
String alertAttribute = filesSetElem.getAttribute(UserDefinedFileTypesManager.ALERT_ATTRIBUTE);
|
||||
boolean alert = Boolean.parseBoolean(alertAttribute);
|
||||
|
||||
/**
|
||||
* Put it all together.
|
||||
*/
|
||||
Signature signature = new Signature(signatureBytes, offset, signatureType);
|
||||
return new FileType(typeName, signature, alert);
|
||||
return new FileType(mimeType, signature, filesSetName, alert);
|
||||
}
|
||||
}
|
||||
|
||||
@ -469,10 +491,10 @@ final class UserDefinedFileTypesManager {
|
||||
if (!textContent.isEmpty()) {
|
||||
return textContent;
|
||||
} else {
|
||||
throw new InvalidXMLException("File type " + tagName + " child element missing text content"); //NON-NLS
|
||||
throw new InvalidXMLException(tagName + " child element missing text content"); //NON-NLS
|
||||
}
|
||||
} else {
|
||||
throw new InvalidXMLException("File type element missing " + tagName + " child element"); //NON-NLS
|
||||
throw new InvalidXMLException("Missing " + tagName + " child element"); //NON-NLS
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user