Better Searching

Instead of providing the entire path in the search result now we can return only what the user is looking for
This commit is contained in:
Konloch 2021-07-29 19:32:32 -07:00
parent e94bee0fb6
commit f4c0e71475
10 changed files with 114 additions and 111 deletions

View file

@ -4,8 +4,8 @@ import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread;
import the.bytecode.club.bytecodeviewer.searching.RegexInsnFinder;
import the.bytecode.club.bytecodeviewer.searching.impl.LDCSearch;
import the.bytecode.club.bytecodeviewer.searching.impl.RegexSearch;
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
@ -38,12 +38,10 @@ import java.util.regex.PatternSyntaxException;
class PerformSearch extends BackgroundSearchThread
{
private final SearchBoxPane searchBoxPane;
private final SearchResultNotifier srn;
public PerformSearch(SearchBoxPane searchBoxPane, SearchResultNotifier srn)
public PerformSearch(SearchBoxPane searchBoxPane)
{
this.searchBoxPane = searchBoxPane;
this.srn = srn;
}
@Override
@ -51,7 +49,8 @@ class PerformSearch extends BackgroundSearchThread
{
try
{
Pattern.compile(RegexInsnFinder.processRegex(RegexSearch.searchText.getText()), Pattern.MULTILINE);
if(RegexSearch.searchText != null)
Pattern.compile(RegexInsnFinder.processRegex(RegexSearch.searchText.getText()), Pattern.MULTILINE);
}
catch (PatternSyntaxException ex)
{
@ -59,8 +58,9 @@ class PerformSearch extends BackgroundSearchThread
}
for (ResourceContainer container : BytecodeViewer.resourceContainers.values())
for (ClassNode c : container.resourceClasses.values())
searchBoxPane.searchType.details.search(container, c, srn, searchBoxPane.exact.isSelected());
container.resourceClasses.forEach((key,cn)->{
searchBoxPane.searchType.panel.search(container, key, cn, searchBoxPane.exact.isSelected());
});
BytecodeViewer.viewer.searchBoxPane.search.setEnabled(true);
BytecodeViewer.viewer.searchBoxPane.search.setText(TranslatedStrings.SEARCH.toString());

View file

@ -18,7 +18,7 @@ import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer;
import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread;
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents;
import the.bytecode.club.bytecodeviewer.translation.components.*;
@ -49,8 +49,6 @@ import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
* @author WaterWolf
* @since 09/29/2011
*/
@SuppressWarnings("rawtypes")
public class SearchBoxPane extends TranslatedVisibleComponent
{
public static final SearchRadius[] SEARCH_RADII = SearchRadius.values();
@ -59,7 +57,7 @@ public class SearchBoxPane extends TranslatedVisibleComponent
public final JCheckBox exact = new TranslatedJCheckBox("Exact", TranslatedComponents.EXACT);
public final TranslatedDefaultMutableTreeNode treeRoot = new TranslatedDefaultMutableTreeNode("Results", TranslatedComponents.RESULTS);
public final JTree tree;
public final JComboBox typeBox;
public final JComboBox<SearchType> typeBox;
public SearchType searchType = null;
public final JComboBox searchRadiusBox;
@ -91,13 +89,13 @@ public class SearchBoxPane extends TranslatedVisibleComponent
for (final SearchType st : SEARCH_TYPES)
model.addElement(st);
typeBox = new JComboBox(model);
typeBox = new JComboBox<SearchType>(model);
final JPanel searchOptPanel = new JPanel();
final ItemListener il = arg0 -> {
searchOptPanel.removeAll();
searchType = (SearchType) typeBox.getSelectedItem();
searchOptPanel.add(Objects.requireNonNull(searchType).details.getPanel());
searchOptPanel.add(Objects.requireNonNull(searchType).panel.getPanel());
searchOptPanel.revalidate();
searchOptPanel.repaint();
@ -138,18 +136,11 @@ public class SearchBoxPane extends TranslatedVisibleComponent
if (selectionEvent.getPath().getPathComponent(0).equals(TranslatedStrings.RESULTS))
return;
selectionEvent.getPath().getPathComponent(1);
LDCSearchTreeNodeResult result = (LDCSearchTreeNodeResult) tree.getLastSelectedPathComponent();
String path = selectionEvent.getPath().getPathComponent(1).toString();
final String name = result.resourceWorkingName;
String containerName = path.split(">", 2)[0];
String className = path.split(">", 2)[1].split("\\.")[0];
ResourceContainer container = BytecodeViewer.getFileContainer(containerName);
final ClassNode fN = Objects.requireNonNull(container).getClassNode(className);
if (fN != null)
BytecodeViewer.viewer.workPane.addClassResource(container, className + ".class");
BytecodeViewer.viewer.workPane.addClassResource(result.container, name);
}
catch (Exception e)
{
@ -166,7 +157,6 @@ public class SearchBoxPane extends TranslatedVisibleComponent
treeRoot.removeAllChildren();
searchType = (SearchType) typeBox.getSelectedItem();
final SearchRadius radius = (SearchRadius) searchRadiusBox.getSelectedItem();
final SearchResultNotifier srn = debug -> treeRoot.add(new DefaultMutableTreeNode(debug));
if (radius == SearchRadius.All_Classes)
{
@ -175,7 +165,7 @@ public class SearchBoxPane extends TranslatedVisibleComponent
BytecodeViewer.viewer.searchBoxPane.search.setEnabled(false);
BytecodeViewer.viewer.searchBoxPane.search.setText("Searching, please wait..");
performSearchThread = new PerformSearch(this, srn);
performSearchThread = new PerformSearch(this);
performSearchThread.start();
}
else
@ -188,7 +178,7 @@ public class SearchBoxPane extends TranslatedVisibleComponent
final ResourceViewer cv = BytecodeViewer.getActiveResource();
if (cv != null)
searchType.details.search(cv.resource.container, cv.resource.getResourceClassNode(), srn, exact.isSelected());
searchType.panel.search(cv.resource.container, cv.resource.workingName, cv.resource.getResourceClassNode(), exact.isSelected());
}
}

View file

@ -1,6 +1,6 @@
package the.bytecode.club.bytecodeviewer.gui.resourcesearch;
import the.bytecode.club.bytecodeviewer.searching.*;
import the.bytecode.club.bytecodeviewer.searching.SearchPanel;
import the.bytecode.club.bytecodeviewer.searching.impl.FieldCallSearch;
import the.bytecode.club.bytecodeviewer.searching.impl.LDCSearch;
import the.bytecode.club.bytecodeviewer.searching.impl.MethodCallSearch;
@ -33,12 +33,13 @@ public enum SearchType
Strings(new LDCSearch()),
Regex(new RegexSearch()),
MethodCall(new MethodCallSearch()),
FieldCall(new FieldCallSearch());
FieldCall(new FieldCallSearch()),
;
public final SearchTypeDetails details;
public final SearchPanel panel;
SearchType(final SearchTypeDetails details)
SearchType(final SearchPanel panel)
{
this.details = details;
this.panel = panel;
}
}

View file

@ -69,6 +69,7 @@ public class Workspace extends TranslatedVisibleComponent
if (index != -1)
tabs.remove(index);
});
closeAllTabs.addActionListener(e ->
{
TabExitButton tabExitButton = (TabExitButton) ((JPopupMenu)((JMenuItem) e.getSource()).getParent()).getInvoker();

View file

@ -1,5 +1,12 @@
package the.bytecode.club.bytecodeviewer.searching;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
import javax.swing.tree.DefaultMutableTreeNode;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
@ -19,13 +26,24 @@ package the.bytecode.club.bytecodeviewer.searching;
***************************************************************************/
/**
* Used to update the search pane that there's been a result found.
*
* @author Konloch
* @author WaterWolf
* @since 09/26/2011
* @since 7/29/2021
*/
public class LDCSearchTreeNodeResult extends DefaultMutableTreeNode
{
public final ResourceContainer container;
public final String resourceWorkingName;
public final String ldc;
public final String ldcType;
public interface SearchResultNotifier {
void notifyOfResult(String debug);
public LDCSearchTreeNodeResult(ResourceContainer container, String resourceWorkingName,
ClassNode cn, MethodNode method, FieldNode field,
String ldc, String ldcType)
{
super("'"+ldc+"' -> " + cn.name);
this.container = container;
this.resourceWorkingName = resourceWorkingName;
this.ldc = ldc;
this.ldcType = ldcType;
}
}

View file

@ -1,9 +1,10 @@
package the.bytecode.club.bytecodeviewer.searching;
import javax.swing.JPanel;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
import javax.swing.*;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
@ -23,16 +24,13 @@ import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
***************************************************************************/
/**
* Search type details
*
* @author Konloch
* @author WaterWolf
* @since 09/26/2011
*/
public interface SearchTypeDetails
public interface SearchPanel
{
JPanel getPanel();
JPanel getPanel();
void search(ResourceContainer container, ClassNode node, SearchResultNotifier srn, boolean exact);
void search(ResourceContainer container, String resourceWorkingName, ClassNode node, boolean exact);
}

View file

@ -7,7 +7,6 @@ import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
/***************************************************************************
@ -38,8 +37,7 @@ import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
public class FieldCallSearch extends MethodCallSearch
{
@Override
public void search(final ResourceContainer container, final ClassNode node, final SearchResultNotifier srn,
boolean exact)
public void search(ResourceContainer container, String resourceWorkingName, ClassNode node, boolean exact)
{
final Iterator<MethodNode> methods = node.methods.iterator();
@ -88,7 +86,7 @@ public class FieldCallSearch extends MethodCallSearch
continue;
}
found(container, node, method, insnNode, srn);
found(container, resourceWorkingName, node, method, insnNode);
}
}
}

View file

@ -4,16 +4,17 @@ import java.awt.GridLayout;
import java.util.Iterator;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.searching.EnterKeyEvent;
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
import the.bytecode.club.bytecodeviewer.searching.SearchTypeDetails;
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
import the.bytecode.club.bytecodeviewer.searching.SearchPanel;
import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents;
import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJLabel;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
@ -44,7 +45,7 @@ import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
* @since 09/29/2011
*/
public class LDCSearch implements SearchTypeDetails
public class LDCSearch implements SearchPanel
{
JTextField searchText;
JPanel myPanel = null;
@ -68,8 +69,7 @@ public class LDCSearch implements SearchTypeDetails
return myPanel;
}
@Override
public void search(final ResourceContainer container, final ClassNode node, final SearchResultNotifier srn,
public void search(final ResourceContainer container, final String resourceWorkingName, final ClassNode node,
boolean caseSensitive)
{
final Iterator<MethodNode> methods = node.methods.iterator();
@ -90,13 +90,6 @@ public class LDCSearch implements SearchTypeDetails
{
final LdcInsnNode ldcObject = ((LdcInsnNode) insnNode);
final String ldcString = ldcObject.cst.toString();
String desc2 = method.desc;
try
{
desc2 = Type.getType(method.desc).toString();
if (desc2.equals("null"))
desc2 = method.desc;
} catch (ArrayIndexOutOfBoundsException ignored) { }
//TODO re-add this at some point when the search pane is redone
boolean exact = false;
@ -107,10 +100,15 @@ public class LDCSearch implements SearchTypeDetails
if (anyMatch)
{
srn.notifyOfResult(container.name + ">" + node.name + "." + method.name
+ desc2
+ " -> \"" + ldcString + "\" > "
+ ldcObject.cst.getClass().getCanonicalName());
BytecodeViewer.viewer.searchBoxPane.treeRoot.add(new LDCSearchTreeNodeResult(
container,
resourceWorkingName,
node,
method,
null,
ldcString,
ldcObject.cst.getClass().getCanonicalName()
));
}
}
}
@ -120,20 +118,17 @@ public class LDCSearch implements SearchTypeDetails
while (methods.hasNext())
{
final FieldNode field = fields.next();
String desc2 = field.desc;
try
{
desc2 = Type.getType(field.desc).toString();
if (desc2.equals("null"))
desc2 = field.desc;
} catch (java.lang.ArrayIndexOutOfBoundsException ignored) { }
if (field.value instanceof String)
{
srn.notifyOfResult(container.name + ">" + node.name + "." + field.name + desc2
+ " -> \"" + field.value + "\" > field");
BytecodeViewer.viewer.resourcePane.treeRoot.add(new LDCSearchTreeNodeResult(container,
resourceWorkingName,
node,
null,
field,
String.valueOf(field.value),
field.value.getClass().getCanonicalName()
));
}
}
}

View file

@ -12,9 +12,10 @@ import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.searching.EnterKeyEvent;
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
import the.bytecode.club.bytecodeviewer.searching.SearchTypeDetails;
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
import the.bytecode.club.bytecodeviewer.searching.SearchPanel;
import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents;
import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJLabel;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
@ -45,7 +46,7 @@ import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
* @since 09/29/2011
*/
public class MethodCallSearch implements SearchTypeDetails
public class MethodCallSearch implements SearchPanel
{
JTextField mOwner;
JTextField mName;
@ -62,7 +63,6 @@ public class MethodCallSearch implements SearchTypeDetails
mDesc.addKeyListener(EnterKeyEvent.SINGLETON);
}
@Override
public JPanel getPanel()
{
if (myPanel == null)
@ -80,8 +80,7 @@ public class MethodCallSearch implements SearchTypeDetails
}
@Override
public void search(final ResourceContainer container, final ClassNode node, final SearchResultNotifier srn,
boolean exact)
public void search(ResourceContainer container, String resourceWorkingName, ClassNode node, boolean exact)
{
final Iterator<MethodNode> methods = node.methods.iterator();
@ -130,29 +129,22 @@ public class MethodCallSearch implements SearchTypeDetails
continue;
}
found(container, node, method, insnNode, srn);
found(container, resourceWorkingName, node, method, insnNode);
}
}
}
}
public void found(final ResourceContainer container, final ClassNode node, final MethodNode method, final AbstractInsnNode insnNode, final SearchResultNotifier srn)
public void found(final ResourceContainer container, final String resourceWorkingName, final ClassNode node, final MethodNode method, final AbstractInsnNode insnNode)
{
String desc = method.desc;
try
{
desc = Type.getType(method.desc).toString();
if (desc.equals("null"))
desc = method.desc;
} catch (ArrayIndexOutOfBoundsException ignored) { }
srn.notifyOfResult(container.name + ">" + node.name
+ "."
+ method.name
+ desc
+ " > "
+ OpcodeInfo.OPCODES.get(insnNode.getOpcode())
.toLowerCase());
BytecodeViewer.viewer.searchBoxPane.treeRoot.add(new LDCSearchTreeNodeResult(
container,
resourceWorkingName,
node,
method,
null,
OpcodeInfo.OPCODES.get(insnNode.getOpcode()).toLowerCase(),
""
));
}
}

View file

@ -5,13 +5,16 @@ import java.util.Iterator;
import java.util.regex.Pattern;
import javax.swing.JPanel;
import javax.swing.JTextField;
import eu.bibl.banalysis.asm.desc.OpcodeInfo;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.searching.EnterKeyEvent;
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
import the.bytecode.club.bytecodeviewer.searching.RegexInsnFinder;
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
import the.bytecode.club.bytecodeviewer.searching.SearchTypeDetails;
import the.bytecode.club.bytecodeviewer.searching.SearchPanel;
import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents;
import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJLabel;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
@ -44,7 +47,7 @@ import static the.bytecode.club.bytecodeviewer.searching.RegexInsnFinder.process
* @since 09/29/2011
*/
public class RegexSearch implements SearchTypeDetails
public class RegexSearch implements SearchPanel
{
public static JTextField searchText;
JPanel myPanel = null;
@ -69,8 +72,7 @@ public class RegexSearch implements SearchTypeDetails
}
@Override
public void search(final ResourceContainer container, final ClassNode node, final SearchResultNotifier srn,
boolean exact)
public void search(final ResourceContainer container, final String resourceWorkingName, final ClassNode node, boolean exact)
{
final Iterator<MethodNode> methods = node.methods.iterator();
final String srchText = searchText.getText();
@ -94,7 +96,15 @@ public class RegexSearch implements SearchTypeDetails
desc2 = method.desc;
} catch (java.lang.ArrayIndexOutOfBoundsException ignored) {}
srn.notifyOfResult(container.name + ">" + node.name + "." + method.name + desc2);
BytecodeViewer.viewer.searchBoxPane.treeRoot.add(new LDCSearchTreeNodeResult(
container,
resourceWorkingName,
node,
method,
null,
node.name + "." + method.name + desc2,
""
));
}
}
}