Autopsy  4.10.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourceLoader.java
Go to the documentation of this file.
1 /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2018-2019 Basis Technology Corp.
6  * Contact: carrier <at> sleuthkit <dot> org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 package org.sleuthkit.autopsy.datamodel.utils;
21 
22 import java.io.File;
23 import java.sql.ResultSet;
24 import java.sql.SQLException;
25 import java.util.HashMap;
26 import java.util.Map;
29 import org.sleuthkit.datamodel.SleuthkitCase;
30 import org.sleuthkit.datamodel.TskCoreException;
31 
39 public class DataSourceLoader {
40 
41  private static final String SELECT_DATA_SOURCES_LOGICAL = "select obj_id, name from tsk_files where obj_id in (SELECT obj_id FROM tsk_objects WHERE obj_id in (select obj_id from data_source_info))";
42 
43  private static final String SELECT_DATA_SOURCES_IMAGE = "select obj_id, name from tsk_image_names where obj_id in (SELECT obj_id FROM tsk_objects WHERE obj_id in (select obj_id from data_source_info))";
44 
45  private void loadLogicalSources(SleuthkitCase tskDb, Map<Long, String> dataSouceMap) throws TskCoreException, SQLException {
46  //try block releases resources - exceptions are handled in done()
47  try (
48  SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_LOGICAL);
49  ResultSet resultSet = query.getResultSet()) {
50  while (resultSet.next()) {
51  Long objectId = resultSet.getLong(1);
52  String dataSourceName = resultSet.getString(2);
53  dataSouceMap.put(objectId, dataSourceName);
54  }
55  }
56  }
57 
58  private void loadImageSources(SleuthkitCase tskDb, Map<Long, String> dataSourceMap) throws SQLException, TskCoreException {
59  //try block releases resources - exceptions are handled in done()
60  try (
61  SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_IMAGE);
62  ResultSet resultSet = query.getResultSet()) {
63 
64  while (resultSet.next()) {
65  Long objectId = resultSet.getLong(1);
66  if (!dataSourceMap.containsKey(objectId)) {
67  String dataSourceName = resultSet.getString(2);
68  File image = new File(dataSourceName);
69  String dataSourceNameTrimmed = image.getName();
70  dataSourceMap.put(objectId, dataSourceNameTrimmed);
71  }
72  }
73  }
74  }
75 
85  public Map<Long, String> getDataSourceMap() throws NoCurrentCaseException, TskCoreException, SQLException {
86  Map<Long, String> dataSouceMap = new HashMap<>();
87 
88  Case currentCase = Case.getCurrentCaseThrows();
89  SleuthkitCase tskDb = currentCase.getSleuthkitCase();
90 
91  loadLogicalSources(tskDb, dataSouceMap);
92 
93  loadImageSources(tskDb, dataSouceMap);
94 
95  return dataSouceMap;
96  }
97 }
void loadLogicalSources(SleuthkitCase tskDb, Map< Long, String > dataSouceMap)
void loadImageSources(SleuthkitCase tskDb, Map< Long, String > dataSourceMap)

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.