19 package org.sleuthkit.autopsy.modules.ileappanalyzer;
22 import java.io.FileNotFoundException;
23 import java.io.IOException;
24 import java.io.UncheckedIOException;
25 import java.nio.file.Files;
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.text.SimpleDateFormat;
29 import java.util.List;
30 import java.util.ArrayList;
31 import java.util.Locale;
32 import java.util.logging.Level;
33 import java.util.stream.Collectors;
34 import java.util.stream.Stream;
35 import org.openide.modules.InstalledFileLocator;
36 import org.openide.util.NbBundle;
63 private static final String
ILEAPP =
"iLeapp";
77 "ILeappAnalyzerIngestModule.executable.not.found=iLeapp Executable Not Found.",
78 "ILeappAnalyzerIngestModule.requires.windows=iLeapp module requires windows.",
79 "ILeappAnalyzerIngestModule.error.ileapp.file.processor.init=Failure to initialize ILeappProcessFile"})
91 throw new IngestModuleException(Bundle.ILeappAnalyzerIngestModule_error_ileapp_file_processor_init(), ex);
96 }
catch (FileNotFoundException exception) {
97 logger.log(Level.WARNING,
"iLeapp executable not found.", exception);
104 "ILeappAnalyzerIngestModule.error.running.iLeapp=Error running iLeapp, see log file.",
105 "ILeappAnalyzerIngestModule.error.creating.output.dir=Error creating iLeapp module output directory.",
106 "ILeappAnalyzerIngestModule.starting.iLeapp=Starting iLeapp",
107 "ILeappAnalyzerIngestModule.running.iLeapp=Running iLeapp",
108 "ILeappAnalyzerIngestModule.has.run=iLeapp",
109 "ILeappAnalyzerIngestModule.iLeapp.cancelled=iLeapp run was canceled",
110 "ILeappAnalyzerIngestModule.completed=iLeapp Processing Completed",
111 "ILeappAnalyzerIngestModule.report.name=iLeapp Html Report"})
115 if (!(context.
getDataSource() instanceof LocalFilesDataSource)) {
119 statusHelper.
progress(Bundle.ILeappAnalyzerIngestModule_starting_iLeapp(), 0);
125 Integer filesProcessedCount = 0;
128 for (AbstractFile iLeappFile : iLeappFilesToProcess) {
130 String currentTime =
new SimpleDateFormat(
"yyyy-MM-dd HH-mm-ss z", Locale.US).format(System.currentTimeMillis());
133 Files.createDirectories(moduleOutputPath);
134 }
catch (IOException ex) {
135 logger.log(Level.SEVERE, String.format(
"Error creating iLeapp output directory %s", moduleOutputPath.toString()), ex);
139 statusHelper.
progress(NbBundle.getMessage(
this.getClass(),
"ILeappAnalyzerIngestModule.processing.file", iLeappFile.getName()), filesProcessedCount);
140 ProcessBuilder iLeappCommand =
buildiLeappCommand(moduleOutputPath, iLeappFile.getLocalAbsPath(), iLeappFile.getNameExtension());
144 logger.log(Level.SEVERE, String.format(
"Error running iLeapp, error code returned %d", result));
150 }
catch (IOException ex) {
151 logger.log(Level.SEVERE, String.format(
"Error when trying to execute iLeapp program against file %s", iLeappFile.getLocalAbsPath()), ex);
156 logger.log(Level.INFO,
"ILeapp Analyser ingest module run was canceled");
166 filesProcessedCount++;
170 Bundle.ILeappAnalyzerIngestModule_has_run(),
171 Bundle.ILeappAnalyzerIngestModule_completed());
185 List<AbstractFile> iLeappFiles =
new ArrayList<>();
187 FileManager fileManager = getCurrentCase().getServices().getFileManager();
191 iLeappFiles = fileManager.
findFiles(dataSource,
"%",
"/");
192 }
catch (TskCoreException ex) {
193 logger.log(Level.WARNING,
"No files found to process");
197 List<AbstractFile> iLeappFilesToProcess =
new ArrayList<>();
198 for (AbstractFile iLeappFile : iLeappFiles) {
199 if ((iLeappFile.getName().toLowerCase().contains(
".zip") || (iLeappFile.getName().toLowerCase().contains(
".tar"))
200 || iLeappFile.getName().toLowerCase().contains(
".tgz"))) {
201 iLeappFilesToProcess.add(iLeappFile);
205 return iLeappFilesToProcess;
208 private ProcessBuilder
buildiLeappCommand(Path moduleOutputPath, String sourceFilePath, String iLeappFileSystemType) {
211 "\"" + iLeappExecutable +
"\"",
212 "-t", iLeappFileSystemType,
213 "-i", sourceFilePath,
214 "-o", moduleOutputPath.toString()
216 processBuilder.redirectError(moduleOutputPath.resolve(
"iLeapp_err.txt").toFile());
217 processBuilder.redirectOutput(moduleOutputPath.resolve(
"iLeapp_out.txt").toFile());
218 return processBuilder;
222 ProcessBuilder processBuilder =
new ProcessBuilder(commandLine);
227 processBuilder.environment().put(
"__COMPAT_LAYER",
"RunAsInvoker");
228 return processBuilder;
232 String executableToFindName = Paths.get(ILEAPP, executableName).toString();
234 File exeFile = InstalledFileLocator.getDefault().locate(executableToFindName,
ILeappAnalyzerIngestModule.class.getPackage().getName(),
false);
235 if (null == exeFile || exeFile.canExecute() ==
false) {
236 throw new FileNotFoundException(executableName +
" executable not found.");
246 List<String> allIndexFiles =
new ArrayList<>();
248 try (Stream<Path> walk = Files.walk(iLeappOutputDir)) {
250 allIndexFiles = walk.map(x -> x.toString())
251 .filter(f -> f.toLowerCase().endsWith(
"index.html")).collect(Collectors.toList());
253 if (!allIndexFiles.isEmpty()) {
254 currentCase.
addReport(allIndexFiles.get(0),
MODULE_NAME, Bundle.ILeappAnalyzerIngestModule_report_name());
257 }
catch (IOException | UncheckedIOException | TskCoreException ex) {
259 logger.log(Level.WARNING, String.format(
"Error finding index file in path %s", iLeappOutputDir.toString()), ex);
static int execute(ProcessBuilder processBuilder)
void startUp(IngestJobContext context)
void addILeappReportToReports(Path iLeappOutputDir, Case currentCase)
ProcessBuilder buildiLeappCommand(Path moduleOutputPath, String sourceFilePath, String iLeappFileSystemType)
static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml)
static File locateExecutable(String executableName)
void addReport(String localPath, String srcModuleName, String reportName)
static final Logger logger
static final String MODULE_NAME
ProcessResult processFiles(Content dataSource, Path moduleOutputPath, AbstractFile iLeappFile)
static ProcessBuilder buildProcessWithRunAsInvoker(String...commandLine)
static final String ILEAPP_EXECUTABLE
void postMessage(final IngestMessage message)
List< AbstractFile > findiLeappFilesToProcess(Content dataSource)
String getModuleDirectory()
boolean dataSourceIngestIsCancelled()
void switchToDeterminate(int workUnits)
synchronized List< AbstractFile > findFiles(String fileName)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
ProcessResult process(Content dataSource, DataSourceIngestModuleProgress statusHelper)
static final String ILEAPP
ILeappFileProcessor iLeappFileProcessor
void progress(int workUnits)
static synchronized IngestServices getInstance()