Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExtractArchiveWithPasswordAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.embeddedfileextractor;
20 
21 import java.awt.event.ActionEvent;
22 import java.nio.file.Paths;
23 import java.util.concurrent.ExecutionException;
24 import java.util.logging.Level;
25 import javax.swing.AbstractAction;
26 import javax.swing.JOptionPane;
27 import javax.swing.SwingWorker;
29 import net.sf.sevenzipjbinding.SevenZipNativeInitializationException;
30 import org.openide.util.NbBundle.Messages;
31 import org.openide.windows.WindowManager;
39 import org.sleuthkit.datamodel.AbstractFile;
40 
46 public class ExtractArchiveWithPasswordAction extends AbstractAction {
47 
48  private static final long serialVersionUID = 1L;
49  private static final Logger logger = Logger.getLogger(ExtractArchiveWithPasswordAction.class.getName());
50  private final AbstractFile archiveFile;
51 
59  @Messages({"ExtractArchiveWithPasswordAction.name.text=Unzip contents with password", "ExtractArchiveWithPasswordAction.prompt.text=Enter Password",
60  "ExtractArchiveWithPasswordAction.prompt.title=Enter Password",
61  "ExtractArchiveWithPasswordAction.extractFailed.title=Failed to Unpack Files, with Password",
62  "# {0} - archiveFile",
63  "ExtractArchiveWithPasswordAction.progress.text=Unpacking contents of archive: {0}"})
64  public ExtractArchiveWithPasswordAction(AbstractFile file) {
65  super(Bundle.ExtractArchiveWithPasswordAction_name_text());
66  archiveFile = file;
67  }
68 
69  @Override
70  public void actionPerformed(ActionEvent e) {
71  String password = getPassword(Bundle.ExtractArchiveWithPasswordAction_prompt_title(), "");
72  if (password != null) {
73  ExtractAndIngestWorker extractWorker = new ExtractAndIngestWorker(password, archiveFile);
74  extractWorker.execute();
75  }
76  }
77 
78  private String getPassword(String title, String oldPassword) {
79  String password = null;
80  Object inputValue = JOptionPane.showInputDialog(WindowManager.getDefault().getMainWindow(), Bundle.ExtractArchiveWithPasswordAction_prompt_text(),
81  title, JOptionPane.PLAIN_MESSAGE, null, null, oldPassword);
82  if (inputValue != null) {
83  password = (String) inputValue;
84  }
85  return password;
86  }
87 
93  private class ExtractAndIngestWorker extends SwingWorker<Boolean, Void> {
94 
95  private final AbstractFile archive;
96  private String password;
97  private final ModalDialogProgressIndicator progress = new ModalDialogProgressIndicator(WindowManager.getDefault().getMainWindow(), "Extracting Archive");
98 
105  private ExtractAndIngestWorker(String pass, AbstractFile file) {
106  archive = file;
107  password = pass;
108  }
109 
110  @Override
111  protected Boolean doInBackground() {
112  boolean done = false;
113  try {
114  String moduleDirRelative = Paths.get(Case.getOpenCase().getModuleOutputDirectoryRelativePath(), EmbeddedFileExtractorModuleFactory.getModuleName()).toString();
115  String moduleDirAbsolute = Paths.get(Case.getOpenCase().getModuleDirectory(), EmbeddedFileExtractorModuleFactory.getModuleName()).toString();
116  /*
117  * Construct a file type detector.
118  */
119  progress.start(Bundle.ExtractArchiveWithPasswordAction_progress_text(archive.getName()));
120  FileTypeDetector fileTypeDetector;
121  try {
122  fileTypeDetector = new FileTypeDetector();
124  return false;
125  }
126  try {
127  SevenZipExtractor extractor = new SevenZipExtractor(null, fileTypeDetector, moduleDirRelative, moduleDirAbsolute);
128  done = extractor.unpack(archive, password);
129  } catch (SevenZipNativeInitializationException ex) {
130  IngestServices.getInstance().postMessage(IngestMessage.createWarningMessage(EmbeddedFileExtractorModuleFactory.getModuleName(), "Unable to extract file with password", password));
131  logger.log(Level.INFO, "Unable to extract file with password", ex);
132  return done;
133  }
134  } catch (NoCurrentCaseException ex) {
135  logger.log(Level.SEVERE, "Error getting open case unable to perform extraction action", ex);
136  } finally {
137  progress.finish();
138  }
139  return done;
140  }
141 
142  @Override
143  protected void done() {
144  boolean done = false;
145  try {
146  done = get();
147  while (!done) {
148  password = getPassword(Bundle.ExtractArchiveWithPasswordAction_extractFailed_title(), password);
149  if (password == null) {
150  //allow them to cancel if they don't know the correct password
151  return;
152  }
153  done = doInBackground();
154  }
155  } catch (InterruptedException ex) {
156  logger.log(Level.SEVERE, "Unable to extract archive successfully", ex);
157  } catch (ExecutionException ex) {
158  logger.log(Level.SEVERE, "Execution Exception: Unable to extract archive successfully", ex.getCause());
159  }
160  if (done) {
161  RunIngestModulesAction runIngest = new RunIngestModulesAction(archive);
162  runIngest.actionPerformed(null);
163  }
164  }
165  }
166 }
synchronized void start(String message, int totalWorkUnits)
void postMessage(final IngestMessage message)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static IngestMessage createWarningMessage(String source, String subject, String detailsHtml)
static synchronized IngestServices getInstance()

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.