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;
41 class HashDbSearchPanel
extends javax.swing.JPanel implements ActionListener {
43 private static final Logger logger = Logger.getLogger(HashDbSearchPanel.class.getName());
44 private static HashDbSearchPanel instance;
49 public static HashDbSearchPanel getDefault() {
50 if (instance == null) {
51 instance =
new HashDbSearchPanel();
59 public void refresh() {
60 boolean running = IngestManager.getInstance().isIngestRunning();
62 titleLabel.setForeground(Color.red);
63 titleLabel.setText(NbBundle.getMessage(
this.getClass(),
"HashDbSearchPanel.titleText.ingestOngoing"));
65 titleLabel.setForeground(Color.black);
66 titleLabel.setText(NbBundle.getMessage(
this.getClass(),
"HashDbSearchPanel.titleLabel.text"));
68 hashField.setEditable(!running);
69 searchButton.setEnabled(!running);
70 addButton.setEnabled(!running);
71 removeButton.setEnabled(!running);
72 hashTable.setEnabled(!running);
73 hashLabel.setEnabled(!running);
74 saveBox.setEnabled(!running);
80 private HashDbSearchPanel() {
81 setName(HashDbPanelSearchAction.ACTION_NAME);
86 final void customInit() {
87 addButton.addActionListener(
this);
88 removeButton.addActionListener(
this);
89 errorField.setVisible(
false);
90 hashField.requestFocus();
92 hashField.setDocument(
new PlainDocument() {
94 public void insertString(
int offset, String str, AttributeSet a)
throws BadLocationException {
95 if ((this.getLength() + str.length()) <= 32) {
96 super.insertString(offset, str, a);
101 hashField.addKeyListener(
new KeyAdapter() {
103 public void keyPressed(KeyEvent e) {
104 if (e.getKeyChar() == KeyEvent.VK_ENTER) {
110 hashTable.addKeyListener(
new KeyAdapter() {
112 public void keyPressed(KeyEvent e) {
113 if (e.getKeyChar() == KeyEvent.VK_DELETE) {
114 removeButton.doClick();
120 void addSearchActionListener(ActionListener l) {
121 for (ActionListener al : searchButton.getActionListeners()) {
122 searchButton.removeActionListener(al);
124 searchButton.addActionListener(l);
127 void addCancelActionListener(ActionListener l) {
128 cancelButton.addActionListener(l);
136 @SuppressWarnings(
"rawtypes")
138 private
void initComponents() {
140 jScrollPane1 =
new javax.swing.JScrollPane();
141 hashTable =
new javax.swing.JTable();
142 hashField =
new javax.swing.JTextField();
143 addButton =
new javax.swing.JButton();
144 hashLabel =
new javax.swing.JLabel();
145 searchButton =
new javax.swing.JButton();
146 removeButton =
new javax.swing.JButton();
147 jSeparator1 =
new javax.swing.JSeparator();
148 titleLabel =
new javax.swing.JLabel();
149 errorField =
new javax.swing.JLabel();
150 saveBox =
new javax.swing.JCheckBox();
151 cancelButton =
new javax.swing.JButton();
153 hashTable.setModel(
new javax.swing.table.DefaultTableModel(
161 Class[] types =
new Class [] {
162 java.lang.String.class
164 boolean[] canEdit =
new boolean [] {
168 public Class getColumnClass(
int columnIndex) {
169 return types [columnIndex];
172 public boolean isCellEditable(
int rowIndex,
int columnIndex) {
173 return canEdit [columnIndex];
176 jScrollPane1.setViewportView(hashTable);
177 if (hashTable.getColumnModel().getColumnCount() > 0) {
178 hashTable.getColumnModel().getColumn(0).setHeaderValue(
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.hashTable.columnModel.title0"));
181 hashField.setText(
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.hashField.text"));
183 org.openide.awt.Mnemonics.setLocalizedText(addButton,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.addButton.text"));
185 org.openide.awt.Mnemonics.setLocalizedText(hashLabel,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.hashLabel.text"));
187 org.openide.awt.Mnemonics.setLocalizedText(searchButton,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.searchButton.text"));
189 org.openide.awt.Mnemonics.setLocalizedText(removeButton,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.removeButton.text"));
191 org.openide.awt.Mnemonics.setLocalizedText(titleLabel,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.titleLabel.text"));
193 errorField.setForeground(
new java.awt.Color(255, 0, 0));
194 org.openide.awt.Mnemonics.setLocalizedText(errorField,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.errorField.text"));
196 org.openide.awt.Mnemonics.setLocalizedText(saveBox,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.saveBox.text"));
197 saveBox.addActionListener(
new java.awt.event.ActionListener() {
198 public void actionPerformed(java.awt.event.ActionEvent evt) {
199 saveBoxActionPerformed(evt);
203 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(HashDbSearchPanel.class,
"HashDbSearchPanel.cancelButton.text"));
205 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
206 this.setLayout(layout);
207 layout.setHorizontalGroup(
208 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
209 .addGroup(layout.createSequentialGroup()
211 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
212 .addComponent(jScrollPane1)
213 .addGroup(layout.createSequentialGroup()
214 .addComponent(hashLabel)
215 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
216 .addComponent(hashField))
217 .addComponent(jSeparator1)
218 .addGroup(layout.createSequentialGroup()
219 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220 .addComponent(titleLabel)
221 .addGroup(layout.createSequentialGroup()
223 .addComponent(addButton)
224 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
225 .addComponent(removeButton)
226 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
227 .addComponent(saveBox)))
228 .addGap(0, 0, Short.MAX_VALUE))
229 .addGroup(layout.createSequentialGroup()
230 .addComponent(errorField)
231 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
232 .addComponent(searchButton)
233 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
234 .addComponent(cancelButton)))
237 layout.setVerticalGroup(
238 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
239 .addGroup(layout.createSequentialGroup()
241 .addComponent(titleLabel)
242 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
243 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
245 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
246 .addComponent(hashLabel)
247 .addComponent(hashField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
248 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
249 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
250 .addComponent(addButton)
251 .addComponent(removeButton)
252 .addComponent(saveBox))
254 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
255 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
256 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
257 .addComponent(searchButton)
258 .addComponent(errorField)
259 .addComponent(cancelButton))
260 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
264 private void saveBoxActionPerformed(java.awt.event.ActionEvent evt) {
269 private javax.swing.JButton addButton;
270 private javax.swing.JButton cancelButton;
271 private javax.swing.JLabel errorField;
272 private javax.swing.JTextField hashField;
273 private javax.swing.JLabel hashLabel;
274 private javax.swing.JTable hashTable;
275 private javax.swing.JScrollPane jScrollPane1;
276 private javax.swing.JSeparator jSeparator1;
277 private javax.swing.JButton removeButton;
278 private javax.swing.JCheckBox saveBox;
279 private javax.swing.JButton searchButton;
280 private javax.swing.JLabel titleLabel;
284 public void actionPerformed(ActionEvent e) {
285 if (e.getSource().equals(addButton)) {
287 }
else if (e.getSource().equals(removeButton)) {
296 @NbBundle.Messages ({
297 "HashDbSearchPanel.noOpenCase.errMsg=No open case available."
301 if (hashTable.getRowCount() != 0) {
304 if (HashDbSearcher.countFilesMd5Hashed() > 0) {
307 JOptionPane.showMessageDialog(
this,
308 NbBundle.getMessage(
this.getClass(),
309 "HashDbSearchPanel.noFilesHaveMD5HashMsg"),
310 NbBundle.getMessage(
this.getClass(),
"HashDbSearchPanel.dlgMsg.title"),
311 JOptionPane.ERROR_MESSAGE);
314 }
catch (NoCurrentCaseException ex) {
315 JOptionPane.showMessageDialog(
this,
316 Bundle.HashDbSearchPanel_noOpenCase_errMsg(),
317 NbBundle.getMessage(this.getClass(),
"HashDbSearchPanel.dlgMsg.title"),
318 JOptionPane.ERROR_MESSAGE);
322 errorField.setText(NbBundle.getMessage(
this.getClass(),
"HashDbSearchPanel.errorText.noHashesAddedMsg"));
323 errorField.setVisible(
true);
328 private boolean doSearch() {
329 errorField.setVisible(
false);
331 int numRows = hashTable.getRowCount();
332 ArrayList<String> hashes =
new ArrayList<String>();
333 for (
int i = 0; i < numRows; i++) {
334 hashes.add((String) hashTable.getValueAt(i, 0));
337 HashDbSearchThread hashThread =
new HashDbSearchThread(hashes);
338 hashThread.execute();
346 errorField.setVisible(
false);
347 DefaultTableModel model = (DefaultTableModel) hashTable.getModel();
348 String hash = hashField.getText();
349 if (!hash.equals(
"")) {
350 if (hash.matches(
"[a-fA-F0-9]{32}")) {
351 for (
int i = 0; i < model.getRowCount(); i++) {
352 if (model.getValueAt(i, 0).equals(hashField.getText())) {
353 hashField.setText(
"");
355 NbBundle.getMessage(
this.getClass(),
"HashDbSearchPanel.errorText.hashAlreadyAddedMsg"));
356 errorField.setVisible(
true);
357 errorField.setVisible(
true);
361 model.addRow(
new String[]{hash});
362 hashField.setText(
"");
364 errorField.setText(NbBundle.getMessage(
this.getClass(),
"HashDbSearchPanel.errorText.invalidMD5HashMsg"));
365 errorField.setVisible(
true);
368 hashField.requestFocus();
375 DefaultTableModel model = (DefaultTableModel) hashTable.getModel();
376 int rows[] = hashTable.getSelectedRows();
379 for (
int i = rows.length - 1; i >= 0; i--) {
380 model.removeRow(rows[i]);
388 if (!saveBox.isSelected()) {
389 DefaultTableModel model = (DefaultTableModel) hashTable.getModel();
390 int numRows = hashTable.getRowCount();
391 for (
int i = numRows - 1; i >= 0; i--) {
395 errorField.setVisible(
false);
396 hashField.setText(
"");