View Javadoc
1   package com.jsql.view.swing.panel.preferences;
2   
3   import com.jsql.util.tampering.TamperingType;
4   import com.jsql.view.swing.panel.PanelPreferences;
5   import com.jsql.view.swing.panel.preferences.listener.TamperingMouseAdapter;
6   import com.jsql.view.swing.popupmenu.JPopupMenuComponent;
7   import com.jsql.view.swing.text.SyntaxTextArea;
8   import com.jsql.view.swing.text.listener.DocumentListenerEditing;
9   import com.jsql.view.swing.util.MediatorHelper;
10  import com.jsql.view.swing.util.UiUtil;
11  import org.apache.commons.lang3.StringUtils;
12  import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
13  import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
14  import org.fife.ui.rtextarea.RTextScrollPane;
15  
16  import javax.swing.*;
17  import java.util.AbstractMap.SimpleEntry;
18  import java.util.Arrays;
19  import java.util.stream.Stream;
20  
21  public class PanelTampering extends JPanel {
22  
23      // no preferences init
24      private final JCheckBox checkboxIsTamperingBase64 = new JCheckBox();
25      private final JCheckBox checkboxIsTamperingVersionComment = new JCheckBox();
26      private final JCheckBox checkboxIsTamperingFunctionComment = new JCheckBox();
27      private final JCheckBox checkboxIsTamperingEqualToLike = new JCheckBox();
28      private final JCheckBox checkboxIsTamperingRandomCase = new JCheckBox();
29      private final JCheckBox checkboxIsTamperingEval = new JCheckBox();
30      private final JCheckBox checkboxIsTamperingHexToChar = new JCheckBox();
31      private final JCheckBox checkboxIsTamperingStringToChar = new JCheckBox();
32      private final JCheckBox checkboxIsTamperingQuoteToUtf8 = new JCheckBox();
33      private final JCheckBox checkboxIsTamperingCharToEncoding = new JCheckBox();
34      private final JRadioButton radioIsTamperingSpaceToMultilineComment = new JRadioButton();
35      private final JRadioButton radioIsTamperingSpaceToDashComment = new JRadioButton();
36      private final JRadioButton radioIsTamperingSpaceToSharpComment = new JRadioButton();
37  
38      private static final RSyntaxTextArea TEXT_PANE_EVAL = new SyntaxTextArea("Click on a tamper to paste source and edit custom script");
39  
40      public PanelTampering(PanelPreferences panelPreferences) {
41          this.checkboxIsTamperingEval.setToolTipText("Custom tamper in JavaScript and Java, e.g. sql.replace(/\\+/gm,'/**/')");
42  
43          PanelTampering.TEXT_PANE_EVAL.setText(StringUtils.EMPTY);
44          PanelTampering.TEXT_PANE_EVAL.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
45          PanelTampering.TEXT_PANE_EVAL.setPopupMenu(new JPopupMenuComponent(PanelTampering.TEXT_PANE_EVAL));
46          PanelTampering.applyTheme();
47  
48          var textAreaIsTamperingEval = new RTextScrollPane(PanelTampering.TEXT_PANE_EVAL, false);
49  
50          PanelTampering.TEXT_PANE_EVAL.getDocument().addDocumentListener(new DocumentListenerEditing() {
51              @Override
52              public void process() {
53                  MediatorHelper.model().getMediatorUtils().getTamperingUtil().setCustomTamper(PanelTampering.TEXT_PANE_EVAL.getText());
54              }
55          });
56          PanelTampering.TEXT_PANE_EVAL.setText(MediatorHelper.model().getMediatorUtils().getTamperingUtil().getCustomTamper());
57          this.checkboxIsTamperingEval.addActionListener(panelPreferences.getActionListenerSave());
58          this.checkboxIsTamperingEval.setText("Enable user tamper script:");
59  
60          Stream.of(
61              new SimpleEntry<>(this.checkboxIsTamperingBase64, TamperingType.BASE64),
62              new SimpleEntry<>(this.checkboxIsTamperingFunctionComment, TamperingType.COMMENT_TO_METHOD_SIGNATURE),
63              new SimpleEntry<>(this.checkboxIsTamperingVersionComment, TamperingType.VERSIONED_COMMENT_TO_METHOD_SIGNATURE),
64              new SimpleEntry<>(this.checkboxIsTamperingEqualToLike, TamperingType.EQUAL_TO_LIKE),
65              new SimpleEntry<>(this.checkboxIsTamperingRandomCase, TamperingType.RANDOM_CASE),
66              new SimpleEntry<>(this.checkboxIsTamperingHexToChar, TamperingType.HEX_TO_CHAR),
67              new SimpleEntry<>(this.checkboxIsTamperingStringToChar, TamperingType.STRING_TO_CHAR),
68              new SimpleEntry<>(this.checkboxIsTamperingQuoteToUtf8, TamperingType.QUOTE_TO_UTF8),
69              new SimpleEntry<>(this.checkboxIsTamperingCharToEncoding, TamperingType.CHAR_TO_ENCODING),
70              new SimpleEntry<>(this.radioIsTamperingSpaceToMultilineComment, TamperingType.SPACE_TO_MULTILINE_COMMENT),
71              new SimpleEntry<>(this.radioIsTamperingSpaceToDashComment, TamperingType.SPACE_TO_DASH_COMMENT),
72              new SimpleEntry<>(this.radioIsTamperingSpaceToSharpComment, TamperingType.SPACE_TO_SHARP_COMMENT)
73          )
74          .forEach(entry -> {
75              entry.getKey().setText(entry.getValue().instance().getDescription());
76              entry.getKey().setToolTipText(entry.getValue().instance().getTooltip());
77              entry.getKey().addMouseListener(new TamperingMouseAdapter(entry.getValue(), PanelTampering.TEXT_PANE_EVAL));
78              entry.getKey().addActionListener(panelPreferences.getActionListenerSave());
79          });
80  
81          var groupSpaceToComment = new ButtonGroup() {
82              @Override
83              public void setSelected(ButtonModel buttonModel, boolean b) {
84                  // Click a 2nd time to uncheck
85                  if (!b) {
86                      this.clearSelection();
87                  } else {
88                      super.setSelected(buttonModel, true);
89                  }
90              }
91          };
92          groupSpaceToComment.add(this.radioIsTamperingSpaceToDashComment);
93          groupSpaceToComment.add(this.radioIsTamperingSpaceToMultilineComment);
94          groupSpaceToComment.add(this.radioIsTamperingSpaceToSharpComment);
95  
96          var labelCommonConversion = new JLabel("<html><b>Common tamper</b></html>");
97          var labelSpaceTamper = new JLabel("<html><br /><b>Space tamper (click again to uncheck)</b></html>");
98          var labelCustomConversion = new JLabel("<html><br /><b>Custom tamper (hover tamper to show implementation, click to paste)</b></html>");
99          Arrays.asList(labelCommonConversion, labelSpaceTamper, labelCustomConversion).forEach(label -> label.setBorder(PanelGeneral.MARGIN));
100 
101         var groupLayout = new GroupLayout(this);
102         this.setLayout(groupLayout);
103         
104         groupLayout.setHorizontalGroup(
105             groupLayout
106             .createSequentialGroup()
107             .addGroup(
108                 groupLayout
109                 .createParallelGroup(GroupLayout.Alignment.LEADING)
110                 .addComponent(labelCommonConversion)
111                 .addComponent(this.checkboxIsTamperingBase64)
112                 .addComponent(this.checkboxIsTamperingFunctionComment)
113                 .addComponent(this.checkboxIsTamperingVersionComment)
114                 .addComponent(this.checkboxIsTamperingEqualToLike)
115                 .addComponent(this.checkboxIsTamperingRandomCase)
116                 .addComponent(this.checkboxIsTamperingStringToChar)
117                 .addComponent(this.checkboxIsTamperingHexToChar)
118                 .addComponent(this.checkboxIsTamperingQuoteToUtf8)
119                 .addComponent(this.checkboxIsTamperingCharToEncoding)
120                 .addComponent(labelSpaceTamper)
121                 .addComponent(this.radioIsTamperingSpaceToMultilineComment)
122                 .addComponent(this.radioIsTamperingSpaceToDashComment)
123                 .addComponent(this.radioIsTamperingSpaceToSharpComment)
124                 .addComponent(labelCustomConversion)
125                 .addComponent(this.checkboxIsTamperingEval)
126                 .addComponent(textAreaIsTamperingEval)
127             )
128         );
129         
130         groupLayout.setVerticalGroup(
131             groupLayout
132             .createSequentialGroup()
133             .addGroup(
134                 groupLayout
135                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
136                 .addComponent(labelCommonConversion)
137             )
138             .addGroup(
139                 groupLayout
140                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
141                 .addComponent(this.checkboxIsTamperingBase64)
142             )
143             .addGroup(
144                 groupLayout
145                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
146                 .addComponent(this.checkboxIsTamperingFunctionComment)
147             )
148             .addGroup(
149                 groupLayout
150                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
151                 .addComponent(this.checkboxIsTamperingVersionComment)
152             )
153             .addGroup(
154                 groupLayout
155                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
156                 .addComponent(this.checkboxIsTamperingEqualToLike)
157             )
158             .addGroup(
159                 groupLayout
160                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
161                 .addComponent(this.checkboxIsTamperingRandomCase)
162             )
163             .addGroup(
164                 groupLayout
165                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
166                 .addComponent(this.checkboxIsTamperingStringToChar)
167             )
168             .addGroup(
169                 groupLayout
170                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
171                 .addComponent(this.checkboxIsTamperingHexToChar)
172             )
173             .addGroup(
174                 groupLayout
175                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
176                 .addComponent(this.checkboxIsTamperingQuoteToUtf8)
177             )
178             .addGroup(
179                 groupLayout
180                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
181                 .addComponent(this.checkboxIsTamperingCharToEncoding)
182             )
183             .addGroup(
184                 groupLayout
185                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
186                 .addComponent(labelSpaceTamper)
187             )
188             .addGroup(
189                 groupLayout
190                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
191                 .addComponent(this.radioIsTamperingSpaceToMultilineComment)
192             )
193             .addGroup(
194                 groupLayout
195                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
196                 .addComponent(this.radioIsTamperingSpaceToDashComment)
197             )
198             .addGroup(
199                 groupLayout
200                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
201                 .addComponent(this.radioIsTamperingSpaceToSharpComment)
202             )
203             .addGroup(
204                 groupLayout
205                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
206                 .addComponent(labelCustomConversion)
207             )
208             .addGroup(
209                 groupLayout
210                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
211                 .addComponent(this.checkboxIsTamperingEval)
212             )
213             .addGroup(
214                 groupLayout
215                 .createParallelGroup(GroupLayout.Alignment.BASELINE)
216                 .addComponent(textAreaIsTamperingEval)
217             )
218         );
219     }
220 
221     public static void applyTheme() {
222         UiUtil.applySyntaxTheme(PanelTampering.TEXT_PANE_EVAL);
223     }
224     
225     
226     // Getter and setter
227 
228     public JCheckBox getCheckboxIsTamperingBase64() {
229         return this.checkboxIsTamperingBase64;
230     }
231     
232     public JCheckBox getCheckboxIsTamperingEqualToLike() {
233         return this.checkboxIsTamperingEqualToLike;
234     }
235     
236     public JCheckBox getCheckboxIsTamperingFunctionComment() {
237         return this.checkboxIsTamperingFunctionComment;
238     }
239     
240     public JCheckBox getCheckboxIsTamperingVersionComment() {
241         return this.checkboxIsTamperingVersionComment;
242     }
243     
244     public JCheckBox getCheckboxIsTamperingRandomCase() {
245         return this.checkboxIsTamperingRandomCase;
246     }
247     
248     public JCheckBox getCheckboxIsTamperingEval() {
249         return this.checkboxIsTamperingEval;
250     }
251     
252     public JRadioButton getRadioIsTamperingSpaceToDashComment() {
253         return this.radioIsTamperingSpaceToDashComment;
254     }
255     
256     public JRadioButton getRadioIsTamperingSpaceToMultilineComment() {
257         return this.radioIsTamperingSpaceToMultilineComment;
258     }
259     
260     public JRadioButton getRadioIsTamperingSpaceToSharpComment() {
261         return this.radioIsTamperingSpaceToSharpComment;
262     }
263   
264     public JCheckBox getCheckboxIsTamperingHexToChar() {
265         return this.checkboxIsTamperingHexToChar;
266     }
267     
268     public JCheckBox getCheckboxIsTamperingQuoteToUtf8() {
269         return this.checkboxIsTamperingQuoteToUtf8;
270     }
271 
272     public JCheckBox getCheckboxIsTamperingCharToEncoding() {
273         return this.checkboxIsTamperingCharToEncoding;
274     }
275 
276     public JCheckBox getCheckboxIsTamperingStringToChar() {
277         return this.checkboxIsTamperingStringToChar;
278     }
279 }