public class ASMUtils
extends java.lang.Object
| Constructor and Description |
|---|
ASMUtils() |
| Modifier and Type | Method and Description |
|---|---|
static org.objectweb.asm.tree.ClassNode |
cloneClass(org.objectweb.asm.tree.ClassNode classNode)
Clone a class node with all its methods and fields.
|
static org.objectweb.asm.tree.InsnList |
cloneInsnList(org.objectweb.asm.tree.InsnList insnList)
Clone an insn list with all its instructions.
|
static org.objectweb.asm.tree.MethodNode |
cloneMethod(org.objectweb.asm.tree.MethodNode methodNode)
Clone a method node with all its instructions.
|
static java.lang.String |
combiToRegex(java.lang.String combi)
Convert a field or method search pattern to a regex pattern.
|
static boolean |
compareType(org.objectweb.asm.Type type,
org.objectweb.asm.Type targetType)
Compare a single type with a target type
This supports the usage of object instead of the actual type but does not check for other inheritance. |
static boolean |
compareTypes(org.objectweb.asm.Type[] types,
org.objectweb.asm.Type[] targetTypes)
Compare an array of types with a target array of types.
|
static boolean |
compareTypes(org.objectweb.asm.Type[] types,
org.objectweb.asm.Type[] targetTypes,
boolean prepend,
org.objectweb.asm.Type... additionalNeededTypes)
Compare an array of types with a target array of types.
|
static org.objectweb.asm.tree.ClassNode |
createEmptyClass(java.lang.String name)
Create an empty class with a default constructor.
|
static java.lang.String |
dot(java.lang.String s)
Replace all slashes with dots in the given class/package name.
|
static org.objectweb.asm.tree.ClassNode |
fromBytes(byte[] bytecode)
Get a class node from the raw bytecode of a class.
|
static org.objectweb.asm.tree.InsnList |
getCast(org.objectweb.asm.Type wantedType)
Get the byte code to cast an object to a given type.
|
static org.objectweb.asm.tree.FieldNode |
getField(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String name,
java.lang.String desc)
Get a field node from a class node using the name.
|
static java.util.List<org.objectweb.asm.tree.FieldNode> |
getFieldsFromCombi(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String combi)
Get a list of method nodes from a class node using the combined name and descriptor.
|
static org.objectweb.asm.tree.AbstractInsnNode |
getFirstConstructorInstruction(java.lang.String superClass,
org.objectweb.asm.tree.MethodNode methodNode)
Get the first instruction of a constructor skipping the super init call.
|
static int |
getFreeVarIndex(org.objectweb.asm.tree.MethodNode methodNode)
Get the last empty local variable index.
|
static int |
getLoadOpcode(org.objectweb.asm.Type type)
Get the needed load opcode for the given type.
|
static org.objectweb.asm.tree.MethodNode |
getMethod(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String name,
java.lang.String desc)
Get a method node from a class node using the name and descriptor.
|
static java.util.List<org.objectweb.asm.tree.MethodNode> |
getMethodsFromCombi(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String combi)
Get a list of method nodes from a class node using the combined name and descriptor.
|
static java.lang.Number |
getNumber(org.objectweb.asm.tree.AbstractInsnNode instruction)
Get a number from an insn node if it represents one.
|
static org.objectweb.asm.tree.AbstractInsnNode |
getPrimitiveToObject(org.objectweb.asm.Type primitive)
Get the byte code to wrap a primitive to its wrapper type (e.g. int to Integer).
|
static int |
getReturnOpcode(org.objectweb.asm.Type returnType)
Get the needed return opcode for the given type.
|
static int |
getStoreOpcode(org.objectweb.asm.Type type)
Get the needed store opcode for the given type.
|
static org.objectweb.asm.tree.AbstractInsnNode |
intPush(int i)
Create a new insn node representing the given int.
|
static boolean |
isAccessLower(int toCheck,
int checkAgainst)
Check if the given access is lower than another.
|
static int |
setAccess(int currentAccess,
int newAccess)
Set the wanted access to a given access mask.
|
static java.lang.String |
slash(java.lang.String s)
Replace all dots with slashes in the given class/package name.
|
static MemberDeclaration |
splitMemberDeclaration(java.lang.String injectDeclaration)
Split an injection declaration into owner, name and descriptor.
|
static byte[] |
toBytes(org.objectweb.asm.tree.ClassNode node,
ClassTree classTree,
IClassProvider classProvider)
Get the bytecode from a class node
|
static byte[] |
toStacklessBytes(org.objectweb.asm.tree.ClassNode node)
Get the bytecode from a class node without calculating stack map frames
|
public static org.objectweb.asm.tree.ClassNode fromBytes(byte[] bytecode)
bytecode - The bytecode of the classpublic static byte[] toBytes(org.objectweb.asm.tree.ClassNode node,
ClassTree classTree,
IClassProvider classProvider)
node - The class nodeclassTree - The class tree used to get the super classesclassProvider - The class provider used for stack frame calculationpublic static byte[] toStacklessBytes(org.objectweb.asm.tree.ClassNode node)
node - The class nodepublic static org.objectweb.asm.tree.MethodNode getMethod(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String name,
java.lang.String desc)
classNode - The class node to search inname - The name of the methoddesc - The descriptor of the methodpublic static org.objectweb.asm.tree.FieldNode getField(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String name,
java.lang.String desc)
classNode - The class node to search inname - The name of the fielddesc - The descriptor of the fieldpublic static java.util.List<org.objectweb.asm.tree.MethodNode> getMethodsFromCombi(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String combi)
classNode - The class node to search incombi - The combined name and descriptorjava.lang.IllegalArgumentException - If the combined name and descriptor is emptypublic static java.util.List<org.objectweb.asm.tree.FieldNode> getFieldsFromCombi(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String combi)
classNode - The class node to search incombi - The combined name and descriptorpublic static java.lang.String combiToRegex(java.lang.String combi)
combi - The search patternpublic static boolean isAccessLower(int toCheck,
int checkAgainst)
toCheck - The access to checkcheckAgainst - The access to check againstpublic static int setAccess(int currentAccess,
int newAccess)
currentAccess - The current access masknewAccess - The wanted accesspublic static int getReturnOpcode(org.objectweb.asm.Type returnType)
returnType - The return type of a methodpublic static int getLoadOpcode(org.objectweb.asm.Type type)
type - The type to get the load opcode forpublic static int getStoreOpcode(org.objectweb.asm.Type type)
type - The type to get the store opcode forpublic static int getFreeVarIndex(org.objectweb.asm.tree.MethodNode methodNode)
methodNode - The method to get the last empty local variable index forpublic static org.objectweb.asm.tree.InsnList getCast(org.objectweb.asm.Type wantedType)
wantedType - The wanted typepublic static org.objectweb.asm.tree.AbstractInsnNode getPrimitiveToObject(org.objectweb.asm.Type primitive)
primitive - The primitive type to wrappublic static MemberDeclaration splitMemberDeclaration(java.lang.String injectDeclaration)
java/lang/String.length()Ijava/lang/System.out:Ljava/io/PrintStream;injectDeclaration - The injection declarationpublic static org.objectweb.asm.tree.AbstractInsnNode getFirstConstructorInstruction(java.lang.String superClass,
org.objectweb.asm.tree.MethodNode methodNode)
superClass - The name of the super classmethodNode - The constructor method nodepublic static java.lang.Number getNumber(org.objectweb.asm.tree.AbstractInsnNode instruction)
Opcodes.ICONST_0)instruction - The insn nodepublic static boolean compareTypes(org.objectweb.asm.Type[] types,
org.objectweb.asm.Type[] targetTypes)
types - The source array of typestargetTypes - The target array of typespublic static boolean compareTypes(org.objectweb.asm.Type[] types,
org.objectweb.asm.Type[] targetTypes,
boolean prepend,
org.objectweb.asm.Type... additionalNeededTypes)
types - The source array of typestargetTypes - The target array of typesprepend - If the additional types array should be prepended or appendedadditionalNeededTypes - The additional types to append/prepend to the sourcepublic static boolean compareType(org.objectweb.asm.Type type,
org.objectweb.asm.Type targetType)
type - The source typetargetType - The target typepublic static org.objectweb.asm.tree.ClassNode cloneClass(org.objectweb.asm.tree.ClassNode classNode)
classNode - The class node to clonepublic static org.objectweb.asm.tree.MethodNode cloneMethod(org.objectweb.asm.tree.MethodNode methodNode)
methodNode - The method node to clonepublic static org.objectweb.asm.tree.InsnList cloneInsnList(org.objectweb.asm.tree.InsnList insnList)
insnList - The insn list to clonepublic static org.objectweb.asm.tree.ClassNode createEmptyClass(java.lang.String name)
name - The name of the classpublic static org.objectweb.asm.tree.AbstractInsnNode intPush(int i)
i - The intpublic static java.lang.String dot(java.lang.String s)
s - The class/package namepublic static java.lang.String slash(java.lang.String s)
s - The class/package name