Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
YaraRuleSetOptionPanel.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.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import javax.swing.JOptionPane;
26 import javax.swing.event.ListSelectionEvent;
27 import javax.swing.event.ListSelectionListener;
28 import org.openide.util.NbBundle.Messages;
32 
37 public class YaraRuleSetOptionPanel extends javax.swing.JPanel {
38 
39  private static final long serialVersionUID = 1L;
40 
41  private static final Logger logger = Logger.getLogger(YaraRuleSetOptionPanel.class.getName());
42 
48 
49  ruleSetPanel.addListSelectionListener(new ListSelectionListener() {
50  @Override
51  public void valueChanged(ListSelectionEvent e) {
53  }
54  });
55 
56  ruleSetPanel.addDeleteRuleListener(new ActionListener() {
57  @Override
58  public void actionPerformed(ActionEvent e) {
60  }
61  });
62 
63  ruleSetPanel.addNewRuleListener(new ActionListener() {
64  @Override
65  public void actionPerformed(ActionEvent e) {
67  }
68  });
69  }
70 
74  void updatePanel() {
76  }
77 
78  @Messages({
79  "# {0} - rule set name",
80  "YaraRuleSetOptionPanel_RuleSet_Missing=The folder for the selected YARA rule set, {0}, no longer exists.",
81  "YaraRuleSetOptionPanel_RuleSet_Missing_title=Folder removed",
82  })
83 
88  private void handleSelectionChange() {
89  RuleSet ruleSet = ruleSetPanel.getSelectedRule();
90 
91  if(ruleSet != null && !ruleSet.getPath().toFile().exists()) {
92  ruleSetDetailsPanel.setRuleSet(null);
93  ruleSetPanel.removeRuleSet(ruleSet);
94  JOptionPane.showMessageDialog(this,
95  Bundle.YaraRuleSetOptionPanel_RuleSet_Missing(ruleSet.getName()),
96  Bundle.YaraRuleSetOptionPanel_RuleSet_Missing_title(),
97  JOptionPane.ERROR_MESSAGE);
98  } else {
99  ruleSetDetailsPanel.setRuleSet(ruleSet);
100  }
101  }
102 
103  @Messages({
104  "YaraRuleSetOptionPanel_new_rule_set_name_msg=Supply a new unique rule set name:",
105  "YaraRuleSetOptionPanel_new_rule_set_name_title=Rule Set Name",
106  "# {0} - rule set name",
107  "YaraRuleSetOptionPanel_badName_msg=Rule set name {0} already exists.\nRule set names must be unique.",
108  "YaraRuleSetOptionPanel_badName_title=Create Rule Set",
109  "YaraRuleSetOptionPanel_badName2_msg=Rule set is invalid.\nRule set names must be non-empty string and unique.",})
114  private void handleNewRuleSet() {
115  String value = JOptionPane.showInputDialog(this,
116  Bundle.YaraRuleSetOptionPanel_new_rule_set_name_msg(),
117  Bundle.YaraRuleSetOptionPanel_new_rule_set_name_title());
118 
119  // User hit cancel.
120  if(value == null) {
121  return;
122  }
123 
124  if (value.isEmpty()) {
125  JOptionPane.showMessageDialog(this,
126  Bundle.YaraRuleSetOptionPanel_badName2_msg(),
127  Bundle.YaraRuleSetOptionPanel_badName_title(),
128  JOptionPane.ERROR_MESSAGE);
129  return;
130  }
131 
132  try {
134  } catch (RuleSetException ex) {
135  JOptionPane.showMessageDialog(this,
136  Bundle.YaraRuleSetOptionPanel_badName_msg(value),
137  Bundle.YaraRuleSetOptionPanel_badName_title(),
138  JOptionPane.ERROR_MESSAGE);
139  logger.log(Level.WARNING, "Failed to create new rule set, user provided existing name.", ex);
140  }
141  }
142 
143  @Messages({
144  "# {0} - rule set name",
145  "YaraRuleSetOptionPanel_rule_set_delete=Unable to delete the selected YARA rule set {0}.\nRule set may have already been removed."
146  })
147 
152  private void handleDeleteRuleSet() {
153  RuleSet ruleSet = ruleSetPanel.getSelectedRule();
154  if (ruleSet != null) {
155  try {
157  } catch (RuleSetException ex) {
158  JOptionPane.showMessageDialog(this,
159  Bundle.YaraRuleSetOptionPanel_rule_set_delete(ruleSet.getName()),
160  Bundle.YaraRuleSetOptionPanel_badName_title(),
161  JOptionPane.ERROR_MESSAGE);
162  logger.log(Level.WARNING, String.format("Failed to delete YARA rule set %s", ruleSet.getName()), ex);
163  }
164  ruleSetPanel.removeRuleSet(ruleSet);
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  javax.swing.JScrollPane scrollPane = new javax.swing.JScrollPane();
179  javax.swing.JPanel viewportPanel = new javax.swing.JPanel();
180  javax.swing.JSeparator separator = new javax.swing.JSeparator();
183 
184  setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
185  setLayout(new java.awt.BorderLayout());
186 
187  scrollPane.setBorder(null);
188 
189  viewportPanel.setMinimumSize(new java.awt.Dimension(1000, 127));
190  viewportPanel.setPreferredSize(new java.awt.Dimension(1020, 400));
191  viewportPanel.setLayout(new java.awt.GridBagLayout());
192 
193  separator.setOrientation(javax.swing.SwingConstants.VERTICAL);
194  gridBagConstraints = new java.awt.GridBagConstraints();
195  gridBagConstraints.gridx = 1;
196  gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
197  gridBagConstraints.weighty = 1.0;
198  viewportPanel.add(separator, gridBagConstraints);
199 
200  ruleSetDetailsPanel.setMinimumSize(new java.awt.Dimension(500, 97));
201  ruleSetDetailsPanel.setPreferredSize(new java.awt.Dimension(500, 204));
202  gridBagConstraints = new java.awt.GridBagConstraints();
203  gridBagConstraints.gridx = 2;
204  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
205  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
206  gridBagConstraints.weightx = 1.0;
207  gridBagConstraints.weighty = 1.0;
208  gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
209  viewportPanel.add(ruleSetDetailsPanel, gridBagConstraints);
210 
211  ruleSetPanel.setMaximumSize(new java.awt.Dimension(400, 2147483647));
212  ruleSetPanel.setMinimumSize(new java.awt.Dimension(400, 107));
213  ruleSetPanel.setPreferredSize(new java.awt.Dimension(400, 214));
214  gridBagConstraints = new java.awt.GridBagConstraints();
215  gridBagConstraints.gridx = 0;
216  gridBagConstraints.gridy = 0;
217  gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
218  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
219  gridBagConstraints.weighty = 1.0;
220  gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
221  viewportPanel.add(ruleSetPanel, gridBagConstraints);
222 
223  scrollPane.setViewportView(viewportPanel);
224 
225  add(scrollPane, java.awt.BorderLayout.CENTER);
226  }// </editor-fold>//GEN-END:initComponents
227 
228 
229  // Variables declaration - do not modify//GEN-BEGIN:variables
232  // End of variables declaration//GEN-END:variables
233 }
static synchronized RuleSetManager getInstance()
org.sleuthkit.autopsy.modules.yara.ui.RuleSetPanel ruleSetPanel
org.sleuthkit.autopsy.modules.yara.ui.RuleSetDetailsPanel ruleSetDetailsPanel

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