diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/ExplorerNodeActionVisitor.java b/Core/src/org/sleuthkit/autopsy/directorytree/ExplorerNodeActionVisitor.java index 583c2aa157..c4def667aa 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/ExplorerNodeActionVisitor.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/ExplorerNodeActionVisitor.java @@ -23,12 +23,15 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; import org.openide.util.NbBundle; import org.openide.util.Utilities; import org.sleuthkit.autopsy.actions.AddContentTagAction; import org.sleuthkit.autopsy.actions.DeleteFileContentTagAction; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.coreutils.ContextMenuExtensionPoint; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.Content; @@ -71,8 +74,12 @@ public class ExplorerNodeActionVisitor extends ContentVisitor.Default visit(final Image img) { List lst = new ArrayList<>(); //TODO lst.add(new ExtractAction("Extract Image", img)); - lst.add(new ExtractUnallocAction( + try { + lst.add(new ExtractUnallocAction( NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.extUnallocToSingleFiles"), img)); + } catch (NoCurrentCaseException ex) { + Logger.getLogger(ExplorerNodeActionVisitor.class.getName()).log(Level.WARNING, "Exception while getting open case.", ex); //NON-NLS + } return lst; } @@ -84,8 +91,12 @@ public class ExplorerNodeActionVisitor extends ContentVisitor.Default visit(final Volume vol) { List lst = new ArrayList<>(); - lst.add(new ExtractUnallocAction( + try { + lst.add(new ExtractUnallocAction( NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.extUnallocToSingleFile"), vol)); + } catch (NoCurrentCaseException ex) { + Logger.getLogger(ExplorerNodeActionVisitor.class.getName()).log(Level.WARNING, "Exception while getting open case.", ex); //NON-NLS + } return lst; } diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java index 1960089075..e288fcb2a2 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java @@ -69,14 +69,14 @@ final class ExtractUnallocAction extends AbstractAction { private long currentImage = 0L; private final boolean isImage; - public ExtractUnallocAction(String title, Volume volume) { + public ExtractUnallocAction(String title, Volume volume) throws NoCurrentCaseException { super(title); isImage = false; OutputFileData outputFileData = new OutputFileData(volume); filesToExtract.add(outputFileData); } - public ExtractUnallocAction(String title, Image image) { + public ExtractUnallocAction(String title, Image image) throws NoCurrentCaseException { super(title); isImage = true; currentImage = image.getId(); @@ -596,14 +596,14 @@ final class ExtractUnallocAction extends AbstractAction { * * @param img Image file to be analyzed */ - OutputFileData(Image img) { + OutputFileData(Image img) throws NoCurrentCaseException { this.layoutFiles = getUnallocFiles(img); Collections.sort(layoutFiles, new SortObjId()); this.volumeId = 0; this.imageId = img.getId(); this.imageName = img.getName(); this.fileName = this.imageName + "-Unalloc-" + this.imageId + "-" + 0 + ".dat"; //NON-NLS - this.fileInstance = new File(Case.getCurrentCase().getExportDirectory() + File.separator + this.fileName); + this.fileInstance = new File(Case.getOpenCase().getExportDirectory() + File.separator + this.fileName); this.sizeInBytes = calcSizeInBytes(); } @@ -612,7 +612,7 @@ final class ExtractUnallocAction extends AbstractAction { * * @param volume Volume file to be analyzed */ - OutputFileData(Volume volume) { + OutputFileData(Volume volume) throws NoCurrentCaseException { try { this.imageName = volume.getDataSource().getName(); this.imageId = volume.getDataSource().getId(); @@ -623,7 +623,7 @@ final class ExtractUnallocAction extends AbstractAction { this.imageId = 0; } this.fileName = this.imageName + "-Unalloc-" + this.imageId + "-" + volumeId + ".dat"; //NON-NLS - this.fileInstance = new File(Case.getCurrentCase().getExportDirectory() + File.separator + this.fileName); + this.fileInstance = new File(Case.getOpenCase().getExportDirectory() + File.separator + this.fileName); this.layoutFiles = getUnallocFiles(volume); Collections.sort(layoutFiles, new SortObjId()); this.sizeInBytes = calcSizeInBytes(); diff --git a/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/Extract.java b/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/Extract.java index 4cb6eaf8e3..403e03c9ed 100644 --- a/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/Extract.java +++ b/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/Extract.java @@ -41,17 +41,23 @@ import org.sleuthkit.datamodel.*; abstract class Extract { - protected Case currentCase = Case.getCurrentCase(); - protected SleuthkitCase tskCase = currentCase.getSleuthkitCase(); + protected Case currentCase; + protected SleuthkitCase tskCase; private final Logger logger = Logger.getLogger(this.getClass().getName()); private final ArrayList errorMessages = new ArrayList<>(); String moduleName = ""; boolean dataFound = false; - Extract() { + Extract() { } void init() throws IngestModuleException { + try { + currentCase = Case.getOpenCase(); + tskCase = currentCase.getSleuthkitCase(); + } catch (NoCurrentCaseException ex) { + throw new IngestModuleException("Exception while getting open case.", ex); + } } abstract void process(Content dataSource, IngestJobContext context); diff --git a/thunderbirdparser/src/org/sleuthkit/autopsy/thunderbirdparser/MboxParser.java b/thunderbirdparser/src/org/sleuthkit/autopsy/thunderbirdparser/MboxParser.java index 77345eb853..bebd365686 100644 --- a/thunderbirdparser/src/org/sleuthkit/autopsy/thunderbirdparser/MboxParser.java +++ b/thunderbirdparser/src/org/sleuthkit/autopsy/thunderbirdparser/MboxParser.java @@ -56,6 +56,7 @@ import org.apache.james.mime4j.stream.MimeConfig; import org.apache.tika.parser.txt.CharsetDetector; import org.apache.tika.parser.txt.CharsetMatch; import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.ingest.IngestServices; import org.sleuthkit.datamodel.TskData; import org.sleuthkit.datamodel.EncodedFileOutputStream; @@ -267,8 +268,18 @@ class MboxParser { * @param email * @param e */ + @NbBundle.Messages ({"MboxParser.handleAttch.noOpenCase.errMsg=Exception while getting open case."}) private void handleAttachment(EmailMessage email, Entity e, long fileID, int index) { - String outputDirPath = ThunderbirdMboxFileIngestModule.getModuleOutputPath() + File.separator; + String outputDirPath; + String relModuleOutputPath; + try { + outputDirPath = ThunderbirdMboxFileIngestModule.getModuleOutputPath() + File.separator; + relModuleOutputPath = ThunderbirdMboxFileIngestModule.getRelModuleOutputPath() + File.separator; + } catch (NoCurrentCaseException ex) { + addErrorMessage(Bundle.MboxParser_handleAttch_noOpenCase_errMsg()); + logger.log(Level.INFO, Bundle.MboxParser_handleAttch_noOpenCase_errMsg(), ex); //NON-NLS + return; + } String filename = e.getFilename(); // sanitize name. Had an attachment with a Japanese encoded path that @@ -325,8 +336,7 @@ class MboxParser { EmailMessage.Attachment attach = new EmailMessage.Attachment(); attach.setName(filename); - attach.setLocalPath(ThunderbirdMboxFileIngestModule.getRelModuleOutputPath() - + File.separator + uniqueFilename); + attach.setLocalPath(relModuleOutputPath + uniqueFilename); attach.setSize(new File(outPath).length()); attach.setEncodingType(TskData.EncodingType.XOR1); email.addAttachment(attach); diff --git a/thunderbirdparser/src/org/sleuthkit/autopsy/thunderbirdparser/PstParser.java b/thunderbirdparser/src/org/sleuthkit/autopsy/thunderbirdparser/PstParser.java index 541415e82b..367e913007 100644 --- a/thunderbirdparser/src/org/sleuthkit/autopsy/thunderbirdparser/PstParser.java +++ b/thunderbirdparser/src/org/sleuthkit/autopsy/thunderbirdparser/PstParser.java @@ -33,6 +33,8 @@ import java.util.List; import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.ingest.IngestModule; import org.sleuthkit.autopsy.ingest.IngestMonitor; import org.sleuthkit.autopsy.ingest.IngestServices; import static org.sleuthkit.autopsy.thunderbirdparser.ThunderbirdMboxFileIngestModule.getRelModuleOutputPath; @@ -206,7 +208,15 @@ class PstParser { */ private void extractAttachments(EmailMessage email, PSTMessage msg, long fileID) { int numberOfAttachments = msg.getNumberOfAttachments(); - String outputDirPath = ThunderbirdMboxFileIngestModule.getModuleOutputPath() + File.separator; + String outputDirPath; + try { + outputDirPath = ThunderbirdMboxFileIngestModule.getModuleOutputPath() + File.separator; + } catch (NoCurrentCaseException ex) { + addErrorMessage( + NbBundle.getMessage(this.getClass(), "PstParser.extractAttch.errMsg.failedToExtractToDisk", + filename)); + logger.log(Level.WARNING, "Failed to extract attachment from pst file.", ex); //NON-NLS + } for (int x = 0; x < numberOfAttachments; x++) { String filename = ""; try { @@ -237,7 +247,7 @@ class PstParser { attachment.setSize(attach.getFilesize()); attachment.setEncodingType(TskData.EncodingType.XOR1); email.addAttachment(attachment); - } catch (PSTException | IOException | NullPointerException ex) { + } catch (PSTException | IOException | NullPointerException | NoCurrentCaseException ex) { /** * Swallowing null pointer as it is caused by a problem with * getting input stream (library problem). diff --git a/thunderbirdparser/src/org/sleuthkit/autopsy/thunderbirdparser/ThunderbirdMboxFileIngestModule.java b/thunderbirdparser/src/org/sleuthkit/autopsy/thunderbirdparser/ThunderbirdMboxFileIngestModule.java index 10dc2d31ce..9215fd3e8b 100644 --- a/thunderbirdparser/src/org/sleuthkit/autopsy/thunderbirdparser/ThunderbirdMboxFileIngestModule.java +++ b/thunderbirdparser/src/org/sleuthkit/autopsy/thunderbirdparser/ThunderbirdMboxFileIngestModule.java @@ -28,9 +28,11 @@ import java.util.Set; import java.util.logging.Level; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.casemodule.services.Blackboard; import org.sleuthkit.autopsy.casemodule.services.FileManager; import org.sleuthkit.autopsy.coreutils.Logger; @@ -76,13 +78,22 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule { @Override public void startUp(IngestJobContext context) throws IngestModuleException { this.context = context; - fileManager = Case.getCurrentCase().getServices().getFileManager(); + try { + fileManager = Case.getOpenCase().getServices().getFileManager(); + } catch (NoCurrentCaseException ex) { + logger.log(Level.SEVERE, "Exception while getting open case.", ex); + } } @Override public ProcessResult process(AbstractFile abstractFile) { - blackboard = Case.getCurrentCase().getServices().getBlackboard(); + try { + blackboard = Case.getOpenCase().getServices().getBlackboard(); + } catch (NoCurrentCaseException ex) { + logger.log(Level.SEVERE, "Exception while getting open case.", ex); + return ProcessResult.ERROR; + } // skip known if (abstractFile.getKnown().equals(TskData.FileKnown.KNOWN)) { @@ -133,8 +144,14 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule { */ @Messages({"ThunderbirdMboxFileIngestModule.processPst.indexError.message=Failed to index encryption detected artifact for keyword search."}) private ProcessResult processPst(AbstractFile abstractFile) { - String fileName = getTempPath() + File.separator + abstractFile.getName() + String fileName; + try { + fileName = getTempPath() + File.separator + abstractFile.getName() + "-" + String.valueOf(abstractFile.getId()); + } catch (NoCurrentCaseException ex) { + logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS + return ProcessResult.ERROR; + } File file = new File(fileName); long freeSpace = services.getFreeDiskSpace(); @@ -225,8 +242,14 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule { emailFolder = emailFolder + mboxFileName; emailFolder = emailFolder.replaceAll(".sbd", ""); //NON-NLS - String fileName = getTempPath() + File.separator + abstractFile.getName() + String fileName; + try { + fileName = getTempPath() + File.separator + abstractFile.getName() + "-" + String.valueOf(abstractFile.getId()); + } catch (NoCurrentCaseException ex) { + logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS + return ProcessResult.ERROR; + } File file = new File(fileName); long freeSpace = services.getFreeDiskSpace(); @@ -270,8 +293,8 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule { * * @return */ - public static String getTempPath() { - String tmpDir = Case.getCurrentCase().getTempDirectory() + File.separator + public static String getTempPath() throws NoCurrentCaseException { + String tmpDir = Case.getOpenCase().getTempDirectory() + File.separator + "EmailParser"; //NON-NLS File dir = new File(tmpDir); if (dir.exists() == false) { @@ -280,8 +303,8 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule { return tmpDir; } - public static String getModuleOutputPath() { - String outDir = Case.getCurrentCase().getModuleDirectory() + File.separator + public static String getModuleOutputPath() throws NoCurrentCaseException { + String outDir = Case.getOpenCase().getModuleDirectory() + File.separator + EmailParserModuleFactory.getModuleName(); File dir = new File(outDir); if (dir.exists() == false) { @@ -290,8 +313,8 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule { return outDir; } - public static String getRelModuleOutputPath() { - return Case.getCurrentCase().getModuleOutputDirectoryRelativePath() + File.separator + public static String getRelModuleOutputPath() throws NoCurrentCaseException { + return Case.getOpenCase().getModuleOutputDirectoryRelativePath() + File.separator + EmailParserModuleFactory.getModuleName(); } @@ -408,11 +431,19 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule { String senderAddress; senderAddressList.addAll(findEmailAddresess(from)); - AccountFileInstance senderAccountInstance = null; + AccountFileInstance senderAccountInstance = null; + + Case openCase; + try { + openCase = Case.getOpenCase(); + } catch (NoCurrentCaseException ex) { + logger.log(Level.WARNING, "Exception while getting open case.", ex); //NON-NLS + return null; + } if (senderAddressList.size() == 1) { senderAddress = senderAddressList.get(0); try { - senderAccountInstance = Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager().createAccountFileInstance(Account.Type.EMAIL, senderAddress, EmailParserModuleFactory.getModuleName(), abstractFile); + senderAccountInstance = openCase.getSleuthkitCase().getCommunicationsManager().createAccountFileInstance(Account.Type.EMAIL, senderAddress, EmailParserModuleFactory.getModuleName(), abstractFile); } catch(TskCoreException ex) { logger.log(Level.WARNING, "Failed to create account for email address " + senderAddress, ex); //NON-NLS @@ -431,7 +462,7 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule { recipientAddresses.forEach((addr) -> { try { AccountFileInstance recipientAccountInstance = - Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager().createAccountFileInstance(Account.Type.EMAIL, addr, + openCase.getSleuthkitCase().getCommunicationsManager().createAccountFileInstance(Account.Type.EMAIL, addr, EmailParserModuleFactory.getModuleName(), abstractFile); recipientAccountInstances.add(recipientAccountInstance); } @@ -467,7 +498,7 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule { bbart.addAttributes(bbattributes); // Add account relationships - Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager().addRelationships(senderAccountInstance, recipientAccountInstances, bbart,Relationship.Type.MESSAGE, dateL); + openCase.getSleuthkitCase().getCommunicationsManager().addRelationships(senderAccountInstance, recipientAccountInstances, bbart,Relationship.Type.MESSAGE, dateL); try { // index the artifact for keyword search