Autopsy  4.9.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-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  ,
47  @ServiceProvider(service = AutoIngestDataSourceProcessor.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 ALL_DESC = NbBundle.getMessage(ImageDSProcessor.class, "ImageDSProcessor.allDesc.text");
57  private static final GeneralFilter allFilter = new GeneralFilter(allExt, ALL_DESC);
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 int sectorSize;
68  private String timeZone;
69  private boolean ignoreFatOrphanFiles;
70  private String md5;
71  private String sha1;
72  private String sha256;
73  private boolean setDataSourceOptionsCalled;
74 
75  static {
76  filtersList.add(allFilter);
77  filtersList.add(rawFilter);
78  filtersList.add(encaseFilter);
79  allExt.addAll(GeneralFilter.RAW_IMAGE_EXTS);
80  allExt.addAll(GeneralFilter.ENCASE_IMAGE_EXTS);
81  if (!System.getProperty("os.name").toLowerCase().contains("mac")) {
82  filtersList.add(virtualMachineFilter);
83  allExt.addAll(GeneralFilter.VIRTUAL_MACHINE_EXTS);
84  }
85  }
86 
93  public ImageDSProcessor() {
94  configPanel = ImageFilePanel.createInstance(ImageDSProcessor.class.getName(), filtersList);
95  }
96 
102  static List<FileFilter> getFileFiltersList() {
103  return filtersList;
104  }
105 
113  public static String getType() {
114  return DATA_SOURCE_TYPE;
115  }
116 
124  @Override
125  public String getDataSourceType() {
126  return getType();
127  }
128 
137  @Override
138  public JPanel getPanel() {
139  configPanel.readSettings();
140  configPanel.select();
141  return configPanel;
142  }
143 
151  @Override
152  public boolean isPanelValid() {
153  return configPanel.validatePanel();
154  }
155 
170  @Override
171  public void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
172  if (!setDataSourceOptionsCalled) {
173  configPanel.storeSettings();
174  deviceId = UUID.randomUUID().toString();
175  imagePath = configPanel.getContentPaths();
176  sectorSize = configPanel.getSectorSize();
177  timeZone = configPanel.getTimeZone();
178  ignoreFatOrphanFiles = configPanel.getNoFatOrphans();
179  md5 = configPanel.getMd5();
180  if (md5.isEmpty()) {
181  md5 = null;
182  }
183  sha1 = configPanel.getSha1();
184  if (sha1.isEmpty()) {
185  sha1 = null;
186  }
187  sha256 = configPanel.getSha256();
188  if (sha256.isEmpty()) {
189  sha256 = null;
190  }
191  }
192  run(deviceId, imagePath, sectorSize, timeZone, ignoreFatOrphanFiles, md5, sha1, sha256, progressMonitor, callback);
193  }
194 
216  public void run(String deviceId, String imagePath, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
217  run(deviceId, imagePath, 0, timeZone, ignoreFatOrphanFiles, null, null, null, progressMonitor, callback);
218  }
219 
245  private void run(String deviceId, String imagePath, int sectorSize, String timeZone, boolean ignoreFatOrphanFiles, String md5, String sha1, String sha256, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
246  addImageTask = new AddImageTask(deviceId, imagePath, sectorSize, timeZone, ignoreFatOrphanFiles, md5, sha1, sha256, null, progressMonitor, callback);
247  new Thread(addImageTask).start();
248  }
249 
257  @Override
258  public void cancel() {
259  if (null != addImageTask) {
260  addImageTask.cancelTask();
261  }
262  }
263 
268  @Override
269  public void reset() {
270  deviceId = null;
271  imagePath = null;
272  timeZone = null;
273  ignoreFatOrphanFiles = false;
274  configPanel.reset();
275  setDataSourceOptionsCalled = false;
276  }
277 
278  private static boolean isAcceptedByFiler(File file, List<FileFilter> filters) {
279  for (FileFilter filter : filters) {
280  if (filter.accept(file)) {
281  return true;
282  }
283  }
284  return false;
285  }
286 
287  @Override
288  public int canProcess(Path dataSourcePath) throws AutoIngestDataSourceProcessorException {
289 
290  // check file extension for supported types
291  if (!isAcceptedByFiler(dataSourcePath.toFile(), filtersList)) {
292  return 0;
293  }
294 
295  try {
296  // verify that the image has a file system that TSK can process
297  Case currentCase = Case.getCurrentCaseThrows();
298  if (!DataSourceUtils.imageHasFileSystem(dataSourcePath)) {
299  // image does not have a file system that TSK can process
300  return 0;
301  }
302  } catch (Exception ex) {
303  throw new AutoIngestDataSourceProcessorException("Exception inside canProcess() method", ex);
304  }
305 
306  // able to process the data source
307  return 100;
308  }
309 
310  @Override
311  public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) {
312  this.deviceId = deviceId;
313  this.imagePath = dataSourcePath.toString();
314  this.sectorSize = 0;
315  this.timeZone = Calendar.getInstance().getTimeZone().getID();
316  this.ignoreFatOrphanFiles = false;
317  setDataSourceOptionsCalled = true;
318  run(deviceId, dataSourcePath.toString(), sectorSize, timeZone, ignoreFatOrphanFiles, null, null, null, progressMonitor, callBack);
319  }
320 
334  @Deprecated
335  public void setDataSourceOptions(String imagePath, String timeZone, boolean ignoreFatOrphanFiles) {
336  this.deviceId = UUID.randomUUID().toString();
337  this.imagePath = imagePath;
338  this.sectorSize = 0;
339  this.timeZone = Calendar.getInstance().getTimeZone().getID();
340  this.ignoreFatOrphanFiles = ignoreFatOrphanFiles;
341  setDataSourceOptionsCalled = true;
342  }
343 
344 }
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, String md5, String sha1, String sha256, 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: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.