Search Cleanup

This commit is contained in:
Konloch 2021-07-04 00:03:40 -07:00
parent 0c53463fd7
commit 4c0bffd40d
12 changed files with 286 additions and 284 deletions

View File

@ -5,7 +5,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI;
import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread;
import the.bytecode.club.bytecodeviewer.searching.RegexInsnFinder;
import the.bytecode.club.bytecodeviewer.searching.RegexSearch;
import the.bytecode.club.bytecodeviewer.searching.impl.RegexSearch;
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
import the.bytecode.club.bytecodeviewer.util.FileContainer;
@ -30,7 +30,7 @@ class PerformSearch extends BackgroundSearchThread
}
@Override
public void doSearch()
public void search()
{
try
{

View File

@ -49,6 +49,7 @@ import the.bytecode.club.bytecodeviewer.util.FileContainer;
*
* @author Konloch
* @author WaterWolf
* @since 09/29/2011
*/
@SuppressWarnings("rawtypes")
@ -69,7 +70,7 @@ public class SearchBoxPane extends VisibleComponent
public JButton search = new JButton("Search");
BackgroundSearchThread t = new BackgroundSearchThread(true) {
@Override
public void doSearch() {
public void search() {
// empty
}
};

View File

@ -1,6 +1,10 @@
package the.bytecode.club.bytecodeviewer.gui.resourcesearch;
import the.bytecode.club.bytecodeviewer.searching.*;
import the.bytecode.club.bytecodeviewer.searching.impl.FieldCallSearch;
import the.bytecode.club.bytecodeviewer.searching.impl.LDCSearch;
import the.bytecode.club.bytecodeviewer.searching.impl.MethodCallSearch;
import the.bytecode.club.bytecodeviewer.searching.impl.RegexSearch;
/**
* @author Konloch

View File

@ -26,11 +26,9 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer;
* @author Konloch
*/
public abstract class BackgroundSearchThread extends Thread {
public BackgroundSearchThread() {
}
public abstract class BackgroundSearchThread extends Thread
{
public BackgroundSearchThread() { }
public BackgroundSearchThread(boolean finished) {
this.finished = finished;
@ -38,12 +36,13 @@ public abstract class BackgroundSearchThread extends Thread {
public boolean finished = false;
public abstract void doSearch();
public abstract void search();
@Override
public void run() {
public void run()
{
BytecodeViewer.viewer.updateBusyStatus(true);
doSearch();
search();
finished = true;
BytecodeViewer.viewer.updateBusyStatus(false);
}

View File

@ -4,22 +4,45 @@ import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
public class EnterKeyEvent implements KeyListener {
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
/**
* searchBoxPane search triggering via enter key
*
* @author Konloch
* @author WaterWolf
* @since 09/26/2011
*/
public class EnterKeyEvent implements KeyListener
{
public static final EnterKeyEvent SINGLETON = new EnterKeyEvent();
@Override
public void keyTyped(KeyEvent e) {
}
public void keyTyped(KeyEvent e) { }
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if (e.getKeyCode() == KeyEvent.VK_ENTER)
BytecodeViewer.viewer.searchBoxPane.search();
}
}
@Override
public void keyReleased(KeyEvent e) {
}
}
public void keyReleased(KeyEvent e) { }
}

View File

@ -1,155 +0,0 @@
package the.bytecode.club.bytecodeviewer.searching;
import eu.bibl.banalysis.asm.desc.OpcodeInfo;
import java.awt.GridLayout;
import java.util.Iterator;
import javax.swing.JLabel;
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.FieldInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.util.FileContainer;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
/**
* Field call searching
*
* @author Konloch
* @author Water Wolf
*/
public class FieldCallSearch implements SearchTypeDetails {
JTextField mOwner;
JTextField mName;
JTextField mDesc;
JPanel myPanel = null;
public FieldCallSearch() {
mOwner = new JTextField("");
mOwner.addKeyListener(EnterKeyEvent.SINGLETON);
mName = new JTextField("");
mName.addKeyListener(EnterKeyEvent.SINGLETON);
mDesc = new JTextField("");
mDesc.addKeyListener(EnterKeyEvent.SINGLETON);
}
@Override
public JPanel getPanel() {
if (myPanel == null) {
myPanel = new JPanel(new GridLayout(3, 2));
myPanel.add(new JLabel("Owner: "));
myPanel.add(mOwner);
myPanel.add(new JLabel("Name: "));
myPanel.add(mName);
myPanel.add(new JLabel("Desc: "));
myPanel.add(mDesc);
}
return myPanel;
}
@Override
public void search(final FileContainer container, final ClassNode node, final SearchResultNotifier srn,
boolean exact) {
final Iterator<MethodNode> methods = node.methods.iterator();
String owner = mOwner.getText();
if (owner.isEmpty()) {
owner = null;
}
String name = mName.getText();
if (name.isEmpty()) {
name = null;
}
String desc = mDesc.getText();
if (desc.isEmpty()) {
desc = null;
}
while (methods.hasNext()) {
final MethodNode method = methods.next();
final InsnList insnlist = method.instructions;
for (AbstractInsnNode insnNode : insnlist) {
if (insnNode instanceof FieldInsnNode) {
final FieldInsnNode min = (FieldInsnNode) insnNode;
if (name == null && owner == null && desc == null)
continue;
if (exact) {
if (name != null && !name.equals(min.name)) {
continue;
}
if (owner != null && !owner.equals(min.owner)) {
continue;
}
if (desc != null && !desc.equals(min.desc)) {
continue;
}
String desc2 = method.desc;
try {
desc2 = Type.getType(method.desc).toString();
if (desc2.equals("null"))
desc2 = method.desc;
} catch (ArrayIndexOutOfBoundsException ignored) {
}
srn.notifyOfResult(container.name + ">" + node.name
+ "."
+ method.name
+ desc2
+ " > "
+ OpcodeInfo.OPCODES.get(insnNode.getOpcode())
.toLowerCase());
} else {
if (name != null && !min.name.contains(name)) {
continue;
}
if (owner != null && !min.owner.contains(owner)) {
continue;
}
if (desc != null && !min.desc.contains(desc)) {
continue;
}
String desc2 = method.desc;
try {
desc2 = Type.getType(method.desc).toString();
if (desc2.equals("null"))
desc2 = method.desc;
} catch (ArrayIndexOutOfBoundsException ignored) {
}
srn.notifyOfResult(container.name + ">" + node.name
+ "."
+ method.name
+ desc2
+ " > "
+ OpcodeInfo.OPCODES.get(insnNode.getOpcode())
.toLowerCase());
}
}
}
}
}
}

View File

@ -23,6 +23,7 @@ package the.bytecode.club.bytecodeviewer.searching;
*
* @author Konloch
* @author WaterWolf
* @since 09/26/2011
*/
public interface SearchResultNotifier {

View File

@ -25,11 +25,14 @@ import the.bytecode.club.bytecodeviewer.util.FileContainer;
/**
* Search type details
*
* @author Konloch
* @author WaterWolf
* @since 09/26/2011
*/
public interface SearchTypeDetails {
public interface SearchTypeDetails
{
JPanel getPanel();
void search(FileContainer container, ClassNode node, SearchResultNotifier srn, boolean exact);
}

View File

@ -0,0 +1,96 @@
package the.bytecode.club.bytecodeviewer.searching.impl;
import java.util.Iterator;
import org.objectweb.asm.tree.AbstractInsnNode;
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.util.FileContainer;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
/**
* Field call searching
*
* @author Konloch
* @author Water Wolf
*/
public class FieldCallSearch extends MethodCallSearch
{
@Override
public void search(final FileContainer container, final ClassNode node, final SearchResultNotifier srn,
boolean exact)
{
final Iterator<MethodNode> methods = node.methods.iterator();
String searchOwner = mOwner.getText();
if (searchOwner.isEmpty())
searchOwner = null;
String searchName = mName.getText();
if (searchName.isEmpty())
searchName = null;
String searchDesc = mDesc.getText();
if (searchDesc.isEmpty())
searchDesc = null;
while (methods.hasNext())
{
final MethodNode method = methods.next();
final InsnList insnlist = method.instructions;
for (AbstractInsnNode insnNode : insnlist)
{
if (insnNode instanceof FieldInsnNode)
{
final FieldInsnNode min = (FieldInsnNode) insnNode;
if (searchName == null && searchOwner == null && searchDesc == null)
continue;
if (exact)
{
if (searchName != null && !searchName.equals(min.name))
continue;
if (searchOwner != null && !searchOwner.equals(min.owner))
continue;
if (searchDesc != null && !searchDesc.equals(min.desc))
continue;
}
else
{
if (searchName != null && !min.name.contains(searchName))
continue;
if (searchOwner != null && !min.owner.contains(searchOwner))
continue;
if (searchDesc != null && !min.desc.contains(searchDesc))
continue;
}
found(container, node, method, insnNode, srn);
}
}
}
}
}

View File

@ -1,4 +1,4 @@
package the.bytecode.club.bytecodeviewer.searching;
package the.bytecode.club.bytecodeviewer.searching.impl;
import java.awt.GridLayout;
import java.util.Iterator;
@ -12,6 +12,9 @@ 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.searching.EnterKeyEvent;
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
import the.bytecode.club.bytecodeviewer.searching.SearchTypeDetails;
import the.bytecode.club.bytecodeviewer.util.FileContainer;
/***************************************************************************
@ -37,21 +40,25 @@ import the.bytecode.club.bytecodeviewer.util.FileContainer;
*
* @author Konloch
* @author WaterWolf
* @since 09/29/2011
*/
public class LDCSearch implements SearchTypeDetails {
public class LDCSearch implements SearchTypeDetails
{
JTextField searchText;
JPanel myPanel = null;
public LDCSearch() {
public LDCSearch()
{
searchText = new JTextField("");
searchText.addKeyListener(EnterKeyEvent.SINGLETON);
}
@Override
public JPanel getPanel() {
if (myPanel == null) {
public JPanel getPanel()
{
if (myPanel == null)
{
myPanel = new JPanel(new GridLayout(1, 2));
myPanel.add(new JLabel("Search String: "));
myPanel.add(searchText);
@ -62,29 +69,35 @@ public class LDCSearch implements SearchTypeDetails {
@Override
public void search(final FileContainer container, final ClassNode node, final SearchResultNotifier srn,
boolean exact) {
boolean exact)
{
final Iterator<MethodNode> methods = node.methods.iterator();
final String srchText = searchText.getText();
if (srchText.isEmpty())
return;
while (methods.hasNext()) {
while (methods.hasNext())
{
final MethodNode method = methods.next();
final InsnList insnlist = method.instructions;
for (AbstractInsnNode insnNode : insnlist) {
if (insnNode instanceof LdcInsnNode) {
for (AbstractInsnNode insnNode : insnlist)
{
if (insnNode instanceof LdcInsnNode)
{
final LdcInsnNode ldcObject = ((LdcInsnNode) insnNode);
final String ldcString = ldcObject.cst.toString();
String desc2 = method.desc;
try {
try
{
desc2 = Type.getType(method.desc).toString();
if (desc2.equals("null"))
desc2 = method.desc;
} catch (ArrayIndexOutOfBoundsException ignored) {
} catch (ArrayIndexOutOfBoundsException ignored) { }
}
if ((exact && ldcString.equals(srchText)) || (!exact && ldcString.contains(srchText))) {
if ((exact && ldcString.equals(srchText)) || (!exact && ldcString.contains(srchText)))
{
srn.notifyOfResult(container.name + ">" + node.name + "." + method.name
+ desc2
+ " -> \"" + ldcString + "\" > "
@ -93,21 +106,26 @@ public class LDCSearch implements SearchTypeDetails {
}
}
}
final Iterator<FieldNode> fields = node.fields.iterator();
while (methods.hasNext()) {
while (methods.hasNext())
{
final FieldNode field = fields.next();
String desc2 = field.desc;
try {
try
{
desc2 = Type.getType(field.desc).toString();
if (desc2.equals("null"))
desc2 = field.desc;
} catch (java.lang.ArrayIndexOutOfBoundsException ignored) {
}
if (field.value instanceof String) {
} catch (java.lang.ArrayIndexOutOfBoundsException ignored) { }
if (field.value instanceof String)
{
srn.notifyOfResult(container.name + ">" + node.name + "." + field.name + desc2
+ " -> \"" + field.value + "\" > field");
}
}
}
}
}

View File

@ -1,4 +1,4 @@
package the.bytecode.club.bytecodeviewer.searching;
package the.bytecode.club.bytecodeviewer.searching.impl;
import eu.bibl.banalysis.asm.desc.OpcodeInfo;
import java.awt.GridLayout;
@ -12,6 +12,9 @@ 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.searching.EnterKeyEvent;
import the.bytecode.club.bytecodeviewer.searching.SearchResultNotifier;
import the.bytecode.club.bytecodeviewer.searching.SearchTypeDetails;
import the.bytecode.club.bytecodeviewer.util.FileContainer;
/***************************************************************************
@ -37,16 +40,18 @@ import the.bytecode.club.bytecodeviewer.util.FileContainer;
*
* @author Konloch
* @author WaterWolf
* @since 09/29/2011
*/
public class MethodCallSearch implements SearchTypeDetails {
public class MethodCallSearch implements SearchTypeDetails
{
JTextField mOwner;
JTextField mName;
JTextField mDesc;
JPanel myPanel = null;
public MethodCallSearch() {
public MethodCallSearch()
{
mOwner = new JTextField("");
mOwner.addKeyListener(EnterKeyEvent.SINGLETON);
mName = new JTextField("");
@ -56,8 +61,10 @@ public class MethodCallSearch implements SearchTypeDetails {
}
@Override
public JPanel getPanel() {
if (myPanel == null) {
public JPanel getPanel()
{
if (myPanel == null)
{
myPanel = new JPanel(new GridLayout(3, 2));
myPanel.add(new JLabel("Owner: "));
myPanel.add(mOwner);
@ -72,83 +79,78 @@ public class MethodCallSearch implements SearchTypeDetails {
@Override
public void search(final FileContainer container, final ClassNode node, final SearchResultNotifier srn,
boolean exact) {
boolean exact)
{
final Iterator<MethodNode> methods = node.methods.iterator();
String owner = mOwner.getText();
if (owner.isEmpty()) {
owner = null;
}
String name = mName.getText();
if (name.isEmpty()) {
name = null;
}
String desc = mDesc.getText();
if (desc.isEmpty()) {
desc = null;
}
String searchOwner = mOwner.getText();
if (searchOwner.isEmpty())
searchOwner = null;
String searchName = mName.getText();
if (searchName.isEmpty())
searchName = null;
String searchDesc = mDesc.getText();
if (searchDesc.isEmpty())
searchDesc = null;
while (methods.hasNext()) {
while (methods.hasNext())
{
final MethodNode method = methods.next();
final InsnList insnlist = method.instructions;
for (AbstractInsnNode insnNode : insnlist) {
if (insnNode instanceof MethodInsnNode) {
for (AbstractInsnNode insnNode : insnlist)
{
if (insnNode instanceof MethodInsnNode)
{
final MethodInsnNode min = (MethodInsnNode) insnNode;
if (name == null && owner == null && desc == null)
if (searchName == null && searchOwner == null && searchDesc == null)
continue;
if (exact) {
if (name != null && !name.equals(min.name)) {
if (exact)
{
if (searchName != null && !searchName.equals(min.name))
continue;
}
if (owner != null && !owner.equals(min.owner)) {
if (searchOwner != null && !searchOwner.equals(min.owner))
continue;
}
if (desc != null && !desc.equals(min.desc)) {
if (searchDesc != null && !searchDesc.equals(min.desc))
continue;
}
String desc2 = method.desc;
try {
desc2 = Type.getType(method.desc).toString();
if (desc2.equals("null"))
desc2 = method.desc;
} catch (ArrayIndexOutOfBoundsException ignored) {
}
srn.notifyOfResult(container.name + ">" + node.name
+ "."
+ method.name
+ desc2
+ " > "
+ OpcodeInfo.OPCODES.get(insnNode.getOpcode())
.toLowerCase());
} else {
if (name != null && !min.name.contains(name)) {
continue;
}
if (owner != null && !min.owner.contains(owner)) {
continue;
}
if (desc != null && !min.desc.contains(desc)) {
continue;
}
String desc2 = method.desc;
try {
desc2 = Type.getType(method.desc).toString();
if (desc2.equals("null"))
desc2 = method.desc;
} catch (ArrayIndexOutOfBoundsException ignored) {
}
srn.notifyOfResult(container.name + ">" + node.name
+ "."
+ method.name
+ desc2
+ " > "
+ OpcodeInfo.OPCODES.get(insnNode.getOpcode())
.toLowerCase());
}
else
{
if (searchName != null && !min.name.contains(searchName))
continue;
if (searchOwner != null && !min.owner.contains(searchOwner))
continue;
if (searchDesc != null && !min.desc.contains(searchDesc))
continue;
}
found(container, node, method, insnNode, srn);
}
}
}
}
public void found(final FileContainer container, final ClassNode node, final MethodNode method, final AbstractInsnNode insnNode, final SearchResultNotifier srn)
{
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());
}
}

View File

@ -1,4 +1,4 @@
package the.bytecode.club.bytecodeviewer.searching;
package the.bytecode.club.bytecodeviewer.searching.impl;
import java.awt.GridLayout;
import java.util.Iterator;
@ -9,6 +9,10 @@ import javax.swing.JTextField;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.searching.EnterKeyEvent;
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.util.FileContainer;
import static the.bytecode.club.bytecodeviewer.searching.RegexInsnFinder.processRegex;
@ -36,21 +40,25 @@ import static the.bytecode.club.bytecodeviewer.searching.RegexInsnFinder.process
*
* @author Konloch
* @author WaterWolf
* @since 09/29/2011
*/
public class RegexSearch implements SearchTypeDetails {
public class RegexSearch implements SearchTypeDetails
{
public static JTextField searchText;
JPanel myPanel = null;
public RegexSearch() {
public RegexSearch()
{
searchText = new JTextField("");
searchText.addKeyListener(EnterKeyEvent.SINGLETON);
}
@Override
public JPanel getPanel() {
if (myPanel == null) {
public JPanel getPanel()
{
if (myPanel == null)
{
myPanel = new JPanel(new GridLayout(1, 2));
myPanel.add(new JLabel("Search Regex: "));
myPanel.add(searchText);
@ -61,27 +69,29 @@ public class RegexSearch implements SearchTypeDetails {
@Override
public void search(final FileContainer container, final ClassNode node, final SearchResultNotifier srn,
boolean exact) {
boolean exact)
{
final Iterator<MethodNode> methods = node.methods.iterator();
final String srchText = searchText.getText();
if (srchText.isEmpty())
return;
Pattern pattern = Pattern.compile(processRegex(srchText),
Pattern.MULTILINE);
while (methods.hasNext()) {
Pattern pattern = Pattern.compile(processRegex(srchText), Pattern.MULTILINE);
while (methods.hasNext())
{
final MethodNode method = methods.next();
if (RegexInsnFinder.staticScan(node, method, pattern)) {
if (RegexInsnFinder.staticScan(node, method, pattern))
{
String desc2 = method.desc;
try {
try
{
desc2 = Type.getType(method.desc).toString();
if (desc2.equals("null"))
desc2 = method.desc;
} catch (java.lang.ArrayIndexOutOfBoundsException ignored) {
}
} catch (java.lang.ArrayIndexOutOfBoundsException ignored) {}
srn.notifyOfResult(container.name + ">" + node.name + "." + method.name + desc2);
}