mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-14 17:06:16 +00:00
requires comma for comment
This commit is contained in:
parent
89298eac2a
commit
928bbd40ed
@ -30,6 +30,7 @@ import javax.swing.JOptionPane;
|
|||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb;
|
import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb;
|
||||||
import org.sleuthkit.datamodel.HashEntry;
|
import org.sleuthkit.datamodel.HashEntry;
|
||||||
@ -46,7 +47,14 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog {
|
|||||||
private final HashDb hashDb;
|
private final HashDb hashDb;
|
||||||
private final List<HashEntry> hashes;
|
private final List<HashEntry> hashes;
|
||||||
private final List<String> invalidHashes;
|
private final List<String> invalidHashes;
|
||||||
private final Pattern md5Pattern;
|
|
||||||
|
// Matches hash with optional comma separated comment.
|
||||||
|
private static final Pattern HASH_LINE_PATTERN = Pattern.compile("^([a-fA-F0-9]{32})(,(.*))?$");
|
||||||
|
// The regex group for the hash.
|
||||||
|
private static final int HASH_GROUP = 1;
|
||||||
|
// The regex group for the comment.
|
||||||
|
private static final int COMMENT_GROUP = 3;
|
||||||
|
|
||||||
private String errorTitle;
|
private String errorTitle;
|
||||||
private String errorMessage;
|
private String errorMessage;
|
||||||
private final String text;
|
private final String text;
|
||||||
@ -64,7 +72,6 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog {
|
|||||||
display(parent);
|
display(parent);
|
||||||
this.hashes = new ArrayList<>();
|
this.hashes = new ArrayList<>();
|
||||||
this.invalidHashes = new ArrayList<>();
|
this.invalidHashes = new ArrayList<>();
|
||||||
this.md5Pattern = Pattern.compile("^([a-fA-F0-9]{32})"); // NON-NLS
|
|
||||||
this.parentRef = parent;
|
this.parentRef = parent;
|
||||||
this.hashDb = hashDb;
|
this.hashDb = hashDb;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
@ -161,17 +168,15 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog {
|
|||||||
// These entries may be of <MD5> or <MD5, comment> format
|
// These entries may be of <MD5> or <MD5, comment> format
|
||||||
for (String hashEntry : linesInTextArea) {
|
for (String hashEntry : linesInTextArea) {
|
||||||
hashEntry = hashEntry.trim();
|
hashEntry = hashEntry.trim();
|
||||||
Matcher m = md5Pattern.matcher(hashEntry);
|
Matcher m = HASH_LINE_PATTERN.matcher(hashEntry);
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
// Is there any text left on this line? If so, treat it as a comment.
|
String hash = m.group(HASH_GROUP);
|
||||||
String comment = hashEntry.substring(m.end()).trim();
|
|
||||||
if (comment.length() > 0) {
|
// if there was a match and the match is not empty, assign to comment
|
||||||
comment = (comment.charAt(0) == ',') ? comment.substring(1) : comment;
|
String comment = StringUtils.isNotBlank(m.group(COMMENT_GROUP)) ?
|
||||||
hashes.add(new HashEntry(null, m.group(0), null, null, comment));
|
m.group(COMMENT_GROUP).trim() : null;
|
||||||
} else {
|
|
||||||
// more information can be added to the HashEntry - sha-1, sha-512, comment
|
hashes.add(new HashEntry(null, hash, null, null, comment));
|
||||||
hashes.add(new HashEntry(null, m.group(0), null, null, null));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!hashEntry.isEmpty()) {
|
if (!hashEntry.isEmpty()) {
|
||||||
invalidHashes.add(hashEntry);
|
invalidHashes.add(hashEntry);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user