19 package org.sleuthkit.autopsy.filesearch;
21 import java.awt.event.ActionListener;
22 import org.openide.util.NbBundle;
23 import org.openide.util.NbBundle.Messages;
29 class HashSearchFilter
extends AbstractFileSearchFilter<HashSearchPanel> {
31 private static final String EMPTY_HASH_MESSAGE = NbBundle
32 .getMessage(HashSearchFilter.class,
"HashSearchPanel.emptyHashMsg.text");
34 public HashSearchFilter() {
35 this(
new HashSearchPanel());
38 public HashSearchFilter(HashSearchPanel component) {
43 public boolean isEnabled() {
44 return (this.getComponent().getMd5HashCheckBox().isSelected()
45 || this.getComponent().getSha256HashCheckBox().isSelected());
49 public String getPredicate() throws FilterValidationException {
50 String predicate =
"";
51 if (this.getComponent().getMd5HashCheckBox().isSelected()) {
52 String md5Hash = this.getComponent().getMd5TextField().getText();
54 if (md5Hash.isEmpty()) {
55 throw new FilterValidationException(EMPTY_HASH_MESSAGE);
57 predicate =
"md5 = '" + md5Hash.toLowerCase() +
"'";
60 if (this.getComponent().getSha256HashCheckBox().isSelected()) {
61 String sha256Hash = this.getComponent().getSha256TextField().getText();
63 if (sha256Hash.isEmpty()) {
64 throw new FilterValidationException(EMPTY_HASH_MESSAGE);
66 if (predicate.isEmpty()) {
67 predicate =
"sha256 = '" + sha256Hash.toLowerCase() +
"'";
69 predicate =
"( " + predicate +
" AND sha256 = '" + sha256Hash.toLowerCase() +
"')";
77 public void addActionListener(ActionListener l) {
78 getComponent().addActionListener(l);
83 "HashSearchFilter.errorMessage.emptyHash=Hash data is empty.",
84 "# {0} - hash data length",
85 "HashSearchFilter.errorMessage.wrongLengthMd5=Input length({0}), doesn''t match the MD5 length(32).",
86 "# {0} - hash data length",
87 "HashSearchFilter.errorMessage.wrongLengthSha256=Input length({0}), doesn''t match the SHA-256 length(64).",
88 "HashSearchFilter.errorMessage.wrongCharacter=MD5 contains invalid hex characters."
90 public boolean isValid() {
91 if (this.getComponent().getMd5HashCheckBox().isSelected()) {
92 String inputHashData = this.getComponent().getMd5TextField().getText();
93 if (inputHashData.isEmpty()) {
94 setLastError(Bundle.HashSearchFilter_errorMessage_emptyHash());
97 if (inputHashData.length() != 32) {
98 setLastError(Bundle.HashSearchFilter_errorMessage_wrongLengthMd5(inputHashData.length()));
101 if (!inputHashData.matches(
"[0-9a-fA-F]+")) {
102 setLastError(Bundle.HashSearchFilter_errorMessage_wrongCharacter());
107 if (this.getComponent().getSha256HashCheckBox().isSelected()) {
108 String inputHashData = this.getComponent().getSha256TextField().getText();
109 if (inputHashData.isEmpty()) {
110 setLastError(Bundle.HashSearchFilter_errorMessage_emptyHash());
113 if (inputHashData.length() != 64) {
114 setLastError(Bundle.HashSearchFilter_errorMessage_wrongLengthSha256(inputHashData.length()));
117 if (!inputHashData.matches(
"[0-9a-fA-F]+")) {
118 setLastError(Bundle.HashSearchFilter_errorMessage_wrongCharacter());