Autopsy  4.21.0
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-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 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;
26 import org.openide.windows.WindowManager;
30 import org.sleuthkit.datamodel.AbstractFile;
31 import org.sleuthkit.datamodel.Content;
32 import org.sleuthkit.datamodel.ContentVisitor;
33 import org.sleuthkit.datamodel.Directory;
34 import org.sleuthkit.datamodel.LayoutFile;
35 import org.sleuthkit.datamodel.SlackFile;
36 import org.sleuthkit.datamodel.VirtualDirectory;
37 
44 public class HashDbSearchAction extends CallableSystemAction implements HashSearchProvider {
45 
47  private AbstractFile file;
48  private static HashDbSearchAction instance = null;
49 
51  super();
52  }
53 
54  public static HashDbSearchAction getDefault() {
55  if (instance == null) {
56  instance = new HashDbSearchAction();
57  }
58  return instance;
59  }
60 
61  @Override
62  public void search(Node contentNode) {
63  Content tempContent = contentNode.getLookup().lookup(Content.class);
64  this.file = tempContent.accept(initializeCV);
65  performAction();
66  }
67 
72  private static class InitializeContentVisitor extends ContentVisitor.Default<AbstractFile> {
73 
74  @Override
75  public AbstractFile visit(org.sleuthkit.datamodel.File f) {
76  return f;
77  }
78 
79  @Override
80  public AbstractFile visit(org.sleuthkit.datamodel.LocalFile lf) {
81  return lf;
82  }
83 
84  @Override
85  public AbstractFile visit(org.sleuthkit.datamodel.DerivedFile df) {
86  return df;
87  }
88 
89  @Override
90  public AbstractFile visit(Directory dir) {
91  return ContentUtils.isDotDirectory(dir) ? null : dir;
92  }
93 
94  @Override
95  protected AbstractFile defaultVisit(Content cntnt) {
96  return null;
97  }
98 
99  @Override
100  public AbstractFile visit(LayoutFile lf) {
101  // layout files do not have times
102  return lf;
103  }
104 
105  @Override
106  public AbstractFile visit(SlackFile f) {
107  return f;
108  }
109 
110  @Override
111  public AbstractFile visit(VirtualDirectory dir) {
112  return ContentUtils.isDotDirectory(dir) ? null : dir;
113  }
114  }
115 
121  @Override
122  @NbBundle.Messages ({
123  "HashDbSearchAction.noOpenCase.errMsg=No open case available."
124  })
125  public void performAction() {
126  // Make sure at least 1 file has an md5 hash
127  try {
128  if (file != null && HashDbSearcher.countFilesMd5Hashed() > 0) {
129  doSearch();
130  } else {
131  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
132  NbBundle.getMessage(this.getClass(),
133  "HashDbSearchAction.dlgMsg.noFilesHaveMD5Calculated"),
134  NbBundle.getMessage(this.getClass(), "HashDbSearchAction.dlgMsg.title"),
135  JOptionPane.ERROR_MESSAGE);
136  }
137  } catch (NoCurrentCaseException ex) {
138  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
139  Bundle.HashDbSearchAction_noOpenCase_errMsg(),
140  NbBundle.getMessage(this.getClass(), "HashDbSearchAction.dlgMsg.title"),
141  JOptionPane.ERROR_MESSAGE);
142  }
143  }
144 
145  private void doSearch() {
146  HashDbSearchThread hashThread = new HashDbSearchThread(file);
147  hashThread.execute();
148  }
149 
150  @Override
151  public String getName() {
152  return NbBundle.getMessage(this.getClass(), "HashDbSearchAction.getName.text");
153  }
154 
155  @Override
156  public HelpCtx getHelpCtx() {
157  return HelpCtx.DEFAULT_HELP;
158  }
159 }
static boolean isDotDirectory(AbstractFile dir)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.