19 package org.sleuthkit.autopsy.externalresults;
22 import java.nio.file.Path;
23 import java.nio.file.Paths;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.logging.Level;
29 import org.openide.util.NbBundle;
30 import org.openide.util.NbBundle.Messages;
59 private final List<ErrorInfo>
errors =
new ArrayList<>();
63 for (BlackboardArtifact.ARTIFACT_TYPE artifactType : BlackboardArtifact.ARTIFACT_TYPE.values()) {
64 standardArtifactTypeIds.add(artifactType.getTypeID());
85 List<ErrorInfo> importErrors =
new ArrayList<>(this.
errors);
93 String localPath = fileData.getLocalPath();
95 File localFile =
new File(localPath);
96 if (localFile.exists()) {
98 if (!relativePath.isEmpty()) {
99 String parentFilePath = fileData.getParentPath();
101 if (parentFile != null) {
102 DerivedFile derivedFile = fileManager.
addDerivedFile(localFile.getName(), relativePath, localFile.length(),
106 TskData.EncodingType.NONE);
109 String errorMessage = NbBundle.getMessage(this.getClass(),
110 "ExternalResultsImporter.importDerivedFiles.errMsg1.text",
111 localPath, parentFilePath);
117 String errorMessage = NbBundle.getMessage(this.getClass(),
118 "ExternalResultsImporter.importDerivedFiles.errMsg2.text",
123 }
catch (TskCoreException ex) {
124 String errorMessage = NbBundle.getMessage(this.getClass(),
125 "ExternalResultsImporter.importDerivedFiles.errMsg3.text",
133 @Messages({
"ExternalResultsImporter.indexError.message=Failed to index imported artifact for keyword search."})
139 int artifactTypeId = caseDb.getArtifactType(artifactData.getType()).getTypeID();
140 if (artifactTypeId == -1) {
141 artifactTypeId = caseDb.addBlackboardArtifactType(artifactData.getType(), artifactData.getType()).getTypeID();
144 if (sourceFile != null) {
145 BlackboardArtifact artifact = sourceFile.newArtifact(artifactTypeId);
148 Collection<BlackboardAttribute> attributes =
new ArrayList<>();
150 BlackboardAttribute.Type attributeType = caseDb.getAttributeType(attributeData.getType());
151 if (attributeType == null) {
152 switch (attributeData.getValueType()) {
154 attributeType = caseDb.addArtifactAttributeType(attributeData.getType(), BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.fromLabel(
"String"), attributeData.getType());
157 attributeType = caseDb.addArtifactAttributeType(attributeData.getType(), BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.fromLabel(
"Integer"), attributeData.getType());
160 attributeType = caseDb.addArtifactAttributeType(attributeData.getType(), BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.fromLabel(
"Long"), attributeData.getType());
163 attributeType = caseDb.addArtifactAttributeType(attributeData.getType(), BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.fromLabel(
"Double"), attributeData.getType());
166 attributeType = caseDb.addArtifactAttributeType(attributeData.getType(), BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.fromLabel(
"DateTime"), attributeData.getType());
170 switch (attributeData.getValueType()) {
172 attributes.add(
new BlackboardAttribute(attributeType, attributeData.getSourceModule(), attributeData.getValue()));
175 int intValue = Integer.parseInt(attributeData.getValue());
176 attributes.add(
new BlackboardAttribute(attributeType, attributeData.getSourceModule(), intValue));
179 long longValue = Long.parseLong(attributeData.getValue());
180 attributes.add(
new BlackboardAttribute(attributeType, attributeData.getSourceModule(), longValue));
183 double doubleValue = Double.parseDouble(attributeData.getValue());
184 attributes.add(
new BlackboardAttribute(attributeType, attributeData.getSourceModule(), doubleValue));
187 long dateTimeValue = Long.parseLong(attributeData.getValue());
188 attributes.add(
new BlackboardAttribute(attributeType, attributeData.getSourceModule(), dateTimeValue));
191 String errorMessage = NbBundle.getMessage(this.getClass(),
192 "ExternalResultsImporter.importArtifacts.caseErrMsg1.text",
193 attributeData.getType(), attributeData.getValue(),
194 artifactData.getType(), artifactData.getSourceFilePath(),
195 attributeData.getValueType());
201 artifact.addAttributes(attributes);
207 logger.log(Level.SEVERE,
"Unable to index blackboard artifact " + artifact.getArtifactID(), ex);
209 Bundle.ExternalResultsImporter_indexError_message(), artifact.getDisplayName());
212 if (standardArtifactTypeIds.contains(artifactTypeId)) {
216 String errorMessage = NbBundle.getMessage(this.getClass(),
217 "ExternalResultsImporter.importArtifacts.errMsg1.text",
218 artifactData.getType(), artifactData.getSourceFilePath());
222 }
catch (TskCoreException | TskDataException ex) {
223 String errorMessage = NbBundle.getMessage(this.getClass(),
224 "ExternalResultsImporter.importArtifacts.errMsg2.text",
225 artifactData.getType(), artifactData.getSourceFilePath());
234 String reportPath = report.getLocalPath();
236 File reportFile =
new File(reportPath);
237 if (reportFile.exists()) {
240 String errorMessage = NbBundle.getMessage(this.getClass(),
"ExternalResultsImporter.importReports.errMsg1.text", reportPath);
244 }
catch (TskCoreException ex) {
245 String errorMessage = NbBundle.getMessage(this.getClass(),
"ExternalResultsImporter.importReports.errMsg2.text", reportPath);
253 AbstractFile file = null;
255 String fileName = filePath;
256 String parentPath =
"";
257 int charPos = filePath.lastIndexOf(
"/");
259 fileName = filePath.substring(charPos + 1);
260 parentPath = filePath.substring(0, charPos + 1);
263 String condition =
"name='" + fileName +
"' AND parent_path='" + parentPath +
"'";
265 if (!files.isEmpty()) {
267 if (files.size() > 1) {
268 String errorMessage = NbBundle.getMessage(this.getClass(),
"ExternalResultsImporter.findFileInCaseDatabase.errMsg1.text", filePath);
276 String relativePath =
"";
278 Path path = Paths.get(localPath);
279 if (path.isAbsolute()) {
280 Path pathBase = Paths.get(caseDirectoryPath);
282 Path pathRelative = pathBase.relativize(path);
283 relativePath = pathRelative.toString();
284 }
catch (IllegalArgumentException ex) {
285 String errorMessage = NbBundle.getMessage(this.getClass(),
286 "ExternalResultsImporter.getPathRelativeToCaseFolder.errMsg1.text",
287 localPath, caseDirectoryPath);
291 String errorMessage = NbBundle.getMessage(this.getClass(),
292 "ExternalResultsImporter.getPathRelativeToCaseFolder.errMsg2.text",
293 localPath, caseDirectoryPath);
301 this.errors.add(
new ErrorInfo(this.getClass().getName(), errorMessage));
306 this.errors.add(
new ErrorInfo(this.getClass().getName(), errorMessage));
void importArtifacts(ExternalResults results)
static final Logger logger
FileManager getFileManager()
String getCaseDirectory()
void importDerivedFiles(ExternalResults results)
void addReport(String localPath, String srcModuleName, String reportName)
static final HashSet< Integer > standardArtifactTypeIds
AbstractFile findFileInCaseDatabase(String filePath)
void recordError(String errorMessage, Exception ex)
void fireModuleDataEvent(ModuleDataEvent moduleDataEvent)
SleuthkitCase getSleuthkitCase()
void recordError(String errorMessage)
List< ErrorInfo > importResults(ExternalResults results)
Blackboard getBlackboard()
void fireModuleContentEvent(ModuleContentEvent moduleContentEvent)
synchronized DerivedFile addDerivedFile(String fileName, String localPath, long size, long ctime, long crtime, long atime, long mtime, boolean isFile, AbstractFile parentFile, String rederiveDetails, String toolName, String toolVersion, String otherDetails, TskData.EncodingType encodingType)
static void error(String title, String message)
synchronized void indexArtifact(BlackboardArtifact artifact)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
void importReports(ExternalResults results)
String getPathRelativeToCaseFolder(String localPath)
final List< ErrorInfo > errors
static synchronized IngestServices getInstance()