19 package org.sleuthkit.autopsy.modules.hashdatabase;
21 import java.awt.Color;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.awt.event.KeyAdapter;
25 import java.awt.event.KeyEvent;
26 import java.util.ArrayList;
28 import org.openide.util.NbBundle;
30 import javax.swing.JOptionPane;
31 import javax.swing.table.DefaultTableModel;
32 import javax.swing.text.AttributeSet;
33 import javax.swing.text.BadLocationException;
34 import javax.swing.text.PlainDocument;
40 class HashDbSearchPanel
extends javax.swing.JPanel implements ActionListener {
41 private static final Logger logger = Logger.getLogger(HashDbSearchPanel.class.getName());
42 private static HashDbSearchPanel instance;
47 public static HashDbSearchPanel getDefault() {
48 if (instance == null) {
49 instance =
new HashDbSearchPanel();
57 public void refresh() {
58 boolean running = IngestManager.getInstance().isIngestRunning();
60 titleLabel.setForeground(Color.red);
61 titleLabel.setText(NbBundle.getMessage(
this.getClass(),
"HashDbSearchPanel.titleText.ingestOngoing"));
63 titleLabel.setForeground(Color.black);
64 titleLabel.setText(NbBundle.getMessage(
this.getClass(),
"HashDbSearchPanel.titleLabel.text"));
66 hashField.setEditable(!running);
67 searchButton.setEnabled(!running);
68 addButton.setEnabled(!running);
69 removeButton.setEnabled(!running);
70 hashTable.setEnabled(!running);
71 hashLabel.setEnabled(!running);
72 saveBox.setEnabled(!running);
78 private HashDbSearchPanel() {
79 setName(HashDbPanelSearchAction.ACTION_NAME);
84 final void customInit() {
85 addButton.addActionListener(
this);
86 removeButton.addActionListener(
this);
87 errorField.setVisible(
false);
88 hashField.requestFocus();
90 hashField.setDocument(
new PlainDocument () {
92 public void insertString(
int offset, String str, AttributeSet a)
throws BadLocationException {
93 if((this.getLength() + str.length()) <= 32) {
94 super.insertString(offset, str, a);
99 hashField.addKeyListener(
new KeyAdapter() {
101 public void keyPressed(KeyEvent e) {
102 if(e.getKeyChar() == KeyEvent.VK_ENTER) {
108 hashTable.addKeyListener(
new KeyAdapter() {
110 public void keyPressed(KeyEvent e) {
111 if(e.getKeyChar() == KeyEvent.VK_DELETE) {
112 removeButton.doClick();
118 void addSearchActionListener(ActionListener l) {
119 for(ActionListener al : searchButton.getActionListeners()) {
120 searchButton.removeActionListener(al);
122 searchButton.addActionListener(l);
125 void addCancelActionListener(ActionListener l) {
126 cancelButton.addActionListener(l);
134 @SuppressWarnings(
"rawtypes")
136 private
void initComponents() {
138 jScrollPane1 =
new javax.swing.JScrollPane();
139 hashTable =
new javax.swing.JTable();
140 hashField =
new javax.swing.JTextField();
141 addButton =
new javax.swing.JButton();
142 hashLabel =
new javax.swing.JLabel();
143 searchButton =
new javax.swing.JButton();
144 removeButton =
new javax.swing.JButton();
145 jSeparator1 =
new javax.swing.JSeparator();
146 titleLabel =
new javax.swing.JLabel();
147 errorField =
new javax.swing.JLabel();
148 saveBox =
new javax.swing.JCheckBox();
149 cancelButton =
new javax.swing.JButton();
151 hashTable.setModel(
new javax.swing.table.DefaultTableModel(
156 NbBundle.getMessage(this.getClass(),
"HashDbSearchPanel.hashTable.defaultModel.title.text")
159 Class[] types =
new Class [] {
160 java.lang.String.class
162 boolean[] canEdit =
new boolean [] {
166 public Class getColumnClass(
int columnIndex) {
167 return types [columnIndex];
170 public boolean isCellEditable(
int rowIndex,
int columnIndex) {
171 return canEdit [columnIndex];
174 jScrollPane1.setViewportView(hashTable);
175 hashTable.getColumnModel().getColumn(0).setHeaderValue(
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.hashTable.columnModel.title0"));
177 hashField.setText(
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.hashField.text"));
179 org.openide.awt.Mnemonics.setLocalizedText(addButton,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.addButton.text"));
181 org.openide.awt.Mnemonics.setLocalizedText(hashLabel,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.hashLabel.text"));
183 org.openide.awt.Mnemonics.setLocalizedText(searchButton,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.searchButton.text"));
185 org.openide.awt.Mnemonics.setLocalizedText(removeButton,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.removeButton.text"));
187 org.openide.awt.Mnemonics.setLocalizedText(titleLabel,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.titleLabel.text"));
189 errorField.setForeground(
new java.awt.Color(255, 0, 0));
190 org.openide.awt.Mnemonics.setLocalizedText(errorField,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.errorField.text"));
192 org.openide.awt.Mnemonics.setLocalizedText(saveBox,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.saveBox.text"));
193 saveBox.addActionListener(
new java.awt.event.ActionListener() {
194 public void actionPerformed(java.awt.event.ActionEvent evt) {
195 saveBoxActionPerformed(evt);
199 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.cancelButton.text"));
201 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
202 this.setLayout(layout);
203 layout.setHorizontalGroup(
204 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
205 .addGroup(layout.createSequentialGroup()
207 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
208 .addComponent(jScrollPane1)
209 .addGroup(layout.createSequentialGroup()
210 .addComponent(hashLabel)
211 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
212 .addComponent(hashField))
213 .addComponent(jSeparator1)
214 .addGroup(layout.createSequentialGroup()
215 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
216 .addComponent(titleLabel)
217 .addGroup(layout.createSequentialGroup()
219 .addComponent(addButton)
220 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
221 .addComponent(removeButton)
222 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
223 .addComponent(saveBox)))
224 .addGap(0, 0, Short.MAX_VALUE))
225 .addGroup(layout.createSequentialGroup()
226 .addComponent(errorField)
227 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
228 .addComponent(searchButton)
229 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
230 .addComponent(cancelButton)))
233 layout.setVerticalGroup(
234 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
235 .addGroup(layout.createSequentialGroup()
237 .addComponent(titleLabel)
238 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
239 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
241 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
242 .addComponent(hashLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
243 .addComponent(hashField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
244 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
245 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
246 .addComponent(addButton)
247 .addComponent(removeButton)
248 .addComponent(saveBox))
250 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
251 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
252 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
253 .addComponent(searchButton)
254 .addComponent(errorField)
255 .addComponent(cancelButton))
256 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
260 private void saveBoxActionPerformed(java.awt.event.ActionEvent evt) {
265 private javax.swing.JButton addButton;
266 private javax.swing.JButton cancelButton;
267 private javax.swing.JLabel errorField;
268 private javax.swing.JTextField hashField;
269 private javax.swing.JLabel hashLabel;
270 private javax.swing.JTable hashTable;
271 private javax.swing.JScrollPane jScrollPane1;
272 private javax.swing.JSeparator jSeparator1;
273 private javax.swing.JButton removeButton;
274 private javax.swing.JCheckBox saveBox;
275 private javax.swing.JButton searchButton;
276 private javax.swing.JLabel titleLabel;
280 public void actionPerformed(ActionEvent e) {
281 if(e.getSource().equals(addButton)) {
283 }
else if(e.getSource().equals(removeButton)) {
294 if(hashTable.getRowCount()!=0) {
296 if(HashDbSearcher.countFilesMd5Hashed() > 0) {
299 JOptionPane.showMessageDialog(null,
300 NbBundle.getMessage(
this.getClass(),
301 "HashDbSearchPanel.noFilesHaveMD5HashMsg"),
302 NbBundle.getMessage(
this.getClass(),
"HashDbSearchPanel.dlgMsg.title"),
303 JOptionPane.ERROR_MESSAGE);
307 errorField.setText(NbBundle.getMessage(
this.getClass(),
"HashDbSearchPanel.errorText.noHashesAddedMsg"));
308 errorField.setVisible(
true);
313 private boolean doSearch() {
314 errorField.setVisible(
false);
316 int numRows = hashTable.getRowCount();
317 ArrayList<String> hashes =
new ArrayList<String>();
318 for(
int i=0; i<numRows; i++) {
319 hashes.add((String) hashTable.getValueAt(i, 0));
322 HashDbSearchThread hashThread =
new HashDbSearchThread(hashes);
323 hashThread.execute();
331 errorField.setVisible(
false);
332 DefaultTableModel model = (DefaultTableModel) hashTable.getModel();
333 String hash = hashField.getText();
334 if(!hash.equals(
"")) {
335 if(hash.matches(
"[a-fA-F0-9]{32}")) {
336 for(
int i=0; i<model.getRowCount(); i++) {
337 if(model.getValueAt(i, 0).equals(hashField.getText())) {
338 hashField.setText(
"");
340 NbBundle.getMessage(
this.getClass(),
"HashDbSearchPanel.errorText.hashAlreadyAddedMsg"));
341 errorField.setVisible(
true);
342 errorField.setVisible(
true);
346 model.addRow(
new String[] {hash});
347 hashField.setText(
"");
349 errorField.setText(NbBundle.getMessage(
this.getClass(),
"HashDbSearchPanel.errorText.invalidMD5HashMsg"));
350 errorField.setVisible(
true);
353 hashField.requestFocus();
360 DefaultTableModel model = (DefaultTableModel) hashTable.getModel();
361 int rows[] = hashTable.getSelectedRows();
364 for(
int i=rows.length-1; i>=0; i--) {
365 model.removeRow(rows[i]);
373 if(!saveBox.isSelected()) {
374 DefaultTableModel model = (DefaultTableModel) hashTable.getModel();
375 int numRows = hashTable.getRowCount();
376 for(
int i=numRows-1; i>=0; i--) {
380 errorField.setVisible(
false);
381 hashField.setText(
"");