19 package org.sleuthkit.autopsy.casemodule;
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.Arrays;
27 import java.util.List;
28 import java.util.UUID;
29 import java.util.logging.Level;
30 import javax.swing.JPanel;
31 import javax.swing.filechooser.FileFilter;
32 import org.apache.commons.io.FilenameUtils;
33 import org.openide.modules.InstalledFileLocator;
34 import org.openide.util.NbBundle;
35 import org.openide.util.NbBundle.Messages;
36 import org.openide.util.lookup.ServiceProvider;
37 import org.openide.util.lookup.ServiceProviders;
54 @ServiceProviders(value = {
55 @ServiceProvider(service = DataSourceProcessor.class),
56 @ServiceProvider(service = AutoIngestDataSourceProcessor.class)
59 "LocalFilesDSProcessor.logicalEvidenceFilter.desc=Logical Evidence Files (L01)"
63 private static final String DATA_SOURCE_TYPE = NbBundle.getMessage(
LocalFilesDSProcessor.class,
"LocalFilesDSProcessor.dsType");
66 private static final String L01_EXTRACTION_DIR =
"L01";
67 private static final String UNIQUENESS_CONSTRAINT_SEPERATOR =
"_";
68 private static final String EWFEXPORT_DIR =
"ewfexport_exec";
69 private static final String EWFEXPORT_32_BIT_DIR =
"32-bit";
70 private static final String EWFEXPORT_64_BIT_DIR =
"64-bit";
71 private static final String EWFEXPORT_WINDOWS_EXE =
"ewfexport.exe";
72 private static final String LOG_FILE_EXTENSION =
".txt";
73 private static final List<String> LOGICAL_EVIDENCE_EXTENSIONS = Arrays.asList(
".l01");
74 private static final String LOGICAL_EVIDENCE_DESC = Bundle.LocalFilesDSProcessor_logicalEvidenceFilter_desc();
89 configPanel = LogicalFilesDspPanel.getDefault();
100 return DATA_SOURCE_TYPE;
112 return DATA_SOURCE_TYPE;
125 configPanel.select();
138 return configPanel.validatePanel();
157 run(null, progressMonitor, callback);
178 localFilePaths = configPanel.getContentPaths();
179 if (configPanel.subTypeIsLogicalEvidencePanel()) {
182 localFilePaths = extractLogicalEvidenceFileContents(localFilePaths);
185 final List<String> errors =
new ArrayList<>();
186 errors.add(ex.getMessage());
190 logger.log(Level.WARNING,
"Exception while getting open case.", ex);
194 run(UUID.randomUUID().toString(), configPanel.getFileSetName(), localFilePaths, host, progressMonitor, callback);
210 final List<String> extractedPaths =
new ArrayList<>();
212 ewfexportPath = locateEwfexportExecutable();
213 List<String> command =
new ArrayList<>();
214 for (
final String l01Path : logicalEvidenceFilePaths) {
216 command.add(ewfexportPath.toAbsolutePath().toString());
218 command.add(
"files");
221 if (!l01Dir.exists()) {
224 Path dirPath = Paths.get(FilenameUtils.getBaseName(l01Path) + UNIQUENESS_CONSTRAINT_SEPERATOR + System.currentTimeMillis());
226 command.add(dirPath.toString());
227 command.add(l01Path);
228 ProcessBuilder processBuilder =
new ProcessBuilder(command);
229 processBuilder.directory(l01Dir);
232 Path logFileName = Paths.get(l01Dir.toString(), dirPath.toString() + LOG_FILE_EXTENSION);
233 File logFile =
new File(logFileName.toString());
234 Path errFileName = Paths.get(l01Dir.toString(), dirPath.toString() + LOG_FILE_EXTENSION);
235 File errFile =
new File(errFileName.toString());
236 processBuilder.redirectError(ProcessBuilder.Redirect.appendTo(errFile));
237 processBuilder.redirectOutput(ProcessBuilder.Redirect.appendTo(logFile));
240 if (l01Dir.toPath().resolve(dirPath).toFile().exists()) {
241 extractedPaths.add(l01Dir.toPath().resolve(dirPath).toString());
243 throw new L01Exception(
"Can not process the selected L01 file, ewfExport was unable to extract any files from it.");
246 }
catch (SecurityException ex) {
247 throw new L01Exception(
"Security exception occcured while trying to extract l01 contents", ex);
248 }
catch (IOException ex) {
249 throw new L01Exception(
"IOException occcured while trying to extract l01 contents", ex);
252 return extractedPaths;
260 static FileFilter getLogicalEvidenceFilter() {
261 return LOGICAL_EVIDENCE_FILTER;
275 throw new L01Exception(
"L01 files are only supported on windows currently");
280 final File ewfRoot = InstalledFileLocator.getDefault().locate(EWFEXPORT_DIR,
LocalFilesDSProcessor.class.getPackage().getName(),
false);
284 executablePath = Paths.get(
285 ewfRoot.getAbsolutePath(),
286 EWFEXPORT_64_BIT_DIR,
287 EWFEXPORT_WINDOWS_EXE);
289 executablePath = Paths.get(
290 ewfRoot.getAbsolutePath(),
291 EWFEXPORT_32_BIT_DIR,
292 EWFEXPORT_WINDOWS_EXE);
297 final File ewfexport = executablePath.toFile();
298 if (null == ewfexport || !ewfexport.exists()) {
301 if (!ewfexport.canExecute()) {
305 return executablePath;
333 new Thread(
new AddLocalFilesTask(deviceId, rootVirtualDirectoryName, localFilePaths, host, progressMonitor, callback)).start();
360 run(deviceId, rootVirtualDirectoryName, localFilePaths, null, progressMonitor, callback);
383 configPanel.select();
384 localFilePaths = null;
393 List<String> filePaths = Arrays.asList(
new String[]{dataSourcePath.toString()});
396 if (filePaths.size() == 1) {
397 for (
final String path : filePaths) {
398 if (
new File(path).isFile() && LOGICAL_EVIDENCE_FILTER.
accept(
new File(path))) {
401 filePaths = extractLogicalEvidenceFileContents(filePaths);
402 }
catch (L01Exception ex) {
403 logger.log(Level.WARNING,
"File extension was .l01 but contents of logical evidence file were unable to be extracted", ex);
407 logger.log(Level.WARNING,
"Exception while getting open case.", ex);
418 process(deviceId, dataSourcePath, null, progressMonitor, callBack);
423 List<String> filePaths = Arrays.asList(
new String[]{dataSourcePath.toString()});
424 run(deviceId,
"", filePaths, host, progressMonitor, callBack);
430 private final class L01Exception
extends Exception {
432 private static final long serialVersionUID = 1L;
434 L01Exception(
final String message) {
438 L01Exception(
final String message,
final Throwable cause) {
439 super(message, cause);
List< String > localFilePaths
final LogicalFilesDspPanel configPanel
void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
static int execute(ProcessBuilder processBuilder)
String getDataSourceType()
void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack)
void done(DataSourceProcessorResult result, List< String > errList, List< Content > newDataSources)
List< String > extractLogicalEvidenceFileContents(final List< String > logicalEvidenceFilePaths)
void run(String deviceId, String rootVirtualDirectoryName, List< String > localFilePaths, Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
String getModuleDirectory()
Path locateEwfexportExecutable()
int canProcess(Path dataSourcePath)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
void process(String deviceId, Path dataSourcePath, Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack)
void run(String deviceId, String rootVirtualDirectoryName, List< String > localFilePaths, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
void run(Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)