From d409ddeda1f57e600cf4756f12d6ba5e8fe5e220 Mon Sep 17 00:00:00 2001 From: "U-BASIS\\zhaohui" Date: Mon, 5 Mar 2018 14:28:19 -0500 Subject: [PATCH] 2229: Part 22: Use getOpenCase() instead of getCurrentCase() in ingest and modules. --- .../autopsy/ingest/DataSourceIngestJob.java | 9 +++++---- .../events/DataSourceAnalysisEvent.java | 7 ++++--- .../FileExtMismatchIngestModule.java | 10 ++++++++-- .../autopsy/modules/iOS/ContactAnalyzer.java | 19 +++++++++++++------ .../autopsy/modules/stix/EvalAddressObj.java | 12 ++++++++++-- .../autopsy/modules/stix/EvalDomainObj.java | 13 ++++++++++--- .../autopsy/modules/stix/EvalURIObj.java | 13 +++++++++++-- 7 files changed, 61 insertions(+), 22 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/ingest/DataSourceIngestJob.java b/Core/src/org/sleuthkit/autopsy/ingest/DataSourceIngestJob.java index 568e410de6..7cddb8028b 100644 --- a/Core/src/org/sleuthkit/autopsy/ingest/DataSourceIngestJob.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/DataSourceIngestJob.java @@ -34,6 +34,7 @@ import org.openide.util.Cancellable; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.NetworkUtils; import org.sleuthkit.datamodel.AbstractFile; @@ -254,12 +255,12 @@ final class DataSourceIngestJob { */ Thread.currentThread().interrupt(); } - SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase(); try { + SleuthkitCase skCase = Case.getOpenCase().getSleuthkitCase(); this.addIngestModules(firstStageDataSourceModuleTemplates, IngestModuleType.DATA_SOURCE_LEVEL, skCase); this.addIngestModules(fileIngestModuleTemplates, IngestModuleType.FILE_LEVEL, skCase); this.addIngestModules(secondStageDataSourceModuleTemplates, IngestModuleType.DATA_SOURCE_LEVEL, skCase); - } catch (TskCoreException ex) { + } catch (TskCoreException | NoCurrentCaseException ex) { logger.log(Level.SEVERE, "Failed to add ingest modules to database.", ex); } } @@ -400,8 +401,8 @@ final class DataSourceIngestJob { this.startSecondStage(); } try { - this.ingestJob = Case.getCurrentCase().getSleuthkitCase().addIngestJob(dataSource, NetworkUtils.getLocalHostName(), ingestModules, new Date(this.createTime), new Date(0), IngestJobStatusType.STARTED, ""); - } catch (TskCoreException ex) { + this.ingestJob = Case.getOpenCase().getSleuthkitCase().addIngestJob(dataSource, NetworkUtils.getLocalHostName(), ingestModules, new Date(this.createTime), new Date(0), IngestJobStatusType.STARTED, ""); + } catch (TskCoreException | NoCurrentCaseException ex) { logger.log(Level.SEVERE, "Failed to add ingest job to database.", ex); } } diff --git a/Core/src/org/sleuthkit/autopsy/ingest/events/DataSourceAnalysisEvent.java b/Core/src/org/sleuthkit/autopsy/ingest/events/DataSourceAnalysisEvent.java index c508d3e276..100db13067 100644 --- a/Core/src/org/sleuthkit/autopsy/ingest/events/DataSourceAnalysisEvent.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/events/DataSourceAnalysisEvent.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2015 Basis Technology Corp. + * Copyright 2015-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.ingest.events; import java.io.Serializable; import java.util.logging.Level; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.AutopsyEvent; import org.sleuthkit.autopsy.ingest.IngestManager; @@ -96,9 +97,9 @@ public abstract class DataSourceAnalysisEvent extends AutopsyEvent implements Se } try { long id = (Long) super.getNewValue(); - dataSource = Case.getCurrentCase().getSleuthkitCase().getContentById(id); + dataSource = Case.getOpenCase().getSleuthkitCase().getContentById(id); return dataSource; - } catch (IllegalStateException | TskCoreException ex) { + } catch (NoCurrentCaseException | TskCoreException ex) { logger.log(Level.SEVERE, "Error doing lazy load for remote event", ex); //NON-NLS return null; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/fileextmismatch/FileExtMismatchIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/fileextmismatch/FileExtMismatchIngestModule.java index 672bf83d97..1d33730e20 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/fileextmismatch/FileExtMismatchIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/fileextmismatch/FileExtMismatchIngestModule.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2016 Basis Technology Corp. + * Copyright 2011-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,6 +25,7 @@ import java.util.logging.Level; 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.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; @@ -108,7 +109,12 @@ public class FileExtMismatchIngestModule implements FileIngestModule { @Override @Messages({"FileExtMismatchIngestModule.indexError.message=Failed to index file extension mismatch artifact for keyword search."}) public ProcessResult process(AbstractFile abstractFile) { - blackboard = Case.getCurrentCase().getServices().getBlackboard(); + try { + blackboard = Case.getOpenCase().getServices().getBlackboard(); + } catch (NoCurrentCaseException ex) { + logger.log(Level.WARNING, "Exception while getting open case.", ex); //NON-NLS + return ProcessResult.ERROR; + } if (this.settings.skipKnownFiles() && (abstractFile.getKnown() == FileKnown.KNOWN)) { return ProcessResult.OK; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/iOS/ContactAnalyzer.java b/Core/src/org/sleuthkit/autopsy/modules/iOS/ContactAnalyzer.java index efa4494f26..31d3f30a68 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/iOS/ContactAnalyzer.java +++ b/Core/src/org/sleuthkit/autopsy/modules/iOS/ContactAnalyzer.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2014 Basis Technology Corp. + * Copyright 2014-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,6 +34,7 @@ import java.util.List; import java.util.logging.Level; 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.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; @@ -59,19 +60,25 @@ class ContactAnalyzer { private Blackboard blackboard; public void findContacts(IngestJobContext context) { - - blackboard = Case.getCurrentCase().getServices().getBlackboard(); + Case openCase; + try { + openCase = Case.getOpenCase(); + } catch (NoCurrentCaseException ex) { + logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS + return; + } + + blackboard = openCase.getServices().getBlackboard(); List absFiles; try { - SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase(); + SleuthkitCase skCase = openCase.getSleuthkitCase(); absFiles = skCase.findAllFilesWhere("LOWER(name) LIKE LOWER('%call_history%') "); //NON-NLS //get exact file names if (absFiles.isEmpty()) { return; } for (AbstractFile AF : absFiles) { try { - jFile = new java.io.File(Case.getCurrentCase().getTempDirectory(), AF.getName().replaceAll("[<>%|\"/:*\\\\]", "")); - //jFile = new java.io.File(Case.getCurrentCase().getTempDirectory(), i+".txt"); + jFile = new java.io.File(openCase.getTempDirectory(), AF.getName().replaceAll("[<>%|\"/:*\\\\]", "")); ContentUtils.writeToFile(AF, jFile, context::dataSourceIngestIsCancelled); //copyFileUsingStreams(AF,jFile); //copyFileUsingStream(AF,jFile); diff --git a/Core/src/org/sleuthkit/autopsy/modules/stix/EvalAddressObj.java b/Core/src/org/sleuthkit/autopsy/modules/stix/EvalAddressObj.java index faaac1dc4e..4141ba874f 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/stix/EvalAddressObj.java +++ b/Core/src/org/sleuthkit/autopsy/modules/stix/EvalAddressObj.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013 Basis Technology Corp. + * Copyright 2013-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,6 +30,7 @@ import org.mitre.cybox.common_2.ConditionApplicationEnum; import org.mitre.cybox.common_2.ConditionTypeEnum; import org.mitre.cybox.objects.Address; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; /** * @@ -54,6 +55,14 @@ class EvalAddressObj extends EvaluatableObject { spacing, ObservableResult.ObservableState.INDETERMINATE, null); } + Case case1; + try { + case1 = Case.getOpenCase(); + } catch (NoCurrentCaseException ex) { + return new ObservableResult(id, "Exception while getting open case.", //NON-NLS + spacing, ObservableResult.ObservableState.FALSE, null); + } + String origAddressStr = obj.getAddressValue().getValue().toString(); // For now, we don't support "NONE" because it honestly doesn't seem like it @@ -67,7 +76,6 @@ class EvalAddressObj extends EvaluatableObject { // Set warnings for any unsupported fields setUnsupportedFieldWarnings(); - Case case1 = Case.getCurrentCase(); SleuthkitCase sleuthkitCase = case1.getSleuthkitCase(); try { diff --git a/Core/src/org/sleuthkit/autopsy/modules/stix/EvalDomainObj.java b/Core/src/org/sleuthkit/autopsy/modules/stix/EvalDomainObj.java index 2dd6c7f680..d06c5a19e0 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/stix/EvalDomainObj.java +++ b/Core/src/org/sleuthkit/autopsy/modules/stix/EvalDomainObj.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013 Basis Technology Corp. + * Copyright 2013-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,6 +27,7 @@ import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.datamodel.SleuthkitCase; /** @@ -52,7 +53,14 @@ class EvalDomainObj extends EvaluatableObject { spacing, ObservableResult.ObservableState.INDETERMINATE, null); } - // Since we have single URL artifacts, ALL and NONE conditions probably don't make sense to test + Case case1; + try { + case1 = Case.getOpenCase(); + } catch (NoCurrentCaseException ex) { + return new ObservableResult(id, "Exception while getting open case.", //NON-NLS + spacing, ObservableResult.ObservableState.FALSE, null); + } + // Since we have single URL artifacts, ALL and NONE conditions probably don't make sense to test if (!((obj.getValue().getApplyCondition() == null) || (obj.getValue().getApplyCondition() == ConditionApplicationEnum.ANY))) { return new ObservableResult(id, "DomainObject: Can not process apply condition " + obj.getValue().getApplyCondition().toString() //NON-NLS @@ -66,7 +74,6 @@ class EvalDomainObj extends EvaluatableObject { + " on DomainName - using substring comparison"); //NON-NLS } - Case case1 = Case.getCurrentCase(); SleuthkitCase sleuthkitCase = case1.getSleuthkitCase(); try { diff --git a/Core/src/org/sleuthkit/autopsy/modules/stix/EvalURIObj.java b/Core/src/org/sleuthkit/autopsy/modules/stix/EvalURIObj.java index c5e598b034..123468041d 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/stix/EvalURIObj.java +++ b/Core/src/org/sleuthkit/autopsy/modules/stix/EvalURIObj.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013 Basis Technology Corp. + * Copyright 2013-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +29,7 @@ import java.util.ArrayList; import org.mitre.cybox.common_2.ConditionApplicationEnum; import org.mitre.cybox.objects.URIObjectType; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; /** * @@ -52,6 +53,15 @@ class EvalURIObj extends EvaluatableObject { return new ObservableResult(id, "URIObject: No URI value field found", //NON-NLS spacing, ObservableResult.ObservableState.INDETERMINATE, null); } + + Case case1; + try { + case1 = Case.getOpenCase(); + } catch (NoCurrentCaseException ex) { + return new ObservableResult(id, "Exception while getting open case: " + ex.getLocalizedMessage(), //NON-NLS + spacing, ObservableResult.ObservableState.FALSE, null); + } + String addressStr = obj.getValue().getValue().toString(); // Strip off http:// or https:// @@ -65,7 +75,6 @@ class EvalURIObj extends EvaluatableObject { + " on URI object", spacing, ObservableResult.ObservableState.INDETERMINATE, null); //NON-NLS } - Case case1 = Case.getCurrentCase(); SleuthkitCase sleuthkitCase = case1.getSleuthkitCase(); try {