Merge pull request #514 from mrtizmo/sevenZip

Pulled static strings into Bundle - SevenZip module
This commit is contained in:
Richard Cordovano 2014-03-07 14:45:43 -05:00
commit edcc66befc
5 changed files with 83 additions and 27 deletions

View File

@ -15,6 +15,14 @@
<specification-version>1.32.1</specification-version> <specification-version>1.32.1</specification-version>
</run-dependency> </run-dependency>
</dependency> </dependency>
<dependency>
<code-name-base>org.openide.util</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>8.25.1</specification-version>
</run-dependency>
</dependency>
<dependency> <dependency>
<code-name-base>org.sleuthkit.autopsy.core</code-name-base> <code-name-base>org.sleuthkit.autopsy.core</code-name-base>
<build-prerequisite/> <build-prerequisite/>

View File

@ -7,3 +7,25 @@ OpenIDE-Module-Long-Description=\
The module is supported on Windows, Linux and Mac operating systems. The module is supported on Windows, Linux and Mac operating systems.
OpenIDE-Module-Name=SevenZip OpenIDE-Module-Name=SevenZip
OpenIDE-Module-Short-Description=7Zip Ingest Module OpenIDE-Module-Short-Description=7Zip Ingest Module
SevenZipContentReadStream.seek.exception.invalidOrigin=Invalid seek origin\: {0}
SevenZipContentReadStream.read.exception.errReadStream=Error reading content stream.
SevenZipIngestModule.moduleName=Archive Extractor
SevenZipIngestModule.moduleDesc.text=Extracts archive files (zip, rar, arj, 7z, gzip, bzip2, tar), reschedules them to current ingest and populates directory tree with new files.
SevenZipIngestModule.encryptionFileLevel=File-level Encryption
SevenZipIngestModule.encryptionFull=Full Encryption
SevenZipIngestModule.init.errInitModule.msg=Error initializing {0}
SevenZipIngestModule.init.errInitModule.details=Error initializing output dir\: {0}\: {1}
SevenZipIngestModule.init.errCantInitLib=Could not initialize 7-ZIP library\: {0}
SevenZipIngestModule.isZipBombCheck.warnMsg=Possible ZIP bomb detected in archive\: {0}, item\: {1}
SevenZipIngestModule.isZipBombCheck.warnDetails=The archive item compression ratio is {0}, skipping processing of this archive item.
SevenZipIngestModule.unpack.warnMsg.zipBomb=Possible ZIP bomb detected\: {0}
SevenZipIngestModule.unpack.warnDetails.zipBomb=The archive is {0} levels deep, skipping processing of this archive and its contents
SevenZipIngestModule.unpack.unknownPath.msg=Unknown item path in archive\: {0}, will use\: {1}
SevenZipIngestModule.unpack.notEnoughDiskSpace.msg=Not enough disk space to unpack archive item\: {0}, {1}
SevenZipIngestModule.unpack.notEnoughDiskSpace.details=The archive item is too large to unpack, skipping unpacking this item.
SevenZipIngestModule.unpack.errUnpacking.msg=Error unpacking {0}
SevenZipIngestModule.unpack.errUnpacking.details=Error unpacking {0}. {1}
SevenZipIngestModule.unpack.encrFileDetected.msg=Encrypted files in archive detected.
SevenZipIngestModule.unpack.encrFileDetected.details=Some files in archive\: {0} are encrypted. {1} extractor was unable to extract all files from this archive.
SevenZipIngestModule.UnpackStream.write.exception.msg=Error writing unpacked file to\: {0}
SevenZipIngestModule.UnpackedTree.exception.msg=Error adding a derived file to db\:{0}

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import net.sf.sevenzipjbinding.IInStream; import net.sf.sevenzipjbinding.IInStream;
import net.sf.sevenzipjbinding.SevenZipException; import net.sf.sevenzipjbinding.SevenZipException;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.ReadContentInputStream; import org.sleuthkit.datamodel.ReadContentInputStream;
@ -57,7 +58,9 @@ public class SevenZipContentReadStream implements IInStream {
newPosition = wrapped.seek(offset); newPosition = wrapped.seek(offset);
break; break;
default: default:
throw new IllegalArgumentException("Invalid seek origin: " + origin); throw new IllegalArgumentException(
NbBundle.getMessage(this.getClass(), "SevenZipContentReadStream.seek.exception.invalidOrigin",
origin));
} }
return newPosition; return newPosition;
@ -82,7 +85,7 @@ public class SevenZipContentReadStream implements IInStream {
return readBytes; return readBytes;
} catch (IOException ex) { } catch (IOException ex) {
String msg = "Error reading content stream."; String msg = NbBundle.getMessage(this.getClass(), "SevenZipContentReadStream.read.exception.errReadStream");
logger.log(Level.SEVERE, msg, ex); logger.log(Level.SEVERE, msg, ex);
throw new SevenZipException(msg, ex); throw new SevenZipException(msg, ex);
} }

View File

@ -32,6 +32,7 @@ import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import net.sf.sevenzipjbinding.ISequentialOutStream; import net.sf.sevenzipjbinding.ISequentialOutStream;
import net.sf.sevenzipjbinding.ISevenZipInArchive; import net.sf.sevenzipjbinding.ISevenZipInArchive;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.ingest.IngestModuleAbstractFile; import org.sleuthkit.autopsy.ingest.IngestModuleAbstractFile;
import org.sleuthkit.autopsy.ingest.IngestModuleInit; import org.sleuthkit.autopsy.ingest.IngestModuleInit;
@ -69,8 +70,9 @@ import org.sleuthkit.datamodel.TskData;
public final class SevenZipIngestModule extends IngestModuleAbstractFile { public final class SevenZipIngestModule extends IngestModuleAbstractFile {
private static final Logger logger = Logger.getLogger(SevenZipIngestModule.class.getName()); private static final Logger logger = Logger.getLogger(SevenZipIngestModule.class.getName());
public static final String MODULE_NAME = "Archive Extractor"; public static final String MODULE_NAME = NbBundle.getMessage(SevenZipIngestModule.class, "SevenZipIngestModule.moduleName");
public static final String MODULE_DESCRIPTION = "Extracts archive files (zip, rar, arj, 7z, gzip, bzip2, tar), reschedules them to current ingest and populates directory tree with new files."; public static final String MODULE_DESCRIPTION = NbBundle.getMessage(SevenZipIngestModule.class,
"SevenZipIngestModule.moduleDesc.text");
final public static String MODULE_VERSION = Version.getVersion(); final public static String MODULE_VERSION = Version.getVersion();
private IngestServices services; private IngestServices services;
private volatile int messageID = 0; private volatile int messageID = 0;
@ -82,8 +84,10 @@ public final class SevenZipIngestModule extends IngestModuleAbstractFile {
private String unpackDirPath; //absolute, to extract to private String unpackDirPath; //absolute, to extract to
private FileManager fileManager; private FileManager fileManager;
//encryption type strings //encryption type strings
private static final String ENCRYPTION_FILE_LEVEL = "File-level Encryption"; private static final String ENCRYPTION_FILE_LEVEL = NbBundle.getMessage(SevenZipIngestModule.class,
private static final String ENCRYPTION_FULL = "Full Encryption"; "SevenZipIngestModule.encryptionFileLevel");
private static final String ENCRYPTION_FULL = NbBundle.getMessage(SevenZipIngestModule.class,
"SevenZipIngestModule.encryptionFull");
//zip bomb detection //zip bomb detection
private static final int MAX_DEPTH = 4; private static final int MAX_DEPTH = 4;
private static final int MAX_COMPRESSION_RATIO = 600; private static final int MAX_COMPRESSION_RATIO = 600;
@ -130,8 +134,11 @@ public final class SevenZipIngestModule extends IngestModuleAbstractFile {
unpackDirPathFile.mkdirs(); unpackDirPathFile.mkdirs();
} catch (SecurityException e) { } catch (SecurityException e) {
logger.log(Level.SEVERE, "Error initializing output dir: " + unpackDirPath, e); logger.log(Level.SEVERE, "Error initializing output dir: " + unpackDirPath, e);
String msg = "Error initializing " + MODULE_NAME; String msg = NbBundle.getMessage(this.getClass(),
String details = "Error initializing output dir: " + unpackDirPath + ": " + e.getMessage(); "SevenZipIngestModule.init.errInitModule.msg", MODULE_NAME);
String details = NbBundle.getMessage(this.getClass(),
"SevenZipIngestModule.init.errInitModule.details",
unpackDirPath, e.getMessage());
//MessageNotifyUtil.Notify.error(msg, details); //MessageNotifyUtil.Notify.error(msg, details);
services.postMessage(IngestMessage.createErrorMessage(++messageID, instance, msg, details)); services.postMessage(IngestMessage.createErrorMessage(++messageID, instance, msg, details));
throw e; throw e;
@ -144,8 +151,10 @@ public final class SevenZipIngestModule extends IngestModuleAbstractFile {
logger.log(Level.INFO, "7-Zip-JBinding library was initialized on supported platform: " + platform); logger.log(Level.INFO, "7-Zip-JBinding library was initialized on supported platform: " + platform);
} catch (SevenZipNativeInitializationException e) { } catch (SevenZipNativeInitializationException e) {
logger.log(Level.SEVERE, "Error initializing 7-Zip-JBinding library", e); logger.log(Level.SEVERE, "Error initializing 7-Zip-JBinding library", e);
String msg = "Error initializing " + MODULE_NAME; String msg = NbBundle.getMessage(this.getClass(), "SevenZipIngestModule.init.errInitModule.msg",
String details = "Could not initialize 7-ZIP library: " + e.getMessage(); MODULE_NAME);
String details = NbBundle.getMessage(this.getClass(), "SevenZipIngestModule.init.errCantInitLib",
e.getMessage());
//MessageNotifyUtil.Notify.error(msg, details); //MessageNotifyUtil.Notify.error(msg, details);
services.postMessage(IngestMessage.createErrorMessage(++messageID, instance, msg, details)); services.postMessage(IngestMessage.createErrorMessage(++messageID, instance, msg, details));
throw new RuntimeException(e); throw new RuntimeException(e);
@ -274,10 +283,10 @@ public final class SevenZipIngestModule extends IngestModuleAbstractFile {
String itemName = archiveFileItem.getPath(); String itemName = archiveFileItem.getPath();
logger.log(Level.INFO, "Possible zip bomb detected, compression ration: " + cRatio logger.log(Level.INFO, "Possible zip bomb detected, compression ration: " + cRatio
+ " for in archive item: " + itemName); + " for in archive item: " + itemName);
String msg = "Possible ZIP bomb detected in archive: " + archiveName String msg = NbBundle.getMessage(this.getClass(),
+ ", item: " + itemName; "SevenZipIngestModule.isZipBombCheck.warnMsg", archiveName, itemName);
String details = "The archive item compression ratio is " + cRatio String details = NbBundle.getMessage(this.getClass(),
+ ", skipping processing of this archive item. "; "SevenZipIngestModule.isZipBombCheck.warnDetails", cRatio);
//MessageNotifyUtil.Notify.error(msg, details); //MessageNotifyUtil.Notify.error(msg, details);
services.postMessage(IngestMessage.createWarningMessage(++messageID, instance, msg, details)); services.postMessage(IngestMessage.createWarningMessage(++messageID, instance, msg, details));
@ -308,9 +317,11 @@ public final class SevenZipIngestModule extends IngestModuleAbstractFile {
if (parentAr == null) { if (parentAr == null) {
parentAr = archiveDepthCountTree.addArchive(null, archiveId); parentAr = archiveDepthCountTree.addArchive(null, archiveId);
} else if (parentAr.getDepth() == MAX_DEPTH) { } else if (parentAr.getDepth() == MAX_DEPTH) {
String msg = "Possible ZIP bomb detected: " + archiveFile.getName(); String msg = NbBundle.getMessage(this.getClass(),
String details = "The archive is " + parentAr.getDepth() "SevenZipIngestModule.unpack.warnMsg.zipBomb", archiveFile.getName());
+ " levels deep, skipping processing of this archive and its contents "; String details = NbBundle.getMessage(this.getClass(),
"SevenZipIngestModule.unpack.warnDetails.zipBomb",
parentAr.getDepth());
//MessageNotifyUtil.Notify.error(msg, details); //MessageNotifyUtil.Notify.error(msg, details);
services.postMessage(IngestMessage.createWarningMessage(++messageID, instance, msg, details)); services.postMessage(IngestMessage.createWarningMessage(++messageID, instance, msg, details));
return unpackedFiles; return unpackedFiles;
@ -390,7 +401,8 @@ public final class SevenZipIngestModule extends IngestModuleAbstractFile {
extractedPath = "/" + useName; extractedPath = "/" + useName;
} }
String msg = "Unknown item path in archive: " + archiveFile.getName() + ", will use: " + extractedPath; String msg = NbBundle.getMessage(this.getClass(), "SevenZipIngestModule.unpack.unknownPath.msg",
archiveFile.getName(), extractedPath);
logger.log(Level.WARNING, msg); logger.log(Level.WARNING, msg);
} }
@ -432,8 +444,11 @@ public final class SevenZipIngestModule extends IngestModuleAbstractFile {
if (freeDiskSpace != IngestMonitor.DISK_FREE_SPACE_UNKNOWN && size > 0) { //if known free space and file not empty if (freeDiskSpace != IngestMonitor.DISK_FREE_SPACE_UNKNOWN && size > 0) { //if known free space and file not empty
long newDiskSpace = freeDiskSpace - size; long newDiskSpace = freeDiskSpace - size;
if (newDiskSpace < MIN_FREE_DISK_SPACE) { if (newDiskSpace < MIN_FREE_DISK_SPACE) {
String msg = "Not enough disk space to unpack archive item: " + archiveFile.getName() + ", " + fileName; String msg = NbBundle.getMessage(this.getClass(),
String details = "The archive item is too large to unpack, skipping unpacking this item. "; "SevenZipIngestModule.unpack.notEnoughDiskSpace.msg",
archiveFile.getName(), fileName);
String details = NbBundle.getMessage(this.getClass(),
"SevenZipIngestModule.unpack.notEnoughDiskSpace.details");
//MessageNotifyUtil.Notify.error(msg, details); //MessageNotifyUtil.Notify.error(msg, details);
services.postMessage(IngestMessage.createErrorMessage(++messageID, instance, msg, details)); services.postMessage(IngestMessage.createErrorMessage(++messageID, instance, msg, details));
logger.log(Level.INFO, "Skipping archive item due not sufficient disk space for this item: " + archiveFile.getName() + ", " + fileName); logger.log(Level.INFO, "Skipping archive item due not sufficient disk space for this item: " + archiveFile.getName() + ", " + fileName);
@ -528,8 +543,11 @@ public final class SevenZipIngestModule extends IngestModuleAbstractFile {
// print a message if the file is allocated // print a message if the file is allocated
if (archiveFile.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.ALLOC)) { if (archiveFile.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.ALLOC)) {
String msg = "Error unpacking " + archiveFile.getName(); String msg = NbBundle.getMessage(this.getClass(), "SevenZipIngestModule.unpack.errUnpacking.msg",
String details = "Error unpacking " + fullName + ". " + ex.getMessage(); archiveFile.getName());
String details = NbBundle.getMessage(this.getClass(),
"SevenZipIngestModule.unpack.errUnpacking.details",
fullName, ex.getMessage());
services.postMessage(IngestMessage.createErrorMessage(++messageID, instance, msg, details)); services.postMessage(IngestMessage.createErrorMessage(++messageID, instance, msg, details));
} }
} finally { } finally {
@ -565,9 +583,10 @@ public final class SevenZipIngestModule extends IngestModuleAbstractFile {
logger.log(Level.SEVERE, "Error creating blackboard artifact for encryption detected for file: " + archiveFile, ex); logger.log(Level.SEVERE, "Error creating blackboard artifact for encryption detected for file: " + archiveFile, ex);
} }
String msg = "Encrypted files in archive detected. "; String msg = NbBundle.getMessage(this.getClass(), "SevenZipIngestModule.unpack.encrFileDetected.msg");
String details = "Some files in archive: " + archiveFile.getName() + " are encrypted. " String details = NbBundle.getMessage(this.getClass(),
+ MODULE_NAME + " extractor was unable to extract all files from this archive."; "SevenZipIngestModule.unpack.encrFileDetected.details",
archiveFile.getName(), MODULE_NAME);
// MessageNotifyUtil.Notify.info(msg, details); // MessageNotifyUtil.Notify.info(msg, details);
services.postMessage(IngestMessage.createWarningMessage(++messageID, instance, msg, details)); services.postMessage(IngestMessage.createWarningMessage(++messageID, instance, msg, details));
@ -693,7 +712,9 @@ public final class SevenZipIngestModule extends IngestModuleAbstractFile {
try { try {
output.write(bytes); output.write(bytes);
} catch (IOException ex) { } catch (IOException ex) {
throw new SevenZipException("Error writing unpacked file to: " + localAbsPath, ex); throw new SevenZipException(
NbBundle.getMessage(this.getClass(), "SevenZipIngestModule.UnpackStream.write.exception.msg",
localAbsPath), ex);
} }
return bytes.length; return bytes.length;
} }
@ -833,7 +854,9 @@ public final class SevenZipIngestModule extends IngestModuleAbstractFile {
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Error adding a derived file to db:" + fileName, ex); logger.log(Level.SEVERE, "Error adding a derived file to db:" + fileName, ex);
throw new TskCoreException("Error adding a derived file to db:" + fileName, ex); throw new TskCoreException(
NbBundle.getMessage(this.getClass(), "SevenZipIngestModule.UnpackedTree.exception.msg",
fileName), ex);
} }
//recurse //recurse