Support hooking class static initializer

This commit is contained in:
LoveSy 2024-08-23 00:41:26 +08:00
parent 3248419435
commit ca2e4b8da8
No known key found for this signature in database
2 changed files with 44 additions and 0 deletions

View File

@ -271,6 +271,37 @@ public interface XposedInterface {
@NonNull @NonNull
MethodUnhooker<Method> hook(@NonNull Method origin, @NonNull Class<? extends Hooker> hooker); MethodUnhooker<Method> hook(@NonNull Method origin, @NonNull Class<? extends Hooker> hooker);
/**
* Hook the static initializer of a class with default priority.
* <p>
* Note: If the class is initialized, the hook will never be called.
* </p>
*
* @param origin The class to be hooked
* @param hooker The hooker class
* @return Unhooker for canceling the hook
* @throws IllegalArgumentException if class has no static initializer or hooker is invalid
* @throws HookFailedError if hook fails due to framework internal error
*/
@NonNull
<T> MethodUnhooker<Constructor<T>> hookClassInitializer(@NonNull Class<T> origin, @NonNull Class<? extends Hooker> hooker);
/**
* Hook the static initializer of a class with specified priority.
* <p>
* Note: If the class is initialized, the hook will never be called.
* </p>
*
* @param origin The class to be hooked
* @param priority The hook priority
* @param hooker The hooker class
* @return Unhooker for canceling the hook
* @throws IllegalArgumentException if class has no static initializer or hooker is invalid
* @throws HookFailedError if hook fails due to framework internal error
*/
@NonNull
<T> MethodUnhooker<Constructor<T>> hookClassInitializer(@NonNull Class<T> origin, int priority, @NonNull Class<? extends Hooker> hooker);
/** /**
* Hook a method with specified priority. * Hook a method with specified priority.
* *
@ -358,6 +389,7 @@ public interface XposedInterface {
/** /**
* Basically the same as {@link Constructor#newInstance(Object...)}, but calls the original constructor * Basically the same as {@link Constructor#newInstance(Object...)}, but calls the original constructor
* as it was before the interception by Xposed. * as it was before the interception by Xposed.
*
* @param constructor The constructor to create and initialize a new instance * @param constructor The constructor to create and initialize a new instance
* @param thisObject The instance to be constructed * @param thisObject The instance to be constructed
* @param args The arguments used for the construction * @param args The arguments used for the construction

View File

@ -55,6 +55,18 @@ public class XposedInterfaceWrapper implements XposedInterface {
return mBase.hook(origin, hooker); return mBase.hook(origin, hooker);
} }
@NonNull
@Override
public <T> MethodUnhooker<Constructor<T>> hookClassInitializer(@NonNull Class<T> origin, @NonNull Class<? extends Hooker> hooker) {
return mBase.hookClassInitializer(origin, hooker);
}
@NonNull
@Override
public <T> MethodUnhooker<Constructor<T>> hookClassInitializer(@NonNull Class<T> origin, int priority, @NonNull Class<? extends Hooker> hooker) {
return mBase.hookClassInitializer(origin, priority, hooker);
}
@NonNull @NonNull
@Override @Override
public final MethodUnhooker<Method> hook(@NonNull Method origin, int priority, @NonNull Class<? extends Hooker> hooker) { public final MethodUnhooker<Method> hook(@NonNull Method origin, int priority, @NonNull Class<? extends Hooker> hooker) {