19 package org.sleuthkit.autopsy.livetriage;
21 import java.io.IOException;
22 import java.nio.file.Path;
23 import java.nio.file.Paths;
24 import java.nio.file.InvalidPathException;
25 import java.util.logging.Level;
26 import java.beans.PropertyChangeListener;
27 import java.beans.PropertyChangeEvent;
28 import javax.swing.JOptionPane;
29 import java.awt.Frame;
30 import javax.swing.SwingWorker;
31 import org.apache.commons.io.FileUtils;
32 import org.openide.awt.ActionID;
33 import org.openide.awt.ActionReference;
34 import org.openide.awt.ActionRegistration;
35 import org.openide.util.HelpCtx;
36 import org.openide.util.NbBundle;
37 import org.openide.util.actions.CallableSystemAction;
38 import org.openide.windows.WindowManager;
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();
53 private String drivePath =
"";
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();
106 if (drivePath.startsWith(
"\\\\.\\")) {
107 drivePath = drivePath.substring(4);
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"));
131 progressIndicator.
start(displayStr);
133 }
else if (
"state".equals(evt.getPropertyName())
134 && (SwingWorker.StateValue.DONE.equals(evt.getNewValue()))) {
135 if (progressIndicator != null) {
136 progressIndicator.
finish();
139 if (worker.hadError()) {
152 private boolean error =
false;
155 this.sourceFolder = sourceFolder;
156 this.drivePath = drivePath;
157 this.appName = appName;
167 copyBatchFile(drivePath, appName);
168 copyApplication(sourceFolder, drivePath, appName);
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");
202 FileUtils.writeStringToFile(batchFilePath.toFile(), getBatchFileContents(appName),
"UTF-8");
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;
void copyBatchFile(String destPath, String appName)
static String getAppName()
void propertyChange(PropertyChangeEvent evt)
String getBatchFileContents(String appName)
void copyApplication(Path sourceFolder, String destBaseFolder, String appName)
synchronized void start(String message, int totalWorkUnits)
synchronized static Logger getLogger(String name)
static void info(String message)
static void error(String message)
synchronized void finish()