Merge pull request #1640 from sleuthkit/file_type_fix

File type fix
This commit is contained in:
Brian Carrier 2015-10-21 12:38:13 -04:00
commit 12f673457a
3 changed files with 79 additions and 46 deletions

View File

@ -117,6 +117,7 @@ final class NewCaseWizardAction extends CallableSystemAction {
AddImageAction addImageAction = SystemAction.get(AddImageAction.class);
addImageAction.actionPerformed(null);
} else {
// @@@ Should we log here?
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.databaseProblem1.text"),
NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.databaseProblem2.text"),
@ -125,6 +126,8 @@ final class NewCaseWizardAction extends CallableSystemAction {
}
} catch (Exception ex) {
logger.log(Level.SEVERE, "Error creating case", ex); //NON-NLS
final String caseName = (String) wizardDescriptor.getProperty("caseName"); //NON-NLS
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(null, NbBundle.getMessage(this.getClass(),

View File

@ -18,6 +18,7 @@
*/
package org.sleuthkit.autopsy.modules.filetypeid;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.logging.Level;
import org.sleuthkit.autopsy.coreutils.Logger;
@ -117,7 +118,6 @@ class FileType {
* The way the signature byte sequence should be interpreted.
*/
enum Type {
RAW, ASCII
};
@ -131,14 +131,42 @@ class FileType {
*
* @param signatureBytes The signature bytes.
* @param offset The offset of the signature bytes.
* @param type The interpretation of the signature bytes
* (e.g., raw bytes, an ASCII string).
* @param type The type of data in the byte array. Impacts
* how it is displayed to the user in the UI.
*/
Signature(final byte[] signatureBytes, long offset, Type type) {
this.signatureBytes = Arrays.copyOf(signatureBytes, signatureBytes.length);
this.offset = offset;
this.type = type;
}
/**
* Creates a file signature consisting of an ASCII string at a
* specific offset within a file.
*
* @param signatureString The ASCII string
* @param offset The offset of the signature bytes.
*/
Signature(String signatureString, long offset) {
this.signatureBytes = signatureString.getBytes(StandardCharsets.US_ASCII);
this.offset = offset;
this.type = Type.ASCII;
}
/**
* Creates a file signature consisting of a sequence of bytes at a
* specific offset within a file. If bytes correspond to an ASCII
* string, use one of the other constructors so that the string is
* displayed to the user instead of the raw bytes.
*
* @param signatureBytes The signature bytes.
* @param offset The offset of the signature bytes.
*/
Signature(final byte[] signatureBytes, long offset) {
this.signatureBytes = Arrays.copyOf(signatureBytes, signatureBytes.length);
this.offset = offset;
this.type = Type.RAW;
}
/**
* Gets the byte sequence of the signature.

View File

@ -183,50 +183,52 @@ final class UserDefinedFileTypesManager {
byte[] byteArray;
FileType fileType;
// Add rule for xml
byteArray = DatatypeConverter.parseHexBinary("3C3F786D6C");
fileType = new FileType("text/xml", new Signature(byteArray, 0L, FileType.Signature.Type.ASCII), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for gzip
byteArray = DatatypeConverter.parseHexBinary("1F8B");
fileType = new FileType("application/x-gzip", new Signature(byteArray, 0L, FileType.Signature.Type.ASCII), "", false); //NON-NLS
try {
// Add rule for xml
fileType = new FileType("text/xml", new Signature("<?xml", 0L), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for .wk1
byteArray = DatatypeConverter.parseHexBinary("0000020006040600080000000000");
fileType = new FileType("application/x-123", new Signature(byteArray, 0L, FileType.Signature.Type.ASCII), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for Radiance image
byteArray = DatatypeConverter.parseHexBinary("233F52414449414E43450A");
fileType = new FileType("image/vnd.radiance", new Signature(byteArray, 0L, FileType.Signature.Type.ASCII), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for .dcx image
byteArray = DatatypeConverter.parseHexBinary("B168DE3A");
fileType = new FileType("image/x-dcx", new Signature(byteArray, 0L, FileType.Signature.Type.ASCII), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for .ics image
byteArray = DatatypeConverter.parseHexBinary("69636E73");
fileType = new FileType("image/x-icns", new Signature(byteArray, 0L, FileType.Signature.Type.ASCII), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for .pict image
byteArray = DatatypeConverter.parseHexBinary("001102FF");
fileType = new FileType("image/x-pict", new Signature(byteArray, 522L, FileType.Signature.Type.ASCII), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for .pam
byteArray = DatatypeConverter.parseHexBinary("P7");
fileType = new FileType("image/x-portable-arbitrarymap", new Signature(byteArray, 0L, FileType.Signature.Type.ASCII), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for .pfm
byteArray = DatatypeConverter.parseHexBinary("PF");
fileType = new FileType("image/x-portable-floatmap", new Signature(byteArray, 0L, FileType.Signature.Type.ASCII), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for gzip
byteArray = DatatypeConverter.parseHexBinary("1F8B"); //NON-NLS
fileType = new FileType("application/x-gzip", new Signature(byteArray, 0L), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for .wk1
byteArray = DatatypeConverter.parseHexBinary("0000020006040600080000000000"); //NON-NLS
fileType = new FileType("application/x-123", new Signature(byteArray, 0L), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for Radiance image
byteArray = DatatypeConverter.parseHexBinary("233F52414449414E43450A");//NON-NLS
fileType = new FileType("image/vnd.radiance", new Signature(byteArray, 0L), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for .dcx image
byteArray = DatatypeConverter.parseHexBinary("B168DE3A"); //NON-NLS
fileType = new FileType("image/x-dcx", new Signature(byteArray, 0L), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for .ics image
fileType = new FileType("image/x-icns", new Signature("icns", 0L), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for .pict image
byteArray = DatatypeConverter.parseHexBinary("001102FF"); //NON-NLS
fileType = new FileType("image/x-pict", new Signature(byteArray, 522L), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for .pam
fileType = new FileType("image/x-portable-arbitrarymap", new Signature("P7", 0L), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
// Add rule for .pfm
fileType = new FileType("image/x-portable-floatmap", new Signature("PF", 0L), "", false); //NON-NLS
fileTypes.put(fileType.getMimeType(), fileType);
}
// parseHexBinary() throws this if the argument passed in is not Hex
catch (IllegalArgumentException e) {
throw new UserDefinedFileTypesException("Error creating predefined file types", e); //
}
}
/**