Class SearchUtils


  • public final class SearchUtils
    extends java.lang.Object
    Utility class to search Java bytecode.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SearchUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.objectweb.asm.tree.FieldNode findField​(org.objectweb.asm.tree.ClassNode classNode, java.lang.String name)
      Find field within a class by its name.
      static java.util.List<org.objectweb.asm.tree.AbstractInsnNode> findInvocationsOf​(org.objectweb.asm.tree.InsnList insnList, java.lang.reflect.Method expectedMethod)
      Find invocations of a certain method.
      static java.util.List<org.objectweb.asm.tree.AbstractInsnNode> findInvocationsWithParameter​(org.objectweb.asm.tree.InsnList insnList, org.objectweb.asm.Type expectedParamType)
      Find invocations of any method where the parameter list contains a type.
      static org.objectweb.asm.tree.LineNumberNode findLineNumberForInstruction​(org.objectweb.asm.tree.InsnList insnList, org.objectweb.asm.tree.AbstractInsnNode insnNode)
      Find line number associated with an instruction.
      static org.objectweb.asm.tree.LocalVariableNode findLocalVariableNodeForInstruction​(java.util.List<org.objectweb.asm.tree.LocalVariableNode> lvnList, org.objectweb.asm.tree.InsnList insnList, org.objectweb.asm.tree.AbstractInsnNode insnNode, int idx)
      Find local variable node for a local variable at some instruction.
      static org.objectweb.asm.tree.MethodNode findMethod​(java.util.Collection<org.objectweb.asm.tree.MethodNode> methodNodes, boolean isStatic, org.objectweb.asm.Type returnType, java.lang.String name, org.objectweb.asm.Type... paramTypes)
      Find a method within a class.
      static java.util.List<org.objectweb.asm.tree.MethodNode> findMethodsWithName​(java.util.Collection<org.objectweb.asm.tree.MethodNode> methodNodes, java.lang.String name)
      Find methods within a class with a specific name.
      static java.util.List<org.objectweb.asm.tree.MethodNode> findMethodsWithParameter​(java.util.Collection<org.objectweb.asm.tree.MethodNode> methodNodes, org.objectweb.asm.Type expectedParamType)
      Find methods within a class where the parameter list contains a certain list of type.
      static java.util.List<org.objectweb.asm.tree.MethodNode> findMethodsWithParameters​(java.util.Collection<org.objectweb.asm.tree.MethodNode> methodNodes, org.objectweb.asm.Type... paramTypes)
      Find methods within a class where the parameter list contains a certain list of type.
      static java.util.List<org.objectweb.asm.tree.MethodNode> findStaticMethods​(java.util.Collection<org.objectweb.asm.tree.MethodNode> methodNodes)
      Find static methods within a class.
      static java.util.List<org.objectweb.asm.tree.TryCatchBlockNode> findTryCatchBlockNodesEncompassingInstruction​(org.objectweb.asm.tree.InsnList insnList, java.util.List<org.objectweb.asm.tree.TryCatchBlockNode> tryCatchBlockNodes, org.objectweb.asm.tree.AbstractInsnNode insnNode)
      Find trycatch blocks within a method that an instruction is apart of.
      static java.util.List<org.objectweb.asm.tree.AbstractInsnNode> searchForOpcodes​(org.objectweb.asm.tree.InsnList insnList, int... opcodes)
      Find instructions in a certain class that are of a certain set of opcodes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SearchUtils

        private SearchUtils()
    • Method Detail

      • findMethodsWithName

        public static java.util.List<org.objectweb.asm.tree.MethodNode> findMethodsWithName​(java.util.Collection<org.objectweb.asm.tree.MethodNode> methodNodes,
                                                                                            java.lang.String name)
        Find methods within a class with a specific name.
        Parameters:
        methodNodes - method nodes to search through
        name - method name to search for
        Returns:
        list of methods
        Throws:
        java.lang.NullPointerException - if any argument is null or contains null
        java.lang.IllegalArgumentException - if any element in expectedStartingParamTypes is either of sort Type.METHOD or Type.VOID
      • findStaticMethods

        public static java.util.List<org.objectweb.asm.tree.MethodNode> findStaticMethods​(java.util.Collection<org.objectweb.asm.tree.MethodNode> methodNodes)
        Find static methods within a class.
        Parameters:
        methodNodes - method nodes to search through
        Returns:
        list of methods
        Throws:
        java.lang.NullPointerException - if any argument is null or contains null
      • findMethodsWithParameter

        public static java.util.List<org.objectweb.asm.tree.MethodNode> findMethodsWithParameter​(java.util.Collection<org.objectweb.asm.tree.MethodNode> methodNodes,
                                                                                                 org.objectweb.asm.Type expectedParamType)
        Find methods within a class where the parameter list contains a certain list of type.
        Parameters:
        methodNodes - method nodes to search through
        expectedParamType - parameter type to search for
        Returns:
        list of methods
        Throws:
        java.lang.NullPointerException - if any argument is null
        java.lang.IllegalArgumentException - if expectedParamType is either of sort Type.METHOD or Type.VOID
      • findMethodsWithParameters

        public static java.util.List<org.objectweb.asm.tree.MethodNode> findMethodsWithParameters​(java.util.Collection<org.objectweb.asm.tree.MethodNode> methodNodes,
                                                                                                  org.objectweb.asm.Type... paramTypes)
        Find methods within a class where the parameter list contains a certain list of type.
        Parameters:
        methodNodes - method nodes to search through
        paramTypes - parameter types to search for (in the order specified)
        Returns:
        list of methods
        Throws:
        java.lang.NullPointerException - if any argument is null or contains null
        java.lang.IllegalArgumentException - if any element in paramTypes is either of sort Type.METHOD or Type.VOID
      • findMethod

        public static org.objectweb.asm.tree.MethodNode findMethod​(java.util.Collection<org.objectweb.asm.tree.MethodNode> methodNodes,
                                                                   boolean isStatic,
                                                                   org.objectweb.asm.Type returnType,
                                                                   java.lang.String name,
                                                                   org.objectweb.asm.Type... paramTypes)
        Find a method within a class.
        Parameters:
        methodNodes - method nodes to search through
        name - method name to search for
        isStatic - true if the method should be static
        returnType - return type to search for
        paramTypes - parameter types to search for (in the order specified)
        Returns:
        method found (or null if no method could be found)
        Throws:
        java.lang.NullPointerException - if any argument is null or contains null
        java.lang.IllegalArgumentException - if any element of paramTypes is either of sort Type.METHOD or Type.VOID, or if returnType is Type.METHOD
      • findInvocationsOf

        public static java.util.List<org.objectweb.asm.tree.AbstractInsnNode> findInvocationsOf​(org.objectweb.asm.tree.InsnList insnList,
                                                                                                java.lang.reflect.Method expectedMethod)
        Find invocations of a certain method.
        Parameters:
        insnList - instruction list to search through
        expectedMethod - type of method being invoked
        Returns:
        list of invocations (may be nodes of type MethodInsnNode or InvokeDynamicInsnNode)
        Throws:
        java.lang.NullPointerException - if any argument is null
        java.lang.NullPointerException - if expectedMethodType isn't of sort Type.METHOD
      • findInvocationsWithParameter

        public static java.util.List<org.objectweb.asm.tree.AbstractInsnNode> findInvocationsWithParameter​(org.objectweb.asm.tree.InsnList insnList,
                                                                                                           org.objectweb.asm.Type expectedParamType)
        Find invocations of any method where the parameter list contains a type.
        Parameters:
        insnList - instruction list to search through
        expectedParamType - parameter type
        Returns:
        list of invocations (may be nodes of type MethodInsnNode or InvokeDynamicInsnNode)
        Throws:
        java.lang.NullPointerException - if any argument is null
        java.lang.IllegalArgumentException - if expectedParamType is either of sort Type.METHOD or Type.VOID
      • searchForOpcodes

        public static java.util.List<org.objectweb.asm.tree.AbstractInsnNode> searchForOpcodes​(org.objectweb.asm.tree.InsnList insnList,
                                                                                               int... opcodes)
        Find instructions in a certain class that are of a certain set of opcodes.
        Parameters:
        insnList - instruction list to search through
        opcodes - opcodes to search for
        Returns:
        list of instructions that contain the opcodes being searched for
        Throws:
        java.lang.NullPointerException - if any argument is null
        java.lang.IllegalArgumentException - if opcodes is empty
      • findTryCatchBlockNodesEncompassingInstruction

        public static java.util.List<org.objectweb.asm.tree.TryCatchBlockNode> findTryCatchBlockNodesEncompassingInstruction​(org.objectweb.asm.tree.InsnList insnList,
                                                                                                                             java.util.List<org.objectweb.asm.tree.TryCatchBlockNode> tryCatchBlockNodes,
                                                                                                                             org.objectweb.asm.tree.AbstractInsnNode insnNode)
        Find trycatch blocks within a method that an instruction is apart of. Only includes the try portion, not the catch (handler) portion.
        Parameters:
        insnList - instruction list for method
        tryCatchBlockNodes - trycatch blocks in method
        insnNode - instruction within method being searched against
        Returns:
        items from tryCatchBlockNodes that insnNode is a part of
        Throws:
        java.lang.NullPointerException - if any argument is null or contains null
        java.lang.IllegalArgumentException - if arguments aren't all from the same method
      • findLineNumberForInstruction

        public static org.objectweb.asm.tree.LineNumberNode findLineNumberForInstruction​(org.objectweb.asm.tree.InsnList insnList,
                                                                                         org.objectweb.asm.tree.AbstractInsnNode insnNode)
        Find line number associated with an instruction.
        Parameters:
        insnList - instruction list for method
        insnNode - instruction within method being searched against
        Returns:
        line number node associated with the instruction, or null if no line number exists
        Throws:
        java.lang.NullPointerException - if any argument is null or contains null
        java.lang.IllegalArgumentException - if arguments aren't all from the same method
      • findLocalVariableNodeForInstruction

        public static org.objectweb.asm.tree.LocalVariableNode findLocalVariableNodeForInstruction​(java.util.List<org.objectweb.asm.tree.LocalVariableNode> lvnList,
                                                                                                   org.objectweb.asm.tree.InsnList insnList,
                                                                                                   org.objectweb.asm.tree.AbstractInsnNode insnNode,
                                                                                                   int idx)
        Find local variable node for a local variable at some instruction.
        Parameters:
        lvnList - list of local variable nodes for method
        insnList - instruction list for method
        insnNode - instruction within method being searched against
        idx - local variable table index, or null if no local variable nodes are specified for idx and insnNode combination
        Returns:
        local variable node associated with the instruction
        Throws:
        java.lang.NullPointerException - if any argument is null or contains null
        java.lang.IllegalArgumentException - if arguments aren't all from the same method, or if idx < 0
      • findField

        public static org.objectweb.asm.tree.FieldNode findField​(org.objectweb.asm.tree.ClassNode classNode,
                                                                 java.lang.String name)
        Find field within a class by its name.
        Parameters:
        classNode - class to search
        name - name to search for
        Returns:
        found field (or null if not found)
        Throws:
        java.lang.NullPointerException - if any argument is null
        java.lang.IllegalArgumentException - if name is empty