Autopsy  4.14.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 
48 @ServiceProviders(value = {
49  @ServiceProvider(service = DataSourceProcessor.class)}
50 )
51 public final class LogicalImagerDSProcessor implements DataSourceProcessor {
52 
53  private static final String LOGICAL_IMAGER_DIR = "LogicalImager"; //NON-NLS
54  private final LogicalImagerPanel configPanel;
55  private AddLogicalImageTask addLogicalImageTask;
56 
57  /*
58  * Constructs a Logical Imager data source processor that implements the
59  * DataSourceProcessor service provider interface to allow integration with
60  * the add data source wizard. It also provides a run method overload to
61  * allow it to be used independently of the wizard.
62  */
64  configPanel = LogicalImagerPanel.createInstance(LogicalImagerDSProcessor.class.getName());
65  }
66 
74  @Messages({"LogicalImagerDSProcessor.dataSourceType=Autopsy Logical Imager Results"})
75  public static String getType() {
76  return Bundle.LogicalImagerDSProcessor_dataSourceType();
77  }
78 
86  @Override
87  public String getDataSourceType() {
88  return Bundle.LogicalImagerDSProcessor_dataSourceType();
89  }
90 
99  @Override
100  public JPanel getPanel() {
101  configPanel.reset();
102  return configPanel;
103  }
104 
112  @Override
113  public boolean isPanelValid() {
114  return configPanel.validatePanel();
115  }
116 
131  @Messages({
132  "# {0} - imageDirPath", "LogicalImagerDSProcessor.imageDirPathNotFound={0} not found.\nUSB drive has been ejected.",
133  "# {0} - directory", "LogicalImagerDSProcessor.failToCreateDirectory=Failed to create directory {0}",
134  "# {0} - directory", "LogicalImagerDSProcessor.directoryAlreadyExists=Directory {0} already exists",
135  "LogicalImagerDSProcessor.destinationDirectoryConfirmation=Destination directory confirmation",
136  "# {0} - directory", "LogicalImagerDSProcessor.destinationDirectoryConfirmationMsg=The logical imager folder {0} already exists,\ndo you want to add it again using a new folder name?",
137  "LogicalImagerDSProcessor.noCurrentCase=No current case",
138  })
139  @Override
140  public void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
141  configPanel.storeSettings();
142 
143  Path imageDirPath = configPanel.getImageDirPath();
144  List<String> errorList = new ArrayList<>();
145  List<Content> emptyDataSources = new ArrayList<>();
146 
147  if (!imageDirPath.toFile().exists()) {
148  // This can happen if the USB drive was selected in the panel, but
149  // was ejected before pressing the NEXT button
150  // TODO: Better ways to detect ejected USB drive?
151  String msg = Bundle.LogicalImagerDSProcessor_imageDirPathNotFound(imageDirPath.toString());
152  errorList.add(msg);
153  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
154  return;
155  }
156 
157  // Create the LogicalImager directory under ModuleDirectory
158  String moduleDirectory = Case.getCurrentCase().getModuleDirectory();
159  File logicalImagerDir = Paths.get(moduleDirectory, LOGICAL_IMAGER_DIR).toFile();
160  if (!logicalImagerDir.exists() && !logicalImagerDir.mkdir()) {
161  // create failed
162  String msg = Bundle.LogicalImagerDSProcessor_failToCreateDirectory(logicalImagerDir);
163  errorList.add(msg);
164  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
165  return;
166  }
167  File dest = Paths.get(logicalImagerDir.toString(), imageDirPath.getFileName().toString()).toFile();
168  if (dest.exists()) {
169  // Destination directory already exists
170  int showConfirmDialog = JOptionPane.showConfirmDialog(configPanel,
171  Bundle.LogicalImagerDSProcessor_destinationDirectoryConfirmationMsg(dest.toString()),
172  Bundle.LogicalImagerDSProcessor_destinationDirectoryConfirmation(),
173  JOptionPane.YES_NO_OPTION);
174  if (showConfirmDialog == YES_OPTION) {
175  // Get unique dest directory
176  String uniqueDirectory = imageDirPath.getFileName() + "_" + TimeStampUtils.createTimeStamp();
177  dest = Paths.get(logicalImagerDir.toString(), uniqueDirectory).toFile();
178  } else {
179  String msg = Bundle.LogicalImagerDSProcessor_directoryAlreadyExists(dest.toString());
180  errorList.add(msg);
181  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
182  return;
183  }
184  }
185  File src = imageDirPath.toFile();
186 
187  try {
188  String deviceId = UUID.randomUUID().toString();
189  String timeZone = Calendar.getInstance().getTimeZone().getID();
190  run(deviceId, timeZone, src, dest,
191  progressMonitor, callback);
192  } catch (NoCurrentCaseException ex) {
193  String msg = Bundle.LogicalImagerDSProcessor_noCurrentCase();
194  errorList.add(msg);
195  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
196  }
197  }
198 
218  private void run(String deviceId, String timeZone,
219  File src, File dest,
221  ) throws NoCurrentCaseException {
222  addLogicalImageTask = new AddLogicalImageTask(deviceId, timeZone, src, dest,
223  progressMonitor, callback);
224  Thread thread = new Thread(addLogicalImageTask);
225  thread.start();
226  }
227 
228  @Override
229  public void cancel() {
230  if (addLogicalImageTask != null) {
231  addLogicalImageTask.cancelTask();
232  }
233  }
234 
239  @Override
240  public void reset() {
241  configPanel.reset();
242  }
243 
244 }
void done(DataSourceProcessorResult result, List< String > errList, List< Content > newDataSources)
void run(String deviceId, String timeZone, File src, File dest, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
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.