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

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.