Autopsy  4.19.0
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-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.hashdatabase;
20 
21 import java.util.Collections;
22 import java.util.LinkedHashMap;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.logging.Level;
26 import javax.swing.SwingWorker;
27 import org.netbeans.api.progress.ProgressHandle;
31 import org.sleuthkit.datamodel.AbstractFile;
32 import org.sleuthkit.datamodel.FsContent;
33 import org.sleuthkit.datamodel.SleuthkitCase;
34 
39 class HashDbSearcher {
40  private static final Logger logger = Logger.getLogger(HashDbSearcher.class.getName());
48  static List<AbstractFile> findFilesByMd5(String md5Hash) throws NoCurrentCaseException {
49  final Case currentCase = Case.getCurrentCaseThrows();
50  final SleuthkitCase skCase = currentCase.getSleuthkitCase();
51  return skCase.findFilesByMd5(md5Hash);
52  }
53 
62  static Map<String, List<AbstractFile>> findFilesBymd5(List<String> md5Hash) throws NoCurrentCaseException {
63  Map<String, List<AbstractFile>> map = new LinkedHashMap<String, List<AbstractFile>>();
64  for (String md5 : md5Hash) {
65  List<AbstractFile> files = findFilesByMd5(md5);
66  if (!files.isEmpty()) {
67  map.put(md5, files);
68  }
69  }
70  return map;
71  }
72 
73  // Same as above, but with a given ProgressHandle to accumulate and StringWorker to check if cancelled
74 
75  static Map<String, List<AbstractFile>> findFilesBymd5(List<String> md5Hash, ProgressHandle progress, SwingWorker<Object, Void> worker) throws NoCurrentCaseException {
76  Map<String, List<AbstractFile>> map = new LinkedHashMap<String, List<AbstractFile>>();
77  if (!worker.isCancelled()) {
78  progress.switchToDeterminate(md5Hash.size());
79  int size = 0;
80  for (String md5 : md5Hash) {
81  if (worker.isCancelled()) {
82  break;
83  }
84  List<AbstractFile> files = findFilesByMd5(md5);
85  if (!files.isEmpty()) {
86  map.put(md5, files);
87  }
88  size++;
89  if (!worker.isCancelled()) {
90  progress.progress(size);
91  }
92  }
93  }
94  return map;
95  }
96 
105  static List<AbstractFile> findFiles(FsContent file) {
106  String md5;
107  try {
108  if ((md5 = file.getMd5Hash()) != null) {
109  return findFilesByMd5(md5);
110  } else {
111  return Collections.<AbstractFile>emptyList();
112  }
113  } catch (NoCurrentCaseException ex) {
114  logger.log(Level.SEVERE, "Exception while getting open case.", ex);
115  return Collections.<AbstractFile>emptyList();
116  }
117  }
118 
125  static boolean allFilesMd5Hashed() throws NoCurrentCaseException {
126  final Case currentCase = Case.getCurrentCaseThrows();
127  final SleuthkitCase skCase = currentCase.getSleuthkitCase();
128  return skCase.allFilesMd5Hashed();
129  }
130 
136  static int countFilesMd5Hashed() throws NoCurrentCaseException {
137  final Case currentCase = Case.getCurrentCaseThrows();
138  final SleuthkitCase skCase = currentCase.getSleuthkitCase();
139  return skCase.countFilesMd5Hashed();
140  }
141 }

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.