Autopsy  4.16.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-2018 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.Calendar;
23 import java.util.List;
24 import java.util.UUID;
25 import java.util.logging.Level;
26 import javax.swing.JPanel;
27 import org.openide.util.NbBundle;
28 import org.openide.util.lookup.ServiceProvider;
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;
60  private boolean ignoreFatOrphanFiles;
61  private boolean setDataSourceOptionsCalled;
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  if (!setDataSourceOptionsCalled) {
139  deviceId = UUID.randomUUID().toString();
140  drivePath = configPanel.getContentPath();
141  sectorSize = configPanel.getSectorSize();
142  timeZone = configPanel.getTimeZone();
143  ignoreFatOrphanFiles = configPanel.getNoFatOrphans();
144  if (configPanel.getImageWriterEnabled()) {
145  imageWriterSettings = configPanel.getImageWriterSettings();
146  } else {
147  imageWriterSettings = null;
148  }
149  }
150 
151  Image image;
152  try {
153  image = SleuthkitJNI.addImageToDatabase(Case.getCurrentCase().getSleuthkitCase(),
154  new String[]{drivePath}, sectorSize,
155  timeZone, null, null, null, deviceId);
156  } catch (TskCoreException ex) {
157  logger.log(Level.SEVERE, "Error adding local disk with path " + drivePath + " to database", ex);
158  final List<String> errors = new ArrayList<>();
159  errors.add(ex.getMessage());
160  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errors, new ArrayList<>());
161  return;
162  }
163 
164  addDiskTask = new AddImageTask(
165  new AddImageTask.ImageDetails(deviceId, image, sectorSize, timeZone, ignoreFatOrphanFiles, null, null, null, imageWriterSettings),
166  progressMonitor,
167  new StreamingAddDataSourceCallbacks(new DefaultIngestStream()),
168  new StreamingAddImageTaskCallback(new DefaultIngestStream(), callback));
169  new Thread(addDiskTask).start();
170  }
171 
193  public void run(String deviceId, String drivePath, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
194  run(deviceId, drivePath, 0, timeZone, ignoreFatOrphanFiles, progressMonitor, callback);
195  }
196 
219  private void run(String deviceId, String drivePath, int sectorSize, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
220  Image image;
221  try {
222  image = SleuthkitJNI.addImageToDatabase(Case.getCurrentCase().getSleuthkitCase(),
223  new String[]{drivePath}, sectorSize,
224  timeZone, null, null, null, deviceId);
225  } catch (TskCoreException ex) {
226  logger.log(Level.SEVERE, "Error adding local disk with path " + drivePath + " to database", ex);
227  final List<String> errors = new ArrayList<>();
228  errors.add(ex.getMessage());
229  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errors, new ArrayList<>());
230  return;
231  }
232 
233  addDiskTask = new AddImageTask(new AddImageTask.ImageDetails(deviceId, image, sectorSize, timeZone, ignoreFatOrphanFiles, null, null, null, imageWriterSettings),
234  progressMonitor,
235  new StreamingAddDataSourceCallbacks(new DefaultIngestStream()),
236  new StreamingAddImageTaskCallback(new DefaultIngestStream(), callback));
237  new Thread(addDiskTask).start();
238  }
239 
247  @Override
248  public void cancel() {
249  if (null != addDiskTask) {
250  addDiskTask.cancelTask();
251  }
252  }
253 
258  @Override
259  public void reset() {
260  deviceId = null;
261  drivePath = null;
262  timeZone = null;
263  ignoreFatOrphanFiles = false;
264  setDataSourceOptionsCalled = false;
265  }
266 
280  @Deprecated
281  public void setDataSourceOptions(String drivePath, String timeZone, boolean ignoreFatOrphanFiles) {
282  this.deviceId = UUID.randomUUID().toString();
283  this.drivePath = drivePath;
284  this.sectorSize = 0;
285  this.timeZone = Calendar.getInstance().getTimeZone().getID();
286  this.ignoreFatOrphanFiles = ignoreFatOrphanFiles;
287  setDataSourceOptionsCalled = true;
288  }
289 
290 }
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
void setDataSourceOptions(String drivePath, String timeZone, boolean ignoreFatOrphanFiles)

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