19
19
import java .awt .event .MouseEvent ;
20
20
import java .awt .event .WindowAdapter ;
21
21
import java .awt .event .WindowEvent ;
22
+ import java .io .BufferedReader ;
22
23
import java .io .File ;
24
+ import java .io .IOException ;
25
+ import java .io .InputStreamReader ;
23
26
import java .io .StringWriter ;
24
27
import java .util .Collections ;
25
28
import java .util .Enumeration ;
26
29
import java .util .jar .JarEntry ;
27
30
import java .util .jar .JarFile ;
31
+ import java .util .regex .Pattern ;
28
32
29
33
import javax .swing .*;
30
34
import javax .swing .GroupLayout .Alignment ;
@@ -36,7 +40,12 @@ public class FindAllBox extends JDialog {
36
40
37
41
private JButton findButton ;
38
42
private JTextField textField ;
43
+ private JCheckBox mcase ;
44
+ private JCheckBox regex ;
45
+ private JCheckBox wholew ;
46
+ private JList <String > list ;
39
47
private JProgressBar progressBar ;
48
+
40
49
private JLabel statusLabel = new JLabel ("" );
41
50
42
51
private DefaultListModel <String > classesList = new DefaultListModel <String >();
@@ -54,9 +63,13 @@ public FindAllBox(final MainWindow mainWindow) {
54
63
findButton = new JButton ("Find" );
55
64
findButton .addActionListener (new FindButton ());
56
65
66
+ mcase = new JCheckBox ("Match Case" );
67
+ regex = new JCheckBox ("Regex" );
68
+ wholew = new JCheckBox ("Whole Words" );
69
+
57
70
this .getRootPane ().setDefaultButton (findButton );
58
71
59
- JList < String > list = new JList <String >(classesList );
72
+ list = new JList <String >(classesList );
60
73
list .setSelectionMode (ListSelectionModel .SINGLE_INTERVAL_SELECTION );
61
74
list .setLayoutOrientation (JList .VERTICAL_WRAP );
62
75
list .setVisibleRowCount (-1 );
@@ -68,18 +81,36 @@ public void mouseClicked(MouseEvent evt) {
68
81
int index = list .locationToIndex (evt .getPoint ());
69
82
String entryName = (String ) list .getModel ().getElementAt (index );
70
83
String [] array = entryName .split ("/" );
71
- String internalName = StringUtilities .removeRight (entryName , ".class" );
72
- TypeReference type = Model .metadataSystem .lookupType (internalName );
73
- try {
74
- mainWindow .getModel ().extractClassToTextPane (type , array [array .length - 1 ], entryName , null );
75
- } catch (Exception e ) {
76
- Luyten .showExceptionDialog ("Exception!" , e );
84
+ if (entryName .toLowerCase ().endsWith (".class" )) {
85
+ String internalName = StringUtilities .removeRight (entryName , ".class" );
86
+ TypeReference type = Model .metadataSystem .lookupType (internalName );
87
+ try {
88
+ mainWindow .getModel ().extractClassToTextPane (type , array [array .length - 1 ], entryName ,
89
+ null );
90
+ } catch (Exception e ) {
91
+ Luyten .showExceptionDialog ("Exception!" , e );
92
+ }
93
+
94
+ } else {
95
+ try {
96
+ JarFile jfile = new JarFile (MainWindow .model .getOpenedFile ());
97
+ mainWindow .getModel ().extractSimpleFileEntryToTextPane (
98
+ jfile .getInputStream (jfile .getEntry (entryName )), array [array .length - 1 ],
99
+ entryName );
100
+ jfile .close ();
101
+ } catch (IOException e ) {
102
+ e .printStackTrace ();
103
+ } catch (Exception e ) {
104
+ e .printStackTrace ();
105
+ }
77
106
}
78
107
79
108
}
80
109
}
81
110
});
82
- JScrollPane listScroller = new JScrollPane (list );
111
+ list .setLayoutOrientation (JList .VERTICAL );
112
+ JScrollPane listScroller = new JScrollPane (list , JScrollPane .VERTICAL_SCROLLBAR_ALWAYS ,
113
+ JScrollPane .HORIZONTAL_SCROLLBAR_AS_NEEDED );
83
114
84
115
Dimension screenSize = Toolkit .getDefaultToolkit ().getScreenSize ();
85
116
final Dimension center = new Dimension ((int ) (screenSize .width * 0.35 ), 500 );
@@ -95,11 +126,17 @@ public void mouseClicked(MouseEvent evt) {
95
126
96
127
layout .setHorizontalGroup (
97
128
layout .createSequentialGroup ().addComponent (label )
98
- .addGroup (layout .createParallelGroup (Alignment .LEADING ).addComponent (statusLabel )
99
- .addComponent (textField )
100
- .addGroup (layout .createSequentialGroup ()
101
- .addGroup (layout .createParallelGroup (Alignment .LEADING )
102
- .addComponent (listScroller ).addComponent (progressBar ))))
129
+ .addGroup (
130
+ layout .createParallelGroup (Alignment .LEADING ).addComponent (statusLabel )
131
+ .addComponent (textField )
132
+ .addGroup (layout .createSequentialGroup ()
133
+ .addGroup (layout .createParallelGroup (Alignment .LEADING )
134
+ .addComponent (mcase ))
135
+ .addGroup (layout .createParallelGroup (Alignment .LEADING ).addComponent (wholew ))
136
+ .addGroup (layout .createParallelGroup (Alignment .LEADING ).addComponent (regex )))
137
+ .addGroup (layout .createSequentialGroup ()
138
+ .addGroup (layout .createParallelGroup (Alignment .LEADING ).addComponent (listScroller )
139
+ .addComponent (progressBar ))))
103
140
.addGroup (layout .createParallelGroup (Alignment .LEADING ).addComponent (findButton ))
104
141
105
142
);
@@ -108,6 +145,8 @@ public void mouseClicked(MouseEvent evt) {
108
145
layout .setVerticalGroup (layout .createSequentialGroup ()
109
146
.addGroup (layout .createParallelGroup (Alignment .BASELINE ).addComponent (label ).addComponent (textField )
110
147
.addComponent (findButton ))
148
+ .addGroup (layout .createParallelGroup (Alignment .BASELINE ).addComponent (mcase ).addComponent (wholew )
149
+ .addComponent (regex ))
111
150
.addGroup (layout .createParallelGroup (Alignment .LEADING )
112
151
.addGroup (layout .createSequentialGroup ()
113
152
.addGroup (layout .createParallelGroup (Alignment .BASELINE ).addComponent (listScroller ))))
@@ -149,6 +188,7 @@ public void run() {
149
188
JarEntry entry = ent .nextElement ();
150
189
String name = entry .getName ();
151
190
setStatus (name );
191
+ System .out .println (entry .getName ());
152
192
if (filter && name .contains ("$" ))
153
193
continue ;
154
194
if (entry .getName ().endsWith (".class" )) {
@@ -169,11 +209,30 @@ public void run() {
169
209
decompilationOptions .getSettings ().isUnicodeOutputEnabled ());
170
210
settings .getLanguage ().decompileType (resolvedType , plainTextOutput ,
171
211
decompilationOptions );
172
- String decompiledSource = stringwriter .toString ().toLowerCase ();
173
- if (decompiledSource .contains (textField .getText ().toLowerCase ())) {
212
+ if (search (stringwriter .toString ()))
174
213
addClassName (entry .getName ());
214
+ }
215
+ } else {
216
+
217
+ StringBuilder sb = new StringBuilder ();
218
+ long nonprintableCharactersCount = 0 ;
219
+ try (InputStreamReader inputStreamReader = new InputStreamReader (
220
+ jfile .getInputStream (entry ));
221
+ BufferedReader reader = new BufferedReader (inputStreamReader );) {
222
+ String line ;
223
+ while ((line = reader .readLine ()) != null ) {
224
+ sb .append (line ).append ("\n " );
225
+
226
+ for (byte nextByte : line .getBytes ()) {
227
+ if (nextByte <= 0 ) {
228
+ nonprintableCharactersCount ++;
229
+ }
230
+ }
231
+
175
232
}
176
233
}
234
+ if (nonprintableCharactersCount < 5 && search (sb .toString ()))
235
+ addClassName (entry .getName ());
177
236
}
178
237
}
179
238
setSearching (false );
@@ -195,6 +254,22 @@ public void run() {
195
254
196
255
}
197
256
257
+ private boolean search (String bulk ) {
258
+ String a = textField .getText ();
259
+ String b = bulk ;
260
+ if (regex .isSelected ())
261
+ return Pattern .matches (a , b );
262
+ if (wholew .isSelected ())
263
+ a = " " + a + " " ;
264
+ if (!mcase .isSelected ()) {
265
+ a = a .toLowerCase ();
266
+ b = b .toLowerCase ();
267
+ }
268
+ if (b .contains (a ))
269
+ return true ;
270
+ return false ;
271
+ }
272
+
198
273
private void setHideOnEscapeButton () {
199
274
Action escapeAction = new AbstractAction () {
200
275
private static final long serialVersionUID = 6846566740472934801L ;
0 commit comments