Autopsy 4.22.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-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 */
20package org.sleuthkit.autopsy.datamodel.utils;
21
22import java.io.File;
23import java.sql.ResultSet;
24import java.sql.SQLException;
25import java.util.HashMap;
26import java.util.Map;
27import org.sleuthkit.autopsy.casemodule.Case;
28import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
29import org.sleuthkit.datamodel.SleuthkitCase;
30import org.sleuthkit.datamodel.TskCoreException;
31
39public 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
55 public static Map<Long, String> getLogicalDataSources(SleuthkitCase tskDb) throws TskCoreException, SQLException {
56
57 Map<Long, String> dataSourceMap = new HashMap<>();
58 //try block releases resources - exceptions are handled in done()
59 try (
60 SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_LOGICAL);
61 ResultSet resultSet = query.getResultSet()) {
62 while (resultSet.next()) {
63 Long objectId = resultSet.getLong(1);
64 String dataSourceName = resultSet.getString(2);
65 dataSourceMap.put(objectId, dataSourceName);
66 }
67 }
68 return dataSourceMap;
69 }
70
81 public static Map<Long, String> getImageDataSources(SleuthkitCase tskDb) throws SQLException, TskCoreException {
82
83 Map<Long, String> dataSourceMap = new HashMap<>();
84 //try block releases resources - exceptions are handled in done()
85 try (
86 SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_IMAGE);
87 ResultSet resultSet = query.getResultSet()) {
88
89 while (resultSet.next()) {
90 Long objectId = resultSet.getLong(1);
91 if (!dataSourceMap.containsKey(objectId)) {
92 String dataSourceName = resultSet.getString(2);
93 File image = new File(dataSourceName);
94 String dataSourceNameTrimmed = image.getName();
95 dataSourceMap.put(objectId, dataSourceNameTrimmed);
96 }
97 }
98 }
99 return dataSourceMap;
100 }
101
112 public static Map<Long, String> getAllDataSources() throws NoCurrentCaseException, TskCoreException, SQLException {
113 Map<Long, String> dataSourceMap = new HashMap<>();
114
115 Case currentCase = Case.getCurrentCaseThrows();
116 SleuthkitCase tskDb = currentCase.getSleuthkitCase();
117
118 dataSourceMap.putAll(getLogicalDataSources(tskDb));
119
120 dataSourceMap.putAll(getImageDataSources(tskDb));
121
122 return dataSourceMap;
123 }
124}
static Map< Long, String > getLogicalDataSources(SleuthkitCase tskDb)
static Map< Long, String > getImageDataSources(SleuthkitCase tskDb)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.