19 package org.sleuthkit.autopsy.modules.hashdatabase;
21 import java.awt.Color;
22 import java.awt.Dimension;
23 import java.awt.Toolkit;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
28 import javax.swing.JLabel;
29 import javax.swing.JOptionPane;
30 import javax.swing.JScrollPane;
31 import javax.swing.JTextArea;
32 import javax.swing.SwingWorker;
33 import org.openide.util.NbBundle;
47 private final List<HashEntry>
hashes;
65 this.hashes =
new ArrayList<>();
66 this.invalidHashes =
new ArrayList<>();
67 this.md5Pattern = Pattern.compile(
"^[a-fA-F0-9]{32}$");
68 this.parentRef = parent;
74 Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
75 setLocation((screenDimension.width - getSize().width) / 2, (screenDimension.height - getSize().height) / 2);
83 final void addHashValuesToDatabase() {
84 parentRef.enableAddHashValuesToDatabaseDialog(
false);
85 new SwingWorker<Object, Void>() {
88 protected Object doInBackground() throws Exception {
95 if (!invalidHashes.isEmpty()) {
100 for (String invalidHash : invalidHashes) {
101 errorMessage = errorMessage + invalidHash +
"\n";
105 }
else if (hashes.isEmpty()) {
106 statusLabel.setText(NbBundle.getMessage(AddHashValuesToDatabaseProgressDialog.class,
"AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.noHashesToAdd"));
112 statusLabel.setText(NbBundle.getMessage(AddHashValuesToDatabaseProgressDialog.class,
"AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.success", hashes.size()));
114 disposeParent =
true;
115 }
catch (TskCoreException ex) {
116 statusLabel.setText(NbBundle.getMessage(AddHashValuesToDatabaseProgressDialog.class,
"AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.errorAddingValidHash"));
118 errorTitle = NbBundle.getMessage(AddHashValuesToDatabaseProgressDialog.class,
"AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.errorAddingValidHash.msg");
119 errorMessage = ex.toString();
161 String[] linesInTextArea = text.split(
"\\r?\\n");
163 for (String hashEntry : linesInTextArea) {
164 hashEntry = hashEntry.trim();
165 Matcher m = md5Pattern.matcher(hashEntry);
168 hashes.add(
new HashEntry(null, m.group(0), null, null, null));
170 if (!hashEntry.isEmpty()) {
171 invalidHashes.add(hashEntry);
182 @SuppressWarnings(
"unchecked")
187 okButton =
new javax.swing.JButton();
191 setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
198 okButton.addActionListener(
new java.awt.event.ActionListener() {
199 public void actionPerformed(java.awt.event.ActionEvent evt) {
209 public void actionPerformed(java.awt.event.ActionEvent evt) {
214 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
215 getContentPane().setLayout(layout);
216 layout.setHorizontalGroup(
217 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
218 .addGroup(layout.createSequentialGroup()
220 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
221 .addGroup(layout.createSequentialGroup()
223 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
225 .addGroup(layout.createSequentialGroup()
228 .addComponent(
okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
229 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
231 layout.setVerticalGroup(
232 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
233 .addGroup(layout.createSequentialGroup()
235 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
236 .addComponent(
addingHashesToDatabaseProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
238 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
239 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
242 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
249 parentRef.enableAddHashValuesToDatabaseDialog(
true);
257 JLabel textLabel =
new JLabel(errorTitle);
258 JTextArea textArea =
new JTextArea(errorMessage);
259 textArea.setEditable(
false);
260 JScrollPane scrollPane =
new JScrollPane(textArea);
261 scrollPane.setPreferredSize(
new Dimension(250, 100));
262 Object[] jOptionPaneComponents = {textLabel, scrollPane};
263 JOptionPane.showMessageDialog(
this, jOptionPaneComponents,
"Error:\n", JOptionPane.OK_OPTION);
javax.swing.JProgressBar addingHashesToDatabaseProgressBar
void okButtonActionPerformed(java.awt.event.ActionEvent evt)
final List< String > invalidHashes
javax.swing.JButton showErrorsButton
javax.swing.JLabel statusLabel
void showErrorsButtonActionPerformed(java.awt.event.ActionEvent evt)
void getHashesFromTextArea(String text)
void addHashes(Content content)
javax.swing.JButton okButton
void finish(boolean success)
final AddHashValuesToDatabaseDialog parentRef
final List< HashEntry > hashes