Class SearchUtils

java.lang.Object
com.offbynull.coroutines.instrumenter.asm.SearchUtils

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

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.objectweb.asm.tree.FieldNode
    findField(org.objectweb.asm.tree.ClassNode classNode, String name)
    Find field within a class by its name.
    static List<org.objectweb.asm.tree.AbstractInsnNode>
    findInvocationsOf(org.objectweb.asm.tree.InsnList insnList, Method expectedMethod)
    Find invocations of a certain method.
    static 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(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(Collection<org.objectweb.asm.tree.MethodNode> methodNodes, boolean isStatic, org.objectweb.asm.Type returnType, String name, org.objectweb.asm.Type... paramTypes)
    Find a method within a class.
    static List<org.objectweb.asm.tree.MethodNode>
    findMethodsWithName(Collection<org.objectweb.asm.tree.MethodNode> methodNodes, String name)
    Find methods within a class with a specific name.
    static List<org.objectweb.asm.tree.MethodNode>
    findMethodsWithParameter(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 List<org.objectweb.asm.tree.MethodNode>
    findMethodsWithParameters(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 List<org.objectweb.asm.tree.MethodNode>
    findStaticMethods(Collection<org.objectweb.asm.tree.MethodNode> methodNodes)
    Find static methods within a class.
    static List<org.objectweb.asm.tree.TryCatchBlockNode>
    findTryCatchBlockNodesEncompassingInstruction(org.objectweb.asm.tree.InsnList insnList, 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 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 Details

    • SearchUtils

      private SearchUtils()
  • Method Details

    • findMethodsWithName

      public static List<org.objectweb.asm.tree.MethodNode> findMethodsWithName(Collection<org.objectweb.asm.tree.MethodNode> methodNodes, 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:
      NullPointerException - if any argument is null or contains null
      IllegalArgumentException - if any element in expectedStartingParamTypes is either of sort Type.METHOD or Type.VOID
    • findStaticMethods

      public static List<org.objectweb.asm.tree.MethodNode> findStaticMethods(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:
      NullPointerException - if any argument is null or contains null
    • findMethodsWithParameter

      public static List<org.objectweb.asm.tree.MethodNode> findMethodsWithParameter(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:
      NullPointerException - if any argument is null
      IllegalArgumentException - if expectedParamType is either of sort Type.METHOD or Type.VOID
    • findMethodsWithParameters

      public static List<org.objectweb.asm.tree.MethodNode> findMethodsWithParameters(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:
      NullPointerException - if any argument is null or contains null
      IllegalArgumentException - if any element in paramTypes is either of sort Type.METHOD or Type.VOID
    • findMethod

      public static org.objectweb.asm.tree.MethodNode findMethod(Collection<org.objectweb.asm.tree.MethodNode> methodNodes, boolean isStatic, org.objectweb.asm.Type returnType, String name, org.objectweb.asm.Type... paramTypes)
      Find a method within a class.
      Parameters:
      methodNodes - method nodes to search through
      isStatic - true if the method should be static
      returnType - return type to search for
      name - method name 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:
      NullPointerException - if any argument is null or contains null
      IllegalArgumentException - if any element of paramTypes is either of sort Type.METHOD or Type.VOID, or if returnType is Type.METHOD
    • findInvocationsOf

      public static List<org.objectweb.asm.tree.AbstractInsnNode> findInvocationsOf(org.objectweb.asm.tree.InsnList insnList, 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:
      NullPointerException - if any argument is null
      NullPointerException - if expectedMethodType isn't of sort Type.METHOD
    • findInvocationsWithParameter

      public static 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:
      NullPointerException - if any argument is null
      IllegalArgumentException - if expectedParamType is either of sort Type.METHOD or Type.VOID
    • searchForOpcodes

      public static 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:
      NullPointerException - if any argument is null
      IllegalArgumentException - if opcodes is empty
    • findTryCatchBlockNodesEncompassingInstruction

      public static List<org.objectweb.asm.tree.TryCatchBlockNode> findTryCatchBlockNodesEncompassingInstruction(org.objectweb.asm.tree.InsnList insnList, 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:
      NullPointerException - if any argument is null or contains null
      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:
      NullPointerException - if any argument is null or contains null
      IllegalArgumentException - if arguments aren't all from the same method
    • findLocalVariableNodeForInstruction

      public static org.objectweb.asm.tree.LocalVariableNode findLocalVariableNodeForInstruction(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:
      NullPointerException - if any argument is null or contains null
      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, 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:
      NullPointerException - if any argument is null
      IllegalArgumentException - if name is empty