Sleuth Kit Java Bindings (JNI)  4.11.0
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-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.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 
71  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, TskData.FileKnown knownState, String parentPath) {
72  super(db, objId, dataSourceObjectId, name, dirType, metaType, dirFlag, metaFlags, md5Hash, sha256Hash, knownState, parentPath);
73  this.objectId = objId;
74  this.deviceId = deviceId;
75  this.timezone = timezone;
76  }
77 
86  @Deprecated
88  return this;
89  }
90 
98  @Override
99  public String getDeviceId() {
100  return deviceId;
101  }
102 
108  @Override
109  public String getTimeZone() {
110  return timezone;
111  }
112 
120  @Override
121  public void setDisplayName(String newName) throws TskCoreException {
122  this.getSleuthkitCase().setFileName(newName, objectId);
123  }
124 
140  @Override
141  public long getContentSize(SleuthkitCase sleuthkitCase) throws TskCoreException {
142  return getContentSize(sleuthkitCase, objectId);
143  }
144 
160  static long getContentSize(SleuthkitCase sleuthkitCase, long dataSourceObjId) throws TskCoreException {
161  SleuthkitCase.CaseDbConnection connection;
162  Statement statement = null;
163  ResultSet resultSet = null;
164  long contentSize = 0;
165 
166  connection = sleuthkitCase.getConnection();
167 
168  try {
169  statement = connection.createStatement();
170  resultSet = connection.executeQuery(statement, "SELECT SUM (size) FROM tsk_files WHERE tsk_files.data_source_obj_id = " + dataSourceObjId);
171  if (resultSet.next()) {
172  contentSize = resultSet.getLong("sum");
173  }
174  } catch (SQLException ex) {
175  throw new TskCoreException(String.format("There was a problem while querying the database for size data for object ID %d.", dataSourceObjId), ex);
176  } finally {
177  closeResultSet(resultSet);
178  closeStatement(statement);
179  connection.close();
180  }
181 
182  return contentSize;
183  }
184 
192  @Override
193  public void setAcquisitionDetails(String details) throws TskCoreException {
194  getSleuthkitCase().setAcquisitionDetails(this, details);
195  }
196 
207  @Override
208  public void setAcquisitionToolDetails(String name, String version, String settings) throws TskCoreException {
209  getSleuthkitCase().setAcquisitionToolDetails(this, name, version, settings);
210  }
211 
219  @Override
220  public String getAcquisitionDetails() throws TskCoreException {
221  return getSleuthkitCase().getAcquisitionDetails(this);
222  }
223 
224 
232  @Override
234  return getSleuthkitCase().getDataSourceInfoString(this, "acquisition_tool_settings");
235  }
236 
244  public String getAcquisitionToolName() throws TskCoreException {
245  return getSleuthkitCase().getDataSourceInfoString(this, "acquisition_tool_name");
246  }
247 
256  return getSleuthkitCase().getDataSourceInfoString(this, "acquisition_tool_version");
257  }
258 
266  @Override
267  public Host getHost() throws TskCoreException {
268  // This is a check-then-act race condition that may occasionally result
269  // in additional processing but is safer than using locks.
270  if (host == null) {
272  }
273  return host;
274  }
275 
283  public Long getDateAdded() throws TskCoreException {
284  return getSleuthkitCase().getDataSourceInfoLong(this, "added_date_time");
285  }
286 
292  private static void closeResultSet(ResultSet resultSet) {
293  if (resultSet != null) {
294  try {
295  resultSet.close();
296  } catch (SQLException ex) {
297  LOGGER.log(Level.SEVERE, "Error closing ResultSet", ex); //NON-NLS
298  }
299  }
300  }
301 
307  private static void closeStatement(Statement statement) {
308  if (statement != null) {
309  try {
310  statement.close();
311  } catch (SQLException ex) {
312  LOGGER.log(Level.SEVERE, "Error closing Statement", ex); //NON-NLS
313  }
314  }
315  }
316 
326  @Override
327  public <T> T accept(ContentVisitor<T> visitor) {
328  return visitor.visit(this);
329  }
330 
340  @Override
341  public <T> T accept(SleuthkitItemVisitor<T> visitor) {
342  return visitor.visit(this);
343  }
344 
371  @Deprecated
372  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) {
373  this(db, objId, dataSourceObjectId, deviceId, name, dirType, metaType, dirFlag, metaFlags, timezone, md5Hash, null, knownState, parentPath);
374  }
375 }
final TSK_FS_NAME_TYPE_ENUM dirType
Host getHostByDataSource(DataSource dataSource)
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, TskData.FileKnown knownState, String parentPath)
Set< TSK_FS_META_FLAG_ENUM > metaFlags
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.