Autopsy  4.9.1
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 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.guiutils;
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  ) {
51  while (resultSet.next()) {
52  Long objectId = resultSet.getLong(1);
53  String dataSourceName = resultSet.getString(2);
54  dataSouceMap.put(objectId, dataSourceName);
55  }
56  }
57  }
58 
59  private void loadImageSources(SleuthkitCase tskDb, Map<Long, String> dataSouceMap) throws SQLException, TskCoreException {
60  //try block releases resources - exceptions are handled in done()
61  try (
62  SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_IMAGE);
63  ResultSet resultSet = query.getResultSet()) {
64 
65  while (resultSet.next()) {
66  Long objectId = resultSet.getLong(1);
67  String dataSourceName = resultSet.getString(2);
68  File image = new File(dataSourceName);
69  String dataSourceNameTrimmed = image.getName();
70  dataSouceMap.put(objectId, dataSourceNameTrimmed);
71  }
72  }
73  }
74 
83  public Map<Long, String> getDataSourceMap() throws NoCurrentCaseException, TskCoreException, SQLException {
84  Map<Long, String> dataSouceMap = new HashMap<>();
85 
86  Case currentCase = Case.getCurrentCaseThrows();
87  SleuthkitCase tskDb = currentCase.getSleuthkitCase();
88 
89  loadLogicalSources(tskDb, dataSouceMap);
90 
91  loadImageSources(tskDb, dataSouceMap);
92 
93  return dataSouceMap;
94  }
95 }
void loadImageSources(SleuthkitCase tskDb, Map< Long, String > dataSouceMap)
void loadLogicalSources(SleuthkitCase tskDb, Map< Long, String > dataSouceMap)

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