Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
LogicalImagerDSProcessor.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 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.nio.file.Path;
23 import java.nio.file.Paths;
24 import java.util.ArrayList;
25 import java.util.Calendar;
26 import java.util.List;
27 import java.util.UUID;
28 import javax.swing.JOptionPane;
29 import static javax.swing.JOptionPane.YES_OPTION;
30 import javax.swing.JPanel;
31 import org.openide.util.NbBundle.Messages;
32 import org.openide.util.lookup.ServiceProvider;
33 import org.openide.util.lookup.ServiceProviders;
40 import org.sleuthkit.datamodel.Content;
41 import org.sleuthkit.datamodel.Host;
42 import org.sleuthkit.datamodel.TskCoreException;
43 
50 @ServiceProviders(value = {
51  @ServiceProvider(service = DataSourceProcessor.class)}
52 )
53 public final class LogicalImagerDSProcessor implements DataSourceProcessor {
54 
55  private static final String LOGICAL_IMAGER_DIR = "LogicalImager"; //NON-NLS
56  private final LogicalImagerPanel configPanel;
57  private AddLogicalImageTask addLogicalImageTask;
58 
59  /*
60  * Constructs a Logical Imager data source processor that implements the
61  * DataSourceProcessor service provider interface to allow integration with
62  * the add data source wizard. It also provides a run method overload to
63  * allow it to be used independently of the wizard.
64  */
66  configPanel = LogicalImagerPanel.createInstance(LogicalImagerDSProcessor.class.getName());
67  }
68 
76  @Messages({"LogicalImagerDSProcessor.dataSourceType=Autopsy Logical Imager Results"})
77  public static String getType() {
78  return Bundle.LogicalImagerDSProcessor_dataSourceType();
79  }
80 
88  @Override
89  public String getDataSourceType() {
90  return Bundle.LogicalImagerDSProcessor_dataSourceType();
91  }
92 
101  @Override
102  public JPanel getPanel() {
103  configPanel.reset();
104  return configPanel;
105  }
106 
114  @Override
115  public boolean isPanelValid() {
116  return configPanel.validatePanel();
117  }
118 
133  @Override
134  public void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
135  run(null, progressMonitor, callback);
136  }
137 
153  @Messages({
154  "# {0} - imageDirPath", "LogicalImagerDSProcessor.imageDirPathNotFound={0} not found.\nUSB drive has been ejected.",
155  "# {0} - directory", "LogicalImagerDSProcessor.failToCreateDirectory=Failed to create directory {0}",
156  "# {0} - directory", "LogicalImagerDSProcessor.directoryAlreadyExists=Directory {0} already exists",
157  "LogicalImagerDSProcessor.destinationDirectoryConfirmation=Destination directory confirmation",
158  "# {0} - directory", "LogicalImagerDSProcessor.destinationDirectoryConfirmationMsg=The logical imager folder {0} already exists,\ndo you want to add it again using a new folder name?",
159  "LogicalImagerDSProcessor.noCurrentCase=No current case",
160  })
161  @Override
162  public void run(Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
163  configPanel.storeSettings();
164  Path imageDirPath = configPanel.getImageDirPath();
165  List<String> errorList = new ArrayList<>();
166  List<Content> emptyDataSources = new ArrayList<>();
167 
168  if (!imageDirPath.toFile().exists()) {
169  // This can happen if the USB drive was selected in the panel, but
170  // was ejected before pressing the NEXT button
171  // TODO: Better ways to detect ejected USB drive?
172  String msg = Bundle.LogicalImagerDSProcessor_imageDirPathNotFound(imageDirPath.toString());
173  errorList.add(msg);
174  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
175  return;
176  }
177 
178  // Create the LogicalImager directory under ModuleDirectory
179  String moduleDirectory = Case.getCurrentCase().getModuleDirectory();
180  File logicalImagerDir = Paths.get(moduleDirectory, LOGICAL_IMAGER_DIR).toFile();
181  if (!logicalImagerDir.exists() && !logicalImagerDir.mkdir()) {
182  // create failed
183  String msg = Bundle.LogicalImagerDSProcessor_failToCreateDirectory(logicalImagerDir);
184  errorList.add(msg);
185  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
186  return;
187  }
188  File dest = Paths.get(logicalImagerDir.toString(), imageDirPath.getFileName().toString()).toFile();
189  if (dest.exists()) {
190  // Destination directory already exists
191  int showConfirmDialog = JOptionPane.showConfirmDialog(configPanel,
192  Bundle.LogicalImagerDSProcessor_destinationDirectoryConfirmationMsg(dest.toString()),
193  Bundle.LogicalImagerDSProcessor_destinationDirectoryConfirmation(),
194  JOptionPane.YES_NO_OPTION);
195  if (showConfirmDialog == YES_OPTION) {
196  // Get unique dest directory
197  String uniqueDirectory = imageDirPath.getFileName() + "_" + TimeStampUtils.createTimeStamp();
198  dest = Paths.get(logicalImagerDir.toString(), uniqueDirectory).toFile();
199  } else {
200  String msg = Bundle.LogicalImagerDSProcessor_directoryAlreadyExists(dest.toString());
201  errorList.add(msg);
202  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
203  return;
204  }
205  }
206  File src = imageDirPath.toFile();
207 
208  try {
209  String deviceId = UUID.randomUUID().toString();
210  String timeZone = Calendar.getInstance().getTimeZone().getID();
211  run(deviceId, timeZone, src, dest, host,
212  progressMonitor, callback);
213  } catch (NoCurrentCaseException ex) {
214  String msg = Bundle.LogicalImagerDSProcessor_noCurrentCase();
215  errorList.add(msg);
216  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
217  }
218  }
219 
240  private void run(String deviceId, String timeZone,
241  File src, File dest, Host host,
243  ) throws NoCurrentCaseException {
244  addLogicalImageTask = new AddLogicalImageTask(deviceId, timeZone, src, dest, host,
245  progressMonitor, callback);
246  Thread thread = new Thread(addLogicalImageTask);
247  thread.start();
248  }
249 
250  @Override
251  public void cancel() {
252  if (addLogicalImageTask != null) {
253  addLogicalImageTask.cancelTask();
254  }
255  }
256 
261  @Override
262  public void reset() {
263  configPanel.reset();
264  }
265 
266 }
void run(String deviceId, String timeZone, File src, File dest, Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
void done(DataSourceProcessorResult result, List< String > errList, List< Content > newDataSources)
void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
void run(Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.