Autopsy  4.16.0
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 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 
22 import java.sql.SQLException;
23 import java.util.Arrays;
24 import java.util.HashSet;
25 import java.util.Set;
28 import org.sleuthkit.datamodel.AbstractFile;
29 import org.sleuthkit.datamodel.BlackboardArtifact;
30 import org.sleuthkit.datamodel.BlackboardAttribute;
31 import org.sleuthkit.datamodel.DataSource;
32 import org.sleuthkit.datamodel.TskCoreException;
33 import org.sleuthkit.datamodel.TskData;
34 
39 
40  private static final Set<Integer> ARTIFACT_UPDATE_TYPE_IDS = new HashSet<>(Arrays.asList(
41  BlackboardArtifact.ARTIFACT_TYPE.TSK_OS_INFO.getTypeID(),
42  BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE.getTypeID()
43  ));
44 
46 
50  public ContainerSummary() {
52  }
53 
60  this.provider = provider;
61  }
62 
63  @Override
64  public boolean isRefreshRequired(ModuleContentEvent evt) {
65  return true;
66  }
67 
68  @Override
69  public boolean isRefreshRequired(AbstractFile file) {
70  return true;
71  }
72 
73  @Override
74  public Set<Integer> getArtifactTypeIdsForRefresh() {
76  }
77 
89  public Long getSizeOfUnallocatedFiles(DataSource currentDataSource)
90  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
91  if (currentDataSource == null) {
92  return null;
93  }
94 
95  final String valueParam = "value";
96  final String countParam = "count";
97  String query = "SELECT SUM(size) AS " + valueParam + ", COUNT(*) AS " + countParam
98  + " FROM tsk_files"
99  + " WHERE " + DataSourceInfoUtilities.getMetaFlagsContainsStatement(TskData.TSK_FS_META_FLAG_ENUM.UNALLOC)
100  + " AND type<>" + TskData.TSK_DB_FILES_TYPE_ENUM.SLACK.getFileType()
101  + " AND type<>" + TskData.TSK_DB_FILES_TYPE_ENUM.VIRTUAL_DIR.getFileType()
102  + " AND dir_type<>" + TskData.TSK_FS_NAME_TYPE_ENUM.VIRT_DIR.getValue()
103  + " AND name<>''"
104  + " AND data_source_obj_id=" + currentDataSource.getId();
105 
106  DataSourceInfoUtilities.ResultSetHandler<Long> handler = (resultSet) -> {
107  if (resultSet.next()) {
108  // ensure that there is an unallocated count result that is attached to this data source
109  long resultCount = resultSet.getLong(valueParam);
110  return (resultCount > 0) ? resultSet.getLong(valueParam) : null;
111  } else {
112  return null;
113  }
114  };
115 
116  return DataSourceInfoUtilities.getBaseQueryResult(provider.get(), query, handler);
117  }
118 
132  public String getOperatingSystems(DataSource dataSource)
133  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
134 
135  if (dataSource == null) {
136  return null;
137  }
138 
139  return getConcattedAttrValue(dataSource.getId(),
140  BlackboardArtifact.ARTIFACT_TYPE.TSK_OS_INFO.getTypeID(),
141  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID());
142  }
143 
157  public String getDataSourceType(DataSource dataSource)
158  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
159 
160  if (dataSource == null) {
161  return null;
162  }
163 
164  return getConcattedAttrValue(dataSource.getId(),
165  BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE.getTypeID(),
166  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION.getTypeID());
167  }
168 
188  private String getConcattedStringsResult(String query, String valueParam, String separator)
189  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
190 
191  DataSourceInfoUtilities.ResultSetHandler<String> handler = (resultSet) -> {
192  String toRet = "";
193  boolean first = true;
194  while (resultSet.next()) {
195  if (first) {
196  first = false;
197  } else {
198  toRet += separator;
199  }
200  toRet += resultSet.getString(valueParam);
201  }
202 
203  return toRet;
204  };
205 
206  return DataSourceInfoUtilities.getBaseQueryResult(provider.get(), query, handler);
207  }
208 
224  private String getConcattedAttrValue(long dataSourceId, int artifactTypeId, int attributeTypeId)
225  throws SleuthkitCaseProvider.SleuthkitCaseProviderException, TskCoreException, SQLException {
226 
227  final String valueParam = "concatted_attribute_value";
228  String query = "SELECT attr.value_text AS " + valueParam
229  + " FROM blackboard_artifacts bba "
230  + " INNER JOIN blackboard_attributes attr ON bba.artifact_id = attr.artifact_id "
231  + " WHERE bba.data_source_obj_id = " + dataSourceId
232  + " AND bba.artifact_type_id = " + artifactTypeId
233  + " AND attr.attribute_type_id = " + attributeTypeId;
234 
235  String separator = ", ";
236  return getConcattedStringsResult(query, valueParam, separator);
237  }
238 }
String getConcattedAttrValue(long dataSourceId, int artifactTypeId, int attributeTypeId)
String getConcattedStringsResult(String query, String valueParam, String separator)

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