Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
HashDbSearcher.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.Collections;
22 import java.util.LinkedHashMap;
23 import java.util.List;
24 import java.util.Map;
25 import javax.swing.SwingWorker;
26 import org.netbeans.api.progress.ProgressHandle;
28 import org.sleuthkit.datamodel.AbstractFile;
29 import org.sleuthkit.datamodel.FsContent;
30 import org.sleuthkit.datamodel.SleuthkitCase;
31 
36 class HashDbSearcher {
37 
45  static List<AbstractFile> findFilesByMd5(String md5Hash) {
46  final Case currentCase = Case.getCurrentCase();
47  final SleuthkitCase skCase = currentCase.getSleuthkitCase();
48  return skCase.findFilesByMd5(md5Hash);
49  }
50 
59  static Map<String, List<AbstractFile>> findFilesBymd5(List<String> md5Hash) {
60  Map<String, List<AbstractFile>> map = new LinkedHashMap<String, List<AbstractFile>>();
61  for (String md5 : md5Hash) {
62  List<AbstractFile> files = findFilesByMd5(md5);
63  if (!files.isEmpty()) {
64  map.put(md5, files);
65  }
66  }
67  return map;
68  }
69 
70  // Same as above, but with a given ProgressHandle to accumulate and StringWorker to check if cancelled
71 
72  static Map<String, List<AbstractFile>> findFilesBymd5(List<String> md5Hash, ProgressHandle progress, SwingWorker<Object, Void> worker) {
73  Map<String, List<AbstractFile>> map = new LinkedHashMap<String, List<AbstractFile>>();
74  if (!worker.isCancelled()) {
75  progress.switchToDeterminate(md5Hash.size());
76  int size = 0;
77  for (String md5 : md5Hash) {
78  if (worker.isCancelled()) {
79  break;
80  }
81  List<AbstractFile> files = findFilesByMd5(md5);
82  if (!files.isEmpty()) {
83  map.put(md5, files);
84  }
85  size++;
86  if (!worker.isCancelled()) {
87  progress.progress(size);
88  }
89  }
90  }
91  return map;
92  }
93 
102  static List<AbstractFile> findFiles(FsContent file) {
103  String md5;
104  if ((md5 = file.getMd5Hash()) != null) {
105  return findFilesByMd5(md5);
106  } else {
107  return Collections.<AbstractFile>emptyList();
108  }
109  }
110 
117  static boolean allFilesMd5Hashed() {
118  final Case currentCase = Case.getCurrentCase();
119  final SleuthkitCase skCase = currentCase.getSleuthkitCase();
120  return skCase.allFilesMd5Hashed();
121  }
122 
128  static int countFilesMd5Hashed() {
129  final Case currentCase = Case.getCurrentCase();
130  final SleuthkitCase skCase = currentCase.getSleuthkitCase();
131  return skCase.countFilesMd5Hashed();
132  }
133 }

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