Autopsy  4.4
Graphical digital forensics platform for The Sleuth Kit and other tools.
HashDbSearchAction.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 javax.swing.JOptionPane;
22 import org.openide.nodes.Node;
23 import org.openide.util.HelpCtx;
24 import org.openide.util.NbBundle;
25 import org.openide.util.actions.CallableSystemAction;
28 import org.sleuthkit.datamodel.AbstractFile;
29 import org.sleuthkit.datamodel.Content;
30 import org.sleuthkit.datamodel.ContentVisitor;
31 import org.sleuthkit.datamodel.Directory;
32 import org.sleuthkit.datamodel.LayoutFile;
33 import org.sleuthkit.datamodel.SlackFile;
34 import org.sleuthkit.datamodel.VirtualDirectory;
35 
42 public class HashDbSearchAction extends CallableSystemAction implements HashSearchProvider {
43 
45  private AbstractFile file;
46  private static HashDbSearchAction instance = null;
47 
49  super();
50  }
51 
52  public static HashDbSearchAction getDefault() {
53  if (instance == null) {
54  instance = new HashDbSearchAction();
55  }
56  return instance;
57  }
58 
59  @Override
60  public void search(Node contentNode) {
61  Content tempContent = contentNode.getLookup().lookup(Content.class);
62  this.file = tempContent.accept(initializeCV);
63  performAction();
64  }
65 
70  private static class InitializeContentVisitor extends ContentVisitor.Default<AbstractFile> {
71 
72  @Override
73  public AbstractFile visit(org.sleuthkit.datamodel.File f) {
74  return f;
75  }
76 
77  @Override
78  public AbstractFile visit(org.sleuthkit.datamodel.LocalFile lf) {
79  return lf;
80  }
81 
82  @Override
83  public AbstractFile visit(org.sleuthkit.datamodel.DerivedFile df) {
84  return df;
85  }
86 
87  @Override
88  public AbstractFile visit(Directory dir) {
89  return ContentUtils.isDotDirectory(dir) ? null : dir;
90  }
91 
92  @Override
93  protected AbstractFile defaultVisit(Content cntnt) {
94  return null;
95  }
96 
97  @Override
98  public AbstractFile visit(LayoutFile lf) {
99  // layout files do not have times
100  return lf;
101  }
102 
103  @Override
104  public AbstractFile visit(SlackFile f) {
105  return f;
106  }
107 
108  @Override
109  public AbstractFile visit(VirtualDirectory dir) {
110  return ContentUtils.isDotDirectory(dir) ? null : dir;
111  }
112  }
113 
119  @Override
120  public void performAction() {
121  // Make sure at least 1 file has an md5 hash
122  if (file != null && HashDbSearcher.countFilesMd5Hashed() > 0) {
123  doSearch();
124  } else {
125  JOptionPane.showMessageDialog(null,
126  NbBundle.getMessage(this.getClass(),
127  "HashDbSearchAction.dlgMsg.noFilesHaveMD5Calculated"),
128  NbBundle.getMessage(this.getClass(), "HashDbSearchAction.dlgMsg.title"),
129  JOptionPane.ERROR_MESSAGE);
130  }
131  }
132 
133  private void doSearch() {
134  HashDbSearchThread hashThread = new HashDbSearchThread(file);
135  hashThread.execute();
136  }
137 
138  @Override
139  public String getName() {
140  return NbBundle.getMessage(this.getClass(), "HashDbSearchAction.getName.text");
141  }
142 
143  @Override
144  public HelpCtx getHelpCtx() {
145  return HelpCtx.DEFAULT_HELP;
146  }
147 }
static boolean isDotDirectory(AbstractFile dir)

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.