Class SearchUtils
java.lang.Object
com.offbynull.coroutines.instrumenter.asm.SearchUtils
Utility class to search Java bytecode.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.objectweb.asm.tree.FieldNode
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.
-
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 throughname
- method name to search for- Returns:
- list of methods
- Throws:
NullPointerException
- if any argument isnull
or containsnull
IllegalArgumentException
- if any element inexpectedStartingParamTypes
is either of sortType.METHOD
orType.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 isnull
or containsnull
-
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 throughexpectedParamType
- parameter type to search for- Returns:
- list of methods
- Throws:
NullPointerException
- if any argument isnull
IllegalArgumentException
- ifexpectedParamType
is either of sortType.METHOD
orType.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 throughparamTypes
- parameter types to search for (in the order specified)- Returns:
- list of methods
- Throws:
NullPointerException
- if any argument isnull
or containsnull
IllegalArgumentException
- if any element inparamTypes
is either of sortType.METHOD
orType.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 throughisStatic
-true
if the method should be staticreturnType
- return type to search forname
- method name to search forparamTypes
- 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 isnull
or containsnull
IllegalArgumentException
- if any element ofparamTypes
is either of sortType.METHOD
orType.VOID
, or ifreturnType
isType.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 throughexpectedMethod
- type of method being invoked- Returns:
- list of invocations (may be nodes of type
MethodInsnNode
orInvokeDynamicInsnNode
) - Throws:
NullPointerException
- if any argument isnull
NullPointerException
- ifexpectedMethodType
isn't of sortType.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 throughexpectedParamType
- parameter type- Returns:
- list of invocations (may be nodes of type
MethodInsnNode
orInvokeDynamicInsnNode
) - Throws:
NullPointerException
- if any argument isnull
IllegalArgumentException
- ifexpectedParamType
is either of sortType.METHOD
orType.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 throughopcodes
- opcodes to search for- Returns:
- list of instructions that contain the opcodes being searched for
- Throws:
NullPointerException
- if any argument isnull
IllegalArgumentException
- ifopcodes
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 methodtryCatchBlockNodes
- trycatch blocks in methodinsnNode
- instruction within method being searched against- Returns:
- items from
tryCatchBlockNodes
thatinsnNode
is a part of - Throws:
NullPointerException
- if any argument isnull
or containsnull
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:
NullPointerException
- if any argument isnull
or containsnull
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 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:
NullPointerException
- if any argument isnull
or containsnull
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, 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:
NullPointerException
- if any argument isnull
IllegalArgumentException
- ifname
is empty
-