Search in sources :

Example 1 with LDCSearchTreeNodeResult

use of the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult in project bytecode-viewer by Konloch.

the class LDCSearch method search.

public void search(final ResourceContainer container, final String resourceWorkingName, final ClassNode node, boolean caseSensitive) {
    final Iterator<MethodNode> methods = node.methods.iterator();
    final String srchText = searchText.getText();
    final String srchTextLowerCase = searchText.getText().toLowerCase();
    if (srchText.isEmpty())
        return;
    while (methods.hasNext()) {
        final MethodNode method = methods.next();
        final InsnList insnlist = method.instructions;
        for (AbstractInsnNode insnNode : insnlist) {
            if (insnNode instanceof LdcInsnNode) {
                final LdcInsnNode ldcObject = ((LdcInsnNode) insnNode);
                final String ldcString = ldcObject.cst.toString();
                // TODO re-add this at some point when the search pane is redone
                boolean exact = false;
                final boolean exactMatch = exact && ldcString.equals(srchText);
                final boolean caseInsensitiveMatch = !exact && caseSensitive && ldcString.contains(srchText);
                final boolean caseSensitiveMatch = !exact && !caseSensitive && ldcString.toLowerCase().contains(srchTextLowerCase);
                final boolean anyMatch = exactMatch || caseInsensitiveMatch || caseSensitiveMatch;
                if (anyMatch) {
                    BytecodeViewer.viewer.searchBoxPane.treeRoot.add(new LDCSearchTreeNodeResult(container, resourceWorkingName, node, method, null, ldcString, ldcObject.cst.getClass().getCanonicalName()));
                }
            }
        }
    }
    final Iterator<FieldNode> fields = node.fields.iterator();
    while (methods.hasNext()) {
        final FieldNode field = fields.next();
        if (field.value instanceof String) {
            BytecodeViewer.viewer.resourcePane.treeRoot.add(new LDCSearchTreeNodeResult(container, resourceWorkingName, node, null, field, String.valueOf(field.value), field.value.getClass().getCanonicalName()));
        }
    }
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) FieldNode(org.objectweb.asm.tree.FieldNode) LDCSearchTreeNodeResult(the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult) InsnList(org.objectweb.asm.tree.InsnList) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 2 with LDCSearchTreeNodeResult

use of the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult in project bytecode-viewer by Konloch.

the class RegexSearch method search.

@Override
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();
    if (srchText.isEmpty())
        return;
    Pattern pattern = Pattern.compile(processRegex(srchText), Pattern.MULTILINE);
    while (methods.hasNext()) {
        final MethodNode method = methods.next();
        if (RegexInsnFinder.staticScan(node, method, pattern)) {
            String desc2 = method.desc;
            try {
                desc2 = Type.getType(method.desc).toString();
                if (desc2.equals("null"))
                    desc2 = method.desc;
            } catch (java.lang.ArrayIndexOutOfBoundsException ignored) {
            }
            BytecodeViewer.viewer.searchBoxPane.treeRoot.add(new LDCSearchTreeNodeResult(container, resourceWorkingName, node, method, null, node.name + "." + method.name + desc2, ""));
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) MethodNode(org.objectweb.asm.tree.MethodNode) LDCSearchTreeNodeResult(the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult)

Aggregations

MethodNode (org.objectweb.asm.tree.MethodNode)2 LDCSearchTreeNodeResult (the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult)2 Pattern (java.util.regex.Pattern)1 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)1 FieldNode (org.objectweb.asm.tree.FieldNode)1 InsnList (org.objectweb.asm.tree.InsnList)1 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)1