19package org.sleuthkit.autopsy.datasourceprocessors.xry;
21import com.google.common.collect.Lists;
23import java.io.IOException;
24import java.io.UncheckedIOException;
25import java.nio.file.Files;
26import java.nio.file.LinkOption;
27import java.nio.file.Path;
28import java.nio.file.attribute.BasicFileAttributes;
29import java.util.Iterator;
32import java.util.concurrent.ExecutionException;
33import java.util.logging.Level;
34import java.util.stream.Collectors;
35import java.util.stream.Stream;
36import javax.swing.JPanel;
37import javax.swing.SwingWorker;
38import org.openide.util.NbBundle;
39import org.openide.util.lookup.ServiceProvider;
40import org.openide.util.lookup.ServiceProviders;
41import org.sleuthkit.autopsy.casemodule.Case;
42import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
43import org.sleuthkit.autopsy.casemodule.services.FileManager;
44import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor;
45import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorCallback;
46import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorProgressMonitor;
47import org.sleuthkit.autopsy.coreutils.Logger;
48import org.sleuthkit.autopsy.datasourceprocessors.AutoIngestDataSourceProcessor;
49import org.sleuthkit.autopsy.datasourceprocessors.AutoIngestDataSourceProcessor.AutoIngestDataSourceProcessorException;
50import org.sleuthkit.datamodel.AbstractFile;
51import org.sleuthkit.datamodel.Blackboard.BlackboardException;
52import org.sleuthkit.datamodel.Host;
53import org.sleuthkit.datamodel.LocalFilesDataSource;
54import org.sleuthkit.datamodel.TskCoreException;
55import org.sleuthkit.datamodel.TskDataException;
60@ServiceProviders(value = {
77 configPanel = XRYDataSourceProcessorConfigPanel.getInstance();
82 "XRYDataSourceProcessor.dataSourceType=XRY Text Export"
85 return Bundle.XRYDataSourceProcessor_dataSourceType();
101 "XRYDataSourceProcessor.noPathSelected=Please select a folder containing exported XRY text files",
102 "XRYDataSourceProcessor.notReadable=Selected path is not readable",
103 "XRYDataSourceProcessor.notXRYFolder=Selected folder did not contain any XRY text files",
104 "XRYDataSourceProcessor.ioError=I/O error occured trying to test the selected folder",
105 "XRYDataSourceProcessor.childNotReadable=Top level path [ %s ] is not readable",
106 "XRYDataSourceProcessor.notAFolder=The selected path is not a folder"
110 String selectedFilePath =
configPanel.getSelectedFilePath();
111 if (selectedFilePath.isEmpty()) {
112 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_noPathSelected());
116 File selectedFile =
new File(selectedFilePath);
117 Path selectedPath = selectedFile.toPath();
120 if (!Files.isReadable(selectedPath)) {
121 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_notReadable());
126 BasicFileAttributes attr = Files.readAttributes(selectedPath,
127 BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
129 if (!attr.isDirectory()) {
130 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_notAFolder());
135 try (Stream<Path> allFiles = Files.walk(selectedPath,
XRY_FILES_DEPTH)) {
136 Iterator<Path> allFilesIterator = allFiles.iterator();
137 while (allFilesIterator.hasNext()) {
138 Path currentPath = allFilesIterator.next();
139 if (!Files.isReadable(currentPath)) {
140 Path fileName = currentPath.subpath(currentPath.getNameCount() - 2,
141 currentPath.getNameCount());
143 Bundle.XRYDataSourceProcessor_childNotReadable(),
144 fileName.toString()));
151 if (!XRYFolder.isXRYFolder(selectedPath)) {
152 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_notXRYFolder());
155 }
catch (IOException | UncheckedIOException ex) {
156 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_ioError());
157 logger.log(Level.WARNING,
"[XRY DSP] I/O exception encountered trying to test the XRY folder.", ex);
178 if (XRYFolder.isXRYFolder(dataSourcePath)) {
181 }
catch (IOException ex) {
198 run(
null, progressMonitor, callback);
218 "XRYDataSourceProcessor.noCurrentCase=No case is open."
222 String selectedFilePath =
configPanel.getSelectedFilePath();
223 File selectedFile =
new File(selectedFilePath);
224 Path selectedPath = selectedFile.toPath();
227 XRYFolder xryFolder =
new XRYFolder(selectedPath);
229 String uniqueUUID = UUID.randomUUID().toString();
232 callback, currentCase, uniqueUUID, host);
235 logger.log(Level.WARNING,
"[XRY DSP] No case is currently open.", ex);
237 Lists.newArrayList(Bundle.XRYDataSourceProcessor_noCurrentCase(),
238 ex.getMessage()), Lists.newArrayList());
244 process(deviceId, dataSourcePath,
null, progressMonitor, callBack);
266 XRYFolder xryFolder =
new XRYFolder(dataSourcePath);
270 callBack, currentCase, deviceId, host);
273 logger.log(Level.WARNING,
"[XRY DSP] No case is currently open.", ex);
275 Lists.newArrayList(Bundle.XRYDataSourceProcessor_noCurrentCase(),
276 ex.getMessage()), Lists.newArrayList());
311 this.xryFolder = folder;
321 "XRYDataSourceProcessor.preppingFiles=Preparing to add files to the case database",
322 "XRYDataSourceProcessor.processingFiles=Processing all XRY files..."
325 TskDataException, IOException, BlackboardException {
326 progressMonitor.setProgressText(Bundle.XRYDataSourceProcessor_preppingFiles());
328 List<Path> nonXRYFiles =
xryFolder.getNonXRYFiles();
329 List<String> filePaths = nonXRYFiles.stream()
332 .collect(Collectors.toList());
333 LocalFilesDataSource dataSource =
currentCase.getServices().getFileManager().addLocalFilesDataSource(
342 progressMonitor.setProgressText(Bundle.XRYDataSourceProcessor_processingFiles());
349 "XRYDataSourceProcessor.unexpectedError=Internal error occurred while processing XRY report"
353 LocalFilesDataSource newDataSource =
get();
355 Lists.newArrayList(), Lists.newArrayList(newDataSource));
356 }
catch (InterruptedException ex) {
357 logger.log(Level.WARNING,
"[XRY DSP] Thread was interrupted while processing the XRY report."
358 +
" The case may or may not have the complete XRY report.", ex);
360 Lists.newArrayList(), Lists.newArrayList());
361 }
catch (ExecutionException ex) {
362 logger.log(Level.SEVERE,
"[XRY DSP] Unexpected internal error while processing XRY report.", ex);
364 Lists.newArrayList(Bundle.XRYDataSourceProcessor_unexpectedError(),
365 ex.toString()), Lists.newArrayList());
373 private class ProgressMonitorAdapter
implements FileManager.FileAddProgressUpdater {
383 "XRYDataSourceProcessor.fileAdded=Added %s to the case database"
386 progressMonitor.setProgressText(String.format(Bundle.XRYDataSourceProcessor_fileAdded(), newFile.getName()));
static Case getCurrentCaseThrows()
void done(DataSourceProcessorResult result, List< String > errList, List< Content > newDataSources)
synchronized static Logger getLogger(String name)
XRYReportProcessorSwingWorker(XRYFolder folder, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback, Case currentCase, String uniqueUUID, Host host)
final DataSourceProcessorProgressMonitor progressMonitor
final XRYFolder xryFolder
final DataSourceProcessorCallback callback
LocalFilesDataSource doInBackground()
void fileAdded(AbstractFile newFile)
final DataSourceProcessorProgressMonitor progressMonitor
final XRYDataSourceProcessorConfigPanel configPanel
void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
static final Logger logger
int canProcess(Path dataSourcePath)
void process(String deviceId, Path dataSourcePath, Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack)
XRYReportProcessorSwingWorker swingWorker
String getDataSourceType()
void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack)
static final int XRY_FILES_DEPTH
void run(Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
void setIndeterminate(boolean indeterminate)