Class SearchUtils
- java.lang.Object
-
- com.offbynull.coroutines.instrumenter.asm.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.
-
-
-
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 throughname
- method name to search for- Returns:
- list of methods
- Throws:
java.lang.NullPointerException
- if any argument isnull
or containsnull
java.lang.IllegalArgumentException
- if any element inexpectedStartingParamTypes
is either of sortType.METHOD
orType.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 isnull
or containsnull
-
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 throughexpectedParamType
- parameter type to search for- Returns:
- list of methods
- Throws:
java.lang.NullPointerException
- if any argument isnull
java.lang.IllegalArgumentException
- ifexpectedParamType
is either of sortType.METHOD
orType.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 throughparamTypes
- parameter types to search for (in the order specified)- Returns:
- list of methods
- Throws:
java.lang.NullPointerException
- if any argument isnull
or containsnull
java.lang.IllegalArgumentException
- if any element inparamTypes
is either of sortType.METHOD
orType.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 throughname
- method name to search forisStatic
-true
if the method should be staticreturnType
- return type to search forparamTypes
- 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 isnull
or containsnull
java.lang.IllegalArgumentException
- if any element ofparamTypes
is either of sortType.METHOD
orType.VOID
, or ifreturnType
isType.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 throughexpectedMethod
- type of method being invoked- Returns:
- list of invocations (may be nodes of type
MethodInsnNode
orInvokeDynamicInsnNode
) - Throws:
java.lang.NullPointerException
- if any argument isnull
java.lang.NullPointerException
- ifexpectedMethodType
isn't of sortType.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 throughexpectedParamType
- parameter type- Returns:
- list of invocations (may be nodes of type
MethodInsnNode
orInvokeDynamicInsnNode
) - Throws:
java.lang.NullPointerException
- if any argument isnull
java.lang.IllegalArgumentException
- ifexpectedParamType
is either of sortType.METHOD
orType.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 throughopcodes
- opcodes to search for- Returns:
- list of instructions that contain the opcodes being searched for
- Throws:
java.lang.NullPointerException
- if any argument isnull
java.lang.IllegalArgumentException
- ifopcodes
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 methodtryCatchBlockNodes
- trycatch blocks in methodinsnNode
- instruction within method being searched against- Returns:
- items from
tryCatchBlockNodes
thatinsnNode
is a part of - Throws:
java.lang.NullPointerException
- if any argument isnull
or containsnull
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 methodinsnNode
- 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 isnull
or containsnull
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 methodinsnList
- instruction list for methodinsnNode
- instruction within method being searched againstidx
- local variable table index, ornull
if no local variable nodes are specified foridx
andinsnNode
combination- Returns:
- local variable node associated with the instruction
- Throws:
java.lang.NullPointerException
- if any argument isnull
or containsnull
java.lang.IllegalArgumentException
- if arguments aren't all from the same method, or ifidx < 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 searchname
- name to search for- Returns:
- found field (or
null
if not found) - Throws:
java.lang.NullPointerException
- if any argument isnull
java.lang.IllegalArgumentException
- ifname
is empty
-
-