Autopsy  4.1
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-2016 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 java.nio.file.Paths;
24 import javax.swing.JPanel;
25 import java.util.ArrayList;
26 import java.util.Calendar;
27 import java.util.List;
28 import java.util.UUID;
29 import javax.swing.filechooser.FileFilter;
30 import org.openide.util.NbBundle;
31 import org.openide.util.lookup.ServiceProvider;
32 import org.openide.util.lookup.ServiceProviders;
38 
45 @ServiceProviders(value={
46  @ServiceProvider(service=DataSourceProcessor.class),
47  @ServiceProvider(service=AutomatedIngestDataSourceProcessor.class)}
48 )
50 
51  private final static String DATA_SOURCE_TYPE = NbBundle.getMessage(ImageDSProcessor.class, "ImageDSProcessor.dsType.text");
52  private static final List<String> allExt = new ArrayList<>();
56  private static final String allDesc = NbBundle.getMessage(ImageDSProcessor.class, "ImageDSProcessor.allDesc.text");
57  private static final GeneralFilter allFilter = new GeneralFilter(allExt, allDesc);
58  private static final List<FileFilter> filtersList = new ArrayList<>();
59  private final ImageFilePanel configPanel;
60  private AddImageTask addImageTask;
61  /*
62  * TODO: Remove the setDataSourceOptionsCalled flag and the settings fields
63  * when the deprecated method setDataSourceOptions is removed.
64  */
65  private String deviceId;
66  private String imagePath;
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  filtersList.add(virtualMachineFilter);
76  allExt.addAll(GeneralFilter.RAW_IMAGE_EXTS);
77  allExt.addAll(GeneralFilter.ENCASE_IMAGE_EXTS);
78  allExt.addAll(GeneralFilter.VIRTUAL_MACHINE_EXTS);
79  }
80 
87  public ImageDSProcessor() {
88  configPanel = ImageFilePanel.createInstance(ImageDSProcessor.class.getName(), filtersList);
89  }
90 
98  public static String getType() {
99  return DATA_SOURCE_TYPE;
100  }
101 
109  @Override
110  public String getDataSourceType() {
111  return getType();
112  }
113 
122  @Override
123  public JPanel getPanel() {
124  configPanel.readSettings();
125  configPanel.select();
126  return configPanel;
127  }
128 
136  @Override
137  public boolean isPanelValid() {
138  return configPanel.validatePanel();
139  }
140 
155  @Override
156  public void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
157  if (!setDataSourceOptionsCalled) {
158  configPanel.storeSettings();
159  deviceId = UUID.randomUUID().toString();
160  imagePath = configPanel.getContentPaths();
161  timeZone = configPanel.getTimeZone();
162  ignoreFatOrphanFiles = configPanel.getNoFatOrphans();
163  }
164  run(deviceId, imagePath, timeZone, ignoreFatOrphanFiles, progressMonitor, callback);
165  }
166 
188  public void run(String deviceId, String imagePath, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
189  addImageTask = new AddImageTask(deviceId, imagePath, timeZone, ignoreFatOrphanFiles, progressMonitor, callback);
190  new Thread(addImageTask).start();
191  }
192 
200  @Override
201  public void cancel() {
202  if (null != addImageTask) {
203  addImageTask.cancelTask();
204  }
205  }
206 
211  @Override
212  public void reset() {
213  deviceId = null;
214  imagePath = null;
215  timeZone = null;
216  ignoreFatOrphanFiles = false;
217  configPanel.reset();
218  setDataSourceOptionsCalled = false;
219  }
220 
234  @Deprecated
235  public void setDataSourceOptions(String imagePath, String timeZone, boolean ignoreFatOrphanFiles) {
236  this.deviceId = UUID.randomUUID().toString();
237  this.imagePath = imagePath;
238  this.timeZone = Calendar.getInstance().getTimeZone().getID();
239  this.ignoreFatOrphanFiles = ignoreFatOrphanFiles;
240  setDataSourceOptionsCalled = true;
241  }
242 
243  private static boolean isAcceptedByFiler(File file, List<FileFilter> filters) {
244  for (FileFilter filter : filters) {
245  if (filter.accept(file)) {
246  return true;
247  }
248  }
249  return false;
250  }
251 
252  @Override
253  public int canProcess(Path dataSourcePath) throws AutomatedIngestDataSourceProcessorException {
254 
255  // check file extension for supported types
256  if (!isAcceptedByFiler(dataSourcePath.toFile(), filtersList)) {
257  return 0;
258  }
259 
260  try {
261  // verify that the image has a file system that TSK can process
262  Case currentCase = Case.getCurrentCase();
263  if (!DataSourceUtils.imageHasFileSystem(dataSourcePath)) {
264  // image does not have a file system that TSK can process
265  return 0;
266  }
267  } catch (Exception ex) {
268  throw new AutomatedIngestDataSourceProcessorException("Exception inside canProcess() method", ex);
269  }
270 
271  // able to process the data source
272  return 100;
273  }
274 
275  @Override
276  public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) throws AutomatedIngestDataSourceProcessorException {
277  this.deviceId = deviceId;
278  this.imagePath = dataSourcePath.toString();
279  this.timeZone = Calendar.getInstance().getTimeZone().getID();
280  this.ignoreFatOrphanFiles = false;
281  setDataSourceOptionsCalled = true;
282  run(deviceId, dataSourcePath.toString(), timeZone, ignoreFatOrphanFiles, progressMonitor, callBack);
283  }
284 }
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)
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 Jan 2 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.