19 package org.sleuthkit.autopsy.casemodule.datasourcesummary;
21 import java.util.ArrayList;
22 import java.util.List;
24 import java.util.logging.Level;
28 import java.util.Collections;
29 import java.util.HashMap;
42 final class DataSourceInfoUtilities {
44 private static final Logger logger = Logger.getLogger(DataSourceInfoUtilities.class.getName());
54 static Map<Long, String> getDataSourceTypes() {
56 SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
57 List<BlackboardArtifact> listOfArtifacts = skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE);
58 Map<Long, String> typeMap =
new HashMap<>();
59 for (BlackboardArtifact typeArtifact : listOfArtifacts) {
60 BlackboardAttribute descriptionAttr = typeArtifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION));
61 if (typeArtifact.getDataSource() != null && descriptionAttr != null) {
62 long dsId = typeArtifact.getDataSource().getId();
63 String type = typeMap.get(typeArtifact.getDataSource().getId());
65 type = descriptionAttr.getValueString();
67 type = type +
", " + descriptionAttr.getValueString();
69 typeMap.put(dsId, type);
73 }
catch (TskCoreException | NoCurrentCaseException ex) {
74 logger.log(Level.WARNING,
"Unable to get types of files for all datasources, providing empty results", ex);
75 return Collections.emptyMap();
87 static Map<Long, Long> getCountsOfFiles() {
89 final String countFilesQuery =
"data_source_obj_id, COUNT(*) AS value"
90 +
" FROM tsk_files WHERE type<>" + TskData.TSK_DB_FILES_TYPE_ENUM.VIRTUAL_DIR.getFileType()
91 +
" AND dir_type<>" + TskData.TSK_FS_NAME_TYPE_ENUM.VIRT_DIR.getValue()
92 +
" AND name<>'' GROUP BY data_source_obj_id";
93 return getValuesMap(countFilesQuery);
94 }
catch (TskCoreException | NoCurrentCaseException ex) {
95 logger.log(Level.WARNING,
"Unable to get counts of files for all datasources, providing empty results", ex);
96 return Collections.emptyMap();
108 static Map<Long, Long> getCountsOfArtifacts() {
110 final String countArtifactsQuery =
"data_source_obj_id, COUNT(*) AS value"
111 +
" FROM blackboard_artifacts WHERE review_status_id !=" + BlackboardArtifact.ReviewStatus.REJECTED.getID()
112 +
" GROUP BY data_source_obj_id";
113 return getValuesMap(countArtifactsQuery);
114 }
catch (TskCoreException | NoCurrentCaseException ex) {
115 logger.log(Level.WARNING,
"Unable to get counts of artifacts for all datasources, providing empty results", ex);
116 return Collections.emptyMap();
129 static Map<Long, Long> getCountsOfTags() {
131 final String countFileTagsQuery =
"data_source_obj_id, COUNT(*) AS value"
132 +
" FROM content_tags as content_tags, tsk_files as tsk_files"
133 +
" WHERE content_tags.obj_id = tsk_files.obj_id"
134 +
" GROUP BY data_source_obj_id";
136 Map<Long, Long> tagCountMap =
new HashMap<>(getValuesMap(countFileTagsQuery));
137 final String countArtifactTagsQuery =
"data_source_obj_id, COUNT(*) AS value"
138 +
" FROM blackboard_artifact_tags as artifact_tags, blackboard_artifacts AS arts"
139 +
" WHERE artifact_tags.artifact_id = arts.artifact_id"
140 +
" GROUP BY data_source_obj_id";
142 getValuesMap(countArtifactTagsQuery).forEach((key, value) -> tagCountMap.merge(key, value, (value1, value2) -> value1 + value2));
144 }
catch (TskCoreException | NoCurrentCaseException ex) {
145 logger.log(Level.WARNING,
"Unable to get counts of tags for all datasources, providing empty results", ex);
146 return Collections.emptyMap();
160 static Map<Long, String> getOperatingSystems() {
161 Map<Long, String> osDetailMap =
new HashMap<>();
163 SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
164 ArrayList<BlackboardArtifact> osInfoArtifacts = skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_OS_INFO);
165 for (BlackboardArtifact osInfo : osInfoArtifacts) {
166 BlackboardAttribute programName = osInfo.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME));
167 if (programName != null) {
168 String currentOsString = osDetailMap.get(osInfo.getDataSource().getId());
169 if (currentOsString == null || currentOsString.isEmpty()) {
170 currentOsString = programName.getValueString();
172 currentOsString = currentOsString +
", " + programName.getValueString();
174 osDetailMap.put(osInfo.getDataSource().getId(), currentOsString);
177 }
catch (TskCoreException | NoCurrentCaseException ex) {
178 logger.log(Level.SEVERE,
"Failed to load OS info artifacts.", ex);
197 static Long getCountOfFilesForMimeTypes(DataSource currentDataSource, Set<String> setOfMimeTypes) {
198 if (currentDataSource != null) {
200 String inClause = String.join(
"', '", setOfMimeTypes);
201 SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
202 return skCase.countFilesWhere(
"data_source_obj_id=" + currentDataSource.getId()
203 +
" AND type<>" + TskData.TSK_DB_FILES_TYPE_ENUM.VIRTUAL_DIR.getFileType()
204 +
" AND dir_type<>" + TskData.TSK_FS_NAME_TYPE_ENUM.VIRT_DIR.getValue()
205 +
" AND mime_type IN ('" + inClause +
"')"
207 }
catch (TskCoreException | NoCurrentCaseException ex) {
208 logger.log(Level.WARNING,
"Unable to get count of files for specified mime types", ex);
223 static Map<Long, Long> getCountsOfUnallocatedFiles() {
225 final String countUnallocatedFilesQuery =
"data_source_obj_id, COUNT(*) AS value"
226 +
" FROM tsk_files WHERE type<>" + TskData.TSK_DB_FILES_TYPE_ENUM.VIRTUAL_DIR.getFileType()
227 +
" AND dir_type<>" + TskData.TSK_FS_NAME_TYPE_ENUM.VIRT_DIR.getValue()
228 +
" AND dir_flags=" + TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC.getValue()
229 +
" AND name<>'' GROUP BY data_source_obj_id";
230 return getValuesMap(countUnallocatedFilesQuery);
231 }
catch (TskCoreException | NoCurrentCaseException ex) {
232 logger.log(Level.WARNING,
"Unable to get counts of unallocated files for all datasources, providing empty results", ex);
233 return Collections.emptyMap();
245 static Map<Long, Long> getSizeOfUnallocatedFiles() {
247 final String countUnallocatedFilesQuery =
"data_source_obj_id, sum(size) AS value"
248 +
" FROM tsk_files WHERE type<>" + TskData.TSK_DB_FILES_TYPE_ENUM.VIRTUAL_DIR.getFileType()
249 +
" AND dir_type<>" + TskData.TSK_FS_NAME_TYPE_ENUM.VIRT_DIR.getValue()
250 +
" AND dir_flags=" + TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC.getValue()
251 +
" AND name<>'' GROUP BY data_source_obj_id";
252 return getValuesMap(countUnallocatedFilesQuery);
253 }
catch (TskCoreException | NoCurrentCaseException ex) {
254 logger.log(Level.WARNING,
"Unable to get size of unallocated files for all datasources, providing empty results", ex);
255 return Collections.emptyMap();
267 static Map<Long, Long> getCountsOfDirectories() {
269 final String countDirectoriesQuery =
"data_source_obj_id, COUNT(*) AS value"
270 +
" FROM tsk_files WHERE type<>" + TskData.TSK_DB_FILES_TYPE_ENUM.VIRTUAL_DIR.getFileType()
271 +
" AND dir_type<>" + TskData.TSK_FS_NAME_TYPE_ENUM.VIRT_DIR.getValue()
272 +
" AND meta_type=" + TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue()
273 +
" AND name<>'' GROUP BY data_source_obj_id";
274 return getValuesMap(countDirectoriesQuery);
275 }
catch (TskCoreException | NoCurrentCaseException ex) {
276 logger.log(Level.WARNING,
"Unable to get counts of directories for all datasources, providing empty results", ex);
277 return Collections.emptyMap();
289 static Map<Long, Long> getCountsOfSlackFiles() {
291 final String countSlackFilesQuery =
"data_source_obj_id, COUNT(*) AS value"
292 +
" FROM tsk_files WHERE type=" + TskData.TSK_DB_FILES_TYPE_ENUM.SLACK.getFileType()
293 +
" AND dir_type<>" + TskData.TSK_FS_NAME_TYPE_ENUM.VIRT_DIR.getValue()
294 +
" AND name<>'' GROUP BY data_source_obj_id";
295 return getValuesMap(countSlackFilesQuery);
296 }
catch (TskCoreException | NoCurrentCaseException ex) {
297 logger.log(Level.WARNING,
"Unable to get counts of slack files for all datasources, providing empty results", ex);
298 return Collections.emptyMap();
311 static Map<Long, Map<String, Long>> getCountsOfArtifactsByType() {
313 final String countArtifactsQuery =
"blackboard_artifacts.data_source_obj_id, blackboard_artifact_types.display_name AS label, COUNT(*) AS value"
314 +
" FROM blackboard_artifacts, blackboard_artifact_types"
315 +
" WHERE blackboard_artifacts.artifact_type_id = blackboard_artifact_types.artifact_type_id"
316 +
" GROUP BY blackboard_artifacts.data_source_obj_id, blackboard_artifact_types.display_name";
317 return getLabeledValuesMap(countArtifactsQuery);
318 }
catch (TskCoreException | NoCurrentCaseException ex) {
319 logger.log(Level.WARNING,
"Unable to get counts of all artifact types for all datasources, providing empty results", ex);
320 return Collections.emptyMap();
336 private static Map<Long, Map<String, Long>> getLabeledValuesMap(String query)
throws TskCoreException, NoCurrentCaseException {
337 SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
338 DataSourceLabeledValueCallback callback =
new DataSourceLabeledValueCallback();
339 skCase.getCaseDbAccessManager().select(query, callback);
340 return callback.getMapOfLabeledValues();
354 private static Map<Long, Long> getValuesMap(String query)
throws TskCoreException, NoCurrentCaseException {
355 SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
356 DataSourceSingleValueCallback callback =
new DataSourceSingleValueCallback();
357 skCase.getCaseDbAccessManager().select(query, callback);
358 return callback.getMapOfValues();
364 private DataSourceInfoUtilities() {