This commit is contained in:
2022-02-04 00:36:51 +08:00
parent 53ab3eae81
commit d3ab6d58b8
9 changed files with 210 additions and 56 deletions

View File

@@ -32,6 +32,7 @@ package com.highcapable.yukihookapi
import android.content.pm.ApplicationInfo
import com.highcapable.yukihookapi.YukiHookAPI.encase
import com.highcapable.yukihookapi.annotation.DoNotUseField
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
import com.highcapable.yukihookapi.param.CustomParam
import com.highcapable.yukihookapi.param.PackageParam
@@ -65,6 +66,21 @@ object YukiHookAPI {
packageParamCallback = initiate
}
/**
* 作为模块装载调用入口方法 - Xposed API
* @param moduleName 模块包名 - 填入当前的 BuildConfig.APPLICATION_ID
* @param hooker Hook 子类数组 - 必填不能为空
* @throws IllegalStateException 如果 [hooker] 是空的
*/
fun encase(moduleName: String = "", vararg hooker: YukiBaseHooker) {
modulePackageName = moduleName
packageParamCallback = {
if (hooker.isNotEmpty())
hooker.forEach { it.assignInstance(packageParam = this) }
else error("Hooker is empty")
}
}
/**
* 自定义 Hook 方法装载入口
* @param classLoader [ClassLoader]

View File

@@ -65,6 +65,15 @@ import com.highcapable.yukihookapi.param.PackageParam
*/
abstract class YukiBaseHooker : PackageParam() {
/**
* 赋值并克隆一个 [PackageParam]
* @param packageParam 需要使用的 [PackageParam]
*/
internal fun assignInstance(packageParam: PackageParam) {
baseAssignInstance(packageParam)
onHook()
}
/** 子类 Hook 开始 */
abstract fun onHook()
}

View File

@@ -34,6 +34,7 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import com.highcapable.yukihookapi.YukiHookAPI
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
import com.highcapable.yukihookapi.hook.proxy.YukiHookXposedInitProxy
import com.highcapable.yukihookapi.param.PackageParam
@@ -45,6 +46,15 @@ import com.highcapable.yukihookapi.param.PackageParam
fun YukiHookXposedInitProxy.encase(moduleName: String = "", initiate: PackageParam.() -> Unit) =
YukiHookAPI.encase(moduleName, initiate)
/**
* 在 [YukiHookXposedInitProxy] 中装载 [YukiHookAPI]
* @param moduleName 模块包名 - 填入当前的 BuildConfig.APPLICATION_ID
* @param hooker Hook 子类数组 - 必填不能为空
* @throws IllegalStateException 如果 [hooker] 是空的
*/
fun YukiHookXposedInitProxy.encase(moduleName: String = "", vararg hooker: YukiBaseHooker) =
YukiHookAPI.encase(moduleName, *hooker)
/**
* 判断模块是否在太极、无极中激活
* @return [Boolean] 是否激活

View File

@@ -64,6 +64,14 @@ import com.highcapable.yukihookapi.hook.factory.encase
*
* ....
*
* 若你喜欢分类创建 Hooker - 还可以这样写:
*
* ......
*
* override fun onHook() = encase(moduleName = "模块包名", MainHooker(), SecondHooker(), ThirdHooker() ...)
*
* ......
*
* 详情请参考 https://github.com/fankes/YukiHookAPI/wiki
*/
@Keep

View File

@@ -44,8 +44,8 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage
* @param customParam 自定义装载类 - 默认空
*/
open class PackageParam(
private val baseParam: XC_LoadPackage.LoadPackageParam? = null,
private val customParam: CustomParam? = null
private var baseParam: XC_LoadPackage.LoadPackageParam? = null,
private var customParam: CustomParam? = null
) {
/**
@@ -85,6 +85,15 @@ open class PackageParam(
*/
val isFirstApplication get() = baseParam?.isFirstApplication ?: true
/**
* 赋值并克隆另一个 [PackageParam]
* @param another 另一个 [PackageParam]
*/
internal fun baseAssignInstance(another: PackageParam) {
this.baseParam = another.baseParam
this.customParam = another.customParam
}
/**
* 装载并 Hook 指定包名的 APP
* @param name 包名
@@ -94,20 +103,13 @@ open class PackageParam(
if (packageName == name) initiate(this)
}
/**
* 装载并 Hook 指定包名的 APP
* @param name 包名
* @param hooker Hook 子类
*/
fun loadApp(name: String, hooker: YukiBaseHooker) {
if (packageName == name) hooker.onHook()
}
/**
* 装载 Hook 子类
*
* 你可以在 Hooker 中继续装载 Hooker
* @param hooker Hook 子类
*/
fun loadHooker(hooker: YukiBaseHooker) = hooker.onHook()
fun loadHooker(hooker: YukiBaseHooker) = hooker.assignInstance(packageParam = this)
/**
* 将目标 [Class] 绑定到 [appClassLoader]