Autopsy  3.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-2014 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 
44  private final List<HashSetModel> knownHashSetModels = new ArrayList<>();
45  private final HashSetsTableModel knownHashSetsTableModel = new HashSetsTableModel(knownHashSetModels);
46  private final List<HashSetModel> knownBadHashSetModels = new ArrayList<>();
47  private final HashSetsTableModel knownBadHashSetsTableModel = new HashSetsTableModel(knownBadHashSetModels);
48 
49  HashLookupModuleSettingsPanel(HashLookupModuleSettings settings) {
50  initializeHashSetModels(settings);
52  customizeComponents(settings);
53  }
54 
55  private void initializeHashSetModels(HashLookupModuleSettings settings) {
58  }
59 
60  private void initializeHashSetModels(HashLookupModuleSettings settings, List<HashDb> hashDbs, List<HashSetModel> hashSetModels) {
61  hashSetModels.clear();
62  for (HashDb db : hashDbs) {
63  String name = db.getHashSetName();
64  hashSetModels.add(new HashSetModel(name, settings.isHashSetEnabled(name), isHashDbIndexed(db)));
65  }
66  }
67 
68  private void customizeComponents(HashLookupModuleSettings settings) {
69  customizeHashSetsTable(jScrollPane1, knownHashTable, knownHashSetsTableModel);
70  customizeHashSetsTable(jScrollPane2, knownBadHashTable, knownBadHashSetsTableModel);
71  alwaysCalcHashesCheckbox.setSelected(settings.shouldCalculateHashes());
72  hashDbManager.addPropertyChangeListener(this);
73  alwaysCalcHashesCheckbox.setText("<html>" + org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.text") + "</html>"); // NOI18N NON-NLS
74  }
75 
76  private void customizeHashSetsTable(JScrollPane scrollPane, JTable table, HashSetsTableModel tableModel) {
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);
82  TableColumn column;
83  for (int i = 0; i < table.getColumnCount(); i++) {
84  column = table.getColumnModel().getColumn(i);
85  if (i == 0) {
86  column.setPreferredWidth(((int) (width1 * 0.07)));
87  } else {
88  column.setPreferredWidth(((int) (width1 * 0.92)));
89  }
90  }
91  }
92 
93  @Override
94  public void propertyChange(PropertyChangeEvent event) {
95  if (event.getPropertyName().equals(HashDbManager.SetEvt.DB_ADDED.name())
96  || event.getPropertyName().equals(HashDbManager.SetEvt.DB_DELETED.name())
97  || event.getPropertyName().equals(HashDbManager.SetEvt.DB_INDEXED.name())) {
98  update();
99  }
100  }
101 
102  @Override
104  List<String> enabledKnownHashSetNames = new ArrayList<>();
105  List<String> disabledKnownHashSetNames = new ArrayList<>();
106  List<String> enabledKnownBadHashSetNames = new ArrayList<>();
107  List<String> disabledKnownBadHashSetNames = new ArrayList<>();
108  getHashSetNames(knownHashSetModels, enabledKnownHashSetNames, disabledKnownHashSetNames);
109  getHashSetNames(knownBadHashSetModels, enabledKnownBadHashSetNames, disabledKnownBadHashSetNames);
110  return new HashLookupModuleSettings(alwaysCalcHashesCheckbox.isSelected(),
111  enabledKnownHashSetNames, enabledKnownBadHashSetNames,
112  disabledKnownHashSetNames, disabledKnownBadHashSetNames);
113  }
114 
115  private void getHashSetNames(List<HashSetModel> hashSetModels, List<String> enabledHashSetNames, List<String> disabledHashSetNames) {
116  for (HashSetModel model : hashSetModels) {
117  if (model.isEnabled() && model.isIndexed()) {
118  enabledHashSetNames.add(model.getName());
119  } else {
120  disabledHashSetNames.add(model.getName());
121  }
122  }
123  }
124 
125  void update() {
127  knownHashSetsTableModel.fireTableDataChanged();
128  knownBadHashSetsTableModel.fireTableDataChanged();
129  }
130 
131  private void updateHashSetModels() {
134  }
135 
136  void updateHashSetModels(List<HashDb> hashDbs, List<HashSetModel> hashSetModels) {
137  Map<String, HashDb> hashSetDbs = new HashMap<>();
138  for (HashDb db : hashDbs) {
139  hashSetDbs.put(db.getHashSetName(), db);
140  }
141 
142  // Update the hash sets and detect deletions.
143  List<HashSetModel> deletedHashSetModels = new ArrayList<>();
144  for (HashSetModel model : hashSetModels) {
145  String hashSetName = model.getName();
146  if (hashSetDbs.containsKey(hashSetName)) {
147  HashDb db = hashSetDbs.get(hashSetName);
148  model.setIndexed(isHashDbIndexed(db));
149  hashSetDbs.remove(hashSetName);
150  } else {
151  deletedHashSetModels.add(model);
152  }
153  }
154 
155  // Remove the deleted hash sets.
156  for (HashSetModel model : deletedHashSetModels) {
157  hashSetModels.remove(model);
158  }
159 
160  // Add any new hash sets. All new sets are enabled by default.
161  for (HashDb db : hashSetDbs.values()) {
162  String name = db.getHashSetName();
163  hashSetModels.add(new HashSetModel(name, true, isHashDbIndexed(db)));
164  }
165  }
166 
167  void reset(HashLookupModuleSettings newSettings) {
168  initializeHashSetModels(newSettings);
169  knownHashSetsTableModel.fireTableDataChanged();
170  knownBadHashSetsTableModel.fireTableDataChanged();
171  }
172 
173  private boolean isHashDbIndexed(HashDb hashDb) {
174  boolean indexed = false;
175  try {
176  indexed = hashDb.hasIndex();
177  } catch (TskCoreException ex) {
178  Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting indexed status info for hash set (name = " + hashDb.getHashSetName() + ")", ex); //NON-NLS
179  }
180  return indexed;
181  }
182 
183  private static final class HashSetModel {
184 
185  private final String name;
186  private boolean indexed;
187  private boolean enabled;
188 
189  HashSetModel(String name, boolean enabled, boolean indexed) {
190  this.name = name;
191  this.enabled = enabled;
192  this.indexed = indexed;
193  }
194 
195  String getName() {
196  return name;
197  }
198 
199  void setEnabled(boolean enabled) {
200  this.enabled = enabled;
201  }
202 
203  boolean isEnabled() {
204  return enabled;
205  }
206 
207  void setIndexed(boolean indexed) {
208  this.indexed = indexed;
209  }
210 
211  boolean isIndexed() {
212  return indexed;
213  }
214  }
215 
216  private static final class HashSetsTableModel extends AbstractTableModel {
217 
218  private final List<HashSetModel> hashSets;
219 
220  HashSetsTableModel(List<HashSetModel> hashSets) {
221  this.hashSets = hashSets;
222  }
223 
224  @Override
225  public int getRowCount() {
226  return hashSets.size();
227  }
228 
229  @Override
230  public int getColumnCount() {
231  return 2;
232  }
233 
234  @Override
235  public Object getValueAt(int rowIndex, int columnIndex) {
236  if (columnIndex == 0) {
237  return hashSets.get(rowIndex).isEnabled();
238  } else {
239  return hashSets.get(rowIndex).getName();
240  }
241  }
242 
243  @Override
244  public boolean isCellEditable(int rowIndex, int columnIndex) {
245  return (columnIndex == 0 && hashSets.get(rowIndex).isIndexed());
246  }
247 
248  @Override
249  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
250  if (columnIndex == 0) {
251  hashSets.get(rowIndex).setEnabled((Boolean) aValue);
252  }
253  }
254 
255  @Override
256  public Class<?> getColumnClass(int c) {
257  return getValueAt(0, c).getClass();
258  }
259  }
260 
266  @SuppressWarnings("unchecked")
267  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
268  private void initComponents() {
269 
270  jScrollPane1 = new javax.swing.JScrollPane();
271  knownHashTable = new javax.swing.JTable();
272  knownBadHashDbsLabel = new javax.swing.JLabel();
273  knownHashDbsLabel = new javax.swing.JLabel();
274  alwaysCalcHashesCheckbox = new javax.swing.JCheckBox();
275  jScrollPane2 = new javax.swing.JScrollPane();
276  knownBadHashTable = new javax.swing.JTable();
277 
278  setPreferredSize(new java.awt.Dimension(292, 150));
279 
280  jScrollPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
281 
282  knownHashTable.setBackground(new java.awt.Color(240, 240, 240));
283  knownHashTable.setShowHorizontalLines(false);
284  knownHashTable.setShowVerticalLines(false);
285  jScrollPane1.setViewportView(knownHashTable);
286 
287  knownBadHashDbsLabel.setText(org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.knownBadHashDbsLabel.text")); // NOI18N
288 
289  knownHashDbsLabel.setText(org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.knownHashDbsLabel.text")); // NOI18N
290 
291  alwaysCalcHashesCheckbox.setText(org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.text")); // NOI18N
292  alwaysCalcHashesCheckbox.setToolTipText(org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.toolTipText")); // NOI18N
293  alwaysCalcHashesCheckbox.setMaximumSize(new java.awt.Dimension(290, 35));
294  alwaysCalcHashesCheckbox.setMinimumSize(new java.awt.Dimension(290, 35));
295  alwaysCalcHashesCheckbox.setPreferredSize(new java.awt.Dimension(271, 35));
296  alwaysCalcHashesCheckbox.setVerticalAlignment(javax.swing.SwingConstants.TOP);
297  alwaysCalcHashesCheckbox.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
298 
299  jScrollPane2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
300 
301  knownBadHashTable.setBackground(new java.awt.Color(240, 240, 240));
302  knownBadHashTable.setModel(new javax.swing.table.DefaultTableModel(
303  new Object [][] {
304 
305  },
306  new String [] {
307 
308  }
309  ));
310  knownBadHashTable.setShowHorizontalLines(false);
311  knownBadHashTable.setShowVerticalLines(false);
312  jScrollPane2.setViewportView(knownBadHashTable);
313 
314  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
315  this.setLayout(layout);
316  layout.setHorizontalGroup(
317  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
318  .addGroup(layout.createSequentialGroup()
319  .addContainerGap()
320  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
321  .addGroup(layout.createSequentialGroup()
322  .addComponent(knownHashDbsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
323  .addGap(0, 0, Short.MAX_VALUE))
324  .addComponent(knownBadHashDbsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
325  .addGroup(layout.createSequentialGroup()
326  .addGap(10, 10, 10)
327  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
328  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
329  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
330  .addComponent(alwaysCalcHashesCheckbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
331  .addContainerGap())
332  );
333  layout.setVerticalGroup(
334  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
335  .addGroup(layout.createSequentialGroup()
336  .addGap(2, 2, 2)
337  .addComponent(knownHashDbsLabel)
338  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
339  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
340  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
341  .addComponent(knownBadHashDbsLabel)
342  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
343  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
344  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
345  .addComponent(alwaysCalcHashesCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
346  .addContainerGap())
347  );
348  }// </editor-fold>//GEN-END:initComponents
349 
350  // Variables declaration - do not modify//GEN-BEGIN:variables
351  private javax.swing.JCheckBox alwaysCalcHashesCheckbox;
352  private javax.swing.JScrollPane jScrollPane1;
353  private javax.swing.JScrollPane jScrollPane2;
354  private javax.swing.JLabel knownBadHashDbsLabel;
355  private javax.swing.JTable knownBadHashTable;
356  private javax.swing.JLabel knownHashDbsLabel;
357  private javax.swing.JTable knownHashTable;
358  // End of variables declaration//GEN-END:variables
359 }
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)
static Logger getLogger(String name)
Definition: Logger.java:131

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.