Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
HashSearchFilter.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017 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.filesearch;
20 
21 import java.awt.event.ActionListener;
22 import org.openide.util.NbBundle;
23 import org.openide.util.NbBundle.Messages;
25 
29 class HashSearchFilter extends AbstractFileSearchFilter<HashSearchPanel> {
30 
31  private static final String EMPTY_HASH_MESSAGE = NbBundle
32  .getMessage(HashSearchFilter.class, "HashSearchPanel.emptyHashMsg.text");
33 
34  public HashSearchFilter() {
35  this(new HashSearchPanel());
36  }
37 
38  public HashSearchFilter(HashSearchPanel component) {
39  super(component);
40  }
41 
42  @Override
43  public boolean isEnabled() {
44  return this.getComponent().getHashCheckBox().isSelected();
45  }
46 
47  @Override
48  public String getPredicate() throws FilterValidationException {
49  String md5Hash = this.getComponent().getSearchTextField().getText();
50 
51  if (md5Hash.isEmpty()) {
52  throw new FilterValidationException(EMPTY_HASH_MESSAGE);
53  }
54 
55  return "md5 = '" + md5Hash.toLowerCase() + "'"; //NON-NLS
56  }
57 
58  @Override
59  public void addActionListener(ActionListener l) {
60  getComponent().addActionListener(l);
61  }
62 
63  @Override
64  @Messages({
65  "HashSearchFilter.errorMessage.emptyHash=Hash data is empty.",
66  "# {0} - hash data length", "HashSearchFilter.errorMessage.wrongLength=Input length({0}), doesn''t match the MD5 length(32).",
67  "HashSearchFilter.errorMessage.wrongCharacter=MD5 contains invalid hex characters."
68  })
69  public boolean isValid() {
70  String inputHashData = this.getComponent().getSearchTextField().getText();
71  if (inputHashData.isEmpty()) {
72  setLastError(Bundle.HashSearchFilter_errorMessage_emptyHash());
73  return false;
74  }
75  if (inputHashData.length() != 32) {
76  setLastError(Bundle.HashSearchFilter_errorMessage_wrongLength(inputHashData.length()));
77  return false;
78  }
79  if (!inputHashData.matches("[0-9a-fA-F]+")) {
80  setLastError(Bundle.HashSearchFilter_errorMessage_wrongCharacter());
81  return false;
82  }
83  return true;
84  }
85 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.