19 package org.sleuthkit.autopsy.report.modules.portablecase;
21 import com.google.common.collect.ArrayListMultimap;
22 import com.google.common.collect.Multimap;
24 import java.util.logging.Level;
25 import java.io.BufferedReader;
27 import java.io.InputStreamReader;
28 import java.io.IOException;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
32 import java.sql.ResultSet;
33 import java.sql.SQLException;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.HashMap;
37 import java.util.List;
39 import org.apache.commons.io.FileUtils;
40 import org.openide.modules.InstalledFileLocator;
41 import org.openide.util.NbBundle;
66 import org.
sleuthkit.datamodel.SleuthkitCase.CaseDbTransaction;
118 "PortableCaseReportModule.getName.name=Portable Case"
122 return Bundle.PortableCaseReportModule_getName_name();
126 "PortableCaseReportModule.getDescription.description=Copies selected items to a new single-user case that can be easily shared"
130 return Bundle.PortableCaseReportModule_getDescription_description();
150 logger.log(Level.INFO,
"Portable case creation canceled by user");
168 logger.log(Level.WARNING, logWarning);
170 logger.log(Level.SEVERE, logWarning, ex);
178 "PortableCaseReportModule.generateReport.verifying=Verifying selected parameters...",
179 "PortableCaseReportModule.generateReport.creatingCase=Creating portable case database...",
180 "PortableCaseReportModule.generateReport.copyingTags=Copying tags...",
182 "PortableCaseReportModule.generateReport.copyingFiles=Copying files tagged as {0}...",
184 "PortableCaseReportModule.generateReport.copyingArtifacts=Copying artifacts tagged as {0}...",
185 "# {0} - output folder",
186 "PortableCaseReportModule.generateReport.outputDirDoesNotExist=Output folder {0} does not exist",
187 "# {0} - output folder",
188 "PortableCaseReportModule.generateReport.outputDirIsNotDir=Output folder {0} is not a folder",
189 "PortableCaseReportModule.generateReport.caseClosed=Current case has been closed",
190 "PortableCaseReportModule.generateReport.interestingItemError=Error loading intersting items",
191 "PortableCaseReportModule.generateReport.errorReadingTags=Error while reading tags from case database",
192 "PortableCaseReportModule.generateReport.errorReadingSets=Error while reading interesting items sets from case database",
193 "PortableCaseReportModule.generateReport.noContentToCopy=No interesting files, results, or tagged items to copy",
194 "PortableCaseReportModule.generateReport.errorCopyingTags=Error copying tags",
195 "PortableCaseReportModule.generateReport.errorCopyingFiles=Error copying tagged files",
196 "PortableCaseReportModule.generateReport.errorCopyingArtifacts=Error copying tagged artifacts",
197 "PortableCaseReportModule.generateReport.errorCopyingInterestingFiles=Error copying interesting files",
198 "PortableCaseReportModule.generateReport.errorCopyingInterestingResults=Error copying interesting results",
199 "PortableCaseReportModule.generateReport.errorCreatingImageTagTable=Error creating image tags table",
200 "# {0} - attribute type name",
201 "PortableCaseReportModule.generateReport.errorLookingUpAttrType=Error looking up attribute type {0}",
202 "PortableCaseReportModule.generateReport.compressingCase=Compressing case..."
206 this.settings = options;
208 progressPanel.
start();
209 progressPanel.
updateStatusLabel(Bundle.PortableCaseReportModule_generateReport_verifying());
215 File outputDir =
new File(reportPath);
216 if (! outputDir.exists()) {
217 handleError(
"Output folder " + outputDir.toString() +
" does not exist",
218 Bundle.PortableCaseReportModule_generateReport_outputDirDoesNotExist(outputDir.toString()), null, progressPanel);
222 if (! outputDir.isDirectory()) {
223 handleError(
"Output folder " + outputDir.toString() +
" is not a folder",
224 Bundle.PortableCaseReportModule_generateReport_outputDirIsNotDir(outputDir.toString()), null, progressPanel);
234 Bundle.PortableCaseReportModule_generateReport_caseClosed(), null, progressPanel);
239 List<TagName> tagNames;
245 Bundle.PortableCaseReportModule_generateReport_errorReadingTags(), ex, progressPanel);
252 List<String> setNames;
257 handleError(
"Unable to get all interesting items sets",
258 Bundle.PortableCaseReportModule_generateReport_errorReadingSets(), ex, progressPanel);
265 if (tagNames.isEmpty() && setNames.isEmpty()) {
267 Bundle.PortableCaseReportModule_generateReport_noContentToCopy(), null, progressPanel);
273 progressPanel.
updateStatusLabel(Bundle.PortableCaseReportModule_generateReport_creatingCase());
275 if (portableSkCase == null) {
289 }
catch (TskCoreException ex) {
290 handleError(
"Error creating image tag table", Bundle.PortableCaseReportModule_generateReport_errorCreatingImageTagTable(), ex, progressPanel);
295 progressPanel.
updateStatusLabel(Bundle.PortableCaseReportModule_generateReport_copyingTags());
297 for(TagName tagName:tagNames) {
298 TagName newTagName = portableSkCase.addOrUpdateTagName(tagName.getDisplayName(), tagName.getDescription(), tagName.getColor(), tagName.getKnownStatus());
299 oldTagNameToNewTagName.put(tagName, newTagName);
301 }
catch (TskCoreException ex) {
302 handleError(
"Error copying tags", Bundle.PortableCaseReportModule_generateReport_errorCopyingTags(), ex, progressPanel);
307 for (BlackboardArtifact.ARTIFACT_TYPE type:BlackboardArtifact.ARTIFACT_TYPE.values()) {
308 oldArtTypeIdToNewArtTypeId.put(type.getTypeID(), type.getTypeID());
310 for (BlackboardAttribute.ATTRIBUTE_TYPE type:BlackboardAttribute.ATTRIBUTE_TYPE.values()) {
313 }
catch (TskCoreException ex) {
314 handleError(
"Error looking up attribute name " + type.getLabel(),
315 Bundle.PortableCaseReportModule_generateReport_errorLookingUpAttrType(type.getLabel()),
322 for(TagName tagName:tagNames) {
328 progressPanel.
updateStatusLabel(Bundle.PortableCaseReportModule_generateReport_copyingFiles(tagName.getDisplayName()));
337 }
catch (TskCoreException ex) {
338 handleError(
"Error copying tagged files", Bundle.PortableCaseReportModule_generateReport_errorCopyingFiles(), ex, progressPanel);
344 for(TagName tagName:tagNames) {
350 progressPanel.
updateStatusLabel(Bundle.PortableCaseReportModule_generateReport_copyingArtifacts(tagName.getDisplayName()));
359 }
catch (TskCoreException ex) {
360 handleError(
"Error copying tagged artifacts", Bundle.PortableCaseReportModule_generateReport_errorCopyingArtifacts(), ex, progressPanel);
365 if (! setNames.isEmpty()) {
367 List<BlackboardArtifact> interestingFiles = currentCase.
getSleuthkitCase().getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT);
368 for (BlackboardArtifact art:interestingFiles) {
375 BlackboardAttribute setAttr = art.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME));
376 if (setNames.contains(setAttr.getValueString())) {
380 }
catch (TskCoreException ex) {
381 handleError(
"Error copying interesting files", Bundle.PortableCaseReportModule_generateReport_errorCopyingInterestingFiles(), ex, progressPanel);
386 List<BlackboardArtifact> interestingResults = currentCase.
getSleuthkitCase().getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT);
387 for (BlackboardArtifact art:interestingResults) {
393 BlackboardAttribute setAttr = art.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME));
394 if (setNames.contains(setAttr.getValueString())) {
398 }
catch (TskCoreException ex) {
399 handleError(
"Error copying interesting results", Bundle.PortableCaseReportModule_generateReport_errorCopyingInterestingResults(), ex, progressPanel);
415 progressPanel.
updateStatusLabel(Bundle.PortableCaseReportModule_generateReport_compressingCase());
450 "PortableCaseReportModule.generateCaseUcoReport.errorCreatingReportFolder=Could not make report folder",
451 "PortableCaseReportModule.generateCaseUcoReport.errorGeneratingCaseUcoReport=Problem while generating CASE-UCO report",
452 "PortableCaseReportModule.generateCaseUcoReport.startCaseUcoReportGeneration=Creating a CASE-UCO report of the portable case",
453 "PortableCaseReportModule.generateCaseUcoReport.successCaseUcoReportGeneration=Successfully created a CASE-UCO report of the portable case"
457 Path reportsDirectory = Paths.get(caseFolder.toString(),
"Reports");
458 if(!reportsDirectory.toFile().mkdir()) {
459 logger.log(Level.SEVERE,
"Could not make the report folder... skipping "
460 +
"CASE-UCO report generation for the portable case");
466 progressPanel.
updateStatusLabel(Bundle.PortableCaseReportModule_generateCaseUcoReport_startCaseUcoReportGeneration());
475 Path tmpDir = Paths.get(caseTempDirectory, CASE_UCO_TMP_DIR);
476 FileUtils.deleteDirectory(tmpDir.toFile());
477 Files.createDirectory(tmpDir);
479 reportGenerator.
addCase(currentCase);
494 boolean dataSourceHasBeenIncluded =
false;
496 for (TagName tagName : tagNames) {
499 dataSource, tmpDir, reportGenerator, dataSourceHasBeenIncluded);
503 dataSource, tmpDir, reportGenerator, dataSourceHasBeenIncluded);
507 for(BlackboardArtifact bArt : artifactsWithSetName.get(dataSource.getId())) {
508 Content sourceContent = bArt.getParent();
509 dataSourceHasBeenIncluded |=
addUniqueFile(sourceContent, dataSource,
510 tmpDir, reportGenerator, dataSourceHasBeenIncluded);
516 progressPanel.
updateStatusLabel(Bundle.PortableCaseReportModule_generateCaseUcoReport_successCaseUcoReportGeneration());
517 }
catch (IOException | TskCoreException ex) {
518 progressPanel.
updateStatusLabel(Bundle.PortableCaseReportModule_generateCaseUcoReport_errorGeneratingCaseUcoReport());
519 logger.log(Level.SEVERE,
"Error encountered while trying to create "
520 +
"CASE-UCO output for portable case.. the portable case will be "
521 +
"completed without a CASE-UCO report.", ex);
531 Multimap<Long, BlackboardArtifact> artifactsWithSetName = ArrayListMultimap.create();
532 if(!setNames.isEmpty()) {
533 List<BlackboardArtifact> allArtifacts = skCase.getBlackboardArtifacts(
534 BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT);
535 allArtifacts.addAll(skCase.getBlackboardArtifacts(
536 BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT));
538 for(BlackboardArtifact bArt : allArtifacts) {
539 BlackboardAttribute setAttr = bArt.getAttribute(
540 new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME));
541 if (setNames.contains(setAttr.getValueString())) {
542 artifactsWithSetName.put(bArt.getDataSource().getId(), bArt);
546 return artifactsWithSetName;
565 boolean dataSourceHasBeenIncluded)
throws IOException, TskCoreException {
566 if (content instanceof AbstractFile && !(content instanceof DataSource)) {
567 AbstractFile absFile = (AbstractFile) content;
568 Path filePath = tmpDir.resolve(Long.toString(absFile.getId()));
569 if (!absFile.isDir() && !Files.exists(filePath)) {
570 if(!dataSourceHasBeenIncluded) {
571 reportGenerator.addDataSource(dataSource, currentCase);
575 reportGenerator.addFile(absFile, dataSource, Paths.get(FILE_FOLDER_NAME, subFolder, fileName));
576 Files.createFile(filePath);
586 List<String> setNames =
new ArrayList<>();
587 Map<String, Long> setCounts;
591 String innerSelect =
"SELECT (value_text) AS set_name FROM blackboard_attributes WHERE (artifact_type_id = '"
592 + BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT.getTypeID() +
"' OR artifact_type_id = '"
593 + BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID() +
"') AND attribute_type_id = '"
594 + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID() +
"'";
597 String query =
"set_name, count(1) AS set_count FROM (" + innerSelect +
") set_names GROUP BY set_name";
602 setNames.addAll(setCounts.keySet());
615 "# {0} - case folder",
616 "PortableCaseReportModule.createCase.caseDirExists=Case folder {0} already exists",
617 "PortableCaseReportModule.createCase.errorCreatingCase=Error creating case",
619 "PortableCaseReportModule.createCase.errorCreatingFolder=Error creating folder {0}",
620 "PortableCaseReportModule.createCase.errorStoringMaxIds=Error storing maximum database IDs",
625 caseFolder = Paths.get(outputDir.toString(),
caseName).toFile();
627 if (caseFolder.exists()) {
628 handleError(
"Case folder " + caseFolder.toString() +
" already exists",
629 Bundle.PortableCaseReportModule_createCase_caseDirExists(caseFolder.toString()), null, progressPanel);
636 }
catch (TskCoreException ex) {
637 handleError(
"Error creating case " + caseName +
" in folder " + caseFolder.toString(),
638 Bundle.PortableCaseReportModule_createCase_errorCreatingCase(), ex, progressPanel);
645 }
catch (TskCoreException ex) {
647 Bundle.PortableCaseReportModule_createCase_errorStoringMaxIds(), ex, progressPanel);
652 copiedFilesFolder = Paths.get(caseFolder.toString(),
FILE_FOLDER_NAME).toFile();
653 if (! copiedFilesFolder.mkdir()) {
654 handleError(
"Error creating folder " + copiedFilesFolder.toString(),
655 Bundle.PortableCaseReportModule_createCase_errorCreatingFolder(copiedFilesFolder.toString()), null, progressPanel);
661 File subFolder = Paths.get(copiedFilesFolder.toString(), cat.getDisplayName()).toFile();
662 if (! subFolder.mkdir()) {
663 handleError(
"Error creating folder " + subFolder.toString(),
664 Bundle.PortableCaseReportModule_createCase_errorCreatingFolder(subFolder.toString()), null, progressPanel);
669 if (! unknownTypeFolder.mkdir()) {
670 handleError(
"Error creating folder " + unknownTypeFolder.toString(),
671 Bundle.PortableCaseReportModule_createCase_errorCreatingFolder(unknownTypeFolder.toString()), null, progressPanel);
684 CaseDbAccessManager currentCaseDbManager = currentCase.
getSleuthkitCase().getCaseDbAccessManager();
686 String tableSchema =
"( table_name TEXT PRIMARY KEY, "
689 portableSkCase.getCaseDbAccessManager().createTable(MAX_ID_TABLE_NAME, tableSchema);
691 currentCaseDbManager.select(
"max(obj_id) as max_id from tsk_objects",
new StoreMaxIdCallback(
"tsk_objects"));
692 currentCaseDbManager.select(
"max(tag_id) as max_id from content_tags",
new StoreMaxIdCallback(
"content_tags"));
693 currentCaseDbManager.select(
"max(tag_id) as max_id from blackboard_artifact_tags",
new StoreMaxIdCallback(
"blackboard_artifact_tags"));
694 currentCaseDbManager.select(
"max(examiner_id) as max_id from tsk_examiners",
new StoreMaxIdCallback(
"tsk_examiners"));
707 CaseDbAccessManager portableDbAccessManager = portableSkCase.getCaseDbAccessManager();
727 for (ContentTag tag : tags) {
734 Content content = tag.getContent();
735 if (content instanceof AbstractFile) {
740 if (! oldTagNameToNewTagName.containsKey(tag.getName())) {
741 throw new TskCoreException(
"TagName map is missing entry for ID " + tag.getName().getId() +
" with display name " + tag.getName().getDisplayName());
743 ContentTag newContentTag = portableSkCase.addContentTag(newIdToContent.get(newFileId), oldTagNameToNewTagName.get(tag.getName()), tag.getComment(), tag.getBeginByteOffset(), tag.getEndByteOffset());
748 if (! appData.isEmpty()) {
768 currentCase.
getSleuthkitCase().getCaseDbAccessManager().select(query, callback);
769 return callback.getAppData();
785 appData = rs.getString(
"app_data");
786 }
catch (SQLException ex) {
787 logger.log(Level.WARNING,
"Unable to get app_data from result set", ex);
790 }
catch (SQLException ex) {
791 logger.log(Level.WARNING,
"Failed to get next result for app_data", ex);
800 String getAppData() {
814 String insert =
"(content_tag_id, app_data) VALUES (" + newContentTag.getId() +
", '" + appData +
"')";
832 for (BlackboardArtifactTag tag : tags) {
840 Content content = tag.getContent();
844 BlackboardArtifact newArtifact =
copyArtifact(newContentId, tag.getArtifact());
847 if (! oldTagNameToNewTagName.containsKey(tag.getName())) {
848 throw new TskCoreException(
"TagName map is missing entry for ID " + tag.getName().getId() +
" with display name " + tag.getName().getDisplayName());
850 portableSkCase.addBlackboardArtifactTag(newArtifact, oldTagNameToNewTagName.get(tag.getName()), tag.getComment());
864 private BlackboardArtifact
copyArtifact(
long newContentId, BlackboardArtifact artifactToCopy)
throws TskCoreException {
866 if (oldArtifactIdToNewArtifact.containsKey(artifactToCopy.getArtifactID())) {
867 return oldArtifactIdToNewArtifact.get(artifactToCopy.getArtifactID());
871 BlackboardAttribute oldAssociatedAttribute = artifactToCopy.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
872 List<BlackboardAttribute> newAttrs =
new ArrayList<>();
873 if (oldAssociatedAttribute != null) {
874 BlackboardArtifact oldAssociatedArtifact = currentCase.
getSleuthkitCase().getBlackboardArtifact(oldAssociatedAttribute.getValueLong());
875 BlackboardArtifact newAssociatedArtifact =
copyArtifact(newContentId, oldAssociatedArtifact);
876 newAttrs.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT,
877 String.join(
",", oldAssociatedAttribute.getSources()), newAssociatedArtifact.getArtifactID()));
882 BlackboardArtifact newArtifact = portableSkCase.newBlackboardArtifact(newArtifactTypeId, newContentId);
883 List<BlackboardAttribute> oldAttrs = artifactToCopy.getAttributes();
886 for (BlackboardAttribute oldAttr:oldAttrs) {
889 if (oldAttr.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT.getTypeID()) {
894 switch (oldAttr.getValueType()) {
896 newAttrs.add(
new BlackboardAttribute(newAttributeType, String.join(
",", oldAttr.getSources()),
897 oldAttr.getValueBytes()));
900 newAttrs.add(
new BlackboardAttribute(newAttributeType, String.join(
",", oldAttr.getSources()),
901 oldAttr.getValueDouble()));
904 newAttrs.add(
new BlackboardAttribute(newAttributeType, String.join(
",", oldAttr.getSources()),
905 oldAttr.getValueInt()));
909 newAttrs.add(
new BlackboardAttribute(newAttributeType, String.join(
",", oldAttr.getSources()),
910 oldAttr.getValueLong()));
914 newAttrs.add(
new BlackboardAttribute(newAttributeType, String.join(
",", oldAttr.getSources()),
915 oldAttr.getValueString()));
918 throw new TskCoreException(
"Unexpected attribute value type found: " + oldAttr.getValueType().getLabel());
922 newArtifact.addAttributes(newAttrs);
924 oldArtifactIdToNewArtifact.put(artifactToCopy.getArtifactID(), newArtifact);
937 if (oldArtTypeIdToNewArtTypeId.containsKey(oldArtifact.getArtifactTypeID())) {
938 return oldArtTypeIdToNewArtTypeId.get(oldArtifact.getArtifactTypeID());
941 BlackboardArtifact.Type oldCustomType = currentCase.
getSleuthkitCase().getArtifactType(oldArtifact.getArtifactTypeName());
943 BlackboardArtifact.Type newCustomType = portableSkCase.addBlackboardArtifactType(oldCustomType.getTypeName(), oldCustomType.getDisplayName());
944 oldArtTypeIdToNewArtTypeId.put(oldArtifact.getArtifactTypeID(), newCustomType.getTypeID());
945 return newCustomType.getTypeID();
946 }
catch (TskDataException ex) {
947 throw new TskCoreException(
"Error creating new artifact type " + oldCustomType.getTypeName(), ex);
959 private BlackboardAttribute.Type
getNewAttributeType(BlackboardAttribute oldAttribute)
throws TskCoreException {
960 BlackboardAttribute.Type oldAttrType = oldAttribute.getAttributeType();
966 BlackboardAttribute.Type newCustomType = portableSkCase.addArtifactAttributeType(oldAttrType.getTypeName(),
967 oldAttrType.getValueType(), oldAttrType.getDisplayName());
969 return newCustomType;
970 }
catch (TskDataException ex) {
971 throw new TskCoreException(
"Error creating new attribute type " + oldAttrType.getTypeName(), ex);
987 "PortableCaseReportModule.copyContentToPortableCase.copyingFile=Copying file {0}",
990 progressPanel.
updateStatusLabel(Bundle.PortableCaseReportModule_copyContentToPortableCase_copyingFile(content.getUniquePath()));
1006 if (oldIdToNewContent.containsKey(content.getId())) {
1007 return oldIdToNewContent.get(content.getId()).getId();
1014 if (content.getParent() != null) {
1019 if (content instanceof BlackboardArtifact) {
1020 BlackboardArtifact artifactToCopy = (BlackboardArtifact)content;
1023 CaseDbTransaction trans = portableSkCase.beginTransaction();
1025 if (content instanceof Image) {
1026 Image image = (Image)content;
1027 newContent = portableSkCase.addImage(image.getType(), image.getSsize(), image.getSize(), image.getName(),
1028 new ArrayList<>(), image.getTimeZone(), image.getMd5(), image.getSha1(), image.getSha256(), image.getDeviceId(), trans);
1029 }
else if (content instanceof VolumeSystem) {
1030 VolumeSystem vs = (VolumeSystem)content;
1031 newContent = portableSkCase.addVolumeSystem(parentId, vs.getType(), vs.getOffset(), vs.getBlockSize(), trans);
1032 }
else if (content instanceof Volume) {
1033 Volume vs = (Volume)content;
1034 newContent = portableSkCase.addVolume(parentId, vs.getAddr(), vs.getStart(), vs.getLength(),
1035 vs.getDescription(), vs.getFlags(), trans);
1036 }
else if (content instanceof Pool) {
1037 Pool pool = (Pool)content;
1038 newContent = portableSkCase.addPool(parentId, pool.getType(), trans);
1039 }
else if (content instanceof FileSystem) {
1040 FileSystem fs = (FileSystem)content;
1041 newContent = portableSkCase.addFileSystem(parentId, fs.getImageOffset(), fs.getFsType(), fs.getBlock_size(),
1042 fs.getBlock_count(), fs.getRoot_inum(), fs.getFirst_inum(), fs.getLastInum(),
1043 fs.getName(), trans);
1044 }
else if (content instanceof BlackboardArtifact) {
1045 BlackboardArtifact artifactToCopy = (BlackboardArtifact)content;
1047 }
else if (content instanceof AbstractFile) {
1048 AbstractFile abstractFile = (AbstractFile)content;
1050 if (abstractFile instanceof LocalFilesDataSource) {
1051 LocalFilesDataSource localFilesDS = (LocalFilesDataSource)abstractFile;
1052 newContent = portableSkCase.addLocalFilesDataSource(localFilesDS.getDeviceId(), localFilesDS.getName(), localFilesDS.getTimeZone(), trans);
1054 if (abstractFile.isDir()) {
1055 newContent = portableSkCase.addLocalDirectory(parentId, abstractFile.getName(), trans);
1061 File exportFolder = Paths.get(copiedFilesFolder.toString(), exportSubFolder).toFile();
1062 File localFile =
new File(exportFolder, fileName);
1066 Content oldParent = abstractFile.getParent();
1067 if (! oldIdToNewContent.containsKey(oldParent.getId())) {
1068 throw new TskCoreException(
"Parent of file with ID " + abstractFile.getId() +
" has not been created");
1070 Content newParent = oldIdToNewContent.get(oldParent.getId());
1073 String relativePath = FILE_FOLDER_NAME + File.separator + exportSubFolder + File.separator + fileName;
1075 newContent = portableSkCase.addLocalFile(abstractFile.getName(), relativePath, abstractFile.getSize(),
1076 abstractFile.getCtime(), abstractFile.getCrtime(), abstractFile.getAtime(), abstractFile.getMtime(),
1077 abstractFile.getMd5Hash(), abstractFile.getKnown(), abstractFile.getMIMEType(),
1078 true, TskData.EncodingType.NONE,
1080 }
catch (IOException ex) {
1081 throw new TskCoreException(
"Error copying file " + abstractFile.getName() +
" with original obj ID "
1082 + abstractFile.getId(), ex);
1087 throw new TskCoreException(
"Trying to copy unexpected Content type " + content.getClass().getName());
1090 }
catch (TskCoreException ex) {
1097 oldIdToNewContent.put(content.getId(), newContent);
1098 newIdToContent.put(newContent.getId(), newContent);
1099 return oldIdToNewContent.get(content.getId()).getId();
1110 if (abstractFile.getMIMEType() == null || abstractFile.getMIMEType().isEmpty()) {
1115 if (cat.getMediaTypes().contains(abstractFile.getMIMEType())) {
1116 return cat.getDisplayName();
1126 oldIdToNewContent.clear();
1127 newIdToContent.clear();
1128 oldTagNameToNewTagName.clear();
1129 oldArtTypeIdToNewArtTypeId.clear();
1131 oldArtifactIdToNewArtifact.clear();
1137 copiedFilesFolder = null;
1144 if (portableSkCase != null) {
1145 portableSkCase.close();
1146 portableSkCase = null;
1170 Long maxId = rs.getLong(
"max_id");
1171 String query =
" (table_name, max_id) VALUES ('" + tableName +
"', '" + maxId +
"')";
1172 portableSkCase.getCaseDbAccessManager().insert(MAX_ID_TABLE_NAME, query);
1174 }
catch (SQLException ex) {
1175 logger.log(Level.WARNING,
"Unable to get maximum ID from result set", ex);
1176 }
catch (TskCoreException ex) {
1177 logger.log(Level.WARNING,
"Unable to save maximum ID from result set", ex);
1181 }
catch (SQLException ex) {
1182 logger.log(Level.WARNING,
"Failed to get maximum ID from result set", ex);
1187 @NbBundle.Messages({
1188 "PortableCaseReportModule.compressCase.errorFinding7zip=Could not locate 7-Zip executable",
1189 "# {0} - Temp folder path",
1190 "PortableCaseReportModule.compressCase.errorCreatingTempFolder=Could not create temporary folder {0}",
1191 "PortableCaseReportModule.compressCase.errorCompressingCase=Error compressing case",
1192 "PortableCaseReportModule.compressCase.canceled=Compression canceled by user",
1200 File tempZipFolder = Paths.get(currentCase.
getTempDirectory(),
"portableCase" + System.currentTimeMillis()).toFile();
1201 if (! tempZipFolder.mkdir()) {
1202 handleError(
"Error creating temporary folder " + tempZipFolder.toString(),
1203 Bundle.PortableCaseReportModule_compressCase_errorCreatingTempFolder(tempZipFolder.toString()), null, progressPanel);
1209 if (sevenZipExe == null) {
1210 handleError(
"Error finding 7-Zip exectuable", Bundle.PortableCaseReportModule_compressCase_errorFinding7zip(), null, progressPanel);
1215 String chunkOption =
"";
1220 File zipFile = Paths.get(tempZipFolder.getAbsolutePath(), caseName +
".zip").toFile();
1221 ProcessBuilder procBuilder =
new ProcessBuilder();
1222 procBuilder.command(
1223 sevenZipExe.getAbsolutePath(),
1225 zipFile.getAbsolutePath(),
1226 caseFolder.getAbsolutePath(),
1231 Process process = procBuilder.start();
1233 while (process.isAlive()) {
1240 int exitCode = process.exitValue();
1241 if (exitCode != 0) {
1243 StringBuilder sb =
new StringBuilder();
1244 try (BufferedReader br =
new BufferedReader(
new InputStreamReader(process.getErrorStream()))) {
1246 while ((line = br.readLine()) != null) {
1247 sb.append(line).append(System.getProperty(
"line.separator"));
1251 handleError(
"Error compressing case\n7-Zip output: " + sb.toString(), Bundle.PortableCaseReportModule_compressCase_errorCompressingCase(), null, progressPanel);
1254 }
catch (IOException | InterruptedException ex) {
1255 handleError(
"Error compressing case", Bundle.PortableCaseReportModule_compressCase_errorCompressingCase(), ex, progressPanel);
1261 FileUtils.cleanDirectory(caseFolder);
1262 FileUtils.copyDirectory(tempZipFolder, caseFolder);
1263 FileUtils.deleteDirectory(tempZipFolder);
1264 }
catch (IOException ex) {
1265 handleError(
"Error compressing case", Bundle.PortableCaseReportModule_compressCase_errorCompressingCase(), ex, progressPanel);
1282 String executableToFindName = Paths.get(
"7-Zip",
"7z.exe").toString();
1284 if (null == exeFile) {
1288 if (!exeFile.canExecute()) {
1301 private final Map<String, Long>
setCounts =
new HashMap<>();
1308 Long setCount = rs.getLong(
"set_count");
1309 String setName = rs.getString(
"set_name");
1311 setCounts.put(setName, setCount);
1313 }
catch (SQLException ex) {
1314 logger.log(Level.WARNING,
"Unable to get data_source_obj_id or value from result set", ex);
1317 }
catch (SQLException ex) {
1318 logger.log(Level.WARNING,
"Failed to get next result for values by datasource", ex);
List< Content > getDataSources()
final Map< Integer, Integer > oldArtTypeIdToNewArtTypeId
void handleError(String logWarning, String dialogWarning, Exception ex, ReportProgressPanel progressPanel)
long copyContent(Content content)
static final Logger logger
int getNewArtifactTypeId(BlackboardArtifact oldArtifact)
static final List< FileTypeCategory > FILE_TYPE_CATEGORIES
static final String MAX_ID_TABLE_NAME
void process(ResultSet rs)
final Map< TagName, TagName > oldTagNameToNewTagName
final Map< Long, Content > oldIdToNewContent
final Map< Long, BlackboardArtifact > oldArtifactIdToNewArtifact
PortableCaseReportModule()
void addCase(Case caseObj)
String getTempDirectory()
boolean compressCase(ReportProgressPanel progressPanel)
long copyContentToPortableCase(Content content, ReportProgressPanel progressPanel)
void addArtifactsToPortableCase(TagName oldTagName, ReportProgressPanel progressPanel)
static final String FILE_FOLDER_NAME
final Map< Integer, BlackboardAttribute.Type > oldAttrTypeIdToNewAttrType
void process(ResultSet rs)
void complete(ReportStatus reportStatus)
List< TagName > getSelectedTagNames()
Map< String, Long > getSetCountMap()
static File locate7ZipExecutable()
Multimap< Long, BlackboardArtifact > getInterestingArtifactsBySetName(SleuthkitCase skCase, List< String > setNames)
static< T > long writeToFile(Content content, java.io.File outputFile, ProgressHandle progress, Future< T > worker, boolean source)
void closePortableCaseDatabase()
List< String > getAllInterestingItemsSets()
static final String UNKNOWN_FILE_TYPE_FOLDER
Logger(String name, String resourceBundleName)
void setIndeterminate(boolean indeterminate)
BlackboardAttribute.Type getNewAttributeType(BlackboardAttribute oldAttribute)
void addFilesToPortableCase(TagName oldTagName, ReportProgressPanel progressPanel)
void generateReport(String reportPath, PortableCaseReportModuleSettings options, ReportProgressPanel progressPanel)
String getRelativeFilePath()
TagsManager getTagsManager()
static final String CASE_UCO_TMP_DIR
void initializeImageTags(ReportProgressPanel progressPanel)
String getExportSubfolder(AbstractFile abstractFile)
static final String TABLE_SCHEMA_SQLITE
final Map< Long, Content > newIdToContent
SleuthkitCase portableSkCase
static final String TABLE_NAME
final Map< String, Long > setCounts
SleuthkitCase getSleuthkitCase()
List< String > getSelectedSetNames()
BlackboardArtifact copyArtifact(long newContentId, BlackboardArtifact artifactToCopy)
void generateCaseUcoReport(List< TagName > tagNames, List< String > setNames, ReportProgressPanel progressPanel)
SleuthkitCase createPortableCase(String caseName, File portableCaseFolder)
boolean areAllTagsSelected()
static String escapeFileName(String fileName)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
void updateStatusLabel(String statusMessage)
String getImageTagDataForContentTag(ContentTag tag)
static final String CASE_UCO_FILE_NAME
String getSevenZipParam()
boolean addUniqueFile(Content content, Content dataSource, Path tmpDir, CaseUcoReportGenerator reportGenerator, boolean dataSourceHasBeenIncluded)
boolean areAllSetsSelected()
void addImageTagToPortableCase(ContentTag newContentTag, String appData)
void handleCancellation(ReportProgressPanel progressPanel)
void createCase(File outputDir, ReportProgressPanel progressPanel)
void process(ResultSet rs)
PortableCaseReportModuleSettings settings