2229: Use getOpenCase() instead of getCurrentCase()

This commit is contained in:
U-BASIS\zhaohui 2018-03-09 18:11:01 -05:00
parent 73c97dc2bd
commit 863e3b7a1b
6 changed files with 98 additions and 30 deletions

View File

@ -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<List<? ext
public List<? extends Action> visit(final Image img) {
List<Action> 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<List<? ext
@Override
public List<? extends Action> visit(final Volume vol) {
List<AbstractAction> 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;
}

View File

@ -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();

View File

@ -41,8 +41,8 @@ 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<String> errorMessages = new ArrayList<>();
String moduleName = "";
@ -52,6 +52,12 @@ abstract class 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);

View File

@ -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);

View File

@ -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).

View File

@ -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();
}
@ -409,10 +432,18 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
senderAddressList.addAll(findEmailAddresess(from));
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