19 package org.sleuthkit.autopsy.modules.leappanalyzers;
21 import java.io.BufferedReader;
23 import java.io.FileNotFoundException;
24 import java.io.FileReader;
25 import java.io.IOException;
26 import java.io.UncheckedIOException;
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30 import java.text.SimpleDateFormat;
31 import java.util.List;
32 import java.util.ArrayList;
33 import java.util.Locale;
34 import java.util.logging.Level;
35 import java.util.stream.Collectors;
36 import java.util.stream.Stream;
37 import org.apache.commons.io.FilenameUtils;
38 import org.openide.modules.InstalledFileLocator;
39 import org.openide.util.NbBundle;
69 private static final String
ILEAPP =
"iLeapp";
74 private static final String
XMLFILE =
"ileapp-artifact-attribute-reference.xml";
87 "ILeappAnalyzerIngestModule.executable.not.found=iLeapp Executable Not Found.",
88 "ILeappAnalyzerIngestModule.requires.windows=iLeapp module requires windows.",
89 "ILeappAnalyzerIngestModule.error.ileapp.file.processor.init=Failure to initialize ILeappProcessFile"})
95 throw new IngestModuleException(NbBundle.getMessage(
this.getClass(),
"IleappAnalyzerIngestModule.not.64.bit.os"));
105 throw new IngestModuleException(Bundle.ILeappAnalyzerIngestModule_error_ileapp_file_processor_init(), ex);
110 }
catch (FileNotFoundException exception) {
111 logger.log(Level.WARNING,
"iLeapp executable not found.", exception);
112 throw new IngestModuleException(Bundle.ILeappAnalyzerIngestModule_executable_not_found(), exception);
118 "ILeappAnalyzerIngestModule.error.running.iLeapp=Error running iLeapp, see log file.",
119 "ILeappAnalyzerIngestModule.error.creating.output.dir=Error creating iLeapp module output directory.",
120 "ILeappAnalyzerIngestModule.running.iLeapp=Running iLeapp",
121 "ILeappAnalyzerIngestModule_processing_iLeapp_results=Processing iLeapp results",
122 "ILeappAnalyzerIngestModule.has.run=iLeapp",
123 "ILeappAnalyzerIngestModule.iLeapp.cancelled=iLeapp run was canceled",
124 "ILeappAnalyzerIngestModule.completed=iLeapp Processing Completed",
125 "ILeappAnalyzerIngestModule.report.name=iLeapp Html Report"})
130 statusHelper.
progress(Bundle.ILeappAnalyzerIngestModule_running_iLeapp());
135 Files.createDirectories(tempOutputPath);
136 }
catch (IOException ex) {
137 logger.log(Level.SEVERE, String.format(
"Error creating iLeapp output directory %s", tempOutputPath.toString()), ex);
142 List<String> iLeappPathsToProcess;
147 logger.log(Level.SEVERE, String.format(
"Error when trying to execute iLeapp program getting file paths to search for result is %d", result));
152 if (iLeappPathsToProcess.isEmpty()) {
153 logger.log(Level.SEVERE, String.format(
"Error getting file paths to search, list is empty"));
157 }
catch (IOException ex) {
158 logger.log(Level.SEVERE, String.format(
"Error when trying to execute iLeapp program getting file paths to search"), ex);
163 if ((context.
getDataSource() instanceof LocalFilesDataSource)) {
169 List<AbstractFile> iLeappFilesToProcess =
LeappFileProcessor.findLeappFilesToProcess(dataSource);
170 if (!iLeappFilesToProcess.isEmpty()) {
172 Integer filesProcessedCount = 0;
173 for (AbstractFile iLeappFile : iLeappFilesToProcess) {
174 processILeappFile(dataSource, currentCase, statusHelper, filesProcessedCount, iLeappFile);
175 filesProcessedCount++;
181 statusHelper.
progress(Bundle.ILeappAnalyzerIngestModule_processing_iLeapp_results());
183 processILeappFs(dataSource, currentCase, statusHelper, tempOutputPath.toString());
186 Bundle.ILeappAnalyzerIngestModule_has_run(),
187 Bundle.ILeappAnalyzerIngestModule_completed());
203 AbstractFile iLeappFile) {
204 statusHelper.
progress(NbBundle.getMessage(
this.getClass(),
"ILeappAnalyzerIngestModule.processing.file", iLeappFile.getName()), filesProcessedCount);
206 String currentTime =
new SimpleDateFormat(
"yyyy-MM-dd HH-mm-ss z", Locale.US).format(System.currentTimeMillis());
209 Files.createDirectories(moduleOutputPath);
210 }
catch (IOException ex) {
211 logger.log(Level.SEVERE, String.format(
"Error creating iLeapp output directory %s", moduleOutputPath.toString()), ex);
215 ProcessBuilder iLeappCommand =
buildiLeappCommand(moduleOutputPath, iLeappFile.getLocalAbsPath(), iLeappFile.getNameExtension());
219 logger.log(Level.WARNING, String.format(
"Error when trying to execute iLeapp program getting file paths to search for result is %d", result));
225 }
catch (IOException ex) {
226 logger.log(Level.SEVERE, String.format(
"Error when trying to execute iLeapp program against file %s", iLeappFile.getLocalAbsPath()), ex);
231 logger.log(Level.INFO,
"ILeapp Analyser ingest module run was canceled");
235 iLeappFileProcessor.
processFiles(dataSource, moduleOutputPath, iLeappFile, statusHelper);
247 statusHelper.
progress(NbBundle.getMessage(
this.getClass(),
"ILeappAnalyzerIngestModule.processing.filesystem"));
248 String currentTime =
new SimpleDateFormat(
"yyyy-MM-dd HH-mm-ss z", Locale.US).format(System.currentTimeMillis());
251 Files.createDirectories(moduleOutputPath);
252 }
catch (IOException ex) {
253 logger.log(Level.SEVERE, String.format(
"Error creating iLeapp output directory %s", moduleOutputPath.toString()), ex);
257 ProcessBuilder iLeappCommand =
buildiLeappCommand(moduleOutputPath, directoryToProcess,
"fs");
261 logger.log(Level.WARNING, String.format(
"Error when trying to execute iLeapp program getting file paths to search for result is %d", result));
267 }
catch (IOException ex) {
268 logger.log(Level.SEVERE, String.format(
"Error when trying to execute iLeapp program against file system"), ex);
273 logger.log(Level.INFO,
"ILeapp Analyser ingest module run was canceled");
277 iLeappFileProcessor.
processFileSystem(dataSource, moduleOutputPath, statusHelper);
289 private ProcessBuilder
buildiLeappCommand(Path moduleOutputPath, String sourceFilePath, String iLeappFileSystemType) {
292 "\"" + iLeappExecutable +
"\"",
293 "-t", iLeappFileSystemType,
294 "-i", sourceFilePath,
295 "-o", moduleOutputPath.toString()
297 processBuilder.redirectError(moduleOutputPath.resolve(
"iLeapp_err.txt").toFile());
298 processBuilder.redirectOutput(moduleOutputPath.resolve(
"iLeapp_out.txt").toFile());
299 return processBuilder;
312 "\"" + iLeappExecutable +
"\"",
315 processBuilder.redirectError(moduleOutputPath.resolve(
"iLeapp_paths_error.txt").toFile());
316 processBuilder.redirectOutput(moduleOutputPath.resolve(
"iLeapp_paths.txt").toFile());
317 return processBuilder;
321 ProcessBuilder processBuilder =
new ProcessBuilder(commandLine);
326 processBuilder.environment().put(
"__COMPAT_LAYER",
"RunAsInvoker");
327 return processBuilder;
331 String executableToFindName = Paths.get(ILEAPP, executableName).toString();
333 File exeFile = InstalledFileLocator.getDefault().locate(executableToFindName,
ILeappAnalyzerIngestModule.class.getPackage().getName(),
false);
334 if (null == exeFile || exeFile.canExecute() ==
false) {
335 throw new FileNotFoundException(executableName +
" executable not found.");
345 List<String> allIndexFiles;
347 try (Stream<Path> walk = Files.walk(iLeappOutputDir)) {
349 allIndexFiles = walk.map(x -> x.toString())
350 .filter(f -> f.toLowerCase().endsWith(
"index.html")).collect(Collectors.toList());
352 if (!allIndexFiles.isEmpty()) {
354 String filePath = FilenameUtils.getFullPathNoEndSeparator(allIndexFiles.get(0));
355 File dataFilesDir =
new File(Paths.get(filePath,
"_TSV Exports").toString());
356 if (dataFilesDir.exists()) {
357 currentCase.
addReport(allIndexFiles.get(0),
MODULE_NAME, Bundle.ILeappAnalyzerIngestModule_report_name());
361 }
catch (IOException | UncheckedIOException | TskCoreException ex) {
363 logger.log(Level.WARNING, String.format(
"Error finding index file in path %s", iLeappOutputDir.toString()), ex);
373 private List<String>
loadIleappPathFile(Path moduleOutputPath)
throws FileNotFoundException, IOException {
374 List<String> iLeappPathsToProcess =
new ArrayList<>();
378 try (BufferedReader reader =
new BufferedReader(
new FileReader(filePath.toString()))) {
379 String line = reader.readLine();
380 while (line != null) {
381 if (line.contains(
"path list generation") || line.length() < 2) {
382 line = reader.readLine();
385 iLeappPathsToProcess.add(line.trim());
386 line = reader.readLine();
390 return iLeappPathsToProcess;
401 FileManager fileManager = getCurrentCase().getServices().getFileManager();
403 for (String fullFilePath : iLeappPathsToProcess) {
406 logger.log(Level.INFO,
"ILeapp Analyser ingest module run was canceled");
410 String ffp = fullFilePath.replaceAll(
"\\*",
"%");
411 ffp = FilenameUtils.normalize(ffp,
true);
412 String fileName = FilenameUtils.getName(ffp);
413 String filePath = FilenameUtils.getPath(ffp);
415 List<AbstractFile> iLeappFiles;
417 if (filePath.isEmpty()) {
418 iLeappFiles = fileManager.
findFiles(dataSource, fileName);
420 iLeappFiles = fileManager.
findFiles(dataSource, fileName, filePath);
422 }
catch (TskCoreException ex) {
423 logger.log(Level.WARNING,
"No files found to process");
427 for (AbstractFile iLeappFile : iLeappFiles) {
428 Path parentPath = Paths.get(moduleOutputPath.toString(), iLeappFile.getParentPath());
429 File fileParentPath =
new File(parentPath.toString());
444 private void extractFileToOutput(Content dataSource, AbstractFile iLeappFile, File fileParentPath, Path parentPath) {
445 if (fileParentPath.exists()) {
446 if (!iLeappFile.isDir()) {
450 Files.createDirectories(Paths.get(parentPath.toString(), iLeappFile.getName()));
451 }
catch (IOException ex) {
452 logger.log(Level.INFO, String.format(
"Error creating iLeapp output directory %s", parentPath.toString()), ex);
457 Files.createDirectories(parentPath);
458 }
catch (IOException ex) {
459 logger.log(Level.INFO, String.format(
"Error creating iLeapp output directory %s", parentPath.toString()), ex);
461 if (!iLeappFile.isDir()) {
465 Files.createDirectories(Paths.get(parentPath.toString(), iLeappFile.getName()));
466 }
catch (IOException ex) {
467 logger.log(Level.INFO, String.format(
"Error creating iLeapp output directory %s", parentPath.toString()), ex);
480 private void writeiLeappFile(Content dataSource, AbstractFile iLeappFile, String parentPath) {
481 String fileName = iLeappFile.getName().replace(
":",
"-");
482 if (!fileName.matches(
".") && !fileName.matches(
"..") && !fileName.toLowerCase().endsWith(
"-slack")) {
483 Path filePath = Paths.get(parentPath, fileName);
484 File localFile =
new File(filePath.toString());
487 }
catch (ReadContentInputStream.ReadContentInputStreamException ex) {
488 logger.log(Level.WARNING, String.format(
"Error reading file '%s' (id=%d).",
489 iLeappFile.getName(), iLeappFile.getId()), ex);
490 }
catch (IOException ex) {
491 logger.log(Level.WARNING, String.format(
"Error writing file local file '%s' (id=%d).",
492 filePath.toString(), iLeappFile.getId()), ex);
504 Bundle.ILeappAnalyzerIngestModule_error_running_iLeapp());
ProcessBuilder buildiLeappListCommand(Path moduleOutputPath)
void processILeappFs(Content dataSource, Case currentCase, DataSourceIngestModuleProgress statusHelper, String directoryToProcess)
void writeErrorMsgToIngestInbox()
static int execute(ProcessBuilder processBuilder)
String getTempDirectory()
List< AbstractFile > findFiles(String fileName)
static final String ILEAPP
void extractFileToOutput(Content dataSource, AbstractFile iLeappFile, File fileParentPath, Path parentPath)
static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml)
static< T > long writeToFile(Content content, java.io.File outputFile, ProgressHandle progress, Future< T > worker, boolean source)
void addReport(String localPath, String srcModuleName, String reportName)
static final String MODULE_NAME
static final String ILEAPP_EXECUTABLE
static ProcessBuilder buildProcessWithRunAsInvoker(String...commandLine)
static final String ILEAPP_FS
ProcessBuilder buildiLeappCommand(Path moduleOutputPath, String sourceFilePath, String iLeappFileSystemType)
static final String XMLFILE
void switchToIndeterminate()
static final Logger logger
void extractFilesFromDataSource(Content dataSource, List< String > iLeappPathsToProcess, Path moduleOutputPath)
static File locateExecutable(String executableName)
void postMessage(final IngestMessage message)
String getModuleDirectory()
void addILeappReportToReports(Path iLeappOutputDir, Case currentCase)
boolean dataSourceIngestIsCancelled()
ProcessResult processFileSystem(Content dataSource, Path moduleOutputPath, DataSourceIngestModuleProgress progress)
void startUp(IngestJobContext context)
void switchToDeterminate(int workUnits)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
ProcessResult process(Content dataSource, DataSourceIngestModuleProgress statusHelper)
static final String ILEAPP_PATHS_FILE
void processILeappFile(Content dataSource, Case currentCase, DataSourceIngestModuleProgress statusHelper, int filesProcessedCount, AbstractFile iLeappFile)
LeappFileProcessor iLeappFileProcessor
void writeiLeappFile(Content dataSource, AbstractFile iLeappFile, String parentPath)
List< String > loadIleappPathFile(Path moduleOutputPath)
void progress(int workUnits)
ProcessResult processFiles(Content dataSource, Path moduleOutputPath, AbstractFile LeappFile, DataSourceIngestModuleProgress progress)
static synchronized IngestServices getInstance()