Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ContainerSummary.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020-2021 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.datasourcesummary.datamodel;
20 
21 import java.sql.SQLException;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Set;
29 import org.sleuthkit.datamodel.BlackboardArtifact;
30 import org.sleuthkit.datamodel.BlackboardAttribute;
31 import org.sleuthkit.datamodel.DataSource;
32 import org.sleuthkit.datamodel.Image;
33 import org.sleuthkit.datamodel.TskCoreException;
34 import org.sleuthkit.datamodel.TskData;
35 
39 public class ContainerSummary {
40 
42 
46  public ContainerSummary() {
48  }
49 
56  this.provider = provider;
57  }
58 
70  public Long getSizeOfUnallocatedFiles(DataSource currentDataSource)
71  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
72  if (currentDataSource == null) {
73  return null;
74  }
75 
76  final String valueParam = "value";
77  final String countParam = "count";
78  String query = "SELECT SUM(size) AS " + valueParam + ", COUNT(*) AS " + countParam
79  + " FROM tsk_files"
80  + " WHERE " + DataSourceInfoUtilities.getMetaFlagsContainsStatement(TskData.TSK_FS_META_FLAG_ENUM.UNALLOC)
81  + " AND type<>" + TskData.TSK_DB_FILES_TYPE_ENUM.SLACK.getFileType()
82  + " AND type<>" + TskData.TSK_DB_FILES_TYPE_ENUM.VIRTUAL_DIR.getFileType()
83  + " AND dir_type<>" + TskData.TSK_FS_NAME_TYPE_ENUM.VIRT_DIR.getValue()
84  + " AND name<>''"
85  + " AND data_source_obj_id=" + currentDataSource.getId();
86 
87  DataSourceInfoUtilities.ResultSetHandler<Long> handler = (resultSet) -> {
88  if (resultSet.next()) {
89  // ensure that there is an unallocated count result that is attached to this data source
90  long resultCount = resultSet.getLong(valueParam);
91  return (resultCount > 0) ? resultSet.getLong(valueParam) : null;
92  } else {
93  return null;
94  }
95  };
96 
97  return DataSourceInfoUtilities.getBaseQueryResult(provider.get(), query, handler);
98  }
99 
113  public String getOperatingSystems(DataSource dataSource)
114  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
115 
116  if (dataSource == null) {
117  return null;
118  }
119 
120  return getConcattedAttrValue(dataSource.getId(),
121  BlackboardArtifact.ARTIFACT_TYPE.TSK_OS_INFO.getTypeID(),
122  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID());
123  }
124 
138  public String getDataSourceType(DataSource dataSource)
139  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
140 
141  if (dataSource == null) {
142  return null;
143  }
144 
145  return getConcattedAttrValue(dataSource.getId(),
146  BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE.getTypeID(),
147  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION.getTypeID());
148  }
149 
165  private String getConcattedStringsResult(String query, String valueParam, String separator)
166  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
167 
168  DataSourceInfoUtilities.ResultSetHandler<String> handler = (resultSet) -> {
169  String toRet = "";
170  boolean first = true;
171  while (resultSet.next()) {
172  if (first) {
173  first = false;
174  } else {
175  toRet += separator;
176  }
177  toRet += resultSet.getString(valueParam);
178  }
179 
180  return toRet;
181  };
182 
183  return DataSourceInfoUtilities.getBaseQueryResult(provider.get(), query, handler);
184  }
185 
201  private String getConcattedAttrValue(long dataSourceId, int artifactTypeId, int attributeTypeId)
202  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
203 
204  final String valueParam = "concatted_attribute_value";
205  String query = "SELECT attr.value_text AS " + valueParam
206  + " FROM blackboard_artifacts bba "
207  + " INNER JOIN blackboard_attributes attr ON bba.artifact_id = attr.artifact_id "
208  + " WHERE bba.data_source_obj_id = " + dataSourceId
209  + " AND bba.artifact_type_id = " + artifactTypeId
210  + " AND attr.attribute_type_id = " + attributeTypeId;
211 
212  String separator = ", ";
213  return getConcattedStringsResult(query, valueParam, separator);
214  }
215 
219  public static class ImageDetails {
220 
221  private final long unallocatedSize;
222  private final long size;
223  private final long sectorSize;
224 
225  private final String timeZone;
226  private final String imageType;
227 
228  private final List<String> paths;
229  private final String md5Hash;
230  private final String sha1Hash;
231  private final String sha256Hash;
232 
246  ImageDetails(long unallocatedSize, long size, long sectorSize,
247  String timeZone, String imageType, List<String> paths, String md5Hash,
248  String sha1Hash, String sha256Hash) {
249  this.unallocatedSize = unallocatedSize;
250  this.size = size;
251  this.sectorSize = sectorSize;
252  this.timeZone = timeZone;
253  this.imageType = imageType;
254  this.paths = paths == null ? Collections.emptyList() : new ArrayList<>(paths);
255  this.md5Hash = md5Hash;
256  this.sha1Hash = sha1Hash;
257  this.sha256Hash = sha256Hash;
258  }
259 
263  public long getUnallocatedSize() {
264  return unallocatedSize;
265  }
266 
270  public long getSize() {
271  return size;
272  }
273 
277  public long getSectorSize() {
278  return sectorSize;
279  }
280 
284  public String getTimeZone() {
285  return timeZone;
286  }
287 
291  public String getImageType() {
292  return imageType;
293  }
294 
298  public List<String> getPaths() {
299  return Collections.unmodifiableList(paths);
300  }
301 
305  public String getMd5Hash() {
306  return md5Hash;
307  }
308 
312  public String getSha1Hash() {
313  return sha1Hash;
314  }
315 
319  public String getSha256Hash() {
320  return sha256Hash;
321  }
322  }
323 
327  public static class ContainerDetails {
328 
329  private final String displayName;
330  private final String originalName;
331  private final String deviceIdValue;
332  private final String acquisitionDetails;
333  private final ImageDetails imageDetails;
334 
347  ContainerDetails(String displayName, String originalName, String deviceIdValue,
348  String acquisitionDetails, ImageDetails imageDetails) {
349  this.displayName = displayName;
350  this.originalName = originalName;
351  this.deviceIdValue = deviceIdValue;
352  this.acquisitionDetails = acquisitionDetails;
353  this.imageDetails = imageDetails;
354  }
355 
359  public String getDisplayName() {
360  return displayName;
361  }
362 
366  public String getOriginalName() {
367  return originalName;
368  }
369 
373  public String getDeviceId() {
374  return deviceIdValue;
375  }
376 
380  public String getAcquisitionDetails() {
381  return acquisitionDetails;
382  }
383 
389  return imageDetails;
390  }
391  }
392 
401  public ContainerDetails getContainerDetails(DataSource ds) throws TskCoreException, SQLException, SleuthkitCaseProvider.SleuthkitCaseProviderException {
402  if (ds == null) {
403  return null;
404  }
405 
406  return new ContainerDetails(
407  ds.getName(),
408  ds.getName(),
409  ds.getDeviceId(),
410  ds.getAcquisitionDetails(),
411  ds instanceof Image ? getImageDetails((Image) ds) : null
412  );
413  }
414 
422  public ImageDetails getImageDetails(Image image) throws TskCoreException, SQLException, SleuthkitCaseProvider.SleuthkitCaseProviderException {
423  if (image == null) {
424  return null;
425  }
426 
427  Long unallocSize = getSizeOfUnallocatedFiles(image);
428  String imageType = image.getType().getName();
429  Long size = image.getSize();
430  Long sectorSize = image.getSsize();
431  String timeZone = image.getTimeZone();
432  List<String> paths = image.getPaths() == null ? Collections.emptyList() : Arrays.asList(image.getPaths());
433  String md5 = image.getMd5();
434  String sha1 = image.getSha1();
435  String sha256 = image.getSha256();
436 
437  return new ImageDetails(unallocSize, size, sectorSize, timeZone, imageType, paths, md5, sha1, sha256);
438  }
439 }
String getConcattedAttrValue(long dataSourceId, int artifactTypeId, int attributeTypeId)
String getConcattedStringsResult(String query, String valueParam, String separator)

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.