forked from KeenSecurityLab/BinAbsInspector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigDialog.java
308 lines (290 loc) · 14.6 KB
/
ConfigDialog.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import com.bai.checkers.CheckerManager;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.bai.util.Config;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.DefaultListSelectionModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
@SuppressWarnings("MethodName")
public class ConfigDialog extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextField kTextField;
private JTextField callStringKTextField;
private JTextField z3TimeouttextField;
private JTextField addressTextField;
private JTextField timeoutTextField;
private JCheckBox debugCheckBox;
private JCheckBox enableZ3CheckBox;
private JLabel warningLabel;
private JList<String> checkerList;
private JCheckBox runAllCheckersCheckBox;
private JScrollPane checkerListScroll;
private Config config;
private boolean isSuccess;
public ConfigDialog(Config config) {
$$$setupUI$$$();
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
setTitle("Analysis Configuration");
this.config = config;
warningLabel.setVisible(false);
setupDefaultConfigs();
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
buttonCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
});
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
runAllCheckersCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JCheckBox box = (JCheckBox) e.getSource();
if (box.isSelected()) {
checkerList.setVisible(false);
CheckerManager.loadAllCheckers(config);
} else {
config.clearCheckers();
checkerList.setVisible(true);
checkerList.clearSelection();
}
}
});
}
@SuppressWarnings("unchekcked")
private void setupDefaultConfigs() {
kTextField.setText(Integer.toString(config.getK()));
callStringKTextField.setText(Integer.toString(config.getCallStringK()));
z3TimeouttextField.setText(Integer.toString(config.getZ3TimeOut()));
timeoutTextField.setText(Integer.toString(config.getTimeout()));
debugCheckBox.setSelected(config.isDebug());
enableZ3CheckBox.setSelected(config.isEnableZ3());
runAllCheckersCheckBox.setSelected(true);
CheckerManager.loadAllCheckers(config);
checkerList.setListData(CheckerManager.getCheckerNames());
checkerList.setVisibleRowCount(6);
checkerList.setSelectionModel(new DefaultListSelectionModel() {
@Override
public void setSelectionInterval(int index0, int index1) {
if (super.isSelectedIndex(index0)) {
super.removeSelectionInterval(index0, index1);
} else {
super.addSelectionInterval(index0, index1);
}
}
});
checkerList.setVisible(false);
}
private boolean updateConfig() {
try {
config.setK(Integer.parseInt(kTextField.getText()));
config.setCallStringK(Integer.parseInt(callStringKTextField.getText()));
config.setZ3TimeOut(Integer.parseInt(z3TimeouttextField.getText()));
config.setTimeout(Integer.parseInt(timeoutTextField.getText()));
String addressText = addressTextField.getText();
if (!addressText.isEmpty()) {
Long.decode(addressText); // try to parse address in hex
config.setEntryAddress(addressText);
}
config.setDebug(debugCheckBox.isSelected());
config.setEnableZ3(enableZ3CheckBox.isSelected());
for (Object checker : checkerList.getSelectedValuesList()) {
config.addChecker((String) checker);
}
return true;
} catch (NumberFormatException e) {
return false;
}
}
private void onOK() {
// add your code here
if (!updateConfig()) {
warningLabel.setForeground(Color.RED);
warningLabel.setVisible(true);
isSuccess = false;
} else {
isSuccess = true;
dispose();
}
}
private void onCancel() {
// add your code here if necessary
isSuccess = false;
dispose();
}
public void showDialog() {
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public boolean isSuccess() {
return isSuccess;
}
/** Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
* DO NOT edit this method OR call it in your code!
* @noinspection ALL
*/
private void $$$setupUI$$$() {
createUIComponents();
contentPane = new JPanel();
contentPane.setLayout(new GridLayoutManager(6, 2, new Insets(10, 10, 10, 10), -1, -1));
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
contentPane.add(panel1,
new GridConstraints(5, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null,
null, 0, false));
final JPanel panel2 = new JPanel();
panel2.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
panel1.add(panel2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0,
false));
buttonCancel = new JButton();
buttonCancel.setText("Cancel");
panel2.add(buttonCancel,
new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
buttonOK = new JButton();
buttonOK.setText("OK");
panel1.add(buttonOK,
new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JPanel panel3 = new JPanel();
panel3.setLayout(new GridLayoutManager(6, 3, new Insets(0, 0, 0, 0), -1, -1));
contentPane.add(panel3,
new GridConstraints(0, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null,
0, false));
final JLabel label1 = new JLabel();
label1.setText("K");
panel3.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
kTextField = new JTextField();
panel3.add(kTextField,
new GridConstraints(0, 1, 2, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
new Dimension(150, -1), null, 0, false));
final JLabel label2 = new JLabel();
label2.setText("Call String K");
panel3.add(label2, new GridConstraints(1, 0, 2, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
callStringKTextField = new JTextField();
panel3.add(callStringKTextField,
new GridConstraints(2, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
new Dimension(150, -1), null, 0, false));
final JLabel label3 = new JLabel();
label3.setText("Z3 Timeout (ms)");
panel3.add(label3, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
z3TimeouttextField = new JTextField();
panel3.add(z3TimeouttextField,
new GridConstraints(3, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
new Dimension(150, -1), null, 0, false));
final JLabel label4 = new JLabel();
label4.setText("Analysis Timeout (s, -1 for no timeout)");
panel3.add(label4, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label5 = new JLabel();
label5.setText("Analysis Start Address (Optional, e.g. 0x100a0)");
panel3.add(label5, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
addressTextField = new JTextField();
panel3.add(addressTextField,
new GridConstraints(5, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
new Dimension(150, -1), null, 0, false));
timeoutTextField = new JTextField();
panel3.add(timeoutTextField,
new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
new Dimension(150, -1), null, 0, false));
final JPanel panel4 = new JPanel();
panel4.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
contentPane.add(panel4,
new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null,
0, false));
debugCheckBox = new JCheckBox();
debugCheckBox.setText("Debug");
panel4.add(debugCheckBox,
new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
enableZ3CheckBox = new JCheckBox();
enableZ3CheckBox.setText("Enable Z3");
panel4.add(enableZ3CheckBox,
new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
warningLabel = new JLabel();
warningLabel.setEnabled(true);
warningLabel.setText("Wrong input, please check!");
contentPane.add(warningLabel,
new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0,
false));
checkerListScroll = new JScrollPane();
contentPane.add(checkerListScroll,
new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null,
0, false));
checkerListScroll.setViewportView(checkerList);
runAllCheckersCheckBox = new JCheckBox();
runAllCheckersCheckBox.setText("Run All Checkers");
contentPane.add(runAllCheckersCheckBox,
new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
}
/** @noinspection ALL */
public JComponent $$$getRootComponent$$$() {
return contentPane;
}
private void createUIComponents() {
checkerList = new JList<>();
}
}