3632 fix some minor codacy issues

This commit is contained in:
William Schaefer 2018-03-26 12:10:21 -04:00
parent 9ea7051a7f
commit fd5df58908
5 changed files with 33 additions and 29 deletions

View File

@ -103,8 +103,7 @@ public class FileManager implements Closeable {
if (null == caseDb) { if (null == caseDb) {
throw new TskCoreException("File manager has been closed"); throw new TskCoreException("File manager has been closed");
} }
List<AbstractFile> files = caseDb.findAllFilesWhere(createParentPathCondition(dataSourceObjectID,parentPath)); return caseDb.findAllFilesWhere(createParentPathCondition(dataSourceObjectID,parentPath));
return files;
} }
/** /**

View File

@ -51,7 +51,7 @@ import org.sleuthkit.datamodel.TskData.TSK_FS_NAME_FLAG_ENUM;
*/ */
public class FileNode extends AbstractFsContentNode<AbstractFile> { public class FileNode extends AbstractFsContentNode<AbstractFile> {
private static Logger logger = Logger.getLogger(FileNode.class.getName()); private static final Logger logger = Logger.getLogger(FileNode.class.getName());
/** /**
* Gets the path to the icon file that should be used to visually represent * Gets the path to the icon file that should be used to visually represent

View File

@ -328,15 +328,16 @@ public class DataResultFilterNode extends FilterNode {
// filter out all non-message artifacts, if displaying the results from the Data Source tree // filter out all non-message artifacts, if displaying the results from the Data Source tree
BlackboardArtifact art = key.getLookup().lookup(BlackboardArtifact.class); BlackboardArtifact art = key.getLookup().lookup(BlackboardArtifact.class);
if (art != null && filterArtifacts) { if (art != null
if ((art.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()) && filterArtifacts
&& (art.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID())) { && art.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()
return new Node[]{}; && art.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID()) {
} return new Node[]{};
} }
return new Node[]{new DataResultFilterNode(key, sourceEm, filterKnown, filterSlack)}; return new Node[]{new DataResultFilterNode(key, sourceEm, filterKnown, filterSlack)};
} }
} }
@NbBundle.Messages("DataResultFilterNode.viewSourceArtifact.text=View Source Result") @NbBundle.Messages("DataResultFilterNode.viewSourceArtifact.text=View Source Result")
@ -405,10 +406,10 @@ public class DataResultFilterNode extends FilterNode {
} else if ((c = ban.getLookup().lookup(LocalFile.class)) != null } else if ((c = ban.getLookup().lookup(LocalFile.class)) != null
|| (c = ban.getLookup().lookup(DerivedFile.class)) != null) { || (c = ban.getLookup().lookup(DerivedFile.class)) != null) {
n = new LocalFileNode((AbstractFile) c); n = new LocalFileNode((AbstractFile) c);
if (FileTypeExtensions.getArchiveExtensions().contains("." + ((AbstractFile)c).getNameExtension().toLowerCase())) { if (FileTypeExtensions.getArchiveExtensions().contains("." + ((AbstractFile) c).getNameExtension().toLowerCase())) {
try { try {
if (c.getArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED).size() > 0) { if (c.getArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED).size() > 0) {
actionsList.add(new ExtractArchiveWithPasswordAction((AbstractFile)c)); actionsList.add(new ExtractArchiveWithPasswordAction((AbstractFile) c));
} }
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
LOGGER.log(Level.WARNING, "Unable to add unzip with password action to context menus", ex); LOGGER.log(Level.WARNING, "Unable to add unzip with password action to context menus", ex);

View File

@ -144,7 +144,7 @@ public class ExtractArchiveWithPasswordAction extends AbstractAction {
boolean done = false; boolean done = false;
try { try {
done = get(); done = get();
while (done != true) { while (!done) {
password = getPassword(Bundle.ExtractArchiveWithPasswordAction_extractFailed_title(), password); password = getPassword(Bundle.ExtractArchiveWithPasswordAction_extractFailed_title(), password);
if (password == null) { if (password == null) {
//allow them to cancel if they don't know the correct password //allow them to cancel if they don't know the correct password

View File

@ -281,12 +281,11 @@ class SevenZipExtractor {
*/ */
private List<AbstractFile> getAlreadyExtractedFiles(AbstractFile archiveFile, String archiveFilePath) throws TskCoreException, NoCurrentCaseException { private List<AbstractFile> getAlreadyExtractedFiles(AbstractFile archiveFile, String archiveFilePath) throws TskCoreException, NoCurrentCaseException {
//check if already has derived files, skip //check if already has derived files, skip
if (archiveFile.hasChildren()) { //check if local unpacked dir exists
//check if local unpacked dir exists if (archiveFile.hasChildren() && new File(moduleDirAbsolute, EmbeddedFileExtractorIngestModule.getUniqueName(archiveFile)).exists()) {
if (new File(moduleDirAbsolute, EmbeddedFileExtractorIngestModule.getUniqueName(archiveFile)).exists()) { return Case.getOpenCase().getServices().getFileManager().findFilesByParentPath(getRootArchiveId(archiveFile), archiveFilePath);
return Case.getOpenCase().getServices().getFileManager().findFilesByParentPath(getRootArchiveId(archiveFile), archiveFilePath);
}
} }
return new ArrayList<>(); return new ArrayList<>();
} }
@ -368,8 +367,10 @@ class SevenZipExtractor {
pathInArchive = "/" + archName + "/" + Integer.toString(itemNumber); pathInArchive = "/" + archName + "/" + Integer.toString(itemNumber);
} else { } else {
pathInArchive = "/" + useName; pathInArchive = "/" + useName;
} }
String msg = NbBundle.getMessage(SevenZipExtractor.class, "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.unknownPath.msg", String msg = NbBundle.getMessage(SevenZipExtractor.class,
"EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.unknownPath.msg",
getArchiveFilePath(archiveFile), pathInArchive); getArchiveFilePath(archiveFile), pathInArchive);
logger.log(Level.WARNING, msg); logger.log(Level.WARNING, msg);
} }
@ -518,6 +519,7 @@ class SevenZipExtractor {
parentAr = archiveDepthCountTree.findArchive(archiveId); parentAr = archiveDepthCountTree.findArchive(archiveId);
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 = NbBundle.getMessage(SevenZipExtractor.class, String msg = NbBundle.getMessage(SevenZipExtractor.class,
"EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.warnMsg.zipBomb", archiveFile.getName()); "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.warnMsg.zipBomb", archiveFile.getName());
@ -562,12 +564,11 @@ class SevenZipExtractor {
long freeDiskSpace; long freeDiskSpace;
try { try {
freeDiskSpace = services.getFreeDiskSpace(); freeDiskSpace = services.getFreeDiskSpace();
} } catch (NullPointerException ex) {
catch(NullPointerException ex) {
//If ingest has not been run at least once getFreeDiskSpace() will throw a null pointer exception //If ingest has not been run at least once getFreeDiskSpace() will throw a null pointer exception
//currently getFreeDiskSpace always returns DISK_FREE_SPACE_UNKNOWN //currently getFreeDiskSpace always returns DISK_FREE_SPACE_UNKNOWN
freeDiskSpace = IngestMonitor.DISK_FREE_SPACE_UNKNOWN; freeDiskSpace = IngestMonitor.DISK_FREE_SPACE_UNKNOWN;
} }
//unpack and process every item in archive //unpack and process every item in archive
int itemNumber = 0; int itemNumber = 0;
@ -602,6 +603,7 @@ class SevenZipExtractor {
//this is additional to zip bomb prevention mechanism //this is additional to zip bomb prevention mechanism
if (freeDiskSpace != IngestMonitor.DISK_FREE_SPACE_UNKNOWN && item.getSize() != null && item.getSize() > 0) { //if free space is known and file is not empty. if (freeDiskSpace != IngestMonitor.DISK_FREE_SPACE_UNKNOWN && item.getSize() != null && item.getSize() > 0) { //if free space is known and file is not empty.
long newDiskSpace = freeDiskSpace - item.getSize(); long newDiskSpace = freeDiskSpace - item.getSize();
if (newDiskSpace < MIN_FREE_DISK_SPACE) { if (newDiskSpace < MIN_FREE_DISK_SPACE) {
String msg = NbBundle.getMessage(SevenZipExtractor.class, String msg = NbBundle.getMessage(SevenZipExtractor.class,
"EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.notEnoughDiskSpace.msg", "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.notEnoughDiskSpace.msg",
@ -681,7 +683,8 @@ class SevenZipExtractor {
// 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 = NbBundle.getMessage(SevenZipExtractor.class, "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.errUnpacking.msg", String msg = NbBundle.getMessage(SevenZipExtractor.class,
"EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.errUnpacking.msg",
archiveFile.getName()); archiveFile.getName());
String details = NbBundle.getMessage(SevenZipExtractor.class, String details = NbBundle.getMessage(SevenZipExtractor.class,
"EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.errUnpacking.details", "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.errUnpacking.details",
@ -730,9 +733,11 @@ class SevenZipExtractor {
services.fireModuleDataEvent(new ModuleDataEvent(EmbeddedFileExtractorModuleFactory.getModuleName(), BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED)); services.fireModuleDataEvent(new ModuleDataEvent(EmbeddedFileExtractorModuleFactory.getModuleName(), BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED));
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Error creating blackboard artifact for encryption detected for file: " + escapedArchiveFilePath, ex); //NON-NLS logger.log(Level.SEVERE, "Error creating blackboard artifact for encryption detected for file: " + escapedArchiveFilePath, ex); //NON-NLS
} }
String msg = NbBundle.getMessage(SevenZipExtractor.class, "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.encrFileDetected.msg"); String msg = NbBundle.getMessage(SevenZipExtractor.class,
"EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.encrFileDetected.msg");
String details = NbBundle.getMessage(SevenZipExtractor.class, String details = NbBundle.getMessage(SevenZipExtractor.class,
"EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.encrFileDetected.details", "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.encrFileDetected.details",
archiveFile.getName(), EmbeddedFileExtractorModuleFactory.getModuleName()); archiveFile.getName(), EmbeddedFileExtractorModuleFactory.getModuleName());
@ -748,6 +753,7 @@ class SevenZipExtractor {
} }
} }
return unpackSuccessful; return unpackSuccessful;
} }
/** /**
@ -1028,17 +1034,15 @@ class SevenZipExtractor {
statusMap.put(getKeyAbstractFile(df), new ZipFileStatusWrapper(df, ZipFileStatus.EXISTS)); statusMap.put(getKeyAbstractFile(df), new ZipFileStatusWrapper(df, ZipFileStatus.EXISTS));
} else { } else {
String key = getKeyAbstractFile(existingFile.getFile()); String key = getKeyAbstractFile(existingFile.getFile());
if (existingFile.getStatus() == ZipFileStatus.EXISTS) { if (existingFile.getStatus() == ZipFileStatus.EXISTS && existingFile.getFile().getSize() < node.getSize()) {
if (existingFile.getFile().getSize() < node.getSize()) { existingFile.setStatus(ZipFileStatus.UPDATE);
existingFile.setStatus(ZipFileStatus.UPDATE); statusMap.put(key, existingFile);
statusMap.put(key, existingFile);
}
} }
if (existingFile.getStatus() == ZipFileStatus.UPDATE) { if (existingFile.getStatus() == ZipFileStatus.UPDATE) {
//if the we are updating a file and its mime type was octet-stream we want to re-type it //if the we are updating a file and its mime type was octet-stream we want to re-type it
String mimeType = existingFile.getFile().getMIMEType().equalsIgnoreCase("application/octet-stream") ? null : existingFile.getFile().getMIMEType(); String mimeType = existingFile.getFile().getMIMEType().equalsIgnoreCase("application/octet-stream") ? null : existingFile.getFile().getMIMEType();
df = fileManager.updateDerivedFile((DerivedFile) existingFile.getFile(), node.getLocalRelPath(), node.getSize(), df = fileManager.updateDerivedFile((DerivedFile) existingFile.getFile(), node.getLocalRelPath(), node.getSize(),
node.getCtime(), node.getCrtime(), node.getAtime(), node.getMtime(), node.getCtime(), node.getCrtime(), node.getAtime(), node.getMtime(),
node.isIsFile(), mimeType, "", EmbeddedFileExtractorModuleFactory.getModuleName(), node.isIsFile(), mimeType, "", EmbeddedFileExtractorModuleFactory.getModuleName(),
"", "", TskData.EncodingType.XOR1); "", "", TskData.EncodingType.XOR1);
} else { } else {