19 package org.sleuthkit.autopsy.modules.hashdatabase;
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.JScrollPane;
27 import javax.swing.JTable;
28 import javax.swing.table.AbstractTableModel;
29 import javax.swing.table.TableColumn;
40 @SuppressWarnings(
"PMD.SingularField")
43 private static final long serialVersionUID = 1L;
45 private final List<HashSetModel> knownHashSetModels =
new ArrayList<>();
47 private final List<HashSetModel> knownBadHashSetModels =
new ArrayList<>();
51 initializeHashSetModels(settings);
53 customizeComponents(settings);
57 initializeHashSetModels(settings, validSetsOnly(hashDbManager.
getKnownFileHashSets()), knownHashSetModels);
58 initializeHashSetModels(settings, validSetsOnly(hashDbManager.
getKnownBadFileHashSets()), knownBadHashSetModels);
61 private void initializeHashSetModels(HashLookupModuleSettings settings, List<HashDb> hashDbs, List<HashSetModel> hashSetModels) {
62 hashSetModels.clear();
63 for (
HashDb db : hashDbs) {
64 hashSetModels.add(
new HashSetModel(db, settings.isHashSetEnabled(db), isHashDbValid(db)));
69 customizeHashSetsTable(jScrollPane1, knownHashTable, knownHashSetsTableModel);
70 customizeHashSetsTable(jScrollPane2, knownBadHashTable, knownBadHashSetsTableModel);
71 alwaysCalcHashesCheckbox.setSelected(settings.shouldCalculateHashes());
73 alwaysCalcHashesCheckbox.setText(
"<html>" +
org.openide.util.NbBundle.getMessage(
HashLookupModuleSettingsPanel.class,
"HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.text") +
"</html>");
77 table.setModel(tableModel);
78 table.setTableHeader(null);
79 table.setRowSelectionAllowed(
false);
80 final int width1 = scrollPane.getPreferredSize().width;
81 knownHashTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
83 for (
int i = 0; i < table.getColumnCount(); i++) {
84 column = table.getColumnModel().getColumn(i);
86 column.setPreferredWidth(((
int) (width1 * 0.07)));
88 column.setPreferredWidth(((
int) (width1 * 0.92)));
104 List<HashDb> enabledHashSets =
new ArrayList<>();
105 List<HashDb> disabledHashSets =
new ArrayList<>();
106 addHashSets(knownHashSetModels, enabledHashSets, disabledHashSets);
107 addHashSets(knownBadHashSetModels, enabledHashSets, disabledHashSets);
108 return new HashLookupModuleSettings(alwaysCalcHashesCheckbox.isSelected(),
109 enabledHashSets, disabledHashSets);
112 private void addHashSets(List<HashSetModel> hashSetModels, List<HashDb> enabledHashSets, List<HashDb> disabledHashSets) {
114 if (model.isEnabled() && model.isValid()) {
115 enabledHashSets.add(model.getDatabase());
117 disabledHashSets.add(model.getDatabase());
123 updateHashSetModels();
124 knownHashSetsTableModel.fireTableDataChanged();
125 knownBadHashSetsTableModel.fireTableDataChanged();
134 List<HashDb> validDbs =
new ArrayList<>();
140 }
catch (TskCoreException ex){
147 void updateHashSetModels(List<HashDb> hashDbs, List<HashSetModel> hashSetModels) {
149 List<HashDb> hashDatabases =
new ArrayList<>(hashDbs);
152 List<HashSetModel> deletedHashSetModels =
new ArrayList<>();
153 for (HashSetModel model : hashSetModels) {
154 boolean foundDatabase =
false;
155 for(
HashDb db : hashDatabases){
156 if(model.getDatabase().equals(db)){
157 model.setValid(isHashDbValid(db));
158 hashDatabases.remove(db);
159 foundDatabase =
true;
164 deletedHashSetModels.add(model);
169 for (HashSetModel model : deletedHashSetModels) {
170 hashSetModels.remove(model);
174 for (HashDb db : hashDatabases) {
175 hashSetModels.add(
new HashSetModel(db,
true, isHashDbValid(db)));
179 void reset(HashLookupModuleSettings newSettings) {
180 initializeHashSetModels(newSettings);
181 alwaysCalcHashesCheckbox.setSelected(newSettings.shouldCalculateHashes());
182 knownHashSetsTableModel.fireTableDataChanged();
183 knownBadHashSetsTableModel.fireTableDataChanged();
187 boolean isValid =
false;
189 isValid = hashDb.isValid();
190 }
catch (TskCoreException ex) {
204 this.enabled = enabled;
213 return db.getDisplayName();
216 void setEnabled(
boolean enabled) {
217 this.enabled = enabled;
220 boolean isEnabled() {
224 void setValid(
boolean valid) {
235 private static final long serialVersionUID = 1L;
239 this.hashSets = hashSets;
244 return hashSets.size();
254 if (columnIndex == 0) {
255 return hashSets.get(rowIndex).isEnabled();
257 return hashSets.get(rowIndex).getName();
263 return (columnIndex == 0 && hashSets.get(rowIndex).isValid());
267 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
268 if (columnIndex == 0) {
269 hashSets.get(rowIndex).setEnabled((Boolean) aValue);
275 return getValueAt(0, c).getClass();
284 @SuppressWarnings(
"unchecked")
286 private
void initComponents() {
288 jScrollPane1 =
new javax.swing.JScrollPane();
289 knownHashTable =
new javax.swing.JTable();
290 knownBadHashDbsLabel =
new javax.swing.JLabel();
291 knownHashDbsLabel =
new javax.swing.JLabel();
292 alwaysCalcHashesCheckbox =
new javax.swing.JCheckBox();
293 jScrollPane2 =
new javax.swing.JScrollPane();
294 knownBadHashTable =
new javax.swing.JTable();
296 setPreferredSize(
new java.awt.Dimension(292, 150));
298 jScrollPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
300 knownHashTable.setBackground(
new java.awt.Color(240, 240, 240));
301 knownHashTable.setShowHorizontalLines(
false);
302 knownHashTable.setShowVerticalLines(
false);
303 jScrollPane1.setViewportView(knownHashTable);
305 knownBadHashDbsLabel.setText(
org.openide.util.NbBundle.getMessage(
HashLookupModuleSettingsPanel.class,
"HashLookupModuleSettingsPanel.knownBadHashDbsLabel.text"));
307 knownHashDbsLabel.setText(
org.openide.util.NbBundle.getMessage(
HashLookupModuleSettingsPanel.class,
"HashLookupModuleSettingsPanel.knownHashDbsLabel.text"));
309 alwaysCalcHashesCheckbox.setText(
org.openide.util.NbBundle.getMessage(
HashLookupModuleSettingsPanel.class,
"HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.text"));
310 alwaysCalcHashesCheckbox.setToolTipText(
org.openide.util.NbBundle.getMessage(
HashLookupModuleSettingsPanel.class,
"HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.toolTipText"));
311 alwaysCalcHashesCheckbox.setMaximumSize(
new java.awt.Dimension(290, 35));
312 alwaysCalcHashesCheckbox.setMinimumSize(
new java.awt.Dimension(290, 35));
313 alwaysCalcHashesCheckbox.setPreferredSize(
new java.awt.Dimension(271, 35));
314 alwaysCalcHashesCheckbox.setVerticalAlignment(javax.swing.SwingConstants.TOP);
315 alwaysCalcHashesCheckbox.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
317 jScrollPane2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
319 knownBadHashTable.setBackground(
new java.awt.Color(240, 240, 240));
320 knownBadHashTable.setModel(
new javax.swing.table.DefaultTableModel(
328 knownBadHashTable.setShowHorizontalLines(
false);
329 knownBadHashTable.setShowVerticalLines(
false);
330 jScrollPane2.setViewportView(knownBadHashTable);
332 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
333 this.setLayout(layout);
334 layout.setHorizontalGroup(
335 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
336 .addGroup(layout.createSequentialGroup()
338 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
339 .addGroup(layout.createSequentialGroup()
340 .addComponent(knownHashDbsLabel)
341 .addGap(0, 0, Short.MAX_VALUE))
342 .addComponent(knownBadHashDbsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
343 .addGroup(layout.createSequentialGroup()
345 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
346 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
347 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
348 .addComponent(alwaysCalcHashesCheckbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
351 layout.setVerticalGroup(
352 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
353 .addGroup(layout.createSequentialGroup()
355 .addComponent(knownHashDbsLabel)
356 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
357 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
358 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
359 .addComponent(knownBadHashDbsLabel)
360 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
361 .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
362 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
363 .addComponent(alwaysCalcHashesCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
javax.swing.JLabel knownBadHashDbsLabel
void setValueAt(Object aValue, int rowIndex, int columnIndex)
javax.swing.JScrollPane jScrollPane1
List< HashDb > validSetsOnly(List< HashDb > hashDbs)
javax.swing.JTable knownBadHashTable
IngestModuleIngestJobSettings getSettings()
void propertyChange(PropertyChangeEvent event)
void updateHashSetModels()
synchronized void addPropertyChangeListener(PropertyChangeListener listener)
void initializeHashSetModels(HashLookupModuleSettings settings, List< HashDb > hashDbs, List< HashSetModel > hashSetModels)
void addHashSets(List< HashSetModel > hashSetModels, List< HashDb > enabledHashSets, List< HashDb > disabledHashSets)
abstract String getHashSetName()
void customizeHashSetsTable(JScrollPane scrollPane, JTable table, HashSetsTableModel tableModel)
javax.swing.JScrollPane jScrollPane2
javax.swing.JTable knownHashTable
boolean isCellEditable(int rowIndex, int columnIndex)
void initializeHashSetModels(HashLookupModuleSettings settings)
synchronized List< HashDb > getKnownBadFileHashSets()
static synchronized HashDbManager getInstance()
boolean isHashDbValid(HashDb hashDb)
void customizeComponents(HashLookupModuleSettings settings)
Object getValueAt(int rowIndex, int columnIndex)
javax.swing.JCheckBox alwaysCalcHashesCheckbox
synchronized static Logger getLogger(String name)
final List< HashSetModel > hashSets
javax.swing.JLabel knownHashDbsLabel
synchronized List< HashDb > getKnownFileHashSets()
Class<?> getColumnClass(int c)