Sleuth Kit Java Bindings (JNI)  4.12.1
Java bindings for using The Sleuth Kit
LocalFilesDataSource.java
Go to the documentation of this file.
1 /*
2  * Sleuth Kit Data Model
3  *
4  * Copyright 2011-2022 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.datamodel;
20 
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
23 import java.sql.Statement;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 
37 public class LocalFilesDataSource extends VirtualDirectory implements DataSource {
38 
39  private final long objectId;
40  private final String deviceId;
41  private final String timezone;
42  private volatile Host host;
43 
44  private static final Logger LOGGER = Logger.getLogger(LocalFilesDataSource.class.getName());
45 
72  public LocalFilesDataSource(SleuthkitCase db, long objId, long dataSourceObjectId, String deviceId, String name, TskData.TSK_FS_NAME_TYPE_ENUM dirType, TskData.TSK_FS_META_TYPE_ENUM metaType, TskData.TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, String timezone, String md5Hash, String sha256Hash, String sha1Hash, TskData.FileKnown knownState, String parentPath) {
73  super(db, objId, dataSourceObjectId, null, name, dirType, metaType, dirFlag, metaFlags, md5Hash, sha256Hash, sha1Hash, knownState, parentPath);
74  this.objectId = objId;
75  this.deviceId = deviceId;
76  this.timezone = timezone;
77  }
78 
87  @Deprecated
89  return this;
90  }
91 
99  @Override
100  public String getDeviceId() {
101  return deviceId;
102  }
103 
109  @Override
110  public String getTimeZone() {
111  return timezone;
112  }
113 
121  @Override
122  public void setDisplayName(String newName) throws TskCoreException {
123  this.getSleuthkitCase().setFileName(newName, objectId);
124  }
125 
141  @Override
142  public long getContentSize(SleuthkitCase sleuthkitCase) throws TskCoreException {
143  return getContentSize(sleuthkitCase, objectId);
144  }
145 
161  static long getContentSize(SleuthkitCase sleuthkitCase, long dataSourceObjId) throws TskCoreException {
162  SleuthkitCase.CaseDbConnection connection;
163  Statement statement = null;
164  ResultSet resultSet = null;
165  long contentSize = 0;
166 
167  connection = sleuthkitCase.getConnection();
168 
169  try {
170  statement = connection.createStatement();
171  resultSet = connection.executeQuery(statement, "SELECT SUM (size) FROM tsk_files WHERE tsk_files.data_source_obj_id = " + dataSourceObjId);
172  if (resultSet.next()) {
173  contentSize = resultSet.getLong("sum");
174  }
175  } catch (SQLException ex) {
176  throw new TskCoreException(String.format("There was a problem while querying the database for size data for object ID %d.", dataSourceObjId), ex);
177  } finally {
178  closeResultSet(resultSet);
179  closeStatement(statement);
180  connection.close();
181  }
182 
183  return contentSize;
184  }
185 
186  @Override
187  public String getUniquePath() throws TskCoreException {
188  return "/" + getName();
189  }
190 
198  @Override
199  public void setAcquisitionDetails(String details) throws TskCoreException {
200  getSleuthkitCase().setAcquisitionDetails(this, details);
201  }
202 
213  @Override
214  public void setAcquisitionToolDetails(String name, String version, String settings) throws TskCoreException {
215  getSleuthkitCase().setAcquisitionToolDetails(this, name, version, settings);
216  }
217 
225  @Override
226  public String getAcquisitionDetails() throws TskCoreException {
227  return getSleuthkitCase().getAcquisitionDetails(this);
228  }
229 
230 
238  @Override
240  return getSleuthkitCase().getDataSourceInfoString(this, "acquisition_tool_settings");
241  }
242 
250  public String getAcquisitionToolName() throws TskCoreException {
251  return getSleuthkitCase().getDataSourceInfoString(this, "acquisition_tool_name");
252  }
253 
262  return getSleuthkitCase().getDataSourceInfoString(this, "acquisition_tool_version");
263  }
264 
272  @Override
273  public Host getHost() throws TskCoreException {
274  // This is a check-then-act race condition that may occasionally result
275  // in additional processing but is safer than using locks.
276  if (host == null) {
278  }
279  return host;
280  }
281 
289  public Long getDateAdded() throws TskCoreException {
290  return getSleuthkitCase().getDataSourceInfoLong(this, "added_date_time");
291  }
292 
298  private static void closeResultSet(ResultSet resultSet) {
299  if (resultSet != null) {
300  try {
301  resultSet.close();
302  } catch (SQLException ex) {
303  LOGGER.log(Level.SEVERE, "Error closing ResultSet", ex); //NON-NLS
304  }
305  }
306  }
307 
313  private static void closeStatement(Statement statement) {
314  if (statement != null) {
315  try {
316  statement.close();
317  } catch (SQLException ex) {
318  LOGGER.log(Level.SEVERE, "Error closing Statement", ex); //NON-NLS
319  }
320  }
321  }
322 
332  @Override
333  public <T> T accept(ContentVisitor<T> visitor) {
334  return visitor.visit(this);
335  }
336 
346  @Override
347  public <T> T accept(SleuthkitItemVisitor<T> visitor) {
348  return visitor.visit(this);
349  }
350 
377  @Deprecated
378  public LocalFilesDataSource(SleuthkitCase db, long objId, long dataSourceObjectId, String deviceId, String name, TskData.TSK_FS_NAME_TYPE_ENUM dirType, TskData.TSK_FS_META_TYPE_ENUM metaType, TskData.TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, String timezone, String md5Hash, TskData.FileKnown knownState, String parentPath) {
379  this(db, objId, dataSourceObjectId, deviceId, name, dirType, metaType, dirFlag, metaFlags, timezone, md5Hash, null, null, knownState, parentPath);
380  }
381 }
final TSK_FS_NAME_TYPE_ENUM dirType
Host getHostByDataSource(DataSource dataSource)
Set< TSK_FS_META_FLAG_ENUM > metaFlags
LocalFilesDataSource(SleuthkitCase db, long objId, long dataSourceObjectId, String deviceId, String name, TskData.TSK_FS_NAME_TYPE_ENUM dirType, TskData.TSK_FS_META_TYPE_ENUM metaType, TskData.TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, String timezone, String md5Hash, String sha256Hash, String sha1Hash, TskData.FileKnown knownState, String parentPath)
void setAcquisitionToolDetails(String name, String version, String settings)
final TSK_FS_META_TYPE_ENUM metaType
LocalFilesDataSource(SleuthkitCase db, long objId, long dataSourceObjectId, String deviceId, String name, TskData.TSK_FS_NAME_TYPE_ENUM dirType, TskData.TSK_FS_META_TYPE_ENUM metaType, TskData.TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, String timezone, String md5Hash, TskData.FileKnown knownState, String parentPath)
long getContentSize(SleuthkitCase sleuthkitCase)

Copyright © 2011-2021 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.