Class SearchUtils
- java.lang.Object
-
- com.offbynull.coroutines.instrumenter.asm.SearchUtils
-
public final class SearchUtils extends java.lang.ObjectUtility class to search Java bytecode.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateSearchUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.objectweb.asm.tree.FieldNodefindField(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.LineNumberNodefindLineNumberForInstruction(org.objectweb.asm.tree.InsnList insnList, org.objectweb.asm.tree.AbstractInsnNode insnNode)Find line number associated with an instruction.static org.objectweb.asm.tree.LocalVariableNodefindLocalVariableNodeForInstruction(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.MethodNodefindMethod(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 isnullor containsnulljava.lang.IllegalArgumentException- if any element inexpectedStartingParamTypesis either of sortType.METHODorType.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 isnullor 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 isnulljava.lang.IllegalArgumentException- ifexpectedParamTypeis either of sortType.METHODorType.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 isnullor containsnulljava.lang.IllegalArgumentException- if any element inparamTypesis either of sortType.METHODorType.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-trueif the method should be staticreturnType- return type to search forparamTypes- parameter types to search for (in the order specified)- Returns:
- method found (or
nullif no method could be found) - Throws:
java.lang.NullPointerException- if any argument isnullor containsnulljava.lang.IllegalArgumentException- if any element ofparamTypesis either of sortType.METHODorType.VOID, or ifreturnTypeisType.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
MethodInsnNodeorInvokeDynamicInsnNode) - Throws:
java.lang.NullPointerException- if any argument isnulljava.lang.NullPointerException- ifexpectedMethodTypeisn'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
MethodInsnNodeorInvokeDynamicInsnNode) - Throws:
java.lang.NullPointerException- if any argument isnulljava.lang.IllegalArgumentException- ifexpectedParamTypeis either of sortType.METHODorType.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 isnulljava.lang.IllegalArgumentException- ifopcodesis 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
tryCatchBlockNodesthatinsnNodeis a part of - Throws:
java.lang.NullPointerException- if any argument isnullor containsnulljava.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
nullif no line number exists - Throws:
java.lang.NullPointerException- if any argument isnullor containsnulljava.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, ornullif no local variable nodes are specified foridxandinsnNodecombination- Returns:
- local variable node associated with the instruction
- Throws:
java.lang.NullPointerException- if any argument isnullor containsnulljava.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
nullif not found) - Throws:
java.lang.NullPointerException- if any argument isnulljava.lang.IllegalArgumentException- ifnameis empty
-
-