19package org.sleuthkit.autopsy.livetriage;
21import java.io.IOException;
22import java.nio.file.Path;
23import java.nio.file.Paths;
24import java.nio.file.InvalidPathException;
25import java.util.logging.Level;
26import java.beans.PropertyChangeListener;
27import java.beans.PropertyChangeEvent;
28import javax.swing.JOptionPane;
30import javax.swing.SwingWorker;
31import org.apache.commons.io.FileUtils;
32import org.openide.awt.ActionID;
33import org.openide.awt.ActionReference;
34import org.openide.awt.ActionRegistration;
35import org.openide.util.HelpCtx;
36import org.openide.util.NbBundle;
37import org.openide.util.actions.CallableSystemAction;
38import org.openide.windows.WindowManager;
39import org.sleuthkit.autopsy.core.UserPreferences;
40import org.sleuthkit.autopsy.coreutils.Logger;
41import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
42import org.sleuthkit.autopsy.coreutils.PlatformUtil;
43import org.sleuthkit.autopsy.progress.ModalDialogProgressIndicator;
45@ActionID(category =
"Tools",
id =
"org.sleuthkit.autopsy.livetriage.CreateLiveTriageDriveAction")
46@ActionReference(path =
"Menu/Tools", position = 1850, separatorBefore = 1849)
47@ActionRegistration(displayName =
"#CTL_CreateLiveTriageDriveAction", lazy =
false)
48@NbBundle.Messages({
"CTL_CreateLiveTriageDriveAction=Make Live Triage Drive"})
51 private static final String
DISPLAY_NAME = Bundle.CTL_CreateLiveTriageDriveAction();
61 @NbBundle.Messages({
"CreateLiveTriageDriveAction.error.title=Error creating live triage disk",
62 "CreateLiveTriageDriveAction.exenotfound.message=Executable could not be found",
63 "CreateLiveTriageDriveAction.batchFileError.message=Error creating batch file",
64 "CreateLiveTriageDriveAction.appPathError.message=Could not location application directory",
65 "CreateLiveTriageDriveAction.copyError.message=Could not copy application. Only works on installed version.",
66 "CreateLiveTriageDriveAction.success.title=Success",
67 "CreateLiveTriageDriveAction.success.message=Live triage drive created. Use RunFromUSB.bat to run the application"
70 @SuppressWarnings(
"fallthrough")
73 Frame mainWindow = WindowManager.getDefault().getMainWindow();
77 String exeName = appName +
"64.exe";
80 Path exePath = Paths.get(installPath,
"bin", exeName);
82 if (!exePath.toFile().exists()) {
83 JOptionPane.showMessageDialog(mainWindow,
84 Bundle.CreateLiveTriageDriveAction_exenotfound_message(),
85 Bundle.CreateLiveTriageDriveAction_error_title(),
86 JOptionPane.ERROR_MESSAGE);
90 Path applicationBasePath;
92 applicationBasePath = exePath.getParent().getParent();
93 }
catch (InvalidPathException ex) {
94 JOptionPane.showMessageDialog(mainWindow,
95 Bundle.CreateLiveTriageDriveAction_appPathError_message(),
96 Bundle.CreateLiveTriageDriveAction_error_title(),
97 JOptionPane.ERROR_MESSAGE);
101 SelectDriveDialog driveDialog =
new SelectDriveDialog(mainWindow,
true);
102 driveDialog.display();
104 if (!driveDialog.getSelectedDrive().isEmpty()) {
105 drivePath = driveDialog.getSelectedDrive();
111 worker.addPropertyChangeListener(
this);
116 @NbBundle.Messages({
"# {0} - drivePath",
117 "CreateLiveTriageDriveAction.progressBar.text=Copying live triage files to {0}",
118 "CreateLiveTriageDriveAction.progressBar.title=Please wait"})
122 if (
"state".equals(evt.getPropertyName())
123 && (SwingWorker.StateValue.STARTED.equals(evt.getNewValue()))) {
126 String displayStr = NbBundle.getMessage(this.getClass(),
"CreateLiveTriageDriveAction.progressBar.text",
130 NbBundle.getMessage(
this.getClass(),
"CreateLiveTriageDriveAction.progressBar.title"));
133 }
else if (
"state".equals(evt.getPropertyName())
134 && (SwingWorker.StateValue.DONE.equals(evt.getNewValue()))) {
147 private class CopyFilesWorker
extends SwingWorker<Void, Void> {
173 @NbBundle.Messages({
"CopyFilesWorker.error.text=Error copying live triage files",
174 "CopyFilesWorker.done.text=Finished creating live triage disk"})
179 }
catch (Exception ex) {
186 private void copyApplication(Path sourceFolder, String destBaseFolder, String appName)
throws IOException {
189 Path destAppFolder = Paths.get(destBaseFolder, appName);
190 if (!destAppFolder.toFile().exists()) {
191 if (!destAppFolder.toFile().mkdirs()) {
192 throw new IOException(
"Failed to create directory " + destAppFolder.toString());
197 FileUtils.copyDirectory(sourceFolder.toFile(), destAppFolder.toFile());
200 private void copyBatchFile(String destPath, String appName)
throws IOException, InvalidPathException {
201 Path batchFilePath = Paths.get(destPath,
"RunFromUSB.bat");
211 +
"REM This restores the working directory when using 'Run as administrator'"
212 +
"@setlocal enableextensions\n"
215 +
"SET appName=\"" + appName +
"\"\n"
217 +
"REM Create the configData directory. Exit if it does not exist after attempting to create it\n"
218 +
"if not exist configData mkdir configData\n"
219 +
"if not exist configData (\n"
220 +
" echo Error creating directory configData\n"
224 +
"REM Create the userdir sub directory. Exit if it does not exist after attempting to create it\n"
225 +
"if not exist configData\\userdir mkdir configData\\userdir\n"
226 +
"if not exist configData\\userdir (\n"
227 +
" echo Error creating directory configData\\userdir\n"
231 +
"REM Create the cachedir sub directory. Exit if it does not exist after attempting to create it\n"
232 +
"REM If it exists to start with, delete it to clear out old data\n"
233 +
"if exist configData\\cachedir rd /s /q configData\\cachedir\n"
234 +
"mkdir configData\\cachedir\n"
235 +
"if not exist configData\\cachedir (\n"
236 +
" echo Error creating directory configData\\cachedir\n"
240 +
"REM Create the temp sub directory. Exit if it does not exist after attempting to create it\n"
241 +
"REM If it exists to start with, delete it to clear out old data\n"
242 +
"if exist configData\\temp rd /s /q configData\\temp\n"
243 +
"mkdir configData\\temp\n"
244 +
"if not exist configData\\temp (\n"
245 +
" echo Error creating directory configData\\temp\n"
249 +
"REM Create the cases directory. It's ok if this fails.\n"
250 +
"if not exist cases mkdir cases\n"
252 +
"if exist %appName% (\n"
253 +
" if not exist %appName%\\bin\\%appName%64.exe (\n"
254 +
" echo %appName%\\bin\\%appName%64.exe does not exist\n"
257 +
" %appName%\\bin\\%appName%64.exe --userdir ..\\configData\\userdir --cachedir ..\\configData\\cachedir -J-Djava.io.tmpdir=..\\configData\\temp --liveAutopsy\n"
259 +
" echo Could not find %appName% directory\n"
265 +
"REM Keep the cmd window open in case there was an error\n"
277 return HelpCtx.DEFAULT_HELP;
static String getAppName()
synchronized static Logger getLogger(String name)
static void error(String message)
static void info(String message)
void copyBatchFile(String destPath, String appName)
String getBatchFileContents(String appName)
static final String DISPLAY_NAME
void propertyChange(PropertyChangeEvent evt)
void copyApplication(Path sourceFolder, String destBaseFolder, String appName)
ModalDialogProgressIndicator progressIndicator