Autopsy  4.14.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  ,
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.reset();
140  configPanel.readSettings();
141  configPanel.select();
142  return configPanel;
143  }
144 
152  @Override
153  public boolean isPanelValid() {
154  return configPanel.validatePanel();
155  }
156 
171  @Override
172  public void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
173  if (!setDataSourceOptionsCalled) {
174  configPanel.storeSettings();
175  deviceId = UUID.randomUUID().toString();
176  imagePath = configPanel.getContentPaths();
177  sectorSize = configPanel.getSectorSize();
178  timeZone = configPanel.getTimeZone();
179  ignoreFatOrphanFiles = configPanel.getNoFatOrphans();
180  md5 = configPanel.getMd5();
181  if (md5.isEmpty()) {
182  md5 = null;
183  }
184  sha1 = configPanel.getSha1();
185  if (sha1.isEmpty()) {
186  sha1 = null;
187  }
188  sha256 = configPanel.getSha256();
189  if (sha256.isEmpty()) {
190  sha256 = null;
191  }
192  }
193  run(deviceId, imagePath, sectorSize, timeZone, ignoreFatOrphanFiles, md5, sha1, sha256, progressMonitor, callback);
194  }
195 
217  public void run(String deviceId, String imagePath, String timeZone, boolean ignoreFatOrphanFiles, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
218  run(deviceId, imagePath, 0, timeZone, ignoreFatOrphanFiles, null, null, null, progressMonitor, callback);
219  }
220 
246  private void run(String deviceId, String imagePath, int sectorSize, String timeZone, boolean ignoreFatOrphanFiles, String md5, String sha1, String sha256, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
247  addImageTask = new AddImageTask(deviceId, imagePath, sectorSize, timeZone, ignoreFatOrphanFiles, md5, sha1, sha256, null, progressMonitor, callback);
248  new Thread(addImageTask).start();
249  }
250 
258  @Override
259  public void cancel() {
260  if (null != addImageTask) {
261  addImageTask.cancelTask();
262  }
263  }
264 
269  @Override
270  public void reset() {
271  deviceId = null;
272  imagePath = null;
273  timeZone = null;
274  ignoreFatOrphanFiles = false;
275  configPanel.reset();
276  setDataSourceOptionsCalled = false;
277  }
278 
279  private static boolean isAcceptedByFiler(File file, List<FileFilter> filters) {
280  for (FileFilter filter : filters) {
281  if (filter.accept(file)) {
282  return true;
283  }
284  }
285  return false;
286  }
287 
288  @Override
289  public int canProcess(Path dataSourcePath) throws AutoIngestDataSourceProcessorException {
290 
291  // check file extension for supported types
292  if (!isAcceptedByFiler(dataSourcePath.toFile(), filtersList)) {
293  return 0;
294  }
295 
296  try {
297  // verify that the image has a file system that TSK can process
298  Case currentCase = Case.getCurrentCaseThrows();
299  if (!DataSourceUtils.imageHasFileSystem(dataSourcePath)) {
300  // image does not have a file system that TSK can process
301  return 0;
302  }
303  } catch (Exception ex) {
304  throw new AutoIngestDataSourceProcessorException("Exception inside canProcess() method", ex);
305  }
306 
307  // able to process the data source
308  return 100;
309  }
310 
311  @Override
312  public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) {
313  this.deviceId = deviceId;
314  this.imagePath = dataSourcePath.toString();
315  this.sectorSize = 0;
316  this.timeZone = Calendar.getInstance().getTimeZone().getID();
317  this.ignoreFatOrphanFiles = false;
318  setDataSourceOptionsCalled = true;
319  run(deviceId, dataSourcePath.toString(), sectorSize, timeZone, ignoreFatOrphanFiles, null, null, null, progressMonitor, callBack);
320  }
321 
335  @Deprecated
336  public void setDataSourceOptions(String imagePath, String timeZone, boolean ignoreFatOrphanFiles) {
337  this.deviceId = UUID.randomUUID().toString();
338  this.imagePath = imagePath;
339  this.sectorSize = 0;
340  this.timeZone = Calendar.getInstance().getTimeZone().getID();
341  this.ignoreFatOrphanFiles = ignoreFatOrphanFiles;
342  setDataSourceOptionsCalled = true;
343  }
344 
345 }
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-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.