Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
YaraIngestSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.yara.ui;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.ArrayList;
24 import java.util.Enumeration;
25 import java.util.List;
26 import javax.swing.DefaultListModel;
34 
39 
40  private static final long serialVersionUID = 1L;
41 
43  private final DefaultListModel<RuleSetListItem> listModel;
44 
50  listModel = new DefaultListModel<>();
51  checkboxList = new CheckBoxJList<>();
52  scrollPane.setViewportView(checkboxList);
53  }
54 
61  this();
62 
63  List<String> setNames = settings.getSelectedRuleSetNames();
64 
65  checkboxList.setModel(listModel);
66  checkboxList.setOpaque(false);
67  List<RuleSet> ruleSetList = RuleSetManager.getInstance().getRuleSetList();
68  for (RuleSet set : ruleSetList) {
69  RuleSetListItem item = new RuleSetListItem(set);
70  item.setChecked(setNames.contains(set.getName()));
71  listModel.addElement(item);
72  }
73 
74  allFilesButton.setSelected(!settings.onlyExecutableFiles());
75  executableFilesButton.setSelected(settings.onlyExecutableFiles());
76 
77  RuleSetManager.addPropertyChangeListener(new PropertyChangeListener() {
78  @Override
79  public void propertyChange(PropertyChangeEvent evt) {
80  switch (evt.getPropertyName()) {
82  handleRuleSetAdded((RuleSet) evt.getNewValue());
83  break;
85  handleRuleSetDeleted((RuleSet) evt.getOldValue());
86  break;
87  }
88  }
89  });
90  }
91 
92  @Override
94  List<RuleSet> selectedRules = new ArrayList<>();
95 
96  Enumeration<RuleSetListItem> enumeration = listModel.elements();
97  while (enumeration.hasMoreElements()) {
98  RuleSetListItem item = enumeration.nextElement();
99  if (item.isChecked()) {
100  selectedRules.add(item.getRuleSet());
101  }
102  }
103 
104  return new YaraIngestJobSettings(selectedRules, executableFilesButton.isSelected());
105  }
106 
112  private void handleRuleSetAdded(RuleSet ruleSet) {
113  if (ruleSet == null) {
114  return;
115  }
116 
117  RuleSetListItem item = new RuleSetListItem(ruleSet);
118  listModel.addElement(item);
119  }
120 
126  private void handleRuleSetDeleted(RuleSet ruleSet) {
127  Enumeration<RuleSetListItem> enumeration = listModel.elements();
128  while (enumeration.hasMoreElements()) {
129  RuleSetListItem item = enumeration.nextElement();
130  if (item.getDisplayName().equals(ruleSet.getName())) {
131  listModel.removeElement(item);
132  return;
133  }
134  }
135  }
136 
140  private final class RuleSetListItem extends AbstractCheckboxListItem {
141 
142  private final RuleSet ruleSet;
143 
149  RuleSetListItem(RuleSet set) {
150  this.ruleSet = set;
151  }
152 
158  RuleSet getRuleSet() {
159  return ruleSet;
160  }
161 
162  @Override
163  public String getDisplayName() {
164  return ruleSet.getName();
165  }
166  }
167 
173  @SuppressWarnings("unchecked")
174  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
175  private void initComponents() {
176  java.awt.GridBagConstraints gridBagConstraints;
177 
178  buttonGroup = new javax.swing.ButtonGroup();
179  scrollPane = new javax.swing.JScrollPane();
180  buttonPanel = new javax.swing.JPanel();
181  allFilesButton = new javax.swing.JRadioButton();
182  executableFilesButton = new javax.swing.JRadioButton();
183 
184  setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(YaraIngestSettingsPanel.class, "YaraIngestSettingsPanel.border.title"))); // NOI18N
185  setLayout(new java.awt.GridBagLayout());
186  gridBagConstraints = new java.awt.GridBagConstraints();
187  gridBagConstraints.gridx = 0;
188  gridBagConstraints.gridy = 0;
189  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
190  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
191  gridBagConstraints.weightx = 1.0;
192  gridBagConstraints.weighty = 1.0;
193  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
194  add(scrollPane, gridBagConstraints);
195 
196  buttonPanel.setLayout(new java.awt.GridBagLayout());
197 
199  org.openide.awt.Mnemonics.setLocalizedText(allFilesButton, org.openide.util.NbBundle.getMessage(YaraIngestSettingsPanel.class, "YaraIngestSettingsPanel.allFilesButton.text")); // NOI18N
200  allFilesButton.setToolTipText(org.openide.util.NbBundle.getMessage(YaraIngestSettingsPanel.class, "YaraIngestSettingsPanel.allFilesButton.toolTipText")); // NOI18N
201  gridBagConstraints = new java.awt.GridBagConstraints();
202  gridBagConstraints.gridx = 0;
203  gridBagConstraints.gridy = 0;
204  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
205  buttonPanel.add(allFilesButton, gridBagConstraints);
206 
208  executableFilesButton.setSelected(true);
209  org.openide.awt.Mnemonics.setLocalizedText(executableFilesButton, org.openide.util.NbBundle.getMessage(YaraIngestSettingsPanel.class, "YaraIngestSettingsPanel.executableFilesButton.text")); // NOI18N
210  gridBagConstraints = new java.awt.GridBagConstraints();
211  gridBagConstraints.gridx = 1;
212  gridBagConstraints.gridy = 0;
213  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
214  buttonPanel.add(executableFilesButton, gridBagConstraints);
215 
216  gridBagConstraints = new java.awt.GridBagConstraints();
217  gridBagConstraints.gridx = 0;
218  gridBagConstraints.gridy = 1;
219  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
220  gridBagConstraints.weightx = 1.0;
221  add(buttonPanel, gridBagConstraints);
222  }// </editor-fold>//GEN-END:initComponents
223 
224 
225  // Variables declaration - do not modify//GEN-BEGIN:variables
226  private javax.swing.JRadioButton allFilesButton;
227  private javax.swing.ButtonGroup buttonGroup;
228  private javax.swing.JPanel buttonPanel;
229  private javax.swing.JRadioButton executableFilesButton;
230  private javax.swing.JScrollPane scrollPane;
231  // End of variables declaration//GEN-END:variables
232 }
static synchronized RuleSetManager getInstance()
static void addPropertyChangeListener(PropertyChangeListener listener)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.