public class TransformerManager
extends java.lang.Object
implements java.lang.instrument.ClassFileTransformer
| Constructor and Description |
|---|
TransformerManager(IClassProvider classProvider) |
TransformerManager(IClassProvider classProvider,
AMapper mapper) |
| Modifier and Type | Method and Description |
|---|---|
void |
addBytecodeTransformer(IBytecodeTransformer bytecodeTransformer)
Add a bytecode transformer to the transformer list
Useful when needing to modify bytecode directly without ASM parsing or all Classes at once |
void |
addInjectionTarget(java.lang.String name,
IInjectionTarget target)
Add a new injection target for use with the
CTarget annotation |
void |
addPostTransformConsumer(IPostTransformer postTransformer)
Add a post transformer to handle the raw byte array after all other transformer have been applied
Useful for dumping transformed classes to disk |
void |
addRawTransformer(java.lang.String className,
IRawTransformer rawTransformer)
Add a raw class transformer to the transformer list
Useful when needing direct access to a ClassNode |
java.util.Set<java.lang.String> |
addTransformer(org.objectweb.asm.tree.ClassNode classNode)
Add a
ClassNode directly to the transformer listThe class must still be annotated with CTransformer |
java.util.Set<java.lang.String> |
addTransformer(org.objectweb.asm.tree.ClassNode classNode,
boolean requireAnnotation)
Add a
ClassNode directly to the transformer listThe class must still be annotated with CTransformer |
void |
addTransformer(java.lang.String transformer)
Add a transformer class to the transformer list
Use the direct class name for a single transformer (e.g. |
void |
addTransformerPreprocessor(ITransformerPreprocessor transformerPreprocessor)
Add a transformer preprocessor to the transformer list
You can modify class transform annotations before they get parsed |
void |
hookInstrumentation(java.lang.instrument.Instrumentation instrumentation)
Hook an
Instrumentation instance to allow for transformation using itThis can be used to transform classes already loaded by the JVM You have to be careful with re-transforming classes since you can't modify the structure (e.g. adding a new method or modifying the signature of an existing one) Hotswapping transformer is disabled by default as it causes a bit more overhead and memory usage |
void |
hookInstrumentation(java.lang.instrument.Instrumentation instrumentation,
boolean hotswappable)
Hook an
Instrumentation instance to allow for transformation using itThis can be used to transform classes already loaded by the JVM You have to be careful with re-transforming classes since you can't modify the structure (e.g. adding a new method or modifying the signature of an existing one) |
void |
setLogger(ILogger logger)
Set the logger used by ClassTransform for errors and warnings
|
byte[] |
transform(java.lang.ClassLoader loader,
java.lang.String className,
java.lang.Class<?> classBeingRedefined,
java.security.ProtectionDomain protectionDomain,
byte[] classfileBuffer)
Support method for
InstrumentationYou can simply add the TransformerManager as a ClassFileTransformer using Instrumentation.addTransformer(ClassFileTransformer) or call hookInstrumentation(Instrumentation) |
byte[] |
transform(java.lang.String name,
byte[] bytecode)
Transform the bytecode of a given class
|
public TransformerManager(IClassProvider classProvider)
classProvider - The ClassLoader to use for transformer loadingpublic TransformerManager(IClassProvider classProvider, AMapper mapper)
classProvider - The ClassLoader to use for transformer loadingmapper - The AMapper instancepublic void setLogger(ILogger logger)
logger - The logger to usepublic void addTransformerPreprocessor(ITransformerPreprocessor transformerPreprocessor)
transformerPreprocessor - The ITransformerPreprocessor instancepublic void addBytecodeTransformer(IBytecodeTransformer bytecodeTransformer)
Classes at oncebytecodeTransformer - The IBytecodeTransformer instancepublic void addRawTransformer(java.lang.String className,
IRawTransformer rawTransformer)
ClassNodeclassName - The name of the transformer targetrawTransformer - The IRawTransformer instancepublic void addTransformer(java.lang.String transformer)
transformer - The name of transformer class to addpublic java.util.Set<java.lang.String> addTransformer(org.objectweb.asm.tree.ClassNode classNode)
ClassNode directly to the transformer listCTransformerclassNode - The ClassNode to addpublic java.util.Set<java.lang.String> addTransformer(org.objectweb.asm.tree.ClassNode classNode,
boolean requireAnnotation)
ClassNode directly to the transformer listCTransformerclassNode - The ClassNode to addpublic void addPostTransformConsumer(IPostTransformer postTransformer)
postTransformer - The BiConsumer instancepublic void addInjectionTarget(java.lang.String name,
IInjectionTarget target)
CTarget annotationname - The name of the injection targettarget - The injection targetpublic byte[] transform(java.lang.String name,
byte[] bytecode)
name - The name of the classbytecode - The bytecode of the classpublic void hookInstrumentation(java.lang.instrument.Instrumentation instrumentation)
Instrumentation instance to allow for transformation using itinstrumentation - The instance of the Instrumentationpublic void hookInstrumentation(java.lang.instrument.Instrumentation instrumentation,
boolean hotswappable)
Instrumentation instance to allow for transformation using itinstrumentation - The instance of the Instrumentationhotswappable - Allow transformer to be hotswappedpublic byte[] transform(java.lang.ClassLoader loader,
java.lang.String className,
java.lang.Class<?> classBeingRedefined,
java.security.ProtectionDomain protectionDomain,
byte[] classfileBuffer)
throws java.lang.instrument.IllegalClassFormatException
InstrumentationTransformerManager as a ClassFileTransformer using Instrumentation.addTransformer(ClassFileTransformer) or call hookInstrumentation(Instrumentation)transform in interface java.lang.instrument.ClassFileTransformerjava.lang.instrument.IllegalClassFormatException