Skip to content

Commit f4c0e71

Browse files
committed
Better Searching
Instead of providing the entire path in the search result now we can return only what the user is looking for
1 parent e94bee0 commit f4c0e71

10 files changed

Lines changed: 114 additions & 111 deletions

File tree

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/PerformSearch.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
55
import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread;
66
import the.bytecode.club.bytecodeviewer.searching.RegexInsnFinder;
7+
import the.bytecode.club.bytecodeviewer.searching.impl.LDCSearch;
78
import the.bytecode.club.bytecodeviewer.searching.impl.RegexSearch;
8-
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
99
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
1010
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
1111

@@ -38,29 +38,29 @@
3838
class PerformSearch extends BackgroundSearchThread
3939
{
4040
private final SearchBoxPane searchBoxPane;
41-
private final SearchResultNotifier srn;
4241

43-
public PerformSearch(SearchBoxPane searchBoxPane, SearchResultNotifier srn)
42+
public PerformSearch(SearchBoxPane searchBoxPane)
4443
{
4544
this.searchBoxPane = searchBoxPane;
46-
this.srn = srn;
4745
}
4846

4947
@Override
5048
public void search()
5149
{
5250
try
5351
{
54-
Pattern.compile(RegexInsnFinder.processRegex(RegexSearch.searchText.getText()), Pattern.MULTILINE);
52+
if(RegexSearch.searchText != null)
53+
Pattern.compile(RegexInsnFinder.processRegex(RegexSearch.searchText.getText()), Pattern.MULTILINE);
5554
}
5655
catch (PatternSyntaxException ex)
5756
{
5857
BytecodeViewer.showMessage("You have an error in your regex syntax.");
5958
}
6059

6160
for (ResourceContainer container : BytecodeViewer.resourceContainers.values())
62-
for (ClassNode c : container.resourceClasses.values())
63-
searchBoxPane.searchType.details.search(container, c, srn, searchBoxPane.exact.isSelected());
61+
container.resourceClasses.forEach((key,cn)->{
62+
searchBoxPane.searchType.panel.search(container, key, cn, searchBoxPane.exact.isSelected());
63+
});
6464

6565
BytecodeViewer.viewer.searchBoxPane.search.setEnabled(true);
6666
BytecodeViewer.viewer.searchBoxPane.search.setText(TranslatedStrings.SEARCH.toString());

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchBoxPane.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
1919
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer;
2020
import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread;
21-
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
21+
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
2222
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
2323
import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents;
2424
import the.bytecode.club.bytecodeviewer.translation.components.*;
@@ -49,8 +49,6 @@
4949
* @author WaterWolf
5050
* @since 09/29/2011
5151
*/
52-
53-
@SuppressWarnings("rawtypes")
5452
public class SearchBoxPane extends TranslatedVisibleComponent
5553
{
5654
public static final SearchRadius[] SEARCH_RADII = SearchRadius.values();
@@ -59,7 +57,7 @@ public class SearchBoxPane extends TranslatedVisibleComponent
5957
public final JCheckBox exact = new TranslatedJCheckBox("Exact", TranslatedComponents.EXACT);
6058
public final TranslatedDefaultMutableTreeNode treeRoot = new TranslatedDefaultMutableTreeNode("Results", TranslatedComponents.RESULTS);
6159
public final JTree tree;
62-
public final JComboBox typeBox;
60+
public final JComboBox<SearchType> typeBox;
6361

6462
public SearchType searchType = null;
6563
public final JComboBox searchRadiusBox;
@@ -91,13 +89,13 @@ public SearchBoxPane()
9189
for (final SearchType st : SEARCH_TYPES)
9290
model.addElement(st);
9391

94-
typeBox = new JComboBox(model);
92+
typeBox = new JComboBox<SearchType>(model);
9593
final JPanel searchOptPanel = new JPanel();
9694

9795
final ItemListener il = arg0 -> {
9896
searchOptPanel.removeAll();
9997
searchType = (SearchType) typeBox.getSelectedItem();
100-
searchOptPanel.add(Objects.requireNonNull(searchType).details.getPanel());
98+
searchOptPanel.add(Objects.requireNonNull(searchType).panel.getPanel());
10199

102100
searchOptPanel.revalidate();
103101
searchOptPanel.repaint();
@@ -138,18 +136,11 @@ public SearchBoxPane()
138136
if (selectionEvent.getPath().getPathComponent(0).equals(TranslatedStrings.RESULTS))
139137
return;
140138

141-
selectionEvent.getPath().getPathComponent(1);
142-
143-
String path = selectionEvent.getPath().getPathComponent(1).toString();
144-
145-
String containerName = path.split(">", 2)[0];
146-
String className = path.split(">", 2)[1].split("\\.")[0];
147-
ResourceContainer container = BytecodeViewer.getFileContainer(containerName);
139+
LDCSearchTreeNodeResult result = (LDCSearchTreeNodeResult) tree.getLastSelectedPathComponent();
148140

149-
final ClassNode fN = Objects.requireNonNull(container).getClassNode(className);
150-
151-
if (fN != null)
152-
BytecodeViewer.viewer.workPane.addClassResource(container, className + ".class");
141+
final String name = result.resourceWorkingName;
142+
143+
BytecodeViewer.viewer.workPane.addClassResource(result.container, name);
153144
}
154145
catch (Exception e)
155146
{
@@ -166,7 +157,6 @@ public void search()
166157
treeRoot.removeAllChildren();
167158
searchType = (SearchType) typeBox.getSelectedItem();
168159
final SearchRadius radius = (SearchRadius) searchRadiusBox.getSelectedItem();
169-
final SearchResultNotifier srn = debug -> treeRoot.add(new DefaultMutableTreeNode(debug));
170160

171161
if (radius == SearchRadius.All_Classes)
172162
{
@@ -175,7 +165,7 @@ public void search()
175165
BytecodeViewer.viewer.searchBoxPane.search.setEnabled(false);
176166
BytecodeViewer.viewer.searchBoxPane.search.setText("Searching, please wait..");
177167

178-
performSearchThread = new PerformSearch(this, srn);
168+
performSearchThread = new PerformSearch(this);
179169
performSearchThread.start();
180170
}
181171
else
@@ -188,7 +178,7 @@ else if (radius == SearchRadius.Current_Class)
188178
final ResourceViewer cv = BytecodeViewer.getActiveResource();
189179

190180
if (cv != null)
191-
searchType.details.search(cv.resource.container, cv.resource.getResourceClassNode(), srn, exact.isSelected());
181+
searchType.panel.search(cv.resource.container, cv.resource.workingName, cv.resource.getResourceClassNode(), exact.isSelected());
192182
}
193183
}
194184

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchType.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package the.bytecode.club.bytecodeviewer.gui.resourcesearch;
22

3-
import the.bytecode.club.bytecodeviewer.searching.*;
3+
import the.bytecode.club.bytecodeviewer.searching.SearchPanel;
44
import the.bytecode.club.bytecodeviewer.searching.impl.FieldCallSearch;
55
import the.bytecode.club.bytecodeviewer.searching.impl.LDCSearch;
66
import the.bytecode.club.bytecodeviewer.searching.impl.MethodCallSearch;
@@ -33,12 +33,13 @@ public enum SearchType
3333
Strings(new LDCSearch()),
3434
Regex(new RegexSearch()),
3535
MethodCall(new MethodCallSearch()),
36-
FieldCall(new FieldCallSearch());
36+
FieldCall(new FieldCallSearch()),
37+
;
3738

38-
public final SearchTypeDetails details;
39+
public final SearchPanel panel;
3940

40-
SearchType(final SearchTypeDetails details)
41+
SearchType(final SearchPanel panel)
4142
{
42-
this.details = details;
43+
this.panel = panel;
4344
}
4445
}

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public Workspace()
6969
if (index != -1)
7070
tabs.remove(index);
7171
});
72+
7273
closeAllTabs.addActionListener(e ->
7374
{
7475
TabExitButton tabExitButton = (TabExitButton) ((JPopupMenu)((JMenuItem) e.getSource()).getParent()).getInvoker();

src/main/java/the/bytecode/club/bytecodeviewer/searching/SearchResultNotifier.java renamed to src/main/java/the/bytecode/club/bytecodeviewer/searching/LDCSearchTreeNodeResult.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package the.bytecode.club.bytecodeviewer.searching;
22

3+
import org.objectweb.asm.tree.ClassNode;
4+
import org.objectweb.asm.tree.FieldNode;
5+
import org.objectweb.asm.tree.MethodNode;
6+
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
7+
8+
import javax.swing.tree.DefaultMutableTreeNode;
9+
310
/***************************************************************************
411
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
512
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
@@ -19,13 +26,24 @@
1926
***************************************************************************/
2027

2128
/**
22-
* Used to update the search pane that there's been a result found.
23-
*
2429
* @author Konloch
25-
* @author WaterWolf
26-
* @since 09/26/2011
30+
* @since 7/29/2021
2731
*/
28-
29-
public interface SearchResultNotifier {
30-
void notifyOfResult(String debug);
32+
public class LDCSearchTreeNodeResult extends DefaultMutableTreeNode
33+
{
34+
public final ResourceContainer container;
35+
public final String resourceWorkingName;
36+
public final String ldc;
37+
public final String ldcType;
38+
39+
public LDCSearchTreeNodeResult(ResourceContainer container, String resourceWorkingName,
40+
ClassNode cn, MethodNode method, FieldNode field,
41+
String ldc, String ldcType)
42+
{
43+
super("'"+ldc+"' -> " + cn.name);
44+
this.container = container;
45+
this.resourceWorkingName = resourceWorkingName;
46+
this.ldc = ldc;
47+
this.ldcType = ldcType;
48+
}
3149
}

src/main/java/the/bytecode/club/bytecodeviewer/searching/SearchTypeDetails.java renamed to src/main/java/the/bytecode/club/bytecodeviewer/searching/SearchPanel.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package the.bytecode.club.bytecodeviewer.searching;
22

3-
import javax.swing.JPanel;
43
import org.objectweb.asm.tree.ClassNode;
54
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
65

6+
import javax.swing.*;
7+
78
/***************************************************************************
89
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
910
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
@@ -23,16 +24,13 @@
2324
***************************************************************************/
2425

2526
/**
26-
* Search type details
27-
*
2827
* @author Konloch
2928
* @author WaterWolf
3029
* @since 09/26/2011
3130
*/
32-
33-
public interface SearchTypeDetails
31+
public interface SearchPanel
3432
{
35-
JPanel getPanel();
36-
37-
void search(ResourceContainer container, ClassNode node, SearchResultNotifier srn, boolean exact);
33+
JPanel getPanel();
34+
35+
void search(ResourceContainer container, String resourceWorkingName, ClassNode node, boolean exact);
3836
}

src/main/java/the/bytecode/club/bytecodeviewer/searching/impl/FieldCallSearch.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.objectweb.asm.tree.FieldInsnNode;
88
import org.objectweb.asm.tree.InsnList;
99
import org.objectweb.asm.tree.MethodNode;
10-
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
1110
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
1211

1312
/***************************************************************************
@@ -38,8 +37,7 @@
3837
public class FieldCallSearch extends MethodCallSearch
3938
{
4039
@Override
41-
public void search(final ResourceContainer container, final ClassNode node, final SearchResultNotifier srn,
42-
boolean exact)
40+
public void search(ResourceContainer container, String resourceWorkingName, ClassNode node, boolean exact)
4341
{
4442
final Iterator<MethodNode> methods = node.methods.iterator();
4543

@@ -88,7 +86,7 @@ public void search(final ResourceContainer container, final ClassNode node, fina
8886
continue;
8987
}
9088

91-
found(container, node, method, insnNode, srn);
89+
found(container, resourceWorkingName, node, method, insnNode);
9290
}
9391
}
9492
}

src/main/java/the/bytecode/club/bytecodeviewer/searching/impl/LDCSearch.java

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
import java.util.Iterator;
55
import javax.swing.JPanel;
66
import javax.swing.JTextField;
7-
import org.objectweb.asm.Type;
7+
88
import org.objectweb.asm.tree.AbstractInsnNode;
99
import org.objectweb.asm.tree.ClassNode;
1010
import org.objectweb.asm.tree.FieldNode;
1111
import org.objectweb.asm.tree.InsnList;
1212
import org.objectweb.asm.tree.LdcInsnNode;
1313
import org.objectweb.asm.tree.MethodNode;
14+
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
1415
import the.bytecode.club.bytecodeviewer.searching.EnterKeyEvent;
15-
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
16-
import the.bytecode.club.bytecodeviewer.searching.SearchTypeDetails;
16+
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
17+
import the.bytecode.club.bytecodeviewer.searching.SearchPanel;
1718
import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents;
1819
import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJLabel;
1920
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
@@ -44,7 +45,7 @@
4445
* @since 09/29/2011
4546
*/
4647

47-
public class LDCSearch implements SearchTypeDetails
48+
public class LDCSearch implements SearchPanel
4849
{
4950
JTextField searchText;
5051
JPanel myPanel = null;
@@ -68,8 +69,7 @@ public JPanel getPanel()
6869
return myPanel;
6970
}
7071

71-
@Override
72-
public void search(final ResourceContainer container, final ClassNode node, final SearchResultNotifier srn,
72+
public void search(final ResourceContainer container, final String resourceWorkingName, final ClassNode node,
7373
boolean caseSensitive)
7474
{
7575
final Iterator<MethodNode> methods = node.methods.iterator();
@@ -90,13 +90,6 @@ public void search(final ResourceContainer container, final ClassNode node, fina
9090
{
9191
final LdcInsnNode ldcObject = ((LdcInsnNode) insnNode);
9292
final String ldcString = ldcObject.cst.toString();
93-
String desc2 = method.desc;
94-
try
95-
{
96-
desc2 = Type.getType(method.desc).toString();
97-
if (desc2.equals("null"))
98-
desc2 = method.desc;
99-
} catch (ArrayIndexOutOfBoundsException ignored) { }
10093

10194
//TODO re-add this at some point when the search pane is redone
10295
boolean exact = false;
@@ -107,10 +100,15 @@ public void search(final ResourceContainer container, final ClassNode node, fina
107100

108101
if (anyMatch)
109102
{
110-
srn.notifyOfResult(container.name + ">" + node.name + "." + method.name
111-
+ desc2
112-
+ " -> \"" + ldcString + "\" > "
113-
+ ldcObject.cst.getClass().getCanonicalName());
103+
BytecodeViewer.viewer.searchBoxPane.treeRoot.add(new LDCSearchTreeNodeResult(
104+
container,
105+
resourceWorkingName,
106+
node,
107+
method,
108+
null,
109+
ldcString,
110+
ldcObject.cst.getClass().getCanonicalName()
111+
));
114112
}
115113
}
116114
}
@@ -120,20 +118,17 @@ public void search(final ResourceContainer container, final ClassNode node, fina
120118
while (methods.hasNext())
121119
{
122120
final FieldNode field = fields.next();
123-
String desc2 = field.desc;
124-
125-
try
126-
{
127-
desc2 = Type.getType(field.desc).toString();
128-
129-
if (desc2.equals("null"))
130-
desc2 = field.desc;
131-
} catch (java.lang.ArrayIndexOutOfBoundsException ignored) { }
132121

133122
if (field.value instanceof String)
134123
{
135-
srn.notifyOfResult(container.name + ">" + node.name + "." + field.name + desc2
136-
+ " -> \"" + field.value + "\" > field");
124+
BytecodeViewer.viewer.resourcePane.treeRoot.add(new LDCSearchTreeNodeResult(container,
125+
resourceWorkingName,
126+
node,
127+
null,
128+
field,
129+
String.valueOf(field.value),
130+
field.value.getClass().getCanonicalName()
131+
));
137132
}
138133
}
139134
}

0 commit comments

Comments
 (0)