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-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;
33 import org.sleuthkit.datamodel.TskCoreException;
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  alwaysCalcHashesCheckbox.setSelected(newSettings.shouldCalculateHashes());
170  knownHashSetsTableModel.fireTableDataChanged();
171  knownBadHashSetsTableModel.fireTableDataChanged();
172  }
173 
174  private boolean isHashDbIndexed(HashDb hashDb) {
175  boolean indexed = false;
176  try {
177  indexed = hashDb.hasIndex();
178  } catch (TskCoreException ex) {
179  Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting indexed status info for hash set (name = " + hashDb.getHashSetName() + ")", ex); //NON-NLS
180  }
181  return indexed;
182  }
183 
184  private static final class HashSetModel {
185 
186  private final String name;
187  private boolean indexed;
188  private boolean enabled;
189 
190  HashSetModel(String name, boolean enabled, boolean indexed) {
191  this.name = name;
192  this.enabled = enabled;
193  this.indexed = indexed;
194  }
195 
196  String getName() {
197  return name;
198  }
199 
200  void setEnabled(boolean enabled) {
201  this.enabled = enabled;
202  }
203 
204  boolean isEnabled() {
205  return enabled;
206  }
207 
208  void setIndexed(boolean indexed) {
209  this.indexed = indexed;
210  }
211 
212  boolean isIndexed() {
213  return indexed;
214  }
215  }
216 
217  private static final class HashSetsTableModel extends AbstractTableModel {
218 
219  private final List<HashSetModel> hashSets;
220 
221  HashSetsTableModel(List<HashSetModel> hashSets) {
222  this.hashSets = hashSets;
223  }
224 
225  @Override
226  public int getRowCount() {
227  return hashSets.size();
228  }
229 
230  @Override
231  public int getColumnCount() {
232  return 2;
233  }
234 
235  @Override
236  public Object getValueAt(int rowIndex, int columnIndex) {
237  if (columnIndex == 0) {
238  return hashSets.get(rowIndex).isEnabled();
239  } else {
240  return hashSets.get(rowIndex).getName();
241  }
242  }
243 
244  @Override
245  public boolean isCellEditable(int rowIndex, int columnIndex) {
246  return (columnIndex == 0 && hashSets.get(rowIndex).isIndexed());
247  }
248 
249  @Override
250  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
251  if (columnIndex == 0) {
252  hashSets.get(rowIndex).setEnabled((Boolean) aValue);
253  }
254  }
255 
256  @Override
257  public Class<?> getColumnClass(int c) {
258  return getValueAt(0, c).getClass();
259  }
260  }
261 
267  @SuppressWarnings("unchecked")
268  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
269  private void initComponents() {
270 
271  jScrollPane1 = new javax.swing.JScrollPane();
272  knownHashTable = new javax.swing.JTable();
273  knownBadHashDbsLabel = new javax.swing.JLabel();
274  knownHashDbsLabel = new javax.swing.JLabel();
275  alwaysCalcHashesCheckbox = new javax.swing.JCheckBox();
276  jScrollPane2 = new javax.swing.JScrollPane();
277  knownBadHashTable = new javax.swing.JTable();
278 
279  setPreferredSize(new java.awt.Dimension(292, 150));
280 
281  jScrollPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
282 
283  knownHashTable.setBackground(new java.awt.Color(240, 240, 240));
284  knownHashTable.setShowHorizontalLines(false);
285  knownHashTable.setShowVerticalLines(false);
286  jScrollPane1.setViewportView(knownHashTable);
287 
288  knownBadHashDbsLabel.setText(org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.knownBadHashDbsLabel.text")); // NOI18N
289 
290  knownHashDbsLabel.setText(org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.knownHashDbsLabel.text")); // NOI18N
291 
292  alwaysCalcHashesCheckbox.setText(org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.text")); // NOI18N
293  alwaysCalcHashesCheckbox.setToolTipText(org.openide.util.NbBundle.getMessage(HashLookupModuleSettingsPanel.class, "HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.toolTipText")); // NOI18N
294  alwaysCalcHashesCheckbox.setMaximumSize(new java.awt.Dimension(290, 35));
295  alwaysCalcHashesCheckbox.setMinimumSize(new java.awt.Dimension(290, 35));
296  alwaysCalcHashesCheckbox.setPreferredSize(new java.awt.Dimension(271, 35));
297  alwaysCalcHashesCheckbox.setVerticalAlignment(javax.swing.SwingConstants.TOP);
298  alwaysCalcHashesCheckbox.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
299 
300  jScrollPane2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
301 
302  knownBadHashTable.setBackground(new java.awt.Color(240, 240, 240));
303  knownBadHashTable.setModel(new javax.swing.table.DefaultTableModel(
304  new Object [][] {
305 
306  },
307  new String [] {
308 
309  }
310  ));
311  knownBadHashTable.setShowHorizontalLines(false);
312  knownBadHashTable.setShowVerticalLines(false);
313  jScrollPane2.setViewportView(knownBadHashTable);
314 
315  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
316  this.setLayout(layout);
317  layout.setHorizontalGroup(
318  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
319  .addGroup(layout.createSequentialGroup()
320  .addContainerGap()
321  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
322  .addGroup(layout.createSequentialGroup()
323  .addComponent(knownHashDbsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
324  .addGap(0, 18, Short.MAX_VALUE))
325  .addComponent(knownBadHashDbsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
326  .addGroup(layout.createSequentialGroup()
327  .addGap(10, 10, 10)
328  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
329  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
330  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
331  .addComponent(alwaysCalcHashesCheckbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
332  .addContainerGap())
333  );
334  layout.setVerticalGroup(
335  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
336  .addGroup(layout.createSequentialGroup()
337  .addGap(2, 2, 2)
338  .addComponent(knownHashDbsLabel)
339  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
340  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
341  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
342  .addComponent(knownBadHashDbsLabel)
343  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
344  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
345  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
346  .addComponent(alwaysCalcHashesCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
347  .addGap(0, 0, 0))
348  );
349  }// </editor-fold>//GEN-END:initComponents
350 
351  // Variables declaration - do not modify//GEN-BEGIN:variables
352  private javax.swing.JCheckBox alwaysCalcHashesCheckbox;
353  private javax.swing.JScrollPane jScrollPane1;
354  private javax.swing.JScrollPane jScrollPane2;
355  private javax.swing.JLabel knownBadHashDbsLabel;
356  private javax.swing.JTable knownBadHashTable;
357  private javax.swing.JLabel knownHashDbsLabel;
358  private javax.swing.JTable knownHashTable;
359  // End of variables declaration//GEN-END:variables
360 }
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: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.