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 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 String timeZone;
67  private boolean ignoreFatOrphanFiles;
68  private boolean setDataSourceOptionsCalled;
69 
70  static {
71  filtersList.add(allFilter);
72  filtersList.add(rawFilter);
73  filtersList.add(encaseFilter);
74  filtersList.add(virtualMachineFilter);
75  allExt.addAll(GeneralFilter.RAW_IMAGE_EXTS);
76  allExt.addAll(GeneralFilter.ENCASE_IMAGE_EXTS);
77  allExt.addAll(GeneralFilter.VIRTUAL_MACHINE_EXTS);
78  }
79 
86  public ImageDSProcessor() {
87  configPanel = ImageFilePanel.createInstance(ImageDSProcessor.class.getName(), filtersList);
88  }
89 
97  public static String getType() {
98  return DATA_SOURCE_TYPE;
99  }
100 
108  @Override
109  public String getDataSourceType() {
110  return getType();
111  }
112 
121  @Override
122  public JPanel getPanel() {
123  configPanel.readSettings();
124  configPanel.select();
125  return configPanel;
126  }
127 
135  @Override
136  public boolean isPanelValid() {
137  return configPanel.validatePanel();
138  }
139 
154  @Override
155  public void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
156  if (!setDataSourceOptionsCalled) {
157  configPanel.storeSettings();
158  deviceId = UUID.randomUUID().toString();
159  imagePath = configPanel.getContentPaths();
160  timeZone = configPanel.getTimeZone();
161  ignoreFatOrphanFiles = configPanel.getNoFatOrphans();
162  }
163  run(deviceId, imagePath, timeZone, ignoreFatOrphanFiles, progressMonitor, callback);
164  }
165 
187  public void run(String deviceId, String imagePath, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
188  addImageTask = new AddImageTask(deviceId, imagePath, timeZone, ignoreFatOrphanFiles, null, progressMonitor, callback);
189  new Thread(addImageTask).start();
190  }
191 
199  @Override
200  public void cancel() {
201  if (null != addImageTask) {
202  addImageTask.cancelTask();
203  }
204  }
205 
210  @Override
211  public void reset() {
212  deviceId = null;
213  imagePath = null;
214  timeZone = null;
215  ignoreFatOrphanFiles = false;
216  configPanel.reset();
217  setDataSourceOptionsCalled = false;
218  }
219 
220  private static boolean isAcceptedByFiler(File file, List<FileFilter> filters) {
221  for (FileFilter filter : filters) {
222  if (filter.accept(file)) {
223  return true;
224  }
225  }
226  return false;
227  }
228 
229  @Override
230  public int canProcess(Path dataSourcePath) throws AutoIngestDataSourceProcessorException {
231 
232  // check file extension for supported types
233  if (!isAcceptedByFiler(dataSourcePath.toFile(), filtersList)) {
234  return 0;
235  }
236 
237  try {
238  // verify that the image has a file system that TSK can process
239  Case currentCase = Case.getCurrentCase();
240  if (!DataSourceUtils.imageHasFileSystem(dataSourcePath)) {
241  // image does not have a file system that TSK can process
242  return 0;
243  }
244  } catch (Exception ex) {
245  throw new AutoIngestDataSourceProcessorException("Exception inside canProcess() method", ex);
246  }
247 
248  // able to process the data source
249  return 100;
250  }
251 
252  @Override
253  public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) throws AutoIngestDataSourceProcessorException {
254  this.deviceId = deviceId;
255  this.imagePath = dataSourcePath.toString();
256  this.timeZone = Calendar.getInstance().getTimeZone().getID();
257  this.ignoreFatOrphanFiles = false;
258  setDataSourceOptionsCalled = true;
259  run(deviceId, dataSourcePath.toString(), timeZone, ignoreFatOrphanFiles, progressMonitor, callBack);
260  }
261 
275  @Deprecated
276  public void setDataSourceOptions(String imagePath, String timeZone, boolean ignoreFatOrphanFiles) {
277  this.deviceId = UUID.randomUUID().toString();
278  this.imagePath = imagePath;
279  this.timeZone = Calendar.getInstance().getTimeZone().getID();
280  this.ignoreFatOrphanFiles = ignoreFatOrphanFiles;
281  setDataSourceOptionsCalled = true;
282  }
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
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 Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.