19 package org.sleuthkit.autopsy.datasourceprocessors.xry;
21 import com.google.common.collect.Lists;
23 import java.io.IOException;
24 import java.io.UncheckedIOException;
25 import java.nio.file.Files;
26 import java.nio.file.LinkOption;
27 import java.nio.file.Path;
28 import java.nio.file.attribute.BasicFileAttributes;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.UUID;
32 import java.util.concurrent.ExecutionException;
33 import java.util.logging.Level;
34 import java.util.stream.Collectors;
35 import java.util.stream.Stream;
36 import javax.swing.JPanel;
37 import javax.swing.SwingWorker;
38 import org.openide.util.NbBundle;
39 import org.openide.util.lookup.ServiceProvider;
40 import org.openide.util.lookup.ServiceProviders;
51 import org.
sleuthkit.datamodel.Blackboard.BlackboardException;
59 @ServiceProviders(value = {
60 @ServiceProvider(service = DataSourceProcessor.class),
61 @ServiceProvider(service = AutoIngestDataSourceProcessor.class)
67 private static final int XRY_FILES_DEPTH = 1;
76 configPanel = XRYDataSourceProcessorConfigPanel.getInstance();
81 "XRYDataSourceProcessor.dataSourceType=XRY Text Export"
84 return Bundle.XRYDataSourceProcessor_dataSourceType();
100 "XRYDataSourceProcessor.noPathSelected=Please select a folder containing exported XRY text files",
101 "XRYDataSourceProcessor.notReadable=Selected path is not readable",
102 "XRYDataSourceProcessor.notXRYFolder=Selected folder did not contain any XRY text files",
103 "XRYDataSourceProcessor.ioError=I/O error occured trying to test the selected folder",
104 "XRYDataSourceProcessor.childNotReadable=Top level path [ %s ] is not readable",
105 "XRYDataSourceProcessor.notAFolder=The selected path is not a folder"
108 configPanel.clearErrorText();
109 String selectedFilePath = configPanel.getSelectedFilePath();
110 if (selectedFilePath.isEmpty()) {
111 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_noPathSelected());
115 File selectedFile =
new File(selectedFilePath);
116 Path selectedPath = selectedFile.toPath();
119 if (!Files.isReadable(selectedPath)) {
120 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_notReadable());
125 BasicFileAttributes attr = Files.readAttributes(selectedPath,
126 BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
128 if (!attr.isDirectory()) {
129 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_notAFolder());
134 try (Stream<Path> allFiles = Files.walk(selectedPath, XRY_FILES_DEPTH)) {
135 Iterator<Path> allFilesIterator = allFiles.iterator();
136 while (allFilesIterator.hasNext()) {
137 Path currentPath = allFilesIterator.next();
138 if (!Files.isReadable(currentPath)) {
139 Path fileName = currentPath.subpath(currentPath.getNameCount() - 2,
140 currentPath.getNameCount());
141 configPanel.setErrorText(String.format(
142 Bundle.XRYDataSourceProcessor_childNotReadable(),
143 fileName.toString()));
150 if (!XRYFolder.isXRYFolder(selectedPath)) {
151 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_notXRYFolder());
154 }
catch (IOException | UncheckedIOException ex) {
155 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_ioError());
156 logger.log(Level.WARNING,
"[XRY DSP] I/O exception encountered trying to test the XRY folder.", ex);
177 if (XRYFolder.isXRYFolder(dataSourcePath)) {
180 }
catch (IOException ex) {
197 "XRYDataSourceProcessor.noCurrentCase=No case is open."
202 String selectedFilePath = configPanel.getSelectedFilePath();
203 File selectedFile =
new File(selectedFilePath);
204 Path selectedPath = selectedFile.toPath();
207 XRYFolder xryFolder =
new XRYFolder(selectedPath);
209 String uniqueUUID = UUID.randomUUID().toString();
212 callback, currentCase, uniqueUUID);
213 swingWorker.execute();
215 logger.log(Level.WARNING,
"[XRY DSP] No case is currently open.", ex);
217 Lists.newArrayList(Bundle.XRYDataSourceProcessor_noCurrentCase(),
218 ex.getMessage()), Lists.newArrayList());
240 XRYFolder xryFolder =
new XRYFolder(dataSourcePath);
244 callBack, currentCase, deviceId);
245 swingWorker.execute();
247 logger.log(Level.WARNING,
"[XRY DSP] No case is currently open.", ex);
249 Lists.newArrayList(Bundle.XRYDataSourceProcessor_noCurrentCase(),
250 ex.getMessage()), Lists.newArrayList());
256 if (swingWorker != null) {
257 swingWorker.cancel(
true);
264 configPanel.clearSelectedFilePath();
282 Case currentCase, String uniqueUUID) {
284 this.xryFolder = folder;
285 this.progressMonitor = progressMonitor;
286 this.callback = callback;
287 this.currentCase = currentCase;
288 this.uniqueUUID = uniqueUUID;
293 "XRYDataSourceProcessor.preppingFiles=Preparing to add files to the case database",
294 "XRYDataSourceProcessor.processingFiles=Processing all XRY files..."
297 TskDataException, IOException, BlackboardException {
298 progressMonitor.
setProgressText(Bundle.XRYDataSourceProcessor_preppingFiles());
300 List<Path> nonXRYFiles = xryFolder.getNonXRYFiles();
301 List<String> filePaths = nonXRYFiles.stream()
304 .collect(Collectors.toList());
313 progressMonitor.
setProgressText(Bundle.XRYDataSourceProcessor_processingFiles());
314 XRYReportProcessor.process(xryFolder, dataSource, currentCase.
getSleuthkitCase());
320 "XRYDataSourceProcessor.unexpectedError=Internal error occurred while processing XRY report"
324 LocalFilesDataSource newDataSource =
get();
326 Lists.newArrayList(), Lists.newArrayList(newDataSource));
327 }
catch (InterruptedException ex) {
328 logger.log(Level.WARNING,
"[XRY DSP] Thread was interrupted while processing the XRY report."
329 +
" The case may or may not have the complete XRY report.", ex);
331 Lists.newArrayList(), Lists.newArrayList());
332 }
catch (ExecutionException ex) {
333 logger.log(Level.SEVERE,
"[XRY DSP] Unexpected internal error while processing XRY report.", ex);
335 Lists.newArrayList(Bundle.XRYDataSourceProcessor_unexpectedError(),
336 ex.toString()), Lists.newArrayList());
349 this.progressMonitor = progressMonitor;
354 "XRYDataSourceProcessor.fileAdded=Added %s to the case database"
357 progressMonitor.
setProgressText(String.format(Bundle.XRYDataSourceProcessor_fileAdded(), newFile.getName()));
FileManager getFileManager()
void setProgressText(String text)
void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
void fileAdded(AbstractFile newFile)
XRYReportProcessorSwingWorker swingWorker
void setIndeterminate(boolean indeterminate)
final XRYFolder xryFolder
void done(DataSourceProcessorResult result, List< String > errList, List< Content > newDataSources)
final DataSourceProcessorCallback callback
int canProcess(Path dataSourcePath)
synchronized LocalFilesDataSource addLocalFilesDataSource(String deviceId, String rootVirtualDirectoryName, String timeZone, List< String > localFilePaths, FileAddProgressUpdater progressUpdater)
SleuthkitCase getSleuthkitCase()
final XRYDataSourceProcessorConfigPanel configPanel
LocalFilesDataSource doInBackground()
XRYReportProcessorSwingWorker(XRYFolder folder, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback, Case currentCase, String uniqueUUID)
final DataSourceProcessorProgressMonitor progressMonitor
String getDataSourceType()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack)
final DataSourceProcessorProgressMonitor progressMonitor