From 06becefd97b203d488d2c0e2b41180f7a70e951d Mon Sep 17 00:00:00 2001 From: Kitsune Date: Tue, 5 Mar 2024 17:03:52 +0800 Subject: [PATCH] Add `createBeforeHook` & `createAfterHook` for HookFactory --- EzXHelper/api/EzXHelper.api | 40 ++++ EzXHelper/build.gradle | 2 +- .../github/kyuubiran/ezxhelper/HookFactory.kt | 182 +++++++++++++++++- README.md | 2 +- README_en.md | 2 +- build.gradle | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 7 files changed, 218 insertions(+), 16 deletions(-) diff --git a/EzXHelper/api/EzXHelper.api b/EzXHelper/api/EzXHelper.api index c855567..f4b1e64 100644 --- a/EzXHelper/api/EzXHelper.api +++ b/EzXHelper/api/EzXHelper.api @@ -156,9 +156,21 @@ public final class com/github/kyuubiran/ezxhelper/HookFactory { public synthetic fun (Ljava/lang/reflect/Method;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun after (Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)V public final fun before (Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)V + public static final fun createConstructorAfterHook (Ljava/lang/reflect/Constructor;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Lde/robv/android/xposed/XC_MethodHook$Unhook; + public static final fun createConstructorAfterHooks (Ljava/lang/Iterable;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public static final fun createConstructorAfterHooks ([Ljava/lang/reflect/Constructor;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public static final fun createConstructorBeforeHook (Ljava/lang/reflect/Constructor;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Lde/robv/android/xposed/XC_MethodHook$Unhook; + public static final fun createConstructorBeforeHooks (Ljava/lang/Iterable;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public static final fun createConstructorBeforeHooks ([Ljava/lang/reflect/Constructor;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; public static final fun createConstructorHook (Ljava/lang/reflect/Constructor;Ljava/util/function/Consumer;)Lde/robv/android/xposed/XC_MethodHook$Unhook; public static final fun createConstructorHooks (Ljava/lang/Iterable;Ljava/util/function/Consumer;)Ljava/util/List; public static final fun createConstructorHooks ([Ljava/lang/reflect/Constructor;Ljava/util/function/Consumer;)Ljava/util/List; + public static final fun createMethodAfterHook (Ljava/lang/reflect/Method;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Lde/robv/android/xposed/XC_MethodHook$Unhook; + public static final fun createMethodAfterHooks (Ljava/lang/Iterable;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public static final fun createMethodAfterHooks ([Ljava/lang/reflect/Method;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public static final fun createMethodBeforeHook (Ljava/lang/reflect/Method;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Lde/robv/android/xposed/XC_MethodHook$Unhook; + public static final fun createMethodBeforeHooks (Ljava/lang/Iterable;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public static final fun createMethodBeforeHooks ([Ljava/lang/reflect/Method;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; public static final fun createMethodHook (Ljava/lang/reflect/Method;Ljava/util/function/Consumer;)Lde/robv/android/xposed/XC_MethodHook$Unhook; public static final fun createMethodHooks (Ljava/lang/Iterable;Ljava/util/function/Consumer;)Ljava/util/List; public static final fun createMethodHooks ([Ljava/lang/reflect/Method;Ljava/util/function/Consumer;)Ljava/util/List; @@ -168,15 +180,39 @@ public final class com/github/kyuubiran/ezxhelper/HookFactory { } public final class com/github/kyuubiran/ezxhelper/HookFactory$-Static { + public final fun -createConstructorAfterHook (Ljava/lang/reflect/Constructor;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Lde/robv/android/xposed/XC_MethodHook$Unhook; + public final fun -createConstructorAfterHooks (Ljava/lang/Iterable;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public final fun -createConstructorAfterHooks ([Ljava/lang/reflect/Constructor;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public final fun -createConstructorBeforeHook (Ljava/lang/reflect/Constructor;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Lde/robv/android/xposed/XC_MethodHook$Unhook; + public final fun -createConstructorBeforeHooks (Ljava/lang/Iterable;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public final fun -createConstructorBeforeHooks ([Ljava/lang/reflect/Constructor;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; public final fun -createConstructorHook (Ljava/lang/reflect/Constructor;Lkotlin/jvm/functions/Function1;)Lde/robv/android/xposed/XC_MethodHook$Unhook; public final fun -createConstructorHooks (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; public final fun -createConstructorHooks ([Ljava/lang/reflect/Constructor;Lkotlin/jvm/functions/Function1;)Ljava/util/List; + public final fun -createMethodAfterHook (Ljava/lang/reflect/Method;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Lde/robv/android/xposed/XC_MethodHook$Unhook; + public final fun -createMethodAfterHooks (Ljava/lang/Iterable;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public final fun -createMethodAfterHooks ([Ljava/lang/reflect/Method;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public final fun -createMethodBeforeHook (Ljava/lang/reflect/Method;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Lde/robv/android/xposed/XC_MethodHook$Unhook; + public final fun -createMethodBeforeHooks (Ljava/lang/Iterable;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public final fun -createMethodBeforeHooks ([Ljava/lang/reflect/Method;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; public final fun -createMethodHook (Ljava/lang/reflect/Method;Lkotlin/jvm/functions/Function1;)Lde/robv/android/xposed/XC_MethodHook$Unhook; public final fun -createMethodHooks (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; public final fun -createMethodHooks ([Ljava/lang/reflect/Method;Lkotlin/jvm/functions/Function1;)Ljava/util/List; + public final fun createConstructorAfterHook (Ljava/lang/reflect/Constructor;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Lde/robv/android/xposed/XC_MethodHook$Unhook; + public final fun createConstructorAfterHooks (Ljava/lang/Iterable;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public final fun createConstructorAfterHooks ([Ljava/lang/reflect/Constructor;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public final fun createConstructorBeforeHook (Ljava/lang/reflect/Constructor;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Lde/robv/android/xposed/XC_MethodHook$Unhook; + public final fun createConstructorBeforeHooks (Ljava/lang/Iterable;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public final fun createConstructorBeforeHooks ([Ljava/lang/reflect/Constructor;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; public final fun createConstructorHook (Ljava/lang/reflect/Constructor;Ljava/util/function/Consumer;)Lde/robv/android/xposed/XC_MethodHook$Unhook; public final fun createConstructorHooks (Ljava/lang/Iterable;Ljava/util/function/Consumer;)Ljava/util/List; public final fun createConstructorHooks ([Ljava/lang/reflect/Constructor;Ljava/util/function/Consumer;)Ljava/util/List; + public final fun createMethodAfterHook (Ljava/lang/reflect/Method;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Lde/robv/android/xposed/XC_MethodHook$Unhook; + public final fun createMethodAfterHooks (Ljava/lang/Iterable;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public final fun createMethodAfterHooks ([Ljava/lang/reflect/Method;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public final fun createMethodBeforeHook (Ljava/lang/reflect/Method;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Lde/robv/android/xposed/XC_MethodHook$Unhook; + public final fun createMethodBeforeHooks (Ljava/lang/Iterable;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; + public final fun createMethodBeforeHooks ([Ljava/lang/reflect/Method;Lcom/github/kyuubiran/ezxhelper/interfaces/IMethodHookCallback;)Ljava/util/List; public final fun createMethodHook (Ljava/lang/reflect/Method;Ljava/util/function/Consumer;)Lde/robv/android/xposed/XC_MethodHook$Unhook; public final fun createMethodHooks (Ljava/lang/Iterable;Ljava/util/function/Consumer;)Ljava/util/List; public final fun createMethodHooks ([Ljava/lang/reflect/Method;Ljava/util/function/Consumer;)Ljava/util/List; @@ -575,10 +611,14 @@ public abstract class com/github/kyuubiran/ezxhelper/finders/base/BaseFinder : c public final fun plusAssign (Lkotlin/sequences/Sequence;)V public final fun plusAssign ([Ljava/lang/Object;)V public final fun requireSingle ()Ljava/lang/Object; + public final fun requireSingle (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun requireSingleOrNull ()Ljava/lang/Object; + public final fun requireSingleOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; protected final fun setSequence (Lkotlin/sequences/Sequence;)V public final fun single ()Ljava/lang/Object; + public final fun single (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun singleOrNull ()Ljava/lang/Object; + public final fun singleOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun toCollection (Ljava/util/Collection;)Ljava/util/Collection; public final fun toHashSet ()Ljava/util/HashSet; public final fun toList ()Ljava/util/List; diff --git a/EzXHelper/build.gradle b/EzXHelper/build.gradle index 9959424..bb64ee2 100644 --- a/EzXHelper/build.gradle +++ b/EzXHelper/build.gradle @@ -6,7 +6,7 @@ plugins { id 'signing' } -def versionName = "2.0.9" +def versionName = "2.1.0" android { compileSdkVersion = 34 diff --git a/EzXHelper/src/main/java/com/github/kyuubiran/ezxhelper/HookFactory.kt b/EzXHelper/src/main/java/com/github/kyuubiran/ezxhelper/HookFactory.kt index 6e28a7e..c44660d 100644 --- a/EzXHelper/src/main/java/com/github/kyuubiran/ezxhelper/HookFactory.kt +++ b/EzXHelper/src/main/java/com/github/kyuubiran/ezxhelper/HookFactory.kt @@ -82,57 +82,219 @@ class HookFactory { companion object `-Static` { @JvmName("-createMethodHook") @KotlinOnly - fun Method.createHook(block: HookFactory.() -> Unit): Unhook = HookFactory(this).also(block).create() + fun Method.createHook(block: HookFactory.() -> Unit): Unhook = + HookFactory(this).also(block).create() + + @JvmName("-createMethodBeforeHook") + @KotlinOnly + fun Method.createBeforeHook(block: IMethodHookCallback): Unhook = + HookFactory(this).apply { beforeHook = block }.create() + + @JvmName("-createMethodAfterHook") + @KotlinOnly + fun Method.createAfterHook(block: IMethodHookCallback): Unhook = + HookFactory(this).apply { afterHook = block }.create() @JvmName("-createConstructorHook") @KotlinOnly - fun Constructor<*>.createHook(block: HookFactory.() -> Unit): Unhook = HookFactory(this).also(block).create() + fun Constructor<*>.createHook(block: HookFactory.() -> Unit): Unhook = + HookFactory(this).also(block).create() + + @JvmName("-createConstructorBeforeHook") + @KotlinOnly + fun Constructor<*>.createBeforeHook(block: IMethodHookCallback): Unhook = + HookFactory(this).apply { beforeHook = block }.create() + + @JvmName("-createConstructorAfterHook") + @KotlinOnly + fun Constructor<*>.createAfterHook(block: IMethodHookCallback): Unhook = + HookFactory(this).apply { afterHook = block }.create() @JvmName("-createMethodHooks") @KotlinOnly - fun Iterable.createHooks(block: HookFactory.() -> Unit): List = map { it.createHook(block) } + fun Iterable.createHooks(block: HookFactory.() -> Unit): List = + map { it.createHook(block) } + + @JvmName("-createMethodBeforeHooks") + @KotlinOnly + fun Iterable.createBeforeHooks(block: IMethodHookCallback): List = + map { it.createBeforeHook(block) } + + @JvmName("-createMethodAfterHooks") + @KotlinOnly + fun Iterable.createAfterHooks(block: IMethodHookCallback): List = + map { it.createAfterHook(block) } @JvmName("-createMethodHooks") @KotlinOnly - fun Array.createHooks(block: HookFactory.() -> Unit): List = map { it.createHook(block) } + fun Array.createHooks(block: HookFactory.() -> Unit): List = + map { it.createHook(block) } + + @JvmName("-createMethodBeforeHooks") + @KotlinOnly + fun Array.createBeforeHooks(block: IMethodHookCallback): List = + map { it.createBeforeHook(block) } + + @JvmName("-createMethodAfterHooks") + @KotlinOnly + fun Array.createAfterHooks(block: IMethodHookCallback): List = + map { it.createAfterHook(block) } @JvmName("-createConstructorHooks") @KotlinOnly - fun Iterable>.createHooks(block: HookFactory.() -> Unit): List = map { it.createHook(block) } + fun Iterable>.createHooks(block: HookFactory.() -> Unit): List = + map { it.createHook(block) } + + @JvmName("-createConstructorBeforeHooks") + @KotlinOnly + fun Iterable>.createBeforeHooks(block: IMethodHookCallback): List = + map { it.createBeforeHook(block) } + + @JvmName("-createConstructorAfterHooks") + @KotlinOnly + fun Iterable>.createAfterHooks(block: IMethodHookCallback): List = + map { it.createAfterHook(block) } @JvmName("-createConstructorHooks") @KotlinOnly - fun Array>.createHooks(block: HookFactory.() -> Unit): List = map { it.createHook(block) } + fun Array>.createHooks(block: HookFactory.() -> Unit): List = + map { it.createHook(block) } + + @JvmName("-createConstructorBeforeHooks") + @KotlinOnly + fun Array>.createBeforeHooks(block: IMethodHookCallback): List = + map { it.createBeforeHook(block) } + + @JvmName("-createConstructorAfterHooks") + @KotlinOnly + fun Array>.createAfterHooks(block: IMethodHookCallback): List = + map { it.createAfterHook(block) } @JvmName("createMethodHook") @JvmStatic fun createHook(m: Method, block: Consumer): XC_MethodHook.Unhook = HookFactory(m).also { block.accept(it) }.create() + @JvmName("createMethodBeforeHook") + @JvmStatic + fun createBeforeHook(m: Method, block: IMethodHookCallback): XC_MethodHook.Unhook = + HookFactory(m).apply { beforeHook = block }.create() + + @JvmName("createMethodAfterHook") + @JvmStatic + fun createAfterHook(m: Method, block: IMethodHookCallback): XC_MethodHook.Unhook = + HookFactory(m).apply { afterHook = block }.create() + @JvmName("createConstructorHook") @JvmStatic fun createHook(c: Constructor<*>, block: Consumer): XC_MethodHook.Unhook = HookFactory(c).also { block.accept(it) }.create() + @JvmName("createConstructorBeforeHook") + @JvmStatic + fun createBeforeHook(c: Constructor<*>, block: IMethodHookCallback): XC_MethodHook.Unhook = + HookFactory(c).apply { beforeHook = block }.create() + + @JvmName("createConstructorAfterHook") + @JvmStatic + fun createAfterHook(c: Constructor<*>, block: IMethodHookCallback): XC_MethodHook.Unhook = + HookFactory(c).apply { afterHook = block }.create() + @JvmName("createMethodHooks") @JvmStatic - fun createHooks(m: Iterable, block: Consumer): List = + fun createHooks( + m: Iterable, + block: Consumer + ): List = m.map { createHook(it, block) } + @JvmName("createMethodBeforeHooks") + @JvmStatic + fun createBeforeHooks( + m: Iterable, + block: IMethodHookCallback + ): List = + m.map { createBeforeHook(it, block) } + + @JvmName("createMethodAfterHooks") + @JvmStatic + fun createAfterHooks( + m: Iterable, + block: IMethodHookCallback + ): List = + m.map { createAfterHook(it, block) } + @JvmName("createMethodHooks") @JvmStatic - fun createHooks(m: Array, block: Consumer): List = + fun createHooks( + m: Array, + block: Consumer + ): List = m.map { createHook(it, block) } + @JvmName("createMethodBeforeHooks") + @JvmStatic + fun createBeforeHooks( + m: Array, + block: IMethodHookCallback + ): List = + m.map { createBeforeHook(it, block) } + + @JvmName("createMethodAfterHooks") + @JvmStatic + fun createAfterHooks( + m: Array, + block: IMethodHookCallback + ): List = + m.map { createAfterHook(it, block) } + @JvmName("createConstructorHooks") @JvmStatic - fun createHooks(c: Iterable>, block: Consumer): List = + fun createHooks( + c: Iterable>, + block: Consumer + ): List = c.map { createHook(it, block) } + @JvmName("createConstructorBeforeHooks") + @JvmStatic + fun createBeforeHooks( + c: Iterable>, + block: IMethodHookCallback + ): List = + c.map { createBeforeHook(it, block) } + + @JvmName("createConstructorAfterHooks") + @JvmStatic + fun createAfterHooks( + c: Iterable>, + block: IMethodHookCallback + ): List = + c.map { createAfterHook(it, block) } + @JvmName("createConstructorHooks") @JvmStatic - fun createHooks(c: Array>, block: Consumer): List = + fun createHooks( + c: Array>, + block: Consumer + ): List = c.map { createHook(it, block) } + + @JvmName("createConstructorBeforeHooks") + @JvmStatic + fun createBeforeHooks( + c: Array>, + block: IMethodHookCallback + ): List = + c.map { createBeforeHook(it, block) } + + @JvmName("createConstructorAfterHooks") + @JvmStatic + fun createAfterHooks( + c: Array>, + block: IMethodHookCallback + ): List = + c.map { createAfterHook(it, block) } } } diff --git a/README.md b/README.md index 79844ab..e825399 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ 加入Telegram群组来获取帮助: [![Telegram](https://img.shields.io/badge/Join-Telegram-blue)](https://t.me/EzXHelper) 一个使Xposed模块开发变的更轻松的工具库,2.x版本已支持Java! -2.x版本已经发布!最新版为`2.0.9` 旧版本请看`1.x`分支 +2.x版本已经发布!最新版为`2.1.0` 旧版本请看`1.x`分支 ### 使用本库的项目 diff --git a/README_en.md b/README_en.md index 52cca80..e939877 100644 --- a/README_en.md +++ b/README_en.md @@ -4,7 +4,7 @@ Join Telegram group to get help: [![Telegram](https://img.shields.io/badge/Join-Telegram-blue)](https://t.me/EzXHelper) A library to make Xposed modules development easier, 2.x version supports Java! -2.x is released now! The latest version is `2.0.9`. Old version please look the `1.x` branch. +2.x is released now! The latest version is `2.1.0`. Old version please look the `1.x` branch. ### Projects that use this library diff --git a/build.gradle b/build.gradle index 1964b49..ffdd8cc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '8.2.2' apply false - id 'com.android.library' version '8.2.2' apply false + id 'com.android.application' version '8.3.0' apply false + id 'com.android.library' version '8.3.0' apply false id 'org.jetbrains.kotlin.android' version '1.9.22' apply false id 'org.jetbrains.dokka' version '1.9.10' apply false id 'org.jetbrains.kotlinx.binary-compatibility-validator' version '0.13.2' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a363877..744c64d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists