Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
HashLookupModuleSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.hashdatabase;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.logging.Level;
28 import javax.swing.JScrollPane;
29 import javax.swing.JTable;
30 import javax.swing.table.AbstractTableModel;
31 import javax.swing.table.TableColumn;
37 
41 public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSettingsPanel implements PropertyChangeListener {
42 
43  private static final long serialVersionUID = 1L;
45  private final List<HashSetModel> knownHashSetModels = new ArrayList<>();
46  private final HashSetsTableModel knownHashSetsTableModel = new HashSetsTableModel(knownHashSetModels);
47  private final List<HashSetModel> knownBadHashSetModels = new ArrayList<>();
48  private final HashSetsTableModel knownBadHashSetsTableModel = new HashSetsTableModel(knownBadHashSetModels);
49 
50  HashLookupModuleSettingsPanel(HashLookupModuleSettings settings) {
51  initializeHashSetModels(settings);
53  customizeComponents(settings);
54  }
55 
56  private void initializeHashSetModels(HashLookupModuleSettings settings) {
59  }
60 
61  private void initializeHashSetModels(HashLookupModuleSettings settings, List<HashDb> hashDbs, List<HashSetModel> hashSetModels) {
62  hashSetModels.clear();
63  for (HashDb db : hashDbs) {
64  String name = db.getHashSetName();
65  hashSetModels.add(new HashSetModel(name, settings.isHashSetEnabled(name), isHashDbIndexed(db)));
66  }
67  }
68 
69  private void customizeComponents(HashLookupModuleSettings settings) {
70  customizeHashSetsTable(jScrollPane1, knownHashTable, knownHashSetsTableModel);
71  customizeHashSetsTable(jScrollPane2, knownBadHashTable, knownBadHashSetsTableModel);
72  alwaysCalcHashesCheckbox.setSelected(settings.shouldCalculateHashes());
73  hashDbManager.addPropertyChangeListener(this);
74  alwaysCalcHashesCheckbox.setText("<html>" + org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.text") + "</html>"); // NOI18N NON-NLS
75  }
76 
77  private void customizeHashSetsTable(JScrollPane scrollPane, JTable table, HashSetsTableModel tableModel) {
78  table.setModel(tableModel);
79  table.setTableHeader(null);
80  table.setRowSelectionAllowed(false);
81  final int width1 = scrollPane.getPreferredSize().width;
82  knownHashTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
83  TableColumn column;
84  for (int i = 0; i < table.getColumnCount(); i++) {
85  column = table.getColumnModel().getColumn(i);
86  if (i == 0) {
87  column.setPreferredWidth(((int) (width1 * 0.07)));
88  } else {
89  column.setPreferredWidth(((int) (width1 * 0.92)));
90  }
91  }
92  }
93 
94  @Override
95  public void propertyChange(PropertyChangeEvent event) {
96  if (event.getPropertyName().equals(HashDbManager.SetEvt.DB_ADDED.name())
97  || event.getPropertyName().equals(HashDbManager.SetEvt.DB_DELETED.name())
98  || event.getPropertyName().equals(HashDbManager.SetEvt.DB_INDEXED.name())) {
99  update();
100  }
101  }
102 
103  @Override
105  List<String> enabledKnownHashSetNames = new ArrayList<>();
106  List<String> disabledKnownHashSetNames = new ArrayList<>();
107  List<String> enabledKnownBadHashSetNames = new ArrayList<>();
108  List<String> disabledKnownBadHashSetNames = new ArrayList<>();
109  getHashSetNames(knownHashSetModels, enabledKnownHashSetNames, disabledKnownHashSetNames);
110  getHashSetNames(knownBadHashSetModels, enabledKnownBadHashSetNames, disabledKnownBadHashSetNames);
111  return new HashLookupModuleSettings(alwaysCalcHashesCheckbox.isSelected(),
112  enabledKnownHashSetNames, enabledKnownBadHashSetNames,
113  disabledKnownHashSetNames, disabledKnownBadHashSetNames);
114  }
115 
116  private void getHashSetNames(List<HashSetModel> hashSetModels, List<String> enabledHashSetNames, List<String> disabledHashSetNames) {
117  for (HashSetModel model : hashSetModels) {
118  if (model.isEnabled() && model.isIndexed()) {
119  enabledHashSetNames.add(model.getName());
120  } else {
121  disabledHashSetNames.add(model.getName());
122  }
123  }
124  }
125 
126  void update() {
128  knownHashSetsTableModel.fireTableDataChanged();
129  knownBadHashSetsTableModel.fireTableDataChanged();
130  }
131 
132  private void updateHashSetModels() {
135  }
136 
137  void updateHashSetModels(List<HashDb> hashDbs, List<HashSetModel> hashSetModels) {
138  Map<String, HashDb> hashSetDbs = new HashMap<>();
139  for (HashDb db : hashDbs) {
140  hashSetDbs.put(db.getHashSetName(), db);
141  }
142 
143  // Update the hash sets and detect deletions.
144  List<HashSetModel> deletedHashSetModels = new ArrayList<>();
145  for (HashSetModel model : hashSetModels) {
146  String hashSetName = model.getName();
147  if (hashSetDbs.containsKey(hashSetName)) {
148  HashDb db = hashSetDbs.get(hashSetName);
149  model.setIndexed(isHashDbIndexed(db));
150  hashSetDbs.remove(hashSetName);
151  } else {
152  deletedHashSetModels.add(model);
153  }
154  }
155 
156  // Remove the deleted hash sets.
157  for (HashSetModel model : deletedHashSetModels) {
158  hashSetModels.remove(model);
159  }
160 
161  // Add any new hash sets. All new sets are enabled by default.
162  for (HashDb db : hashSetDbs.values()) {
163  String name = db.getHashSetName();
164  hashSetModels.add(new HashSetModel(name, true, isHashDbIndexed(db)));
165  }
166  }
167 
168  void reset(HashLookupModuleSettings newSettings) {
169  initializeHashSetModels(newSettings);
170  alwaysCalcHashesCheckbox.setSelected(newSettings.shouldCalculateHashes());
171  knownHashSetsTableModel.fireTableDataChanged();
172  knownBadHashSetsTableModel.fireTableDataChanged();
173  }
174 
175  private boolean isHashDbIndexed(HashDb hashDb) {
176  boolean indexed = false;
177  try {
178  indexed = hashDb.hasIndex();
179  } catch (TskCoreException ex) {
180  Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting indexed status info for hash set (name = " + hashDb.getHashSetName() + ")", ex); //NON-NLS
181  }
182  return indexed;
183  }
184 
185  private static final class HashSetModel {
186 
187  private final String name;
188  private boolean indexed;
189  private boolean enabled;
190 
191  HashSetModel(String name, boolean enabled, boolean indexed) {
192  this.name = name;
193  this.enabled = enabled;
194  this.indexed = indexed;
195  }
196 
197  String getName() {
198  return name;
199  }
200 
201  void setEnabled(boolean enabled) {
202  this.enabled = enabled;
203  }
204 
205  boolean isEnabled() {
206  return enabled;
207  }
208 
209  void setIndexed(boolean indexed) {
210  this.indexed = indexed;
211  }
212 
213  boolean isIndexed() {
214  return indexed;
215  }
216  }
217 
218  private static final class HashSetsTableModel extends AbstractTableModel {
219 
220  private static final long serialVersionUID = 1L;
221  private final List<HashSetModel> hashSets;
222 
223  HashSetsTableModel(List<HashSetModel> hashSets) {
224  this.hashSets = hashSets;
225  }
226 
227  @Override
228  public int getRowCount() {
229  return hashSets.size();
230  }
231 
232  @Override
233  public int getColumnCount() {
234  return 2;
235  }
236 
237  @Override
238  public Object getValueAt(int rowIndex, int columnIndex) {
239  if (columnIndex == 0) {
240  return hashSets.get(rowIndex).isEnabled();
241  } else {
242  return hashSets.get(rowIndex).getName();
243  }
244  }
245 
246  @Override
247  public boolean isCellEditable(int rowIndex, int columnIndex) {
248  return (columnIndex == 0 && hashSets.get(rowIndex).isIndexed());
249  }
250 
251  @Override
252  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
253  if (columnIndex == 0) {
254  hashSets.get(rowIndex).setEnabled((Boolean) aValue);
255  }
256  }
257 
258  @Override
259  public Class<?> getColumnClass(int c) {
260  return getValueAt(0, c).getClass();
261  }
262  }
263 
269  @SuppressWarnings("unchecked")
270  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
271  private void initComponents() {
272 
273  jScrollPane1 = new javax.swing.JScrollPane();
274  knownHashTable = new javax.swing.JTable();
275  knownBadHashDbsLabel = new javax.swing.JLabel();
276  knownHashDbsLabel = new javax.swing.JLabel();
277  alwaysCalcHashesCheckbox = new javax.swing.JCheckBox();
278  jScrollPane2 = new javax.swing.JScrollPane();
279  knownBadHashTable = new javax.swing.JTable();
280 
281  setPreferredSize(new java.awt.Dimension(292, 150));
282 
283  jScrollPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
284 
285  knownHashTable.setBackground(new java.awt.Color(240, 240, 240));
286  knownHashTable.setShowHorizontalLines(false);
287  knownHashTable.setShowVerticalLines(false);
288  jScrollPane1.setViewportView(knownHashTable);
289 
290  knownBadHashDbsLabel.setText(org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.knownBadHashDbsLabel.text")); // NOI18N
291 
292  knownHashDbsLabel.setText(org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.knownHashDbsLabel.text")); // NOI18N
293 
294  alwaysCalcHashesCheckbox.setText(org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.text")); // NOI18N
295  alwaysCalcHashesCheckbox.setToolTipText(org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.toolTipText")); // NOI18N
296  alwaysCalcHashesCheckbox.setMaximumSize(new java.awt.Dimension(290, 35));
297  alwaysCalcHashesCheckbox.setMinimumSize(new java.awt.Dimension(290, 35));
298  alwaysCalcHashesCheckbox.setPreferredSize(new java.awt.Dimension(271, 35));
299  alwaysCalcHashesCheckbox.setVerticalAlignment(javax.swing.SwingConstants.TOP);
300  alwaysCalcHashesCheckbox.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
301 
302  jScrollPane2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
303 
304  knownBadHashTable.setBackground(new java.awt.Color(240, 240, 240));
305  knownBadHashTable.setModel(new javax.swing.table.DefaultTableModel(
306  new Object [][] {
307 
308  },
309  new String [] {
310 
311  }
312  ));
313  knownBadHashTable.setShowHorizontalLines(false);
314  knownBadHashTable.setShowVerticalLines(false);
315  jScrollPane2.setViewportView(knownBadHashTable);
316 
317  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
318  this.setLayout(layout);
319  layout.setHorizontalGroup(
320  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
321  .addGroup(layout.createSequentialGroup()
322  .addContainerGap()
323  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
324  .addGroup(layout.createSequentialGroup()
325  .addComponent(knownHashDbsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
326  .addGap(0, 18, Short.MAX_VALUE))
327  .addComponent(knownBadHashDbsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
328  .addGroup(layout.createSequentialGroup()
329  .addGap(10, 10, 10)
330  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
331  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
332  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
333  .addComponent(alwaysCalcHashesCheckbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
334  .addContainerGap())
335  );
336  layout.setVerticalGroup(
337  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
338  .addGroup(layout.createSequentialGroup()
339  .addGap(2, 2, 2)
340  .addComponent(knownHashDbsLabel)
341  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
342  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
343  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
344  .addComponent(knownBadHashDbsLabel)
345  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
346  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
347  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
348  .addComponent(alwaysCalcHashesCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
349  .addGap(0, 0, 0))
350  );
351  }// </editor-fold>//GEN-END:initComponents
352 
353  // Variables declaration - do not modify//GEN-BEGIN:variables
354  private javax.swing.JCheckBox alwaysCalcHashesCheckbox;
355  private javax.swing.JScrollPane jScrollPane1;
356  private javax.swing.JScrollPane jScrollPane2;
357  private javax.swing.JLabel knownBadHashDbsLabel;
358  private javax.swing.JTable knownBadHashTable;
359  private javax.swing.JLabel knownHashDbsLabel;
360  private javax.swing.JTable knownHashTable;
361  // End of variables declaration//GEN-END:variables
362 }
synchronized void addPropertyChangeListener(PropertyChangeListener listener)
void getHashSetNames(List< HashSetModel > hashSetModels, List< String > enabledHashSetNames, List< String > disabledHashSetNames)
void initializeHashSetModels(HashLookupModuleSettings settings, List< HashDb > hashDbs, List< HashSetModel > hashSetModels)
void customizeHashSetsTable(JScrollPane scrollPane, JTable table, HashSetsTableModel tableModel)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.