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

Copyright © 2012-2016 Basis Technology. Generated on: Tue Jun 13 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.