Skip to content

Commit

Permalink
Add createBeforeHook & createAfterHook for HookFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
KyuubiRan committed Mar 5, 2024
1 parent dcb2905 commit 06becef
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 16 deletions.
40 changes: 40 additions & 0 deletions EzXHelper/api/EzXHelper.api
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,21 @@ public final class com/github/kyuubiran/ezxhelper/HookFactory {
public synthetic fun <init> (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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion EzXHelper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id 'signing'
}

def versionName = "2.0.9"
def versionName = "2.1.0"

android {
compileSdkVersion = 34
Expand Down
182 changes: 172 additions & 10 deletions EzXHelper/src/main/java/com/github/kyuubiran/ezxhelper/HookFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Method>.createHooks(block: HookFactory.() -> Unit): List<Unhook> = map { it.createHook(block) }
fun Iterable<Method>.createHooks(block: HookFactory.() -> Unit): List<Unhook> =
map { it.createHook(block) }

@JvmName("-createMethodBeforeHooks")
@KotlinOnly
fun Iterable<Method>.createBeforeHooks(block: IMethodHookCallback): List<Unhook> =
map { it.createBeforeHook(block) }

@JvmName("-createMethodAfterHooks")
@KotlinOnly
fun Iterable<Method>.createAfterHooks(block: IMethodHookCallback): List<Unhook> =
map { it.createAfterHook(block) }

@JvmName("-createMethodHooks")
@KotlinOnly
fun Array<Method>.createHooks(block: HookFactory.() -> Unit): List<Unhook> = map { it.createHook(block) }
fun Array<Method>.createHooks(block: HookFactory.() -> Unit): List<Unhook> =
map { it.createHook(block) }

@JvmName("-createMethodBeforeHooks")
@KotlinOnly
fun Array<Method>.createBeforeHooks(block: IMethodHookCallback): List<Unhook> =
map { it.createBeforeHook(block) }

@JvmName("-createMethodAfterHooks")
@KotlinOnly
fun Array<Method>.createAfterHooks(block: IMethodHookCallback): List<Unhook> =
map { it.createAfterHook(block) }

@JvmName("-createConstructorHooks")
@KotlinOnly
fun Iterable<Constructor<*>>.createHooks(block: HookFactory.() -> Unit): List<Unhook> = map { it.createHook(block) }
fun Iterable<Constructor<*>>.createHooks(block: HookFactory.() -> Unit): List<Unhook> =
map { it.createHook(block) }

@JvmName("-createConstructorBeforeHooks")
@KotlinOnly
fun Iterable<Constructor<*>>.createBeforeHooks(block: IMethodHookCallback): List<Unhook> =
map { it.createBeforeHook(block) }

@JvmName("-createConstructorAfterHooks")
@KotlinOnly
fun Iterable<Constructor<*>>.createAfterHooks(block: IMethodHookCallback): List<Unhook> =
map { it.createAfterHook(block) }

@JvmName("-createConstructorHooks")
@KotlinOnly
fun Array<Constructor<*>>.createHooks(block: HookFactory.() -> Unit): List<Unhook> = map { it.createHook(block) }
fun Array<Constructor<*>>.createHooks(block: HookFactory.() -> Unit): List<Unhook> =
map { it.createHook(block) }

@JvmName("-createConstructorBeforeHooks")
@KotlinOnly
fun Array<Constructor<*>>.createBeforeHooks(block: IMethodHookCallback): List<Unhook> =
map { it.createBeforeHook(block) }

@JvmName("-createConstructorAfterHooks")
@KotlinOnly
fun Array<Constructor<*>>.createAfterHooks(block: IMethodHookCallback): List<Unhook> =
map { it.createAfterHook(block) }

@JvmName("createMethodHook")
@JvmStatic
fun createHook(m: Method, block: Consumer<HookFactory>): 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<HookFactory>): 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<Method>, block: Consumer<HookFactory>): List<XC_MethodHook.Unhook> =
fun createHooks(
m: Iterable<Method>,
block: Consumer<HookFactory>
): List<XC_MethodHook.Unhook> =
m.map { createHook(it, block) }

@JvmName("createMethodBeforeHooks")
@JvmStatic
fun createBeforeHooks(
m: Iterable<Method>,
block: IMethodHookCallback
): List<XC_MethodHook.Unhook> =
m.map { createBeforeHook(it, block) }

@JvmName("createMethodAfterHooks")
@JvmStatic
fun createAfterHooks(
m: Iterable<Method>,
block: IMethodHookCallback
): List<XC_MethodHook.Unhook> =
m.map { createAfterHook(it, block) }

@JvmName("createMethodHooks")
@JvmStatic
fun createHooks(m: Array<Method>, block: Consumer<HookFactory>): List<XC_MethodHook.Unhook> =
fun createHooks(
m: Array<Method>,
block: Consumer<HookFactory>
): List<XC_MethodHook.Unhook> =
m.map { createHook(it, block) }

@JvmName("createMethodBeforeHooks")
@JvmStatic
fun createBeforeHooks(
m: Array<Method>,
block: IMethodHookCallback
): List<XC_MethodHook.Unhook> =
m.map { createBeforeHook(it, block) }

@JvmName("createMethodAfterHooks")
@JvmStatic
fun createAfterHooks(
m: Array<Method>,
block: IMethodHookCallback
): List<XC_MethodHook.Unhook> =
m.map { createAfterHook(it, block) }

@JvmName("createConstructorHooks")
@JvmStatic
fun createHooks(c: Iterable<Constructor<*>>, block: Consumer<HookFactory>): List<XC_MethodHook.Unhook> =
fun createHooks(
c: Iterable<Constructor<*>>,
block: Consumer<HookFactory>
): List<XC_MethodHook.Unhook> =
c.map { createHook(it, block) }

@JvmName("createConstructorBeforeHooks")
@JvmStatic
fun createBeforeHooks(
c: Iterable<Constructor<*>>,
block: IMethodHookCallback
): List<XC_MethodHook.Unhook> =
c.map { createBeforeHook(it, block) }

@JvmName("createConstructorAfterHooks")
@JvmStatic
fun createAfterHooks(
c: Iterable<Constructor<*>>,
block: IMethodHookCallback
): List<XC_MethodHook.Unhook> =
c.map { createAfterHook(it, block) }

@JvmName("createConstructorHooks")
@JvmStatic
fun createHooks(c: Array<Constructor<*>>, block: Consumer<HookFactory>): List<XC_MethodHook.Unhook> =
fun createHooks(
c: Array<Constructor<*>>,
block: Consumer<HookFactory>
): List<XC_MethodHook.Unhook> =
c.map { createHook(it, block) }

@JvmName("createConstructorBeforeHooks")
@JvmStatic
fun createBeforeHooks(
c: Array<Constructor<*>>,
block: IMethodHookCallback
): List<XC_MethodHook.Unhook> =
c.map { createBeforeHook(it, block) }

@JvmName("createConstructorAfterHooks")
@JvmStatic
fun createAfterHooks(
c: Array<Constructor<*>>,
block: IMethodHookCallback
): List<XC_MethodHook.Unhook> =
c.map { createAfterHook(it, block) }
}
}

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`分支

### 使用本库的项目

Expand Down
2 changes: 1 addition & 1 deletion README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit 06becef

Please sign in to comment.