Example usage for org.objectweb.asm.tree InsnList iterator

List of usage examples for org.objectweb.asm.tree InsnList iterator

Introduction

In this page you can find the example usage for org.objectweb.asm.tree InsnList iterator.

Prototype

@Override
public ListIterator<AbstractInsnNode> iterator() 

Source Link

Document

Returns an iterator over the instructions in this list.

Usage

From source file:the.bytecode.club.bytecodeviewer.searching.LDCSearch.java

License:Open Source License

@Override
public void search(final ClassNode node, final SearchResultNotifier srn, boolean exact) {
    final Iterator<MethodNode> methods = node.methods.iterator();
    final String srchText = searchText.getText();
    if (srchText.isEmpty())
        return;/*  w  ww .j a  va 2 s  .  co  m*/
    while (methods.hasNext()) {
        final MethodNode method = methods.next();

        final InsnList insnlist = method.instructions;
        final ListIterator<AbstractInsnNode> instructions = insnlist.iterator();
        while (instructions.hasNext()) {
            final AbstractInsnNode insnNode = instructions.next();
            if (insnNode instanceof LdcInsnNode) {
                final LdcInsnNode ldcObject = ((LdcInsnNode) insnNode);
                final String ldcString = ldcObject.cst.toString();
                String desc2 = method.desc;
                try {
                    desc2 = Type.getType(method.desc).toString();
                    if (desc2 == null || desc2.equals("null"))
                        desc2 = method.desc;
                } catch (java.lang.ArrayIndexOutOfBoundsException e) {

                }
                if ((exact && ldcString.equals(srchText)) || (!exact && ldcString.contains(srchText))) {
                    srn.notifyOfResult(node.name + "." + method.name + desc2 + " -> \"" + ldcString + "\" > "
                            + ldcObject.cst.getClass().getCanonicalName());
                }
            }
        }

    }
    final Iterator<FieldNode> fields = node.fields.iterator();
    while (methods.hasNext()) {
        final FieldNode field = fields.next();
        String desc2 = field.desc;
        try {
            desc2 = Type.getType(field.desc).toString();
            if (desc2 == null || desc2.equals("null"))
                desc2 = field.desc;
        } catch (java.lang.ArrayIndexOutOfBoundsException e) {

        }
        if (field.value instanceof String) {
            srn.notifyOfResult(node.name + "." + field.name + desc2 + " -> \"" + field.value + "\" > field");
        }
    }

}

From source file:the.bytecode.club.bytecodeviewer.searching.MethodCallSearch.java

License:Open Source License

@Override
public void search(final ClassNode node, final SearchResultNotifier srn, boolean exact) {
    final Iterator<MethodNode> methods = node.methods.iterator();
    String owner = mOwner.getText();
    if (owner.isEmpty()) {
        owner = null;//from   www.ja  v  a2s  .  c o m
    }
    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;
        final ListIterator<AbstractInsnNode> instructions = insnlist.iterator();
        while (instructions.hasNext()) {
            final AbstractInsnNode insnNode = instructions.next();
            if (insnNode instanceof MethodInsnNode) {
                final MethodInsnNode min = (MethodInsnNode) 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 == null || desc2.equals("null"))
                            desc2 = method.desc;
                    } catch (java.lang.ArrayIndexOutOfBoundsException e) {

                    }
                    srn.notifyOfResult(node.name + "." + method.name + desc2 + " > "
                            + OpcodeInfo.OPCODES.get(insnNode.opcode()).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 == null || desc2.equals("null"))
                            desc2 = method.desc;
                    } catch (java.lang.ArrayIndexOutOfBoundsException e) {

                    }
                    srn.notifyOfResult(node.name + "." + method.name + desc2 + " > "
                            + OpcodeInfo.OPCODES.get(insnNode.opcode()).toLowerCase());
                }
            }
        }

    }
}

From source file:the.bytecode.club.bytecodeviewer.searching.RegexInsnFinder.java

License:Open Source License

private AbstractInsnNode[] cleanInsn(final InsnList insnList) {
    final List<AbstractInsnNode> il = new ArrayList<AbstractInsnNode>();

    final Iterator<AbstractInsnNode> iIt = insnList.iterator();
    while (iIt.hasNext()) {
        final AbstractInsnNode node = iIt.next();
        if (node.opcode() >= 0) {
            il.add(node);//w  w w.  j  av a2 s. c  o m
        }
    }
    return il.toArray(new AbstractInsnNode[il.size()]);
}