Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
LocalDiskDSProcessor.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-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.autopsy.casemodule;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.UUID;
24 import java.util.logging.Level;
25 import javax.swing.JPanel;
26 import org.openide.util.NbBundle;
27 import org.openide.util.lookup.ServiceProvider;
33 import org.sleuthkit.datamodel.Host;
34 import org.sleuthkit.datamodel.Image;
35 import org.sleuthkit.datamodel.SleuthkitJNI;
36 import org.sleuthkit.datamodel.TskCoreException;
37 
44 @ServiceProvider(service = DataSourceProcessor.class)
45 public class LocalDiskDSProcessor implements DataSourceProcessor {
46 
47  private final Logger logger = Logger.getLogger(LocalDiskDSProcessor.class.getName());
48  private static final String DATA_SOURCE_TYPE = NbBundle.getMessage(LocalDiskDSProcessor.class, "LocalDiskDSProcessor.dsType.text");
49  private final LocalDiskPanel configPanel;
50  private AddImageTask addDiskTask;
51  /*
52  * TODO: Remove the setDataSourceOptionsCalled flag and the settings fields
53  * when the deprecated method setDataSourceOptions is removed.
54  */
55  private String deviceId;
56  private String drivePath;
57  private int sectorSize;
58  private String timeZone;
59  private Host host;
61  private boolean ignoreFatOrphanFiles;
62 
70  configPanel = LocalDiskPanel.getDefault();
71  }
72 
80  public static String getType() {
81  return DATA_SOURCE_TYPE;
82  }
83 
91  @Override
92  public String getDataSourceType() {
93  return DATA_SOURCE_TYPE;
94  }
95 
104  @Override
105  public JPanel getPanel() {
106  configPanel.resetLocalDiskSelection();
107  return configPanel;
108  }
109 
117  @Override
118  public boolean isPanelValid() {
119  return configPanel.validatePanel();
120  }
121 
136  @Override
137  public void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
138  run(null, progressMonitor, callback);
139  }
140 
156  @Override
157  public void run(Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
158  deviceId = UUID.randomUUID().toString();
159  drivePath = configPanel.getContentPath();
160  sectorSize = configPanel.getSectorSize();
161  timeZone = configPanel.getTimeZone();
162  ignoreFatOrphanFiles = configPanel.getNoFatOrphans();
163  if (configPanel.getImageWriterEnabled()) {
164  imageWriterSettings = configPanel.getImageWriterSettings();
165  } else {
166  imageWriterSettings = null;
167  }
168 
169  this.host = host;
170 
171  Image image;
172  try {
173  image = SleuthkitJNI.addImageToDatabase(Case.getCurrentCase().getSleuthkitCase(),
174  new String[]{drivePath}, sectorSize,
175  timeZone, null, null, null, deviceId, this.host);
176  } catch (TskCoreException ex) {
177  logger.log(Level.SEVERE, "Error adding local disk with path " + drivePath + " to database", ex);
178  final List<String> errors = new ArrayList<>();
179  errors.add(ex.getMessage());
180  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errors, new ArrayList<>());
181  return;
182  }
183 
184  addDiskTask = new AddImageTask(
185  new AddImageTask.ImageDetails(deviceId, image, sectorSize, timeZone, ignoreFatOrphanFiles, null, null, null, imageWriterSettings),
186  progressMonitor,
187  new StreamingAddDataSourceCallbacks(new DefaultIngestStream()),
188  new StreamingAddImageTaskCallback(new DefaultIngestStream(), callback));
189  new Thread(addDiskTask).start();
190  }
191 
213  public void run(String deviceId, String drivePath, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
214  run(deviceId, drivePath, 0, timeZone, ignoreFatOrphanFiles, progressMonitor, callback);
215  }
216 
239  private void run(String deviceId, String drivePath, int sectorSize, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
240  Image image;
241  try {
242  image = SleuthkitJNI.addImageToDatabase(Case.getCurrentCase().getSleuthkitCase(),
243  new String[]{drivePath}, sectorSize,
244  timeZone, null, null, null, deviceId);
245  } catch (TskCoreException ex) {
246  logger.log(Level.SEVERE, "Error adding local disk with path " + drivePath + " to database", ex);
247  final List<String> errors = new ArrayList<>();
248  errors.add(ex.getMessage());
249  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errors, new ArrayList<>());
250  return;
251  }
252 
253  addDiskTask = new AddImageTask(new AddImageTask.ImageDetails(deviceId, image, sectorSize, timeZone, ignoreFatOrphanFiles, null, null, null, imageWriterSettings),
254  progressMonitor,
255  new StreamingAddDataSourceCallbacks(new DefaultIngestStream()),
256  new StreamingAddImageTaskCallback(new DefaultIngestStream(), callback));
257  new Thread(addDiskTask).start();
258  }
259 
267  @Override
268  public void cancel() {
269  if (null != addDiskTask) {
270  addDiskTask.cancelTask();
271  }
272  }
273 
278  @Override
279  public void reset() {
280  deviceId = null;
281  drivePath = null;
282  timeZone = null;
283  ignoreFatOrphanFiles = false;
284  }
285 }
void run(Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
void done(DataSourceProcessorResult result, List< String > errList, List< Content > newDataSources)
void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
void run(String deviceId, String drivePath, int sectorSize, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
void run(String deviceId, String drivePath, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.