Package proguard.classfile.util.inject
Class CodeInjector
- java.lang.Object
-
- proguard.classfile.util.inject.CodeInjector
-
public class CodeInjector extends java.lang.Object
This utility class allow for injecting a method invocation instruction optionally with arguments modeled by instances of classes implementingInjectedArgument
interface to the specified target method at an offset determined by the implementation of theInjectStrategy
interface.Example usage: new CodeInjector() .injectInvokeStatic(logUtilClass, logDebugMethod, new ConstantPrimitive
(1), new ConstantString("Hello world")) .into(MainProgramClass, mainMethod) .at(new FirstBlock()) .commit();
-
-
Constructor Summary
Constructors Constructor Description CodeInjector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CodeInjector
at(InjectStrategy injectStrategy)
Specify the location in which the invoke instruction should be injected into.void
commit()
Apply the invoke instruction in accordance to the specifications provided via the `.injectInvokeStatic(...)`, `.into(...)` and `at(...)` method.CodeInjector
injectInvokeStatic(Clazz clazz, Method method)
Specify the static method to be invoked.CodeInjector
injectInvokeStatic(Clazz clazz, Method method, InjectedArgument... arguments)
Specify the static method to be invoked.CodeInjector
into(ProgramClass programClass, ProgramMethod programMethod)
Specify the method where a static method invocation shall be injected into.
-
-
-
Method Detail
-
injectInvokeStatic
public CodeInjector injectInvokeStatic(Clazz clazz, Method method)
Specify the static method to be invoked.- Parameters:
clazz
- The class in which the static method belongs to.method
- The method to be invoked.
-
injectInvokeStatic
public CodeInjector injectInvokeStatic(Clazz clazz, Method method, InjectedArgument... arguments)
Specify the static method to be invoked.- Parameters:
clazz
- The class in which the static method belongs to.method
- The method to be invoked.arguments
- a list of arguments to be passed to the method to be invoked.
-
into
public CodeInjector into(ProgramClass programClass, ProgramMethod programMethod)
Specify the method where a static method invocation shall be injected into.- Parameters:
programClass
- The program class that has the method where a static method invocation shall be injected into.programMethod
- the method where a static method invocation shall be injected into.
-
at
public CodeInjector at(InjectStrategy injectStrategy)
Specify the location in which the invoke instruction should be injected into.- Parameters:
injectStrategy
- The implementation of InjectStrategy interface which determine the offset to inject the invoke instruction.- Returns:
-
commit
public void commit()
Apply the invoke instruction in accordance to the specifications provided via the `.injectInvokeStatic(...)`, `.into(...)` and `at(...)` method.
-
-