Autopsy  4.8.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 
98  static List<FileFilter> getFileFiltersList() {
99  return filtersList;
100  }
101 
109  public static String getType() {
110  return DATA_SOURCE_TYPE;
111  }
112 
120  @Override
121  public String getDataSourceType() {
122  return getType();
123  }
124 
133  @Override
134  public JPanel getPanel() {
135  configPanel.readSettings();
136  configPanel.select();
137  return configPanel;
138  }
139 
147  @Override
148  public boolean isPanelValid() {
149  return configPanel.validatePanel();
150  }
151 
166  @Override
167  public void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
168  if (!setDataSourceOptionsCalled) {
169  configPanel.storeSettings();
170  deviceId = UUID.randomUUID().toString();
171  imagePath = configPanel.getContentPaths();
172  sectorSize = configPanel.getSectorSize();
173  timeZone = configPanel.getTimeZone();
174  ignoreFatOrphanFiles = configPanel.getNoFatOrphans();
175  }
176  run(deviceId, imagePath, sectorSize, timeZone, ignoreFatOrphanFiles, progressMonitor, callback);
177  }
178 
200  public void run(String deviceId, String imagePath, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
201  run(deviceId, imagePath, 0, timeZone, ignoreFatOrphanFiles, progressMonitor, callback);
202  }
203 
226  private void run(String deviceId, String imagePath, int sectorSize, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
227  addImageTask = new AddImageTask(deviceId, imagePath, sectorSize, timeZone, ignoreFatOrphanFiles, null, progressMonitor, callback);
228  new Thread(addImageTask).start();
229  }
230 
238  @Override
239  public void cancel() {
240  if (null != addImageTask) {
241  addImageTask.cancelTask();
242  }
243  }
244 
249  @Override
250  public void reset() {
251  deviceId = null;
252  imagePath = null;
253  timeZone = null;
254  ignoreFatOrphanFiles = false;
255  configPanel.reset();
256  setDataSourceOptionsCalled = false;
257  }
258 
259  private static boolean isAcceptedByFiler(File file, List<FileFilter> filters) {
260  for (FileFilter filter : filters) {
261  if (filter.accept(file)) {
262  return true;
263  }
264  }
265  return false;
266  }
267 
268  @Override
269  public int canProcess(Path dataSourcePath) throws AutoIngestDataSourceProcessorException {
270 
271  // check file extension for supported types
272  if (!isAcceptedByFiler(dataSourcePath.toFile(), filtersList)) {
273  return 0;
274  }
275 
276  try {
277  // verify that the image has a file system that TSK can process
278  Case currentCase = Case.getCurrentCaseThrows();
279  if (!DataSourceUtils.imageHasFileSystem(dataSourcePath)) {
280  // image does not have a file system that TSK can process
281  return 0;
282  }
283  } catch (Exception ex) {
284  throw new AutoIngestDataSourceProcessorException("Exception inside canProcess() method", ex);
285  }
286 
287  // able to process the data source
288  return 100;
289  }
290 
291  @Override
292  public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) {
293  this.deviceId = deviceId;
294  this.imagePath = dataSourcePath.toString();
295  this.sectorSize = 0;
296  this.timeZone = Calendar.getInstance().getTimeZone().getID();
297  this.ignoreFatOrphanFiles = false;
298  setDataSourceOptionsCalled = true;
299  run(deviceId, dataSourcePath.toString(), sectorSize, timeZone, ignoreFatOrphanFiles, progressMonitor, callBack);
300  }
301 
315  @Deprecated
316  public void setDataSourceOptions(String imagePath, String timeZone, boolean ignoreFatOrphanFiles) {
317  this.deviceId = UUID.randomUUID().toString();
318  this.imagePath = imagePath;
319  this.sectorSize = 0;
320  this.timeZone = Calendar.getInstance().getTimeZone().getID();
321  this.ignoreFatOrphanFiles = ignoreFatOrphanFiles;
322  setDataSourceOptionsCalled = true;
323  }
324 
325 }
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-2018 Basis Technology. Generated on: Thu Oct 4 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.