diff --git a/api/src/main/java/io/github/libxposed/XposedContext.java b/api/src/main/java/io/github/libxposed/XposedContext.java index 7465c0f..83806f8 100644 --- a/api/src/main/java/io/github/libxposed/XposedContext.java +++ b/api/src/main/java/io/github/libxposed/XposedContext.java @@ -2,6 +2,9 @@ package io.github.libxposed; import android.content.Context; +/** + * The type Xposed context. + */ public abstract class XposedContext extends Context implements XposedInterface { } diff --git a/api/src/main/java/io/github/libxposed/XposedContextWrapper.java b/api/src/main/java/io/github/libxposed/XposedContextWrapper.java index 7967070..d084da7 100644 --- a/api/src/main/java/io/github/libxposed/XposedContextWrapper.java +++ b/api/src/main/java/io/github/libxposed/XposedContextWrapper.java @@ -13,17 +13,35 @@ import java.nio.ByteBuffer; import io.github.libxposed.utils.DexParser; +/** + * The type Xposed context wrapper. + */ @SuppressWarnings("unused") public class XposedContextWrapper extends ContextWrapper implements XposedInterface { + /** + * Instantiates a new Xposed context wrapper. + * + * @param base the base + */ XposedContextWrapper(XposedContext base) { super(base); } + /** + * Instantiates a new Xposed context wrapper. + * + * @param base the base + */ public XposedContextWrapper(XposedContextWrapper base) { super(base); } + /** + * Gets api version. + * + * @return the api version + */ final public int getAPIVersion() { return API; } diff --git a/api/src/main/java/io/github/libxposed/XposedInterface.java b/api/src/main/java/io/github/libxposed/XposedInterface.java index 2bf0418..75c040e 100644 --- a/api/src/main/java/io/github/libxposed/XposedInterface.java +++ b/api/src/main/java/io/github/libxposed/XposedInterface.java @@ -12,152 +12,505 @@ import java.util.ConcurrentModificationException; import io.github.libxposed.utils.DexParser; +/** + * The interface Xposed interface. + */ @SuppressWarnings("unused") public interface XposedInterface { + /** + * The constant API. + */ int API = 100; + /** + * The constant FRAMEWORK_PRIVILEGE_ROOT. + */ int FRAMEWORK_PRIVILEGE_ROOT = 0; + /** + * The constant FRAMEWORK_PRIVILEGE_CONTAINER. + */ int FRAMEWORK_PRIVILEGE_CONTAINER = 1; + /** + * The constant FRAMEWORK_PRIVILEGE_APP. + */ int FRAMEWORK_PRIVILEGE_APP = 2; + /** + * The constant FRAMEWORK_PRIVILEGE_EMBEDDED. + */ int FRAMEWORK_PRIVILEGE_EMBEDDED = 3; + /** + * The interface Before hook callback. + * + * @param the type parameter + */ interface BeforeHookCallback { + /** + * Gets origin. + * + * @return the origin + */ @NonNull T getOrigin(); + /** + * Gets this. + * + * @return the this + */ @Nullable Object getThis(); + /** + * Get args object [ ]. + * + * @return the object [ ] + */ @NonNull Object[] getArgs(); + /** + * Gets arg. + * + * @param the type parameter + * @param index the index + * @return the arg + */ @Nullable U getArg(int index); + /** + * Sets arg. + * + * @param the type parameter + * @param index the index + * @param value the value + */ void setArg(int index, U value); + /** + * Return and skip. + * + * @param returnValue the return value + */ void returnAndSkip(@Nullable Object returnValue); + /** + * Throw and skip. + * + * @param throwable the throwable + */ void throwAndSkip(@Nullable Throwable throwable); + /** + * Invoke origin object. + * + * @param thisObject the this object + * @param args the args + * @return the object + * @throws InvocationTargetException the invocation target exception + * @throws IllegalAccessException the illegal access exception + */ @Nullable Object invokeOrigin(@Nullable Object thisObject, Object[] args) throws InvocationTargetException, IllegalAccessException; + /** + * Invoke origin object. + * + * @return the object + * @throws InvocationTargetException the invocation target exception + * @throws IllegalAccessException the illegal access exception + */ @Nullable Object invokeOrigin() throws InvocationTargetException, IllegalAccessException; + /** + * Sets extra. + * + * @param the type parameter + * @param key the key + * @param value the value + * @throws ConcurrentModificationException the concurrent modification exception + */ void setExtra(@NonNull String key, @Nullable U value) throws ConcurrentModificationException; } + /** + * The interface After hook callback. + * + * @param the type parameter + */ interface AfterHookCallback { + /** + * Gets origin. + * + * @return the origin + */ @NonNull T getOrigin(); + /** + * Gets this. + * + * @return the this + */ @Nullable Object getThis(); + /** + * Get args object [ ]. + * + * @return the object [ ] + */ @NonNull Object[] getArgs(); + /** + * Gets result. + * + * @return the result + */ @Nullable Object getResult(); + /** + * Gets throwable. + * + * @return the throwable + */ @Nullable Throwable getThrowable(); + /** + * Is skipped boolean. + * + * @return the boolean + */ boolean isSkipped(); + /** + * Sets result. + * + * @param result the result + */ void setResult(@Nullable Object result); + /** + * Sets throwable. + * + * @param throwable the throwable + */ void setThrowable(@Nullable Throwable throwable); + /** + * Invoke origin object. + * + * @param thisObject the this object + * @param args the args + * @return the object + * @throws InvocationTargetException the invocation target exception + * @throws IllegalAccessException the illegal access exception + */ @Nullable Object invokeOrigin(@Nullable Object thisObject, Object[] args) throws InvocationTargetException, IllegalAccessException; + /** + * Invoke origin object. + * + * @return the object + * @throws InvocationTargetException the invocation target exception + * @throws IllegalAccessException the illegal access exception + */ @Nullable Object invokeOrigin() throws InvocationTargetException, IllegalAccessException; + /** + * Gets extra. + * + * @param the type parameter + * @param key the key + * @return the extra + */ @Nullable U getExtra(@NonNull String key); } + /** + * The interface Before hooker. + * + * @param the type parameter + */ interface BeforeHooker { + /** + * Before. + * + * @param callback the callback + */ void before(@NonNull BeforeHookCallback callback); } + /** + * The interface After hooker. + * + * @param the type parameter + */ interface AfterHooker { + /** + * After. + * + * @param callback the callback + */ void after(@NonNull AfterHookCallback callback); } + /** + * The interface Hooker. + * + * @param the type parameter + */ interface Hooker extends BeforeHooker, AfterHooker { } + /** + * The interface Method unhooker. + * + * @param the type parameter + * @param the type parameter + */ interface MethodUnhooker { + /** + * Gets origin. + * + * @return the origin + */ @NonNull U getOrigin(); + /** + * Gets hooker. + * + * @return the hooker + */ @NonNull T getHooker(); + /** + * Unhook. + */ void unhook(); } + /** + * Gets framework name. + * + * @return the framework name + */ @NonNull String getFrameworkName(); + /** + * Gets framework version. + * + * @return the framework version + */ @NonNull String getFrameworkVersion(); + /** + * Gets framework version code. + * + * @return the framework version code + */ long getFrameworkVersionCode(); + /** + * Gets framework privilege. + * + * @return the framework privilege + */ int getFrameworkPrivilege(); + /** + * Featured method object. + * + * @param name the name + * @param args the args + * @return the object + */ Object featuredMethod(String name, Object... args); + /** + * Hook before method unhooker. + * + * @param origin the origin + * @param hooker the hooker + * @return the method unhooker + */ @Nullable MethodUnhooker, Method> hookBefore(@NonNull Method origin, @NonNull BeforeHooker hooker); + /** + * Hook after method unhooker. + * + * @param origin the origin + * @param hooker the hooker + * @return the method unhooker + */ @Nullable MethodUnhooker, Method> hookAfter(@NonNull Method origin, @NonNull AfterHooker hooker); + /** + * Hook method unhooker. + * + * @param origin the origin + * @param hooker the hooker + * @return the method unhooker + */ @Nullable MethodUnhooker, Method> hook(@NonNull Method origin, @NonNull Hooker hooker); + /** + * Hook before method unhooker. + * + * @param origin the origin + * @param priority the priority + * @param hooker the hooker + * @return the method unhooker + */ @Nullable MethodUnhooker, Method> hookBefore(@NonNull Method origin, int priority, @NonNull BeforeHooker hooker); + /** + * Hook after method unhooker. + * + * @param origin the origin + * @param priority the priority + * @param hooker the hooker + * @return the method unhooker + */ @Nullable MethodUnhooker, Method> hookAfter(@NonNull Method origin, int priority, @NonNull AfterHooker hooker); + /** + * Hook method unhooker. + * + * @param origin the origin + * @param priority the priority + * @param hooker the hooker + * @return the method unhooker + */ @Nullable MethodUnhooker, Method> hook(@NonNull Method origin, int priority, @NonNull Hooker hooker); + /** + * Hook before method unhooker. + * + * @param the type parameter + * @param origin the origin + * @param hooker the hooker + * @return the method unhooker + */ @Nullable MethodUnhooker>, Constructor> hookBefore(@NonNull Constructor origin, @NonNull BeforeHooker> hooker); + /** + * Hook after method unhooker. + * + * @param the type parameter + * @param origin the origin + * @param hooker the hooker + * @return the method unhooker + */ @Nullable MethodUnhooker>, Constructor> hookAfter(@NonNull Constructor origin, @NonNull AfterHooker> hooker); + /** + * Hook method unhooker. + * + * @param the type parameter + * @param origin the origin + * @param hooker the hooker + * @return the method unhooker + */ @Nullable MethodUnhooker>, Constructor> hook(@NonNull Constructor origin, @NonNull Hooker> hooker); + /** + * Hook before method unhooker. + * + * @param the type parameter + * @param origin the origin + * @param priority the priority + * @param hooker the hooker + * @return the method unhooker + */ @Nullable MethodUnhooker>, Constructor> hookBefore(@NonNull Constructor origin, int priority, @NonNull BeforeHooker> hooker); + /** + * Hook after method unhooker. + * + * @param the type parameter + * @param origin the origin + * @param priority the priority + * @param hooker the hooker + * @return the method unhooker + */ @Nullable MethodUnhooker>, Constructor> hookAfter(@NonNull Constructor origin, int priority, @NonNull AfterHooker> hooker); + /** + * Hook method unhooker. + * + * @param the type parameter + * @param origin the origin + * @param priority the priority + * @param hooker the hooker + * @return the method unhooker + */ @Nullable MethodUnhooker>, Constructor> hook(@NonNull Constructor origin, int priority, @NonNull Hooker> hooker); + /** + * Deoptimize boolean. + * + * @param method the method + * @return the boolean + */ boolean deoptimize(@NonNull Method method); + /** + * Deoptimize boolean. + * + * @param the type parameter + * @param constructor the constructor + * @return the boolean + */ boolean deoptimize(@NonNull Constructor constructor); + /** + * Log. + * + * @param message the message + */ void log(@NonNull String message); + /** + * Log. + * + * @param message the message + * @param throwable the throwable + */ void log(@NonNull String message, @NonNull Throwable throwable); + /** + * Parse dex dex parser. + * + * @param dexData the dex data + * @param includeAnnotations the include annotations + * @return the dex parser + * @throws IOException the io exception + */ @Nullable DexParser parseDex(@NonNull ByteBuffer dexData, boolean includeAnnotations) throws IOException; } diff --git a/api/src/main/java/io/github/libxposed/XposedModule.java b/api/src/main/java/io/github/libxposed/XposedModule.java index 4fb1525..23a6ed6 100644 --- a/api/src/main/java/io/github/libxposed/XposedModule.java +++ b/api/src/main/java/io/github/libxposed/XposedModule.java @@ -2,8 +2,17 @@ package io.github.libxposed; import androidx.annotation.NonNull; +/** + * The type Xposed module. + */ @SuppressWarnings("unused") public abstract class XposedModule extends XposedContextWrapper implements XposedModuleInterface { + /** + * Instantiates a new Xposed module. + * + * @param base the base + * @param param the param + */ public XposedModule(XposedContext base, @NonNull ModuleLoadedParam param) { super(base); } diff --git a/api/src/main/java/io/github/libxposed/XposedModuleInterface.java b/api/src/main/java/io/github/libxposed/XposedModuleInterface.java index 373f0b1..7103523 100644 --- a/api/src/main/java/io/github/libxposed/XposedModuleInterface.java +++ b/api/src/main/java/io/github/libxposed/XposedModuleInterface.java @@ -6,39 +6,103 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +/** + * The interface Xposed module interface. + */ @SuppressWarnings("unused") public interface XposedModuleInterface { + /** + * The interface Module loaded param. + */ interface ModuleLoadedParam { + /** + * Is system server boolean. + * + * @return the boolean + */ boolean isSystemServer(); + /** + * Gets process name. + * + * @return the process name + */ @NonNull String getProcessName(); + /** + * Gets app data dir. + * + * @return the app data dir + */ @NonNull String getAppDataDir(); + /** + * Gets extras. + * + * @return the extras + */ @Nullable Bundle getExtras(); } + /** + * The interface Package loaded param. + */ interface PackageLoadedParam { + /** + * Gets package name. + * + * @return the package name + */ @NonNull String getPackageName(); + /** + * Gets app info. + * + * @return the app info + */ @NonNull ApplicationInfo getAppInfo(); + /** + * Gets class loader. + * + * @return the class loader + */ @NonNull ClassLoader getClassLoader(); + /** + * Gets process name. + * + * @return the process name + */ @NonNull String getProcessName(); + /** + * Is first application boolean. + * + * @return the boolean + */ boolean isFirstApplication(); + /** + * Gets extras. + * + * @return the extras + */ @Nullable Bundle getExtras(); } + /** + * On package loaded. + * + * @param param the param + */ void onPackageLoaded(@NonNull PackageLoadedParam param); } diff --git a/api/src/main/java/io/github/libxposed/utils/DexParser.java b/api/src/main/java/io/github/libxposed/utils/DexParser.java index 3ba66f8..8e6ba86 100644 --- a/api/src/main/java/io/github/libxposed/utils/DexParser.java +++ b/api/src/main/java/io/github/libxposed/utils/DexParser.java @@ -5,130 +5,372 @@ import androidx.annotation.Nullable; import java.io.Closeable; +/** + * The interface Dex parser. + */ @SuppressWarnings("unused") public interface DexParser extends Closeable { + /** + * The constant NO_INDEX. + */ int NO_INDEX = 0xffffffff; + /** + * The interface Array. + */ interface Array { + /** + * Get values value [ ]. + * + * @return the value [ ] + */ @NonNull Value[] getValues(); } + /** + * The interface Annotation. + */ interface Annotation { + /** + * Gets visibility. + * + * @return the visibility + */ int getVisibility(); + /** + * Gets type. + * + * @return the type + */ @NonNull TypeId getType(); + /** + * Get elements element [ ]. + * + * @return the element [ ] + */ @NonNull Element[] getElements(); } + /** + * The interface Value. + */ interface Value { + /** + * Get value byte [ ]. + * + * @return the byte [ ] + */ @Nullable byte[] getValue(); + /** + * Gets value type. + * + * @return the value type + */ int getValueType(); } + /** + * The interface Element. + */ interface Element extends Value { + /** + * Gets name. + * + * @return the name + */ @NonNull StringId getName(); } + /** + * The interface Type id. + */ interface TypeId { + /** + * Gets descriptor. + * + * @return the descriptor + */ @NonNull StringId getDescriptor(); } + /** + * The interface Id. + */ interface Id { + /** + * Gets id. + * + * @return the id + */ int getId(); } + /** + * The interface String id. + */ interface StringId extends Id { + /** + * Gets string. + * + * @return the string + */ @NonNull String getString(); } + /** + * The interface Field id. + */ interface FieldId extends Id { + /** + * Gets type. + * + * @return the type + */ @NonNull TypeId getType(); + /** + * Gets declaring class. + * + * @return the declaring class + */ @NonNull TypeId getDeclaringClass(); + /** + * Gets name. + * + * @return the name + */ @NonNull StringId getName(); } + /** + * The interface Method id. + */ interface MethodId extends Id { + /** + * Gets declaring class. + * + * @return the declaring class + */ @NonNull TypeId getDeclaringClass(); + /** + * Gets prototype. + * + * @return the prototype + */ @NonNull ProtoId getPrototype(); + /** + * Gets name. + * + * @return the name + */ @NonNull StringId getName(); } + /** + * The interface Proto id. + */ interface ProtoId extends Id { + /** + * Gets shorty. + * + * @return the shorty + */ @NonNull StringId getShorty(); + /** + * Gets return type. + * + * @return the return type + */ @NonNull TypeId getReturnType(); + /** + * Get parameters type id [ ]. + * + * @return the type id [ ] + */ @Nullable TypeId[] getParameters(); } + /** + * Get string id string id [ ]. + * + * @return the string id [ ] + */ @NonNull StringId[] getStringId(); + /** + * Get type id type id [ ]. + * + * @return the type id [ ] + */ @NonNull TypeId[] getTypeId(); + /** + * Get field id field id [ ]. + * + * @return the field id [ ] + */ @NonNull FieldId[] getFieldId(); + /** + * Get method id method id [ ]. + * + * @return the method id [ ] + */ @NonNull MethodId[] getMethodId(); + /** + * Get proto id proto id [ ]. + * + * @return the proto id [ ] + */ @NonNull ProtoId[] getProtoId(); + /** + * Get annotations annotation [ ]. + * + * @return the annotation [ ] + */ @NonNull Annotation[] getAnnotations(); + /** + * Get arrays array [ ]. + * + * @return the array [ ] + */ @NonNull Array[] getArrays(); + /** + * The interface Early stop visitor. + */ interface EarlyStopVisitor { + /** + * Stop boolean. + * + * @return the boolean + */ boolean stop(); } + /** + * The interface Member visitor. + */ interface MemberVisitor extends EarlyStopVisitor { } + /** + * The interface Class visitor. + */ interface ClassVisitor extends EarlyStopVisitor { + /** + * Visit member visitor. + * + * @param clazz the clazz + * @param accessFlags the access flags + * @param superClass the super class + * @param interfaces the interfaces + * @param sourceFile the source file + * @param staticFields the static fields + * @param staticFieldsAccessFlags the static fields access flags + * @param instanceFields the instance fields + * @param instanceFieldsAccessFlags the instance fields access flags + * @param directMethods the direct methods + * @param directMethodsAccessFlags the direct methods access flags + * @param virtualMethods the virtual methods + * @param virtualMethodsAccessFlags the virtual methods access flags + * @param annotations the annotations + * @return the member visitor + */ @Nullable MemberVisitor visit(int clazz, int accessFlags, int superClass, @NonNull int[] interfaces, int sourceFile, @NonNull int[] staticFields, @NonNull int[] staticFieldsAccessFlags, @NonNull int[] instanceFields, @NonNull int[] instanceFieldsAccessFlags, @NonNull int[] directMethods, @NonNull int[] directMethodsAccessFlags, @NonNull int[] virtualMethods, @NonNull int[] virtualMethodsAccessFlags, @NonNull int[] annotations); } + /** + * The interface Field visitor. + */ interface FieldVisitor extends MemberVisitor { + /** + * Visit. + * + * @param field the field + * @param accessFlags the access flags + * @param annotations the annotations + */ void visit(int field, int accessFlags, @NonNull int[] annotations); } + /** + * The interface Method visitor. + */ interface MethodVisitor extends MemberVisitor { + /** + * Visit method body visitor. + * + * @param method the method + * @param accessFlags the access flags + * @param hasBody the has body + * @param annotations the annotations + * @param parameterAnnotations the parameter annotations + * @return the method body visitor + */ @Nullable MethodBodyVisitor visit(int method, int accessFlags, boolean hasBody, @NonNull int[] annotations, @NonNull int[] parameterAnnotations); } + /** + * The interface Method body visitor. + */ interface MethodBodyVisitor { + /** + * Visit. + * + * @param method the method + * @param accessFlags the access flags + * @param referredStrings the referred strings + * @param invokedMethods the invoked methods + * @param accessedFields the accessed fields + * @param assignedFields the assigned fields + * @param opcodes the opcodes + */ void visit(int method, int accessFlags, @NonNull int[] referredStrings, @NonNull int[] invokedMethods, @NonNull int[] accessedFields, @NonNull int[] assignedFields, @NonNull byte[] opcodes); } + /** + * Visit defined classes. + * + * @param visitor the visitor + * @throws IllegalStateException the illegal state exception + */ void visitDefinedClasses(@NonNull ClassVisitor visitor) throws IllegalStateException; }