Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
LogicalImagerDSProcessor.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2019 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.logicalimager.dsp;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.nio.file.Path;
24 import java.nio.file.Paths;
25 import java.util.ArrayList;
26 import java.util.Calendar;
27 import java.util.List;
28 import java.util.UUID;
29 import javax.swing.JPanel;
30 import org.openide.util.NbBundle.Messages;
31 import org.openide.util.lookup.ServiceProvider;
32 import org.openide.util.lookup.ServiceProviders;
38 import org.sleuthkit.datamodel.Content;
39 
46 @ServiceProviders(value={
47  @ServiceProvider(service=DataSourceProcessor.class)}
48 )
49 public final class LogicalImagerDSProcessor implements DataSourceProcessor {
50 
51  private static final String LOGICAL_IMAGER_DIR = "LogicalImager"; //NON-NLS
52  private final LogicalImagerPanel configPanel;
53  private AddLogicalImageTask addLogicalImageTask;
54 
55  /*
56  * Constructs a Logical Imager data source processor that implements the
57  * DataSourceProcessor service provider interface to allow integration with
58  * the add data source wizard. It also provides a run method overload to
59  * allow it to be used independently of the wizard.
60  */
62  configPanel = LogicalImagerPanel.createInstance(LogicalImagerDSProcessor.class.getName());
63  }
64 
72  @Messages({"LogicalImagerDSProcessor.dataSourceType=Autopsy Imager"})
73  public static String getType() {
74  return Bundle.LogicalImagerDSProcessor_dataSourceType();
75  }
76 
84  @Override
85  public String getDataSourceType() {
86  return Bundle.LogicalImagerDSProcessor_dataSourceType();
87  }
88 
97  @Override
98  public JPanel getPanel() {
99  configPanel.reset();
100  return configPanel;
101  }
102 
110  @Override
111  public boolean isPanelValid() {
112  return configPanel.validatePanel();
113  }
114 
129  @Messages({
130  "# {0} - imageDirPath", "LogicalImagerDSProcessor.imageDirPathNotFound={0} not found.\nUSB drive has been ejected.",
131  "# {0} - directory", "LogicalImagerDSProcessor.failToCreateDirectory=Failed to create directory {0}",
132  "# {0} - directory", "LogicalImagerDSProcessor.directoryAlreadyExists=Directory {0} already exists",
133  "# {0} - file", "LogicalImagerDSProcessor.failToGetCanonicalPath=Fail to get canonical path for {0}",
134  "LogicalImagerDSProcessor.noCurrentCase=No current case",
135  })
136  @Override
137  public void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
138  configPanel.storeSettings();
139 
140  Path imageDirPath = configPanel.getImageDirPath();
141  List<String> errorList = new ArrayList<>();
142  List<Content> emptyDataSources = new ArrayList<>();
143 
144  if (!imageDirPath.toFile().exists()) {
145  // This can happen if the USB drive was selected in the panel, but
146  // was ejected before pressing the NEXT button
147  // TODO: Better ways to detect ejected USB drive?
148  String msg = Bundle.LogicalImagerDSProcessor_imageDirPathNotFound(imageDirPath.toString());
149  errorList.add(msg);
150  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
151  return;
152  }
153 
154  // Create the LogicalImager directory under ModuleDirectory
155  String moduleDirectory = Case.getCurrentCase().getModuleDirectory();
156  File logicalImagerDir = Paths.get(moduleDirectory, LOGICAL_IMAGER_DIR).toFile();
157  if (!logicalImagerDir.exists() && !logicalImagerDir.mkdir()) {
158  // create failed
159  String msg = Bundle.LogicalImagerDSProcessor_failToCreateDirectory(logicalImagerDir);
160  errorList.add(msg);
161  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
162  return;
163  }
164  File dest = Paths.get(logicalImagerDir.toString(), imageDirPath.getFileName().toString()).toFile();
165  if (dest.exists()) {
166  // Destination directory already exists
167  String msg = Bundle.LogicalImagerDSProcessor_directoryAlreadyExists(dest.toString());
168  errorList.add(msg);
169  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
170  return;
171  }
172  File src = imageDirPath.toFile();
173 
174  // Get all VHD files in the src directory
175  List<String> imagePaths = new ArrayList<>();
176  for (File f : src.listFiles()) {
177  if (f.getName().endsWith(".vhd")) {
178  try {
179  imagePaths.add(f.getCanonicalPath());
180  } catch (IOException ex) {
181  String msg = Bundle.LogicalImagerDSProcessor_failToGetCanonicalPath(f.getName());
182  errorList.add(msg);
183  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
184  return;
185  }
186  }
187  }
188  try {
189  String deviceId = UUID.randomUUID().toString();
190  String timeZone = Calendar.getInstance().getTimeZone().getID();
191  run(deviceId, imagePaths,
192  timeZone, src, dest,
193  progressMonitor, callback);
194  } catch (NoCurrentCaseException ex) {
195  String msg = Bundle.LogicalImagerDSProcessor_noCurrentCase();
196  errorList.add(msg);
197  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
198  return;
199  }
200  }
201 
223  private void run(String deviceId, List<String> imagePaths, String timeZone,
224  File src, File dest,
226  ) throws NoCurrentCaseException {
227  addLogicalImageTask = new AddLogicalImageTask(deviceId, imagePaths, timeZone, src, dest,
228  progressMonitor, callback);
229  new Thread(addLogicalImageTask).start();
230  }
231 
232  @Override
233  public void cancel() {
234  if (addLogicalImageTask != null) {
235  addLogicalImageTask.cancelTask();
236  }
237  }
238 
243  @Override
244  public void reset() {
245  configPanel.reset();
246  }
247 
248 }
void run(String deviceId, List< String > imagePaths, String timeZone, File src, File dest, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
void done(DataSourceProcessorResult result, List< String > errList, List< Content > newDataSources)
void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.