Autopsy  4.7.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ImageDSProcessor.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.io.File;
22 import java.nio.file.Path;
23 import javax.swing.JPanel;
24 import java.util.ArrayList;
25 import java.util.Calendar;
26 import java.util.List;
27 import java.util.UUID;
28 import javax.swing.filechooser.FileFilter;
29 import org.openide.util.NbBundle;
30 import org.openide.util.lookup.ServiceProvider;
31 import org.openide.util.lookup.ServiceProviders;
37 
44 @ServiceProviders(value={
45  @ServiceProvider(service=DataSourceProcessor.class),
46  @ServiceProvider(service=AutoIngestDataSourceProcessor.class)}
47 )
49 
50  private final static String DATA_SOURCE_TYPE = NbBundle.getMessage(ImageDSProcessor.class, "ImageDSProcessor.dsType.text");
51  private static final List<String> allExt = new ArrayList<>();
55  private static final String ALL_DESC = NbBundle.getMessage(ImageDSProcessor.class, "ImageDSProcessor.allDesc.text");
56  private static final GeneralFilter allFilter = new GeneralFilter(allExt, ALL_DESC);
57  private static final List<FileFilter> filtersList = new ArrayList<>();
58  private final ImageFilePanel configPanel;
59  private AddImageTask addImageTask;
60  /*
61  * TODO: Remove the setDataSourceOptionsCalled flag and the settings fields
62  * when the deprecated method setDataSourceOptions is removed.
63  */
64  private String deviceId;
65  private String imagePath;
66  private int sectorSize;
67  private String timeZone;
68  private boolean ignoreFatOrphanFiles;
69  private boolean setDataSourceOptionsCalled;
70 
71  static {
72  filtersList.add(allFilter);
73  filtersList.add(rawFilter);
74  filtersList.add(encaseFilter);
75  allExt.addAll(GeneralFilter.RAW_IMAGE_EXTS);
76  allExt.addAll(GeneralFilter.ENCASE_IMAGE_EXTS);
77  if(!System.getProperty("os.name").toLowerCase().contains("mac")){
78  filtersList.add(virtualMachineFilter);
79  allExt.addAll(GeneralFilter.VIRTUAL_MACHINE_EXTS);
80  }
81  }
82 
89  public ImageDSProcessor() {
90  configPanel = ImageFilePanel.createInstance(ImageDSProcessor.class.getName(), filtersList);
91  }
92 
100  public static String getType() {
101  return DATA_SOURCE_TYPE;
102  }
103 
111  @Override
112  public String getDataSourceType() {
113  return getType();
114  }
115 
124  @Override
125  public JPanel getPanel() {
126  configPanel.readSettings();
127  configPanel.select();
128  return configPanel;
129  }
130 
138  @Override
139  public boolean isPanelValid() {
140  return configPanel.validatePanel();
141  }
142 
157  @Override
158  public void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
159  if (!setDataSourceOptionsCalled) {
160  configPanel.storeSettings();
161  deviceId = UUID.randomUUID().toString();
162  imagePath = configPanel.getContentPaths();
163  sectorSize = configPanel.getSectorSize();
164  timeZone = configPanel.getTimeZone();
165  ignoreFatOrphanFiles = configPanel.getNoFatOrphans();
166  }
167  run(deviceId, imagePath, sectorSize, timeZone, ignoreFatOrphanFiles, progressMonitor, callback);
168  }
169 
191  public void run(String deviceId, String imagePath, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
192  run(deviceId, imagePath, 0, timeZone, ignoreFatOrphanFiles, progressMonitor, callback);
193  }
194 
217  private void run(String deviceId, String imagePath, int sectorSize, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
218  addImageTask = new AddImageTask(deviceId, imagePath, sectorSize, timeZone, ignoreFatOrphanFiles, null, progressMonitor, callback);
219  new Thread(addImageTask).start();
220  }
221 
229  @Override
230  public void cancel() {
231  if (null != addImageTask) {
232  addImageTask.cancelTask();
233  }
234  }
235 
240  @Override
241  public void reset() {
242  deviceId = null;
243  imagePath = null;
244  timeZone = null;
245  ignoreFatOrphanFiles = false;
246  configPanel.reset();
247  setDataSourceOptionsCalled = false;
248  }
249 
250  private static boolean isAcceptedByFiler(File file, List<FileFilter> filters) {
251  for (FileFilter filter : filters) {
252  if (filter.accept(file)) {
253  return true;
254  }
255  }
256  return false;
257  }
258 
259  @Override
260  public int canProcess(Path dataSourcePath) throws AutoIngestDataSourceProcessorException {
261 
262  // check file extension for supported types
263  if (!isAcceptedByFiler(dataSourcePath.toFile(), filtersList)) {
264  return 0;
265  }
266 
267  try {
268  // verify that the image has a file system that TSK can process
269  Case currentCase = Case.getCurrentCaseThrows();
270  if (!DataSourceUtils.imageHasFileSystem(dataSourcePath)) {
271  // image does not have a file system that TSK can process
272  return 0;
273  }
274  } catch (Exception ex) {
275  throw new AutoIngestDataSourceProcessorException("Exception inside canProcess() method", ex);
276  }
277 
278  // able to process the data source
279  return 100;
280  }
281 
282  @Override
283  public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) {
284  this.deviceId = deviceId;
285  this.imagePath = dataSourcePath.toString();
286  this.sectorSize = 0;
287  this.timeZone = Calendar.getInstance().getTimeZone().getID();
288  this.ignoreFatOrphanFiles = false;
289  setDataSourceOptionsCalled = true;
290  run(deviceId, dataSourcePath.toString(), sectorSize, timeZone, ignoreFatOrphanFiles, progressMonitor, callBack);
291  }
292 
306  @Deprecated
307  public void setDataSourceOptions(String imagePath, String timeZone, boolean ignoreFatOrphanFiles) {
308  this.deviceId = UUID.randomUUID().toString();
309  this.imagePath = imagePath;
310  this.sectorSize = 0;
311  this.timeZone = Calendar.getInstance().getTimeZone().getID();
312  this.ignoreFatOrphanFiles = ignoreFatOrphanFiles;
313  setDataSourceOptionsCalled = true;
314  }
315 
316 }
void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack)
static boolean isAcceptedByFiler(File file, List< FileFilter > filters)
static synchronized ImageFilePanel createInstance(String context, List< FileFilter > fileChooserFilters)
void run(String deviceId, String imagePath, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
void run(String deviceId, String imagePath, int sectorSize, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
static final List< String > VIRTUAL_MACHINE_EXTS
static final List< String > ENCASE_IMAGE_EXTS
void setDataSourceOptions(String imagePath, String timeZone, boolean ignoreFatOrphanFiles)
static boolean imageHasFileSystem(Path dataSourcePath)
void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)

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