Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
HashDbSearchThread.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011 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.hashdatabase;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.concurrent.CancellationException;
25 import java.util.logging.Level;
26 
27 import org.openide.util.NbBundle;
29 import javax.swing.JOptionPane;
30 import javax.swing.SwingWorker;
31 import org.netbeans.api.progress.ProgressHandle;
32 import org.netbeans.api.progress.ProgressHandleFactory;
33 import org.openide.util.Cancellable;
34 import org.sleuthkit.datamodel.AbstractFile;
35 
36 class HashDbSearchThread extends SwingWorker<Object, Void> {
37 
38  private Logger logger = Logger.getLogger(HashDbSearchThread.class.getName());
39  private ProgressHandle progress;
40  private Map<String, List<AbstractFile>> map;
41  private ArrayList<String> hashes = new ArrayList<>();
42  private AbstractFile file;
43 
44  HashDbSearchThread(AbstractFile file) {
45  this.file = file;
46  this.hashes.add(this.file.getMd5Hash());
47  }
48 
49  HashDbSearchThread(ArrayList<String> hashes) {
50  this.hashes = hashes;
51  }
52 
53  @Override
54  protected Object doInBackground() throws Exception {
55  logger.log(Level.INFO, "Starting background processing for file search by MD5 hash."); //NON-NLS
56 
57  // Setup progress bar
58  final String displayName = NbBundle.getMessage(this.getClass(), "HashDbSearchThread.name.searching");
59  progress = ProgressHandleFactory.createHandle(displayName, new Cancellable() {
60  @Override
61  public boolean cancel() {
62  if (progress != null) {
63  progress.setDisplayName(
64  NbBundle.getMessage(this.getClass(), "HashDbSearchThread.progress.cancellingSearch",
65  displayName));
66  }
67  return HashDbSearchThread.this.cancel(true);
68  }
69  });
70  // Start the progress bar as indeterminate
71  progress.start();
72  progress.switchToIndeterminate();
73 
74  // Do the querying
75  map = HashDbSearcher.findFilesBymd5(hashes, progress, this);
76  logger.log(Level.INFO, "Done background processing"); //NON-NLS
77 
78  return null;
79  }
80 
81  @Override
82  protected void done() {
83  try {
84  super.get(); //block and get all exceptions thrown while doInBackground()
85  } catch (CancellationException ex) {
86  logger.log(Level.INFO, "File search by MD5 hash was canceled."); //NON-NLS
87  } catch (InterruptedException ex) {
88  logger.log(Level.INFO, "File search by MD5 hash was interrupted."); //NON-NLS
89  } catch (Exception ex) {
90  logger.log(Level.SEVERE, "Fatal error during file search by MD5 hash.", ex); //NON-NLS
91  } finally {
92  progress.finish();
93  if (!this.isCancelled()) {
94  logger.log(Level.INFO, "File search by MD5 hash completed without cancellation."); //NON-NLS
95  // If its a right click action, we are given an FsContent which
96  // is the file right clicked, so we can remove that from the search
97  if (file != null) {
98  boolean quit = true;
99  for (List<AbstractFile> files : map.values()) {
100  files.remove(file);
101  if (!files.isEmpty()) {
102  quit = false;
103  }
104  }
105  if (quit) {
106  JOptionPane.showMessageDialog(null,
107  NbBundle.getMessage(this.getClass(),
108  "HashDbSearchThread.noMoreFilesWithMD5Msg"));
109  return;
110  }
111  }
112  HashDbSearchManager man = new HashDbSearchManager(map);
113  man.execute();
114  } else {
115  logger.log(Level.INFO, "File search by MD5 hash was canceled."); //NON-NLS
116  }
117  }
118  }
119 
120 }

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.