mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 17:55:24 +08:00
Changed HookParam.kt
This commit is contained in:
@@ -102,7 +102,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
// 在方法执行之前拦截
|
// 在方法执行之前拦截
|
||||||
beforeHook {
|
beforeHook {
|
||||||
// 设置 0 号 param
|
// 设置 0 号 param
|
||||||
args().set("I am hook method param")
|
args().first().set("I am hook method param")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 注入要 Hook 的方法
|
// 注入要 Hook 的方法
|
||||||
@@ -115,7 +115,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
// 在方法执行之前拦截
|
// 在方法执行之前拦截
|
||||||
beforeHook {
|
beforeHook {
|
||||||
// 设置 0 号 param
|
// 设置 0 号 param
|
||||||
args().array<String>()[0] = "peach"
|
args().first().array<String>()[0] = "peach"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 注入要 Hook 的方法
|
// 注入要 Hook 的方法
|
||||||
@@ -151,7 +151,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
// 在方法执行之前拦截
|
// 在方法执行之前拦截
|
||||||
beforeHook {
|
beforeHook {
|
||||||
// 设置 0 号 param
|
// 设置 0 号 param
|
||||||
args().set("I am hook constructor param")
|
args().first().set("I am hook constructor param")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 注入要 Hook 的方法
|
// 注入要 Hook 的方法
|
||||||
|
@@ -26,33 +26,25 @@ val args: Array<Any?>
|
|||||||
|
|
||||||
> 获取当前 Hook 对象 `member` 或 `constructor` 的参数对象数组。
|
> 获取当前 Hook 对象 `member` 或 `constructor` 的参数对象数组。
|
||||||
|
|
||||||
### firstArgs [field]
|
### ~~firstArgs [field]~~
|
||||||
|
|
||||||
```kotlin
|
|
||||||
val firstArgs: Any?
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>变更记录</b>
|
<b>变更记录</b>
|
||||||
|
|
||||||
`v1.0` `添加`
|
`v1.0` `添加`
|
||||||
|
|
||||||
<b>功能描述</b>
|
`v1.0.75` `移除`
|
||||||
|
|
||||||
> 获取当前 Hook 对象 `member` 或 `constructor` 的参数对象数组第一位。
|
请使用 `args(index = 0)` 或 `args().first()`
|
||||||
|
|
||||||
### lastArgs [field]
|
### ~~lastArgs [field]~~
|
||||||
|
|
||||||
```kotlin
|
|
||||||
val lastArgs: Any?
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>变更记录</b>
|
<b>变更记录</b>
|
||||||
|
|
||||||
`v1.0` `添加`
|
`v1.0` `添加`
|
||||||
|
|
||||||
<b>功能描述</b>
|
`v1.0.75` `移除`
|
||||||
|
|
||||||
> 获取当前 Hook 对象 `member` 或 `constructor` 的参数对象数组最后一位。
|
请使用 `args().last()`
|
||||||
|
|
||||||
### instance [field]
|
### instance [field]
|
||||||
|
|
||||||
@@ -126,33 +118,35 @@ var result: Any?
|
|||||||
|
|
||||||
> 获取、设置当前 Hook 对象的 `method` 或 `constructor` 的返回值。
|
> 获取、设置当前 Hook 对象的 `method` 或 `constructor` 的返回值。
|
||||||
|
|
||||||
### firstArgs [method]
|
### result [method]
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
inline fun <reified T> firstArgs(): T?
|
inline fun <reified T> result(): T?
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>变更记录</b>
|
<b>变更记录</b>
|
||||||
|
|
||||||
|
`v1.0.75` `新增`
|
||||||
|
|
||||||
|
<b>功能描述</b>
|
||||||
|
|
||||||
|
> 获取当前 Hook 对象的 `method` 或 `constructor` 的返回值 `T`。
|
||||||
|
|
||||||
|
### ~~firstArgs [method]~~
|
||||||
|
|
||||||
|
<b>变更记录</b>
|
||||||
|
|
||||||
`v1.0.66` `新增`
|
`v1.0.66` `新增`
|
||||||
|
|
||||||
<b>功能描述</b>
|
`v1.0.75` `移除`
|
||||||
|
|
||||||
> 获取当前 Hook 对象 [method] or [constructor] 的参数对象数组第一位 `T`。
|
### ~~lastArgs [method]~~
|
||||||
|
|
||||||
### lastArgs [method]
|
|
||||||
|
|
||||||
```kotlin
|
|
||||||
inline fun <reified T> lastArgs(): T?
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>变更记录</b>
|
<b>变更记录</b>
|
||||||
|
|
||||||
`v1.0.66` `新增`
|
`v1.0.66` `新增`
|
||||||
|
|
||||||
<b>功能描述</b>
|
`v1.0.75` `移除`
|
||||||
|
|
||||||
> 获取当前 Hook 对象 [method] or [constructor] 的参数对象数组最后一位 `T`。
|
|
||||||
|
|
||||||
### instance [method]
|
### instance [method]
|
||||||
|
|
||||||
@@ -180,6 +174,20 @@ instance<Activity>().finish()
|
|||||||
|
|
||||||
### args [method]
|
### args [method]
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
fun args(): ArgsIndexCondition
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>变更记录</b>
|
||||||
|
|
||||||
|
`v1.0.75` `新增`
|
||||||
|
|
||||||
|
<b>功能描述</b>
|
||||||
|
|
||||||
|
> 获取当前 Hook 对象的 `method` or `constructor` 的参数数组下标实例化类。
|
||||||
|
|
||||||
|
### args [method]
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
fun args(index: Int): ArgsModifyer
|
fun args(index: Int): ArgsModifyer
|
||||||
```
|
```
|
||||||
@@ -188,6 +196,10 @@ fun args(index: Int): ArgsModifyer
|
|||||||
|
|
||||||
`v1.0` `添加`
|
`v1.0` `添加`
|
||||||
|
|
||||||
|
`v1.0.75` `修改`
|
||||||
|
|
||||||
|
默认值 `index = 0` 移动到新的使用方法 `args().first()`
|
||||||
|
|
||||||
<b>功能描述</b>
|
<b>功能描述</b>
|
||||||
|
|
||||||
> 获取当前 Hook 对象的 `method` 或 `constructor` 的参数实例化对象类。
|
> 获取当前 Hook 对象的 `method` 或 `constructor` 的参数实例化对象类。
|
||||||
@@ -196,8 +208,6 @@ fun args(index: Int): ArgsModifyer
|
|||||||
|
|
||||||
你可以通过 `args` 方法修改当前 Hook 实例的方法、构造方法的参数内容。
|
你可以通过 `args` 方法修改当前 Hook 实例的方法、构造方法的参数内容。
|
||||||
|
|
||||||
`index` 的默认值为 `0`,如果只有一位 `param` 参数,你可以不写。
|
|
||||||
|
|
||||||
你可以直接使用 `set` 方法设置 `param` 为你的目标实例,接受 `Any` 类型。
|
你可以直接使用 `set` 方法设置 `param` 为你的目标实例,接受 `Any` 类型。
|
||||||
|
|
||||||
!> 请确保 `param` 类型为你的目标实例类型。
|
!> 请确保 `param` 类型为你的目标实例类型。
|
||||||
@@ -205,7 +215,23 @@ fun args(index: Int): ArgsModifyer
|
|||||||
> 示例如下
|
> 示例如下
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
args().set("modify the value")
|
args(index = 0).set("modify the value")
|
||||||
|
```
|
||||||
|
|
||||||
|
你可以这样直接设置第一位 `param` 的值。
|
||||||
|
|
||||||
|
> 示例如下
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
args().first().set("modify the value")
|
||||||
|
```
|
||||||
|
|
||||||
|
你还可以直接设置最后一位 `param` 的值。
|
||||||
|
|
||||||
|
> 示例如下
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
args().last().set("modify the value")
|
||||||
```
|
```
|
||||||
|
|
||||||
你还可以使用 `setNull` 方法设置 `param` 为空。
|
你还可以使用 `setNull` 方法设置 `param` 为空。
|
||||||
@@ -223,7 +249,7 @@ args(index = 1).setNull()
|
|||||||
> 示例如下
|
> 示例如下
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
args(index = 2).setTrue()
|
args(index = 1).setTrue()
|
||||||
```
|
```
|
||||||
|
|
||||||
你还可以使用 `setFalse` 方法设置 `param` 为 `false`。
|
你还可以使用 `setFalse` 方法设置 `param` 为 `false`。
|
||||||
@@ -233,7 +259,7 @@ args(index = 2).setTrue()
|
|||||||
> 示例如下
|
> 示例如下
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
args(index = 3).setFalse()
|
args(index = 1).setFalse()
|
||||||
```
|
```
|
||||||
|
|
||||||
### invokeOriginal [method]
|
### invokeOriginal [method]
|
||||||
@@ -306,6 +332,48 @@ fun resultNull()
|
|||||||
|
|
||||||
!> 此方法将强制设置 Hook 对象方法的 `result` 为 `null`。
|
!> 此方法将强制设置 Hook 对象方法的 `result` 为 `null`。
|
||||||
|
|
||||||
|
### ArgsIndexCondition [class]
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
inner class ArgsIndexCondition
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>变更记录</b>
|
||||||
|
|
||||||
|
`v1.0.75` `新增`
|
||||||
|
|
||||||
|
<b>功能描述</b>
|
||||||
|
|
||||||
|
> 对方法参数的数组下标进行实例化类。
|
||||||
|
|
||||||
|
#### first [method]
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
fun first(): ArgsModifyer
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>变更记录</b>
|
||||||
|
|
||||||
|
`v1.0.75` `新增`
|
||||||
|
|
||||||
|
<b>功能描述</b>
|
||||||
|
|
||||||
|
> 获取当前 Hook 对象的 `method` or `constructor` 的参数数组第一位。
|
||||||
|
|
||||||
|
#### last [method]
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
fun last(): ArgsModifyer
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>变更记录</b>
|
||||||
|
|
||||||
|
`v1.0.75` `新增`
|
||||||
|
|
||||||
|
<b>功能描述</b>
|
||||||
|
|
||||||
|
> 获取当前 Hook 对象的 `method` or `constructor` 的参数数组最后一位。
|
||||||
|
|
||||||
### ArgsModifyer [class]
|
### ArgsModifyer [class]
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
|
@@ -438,11 +438,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
`YukiHookModulePrefs` 支持的类型只有 `String`、`Int`、`Float`、`Long`、`Boolean`,请传入支持的类型。
|
`YukiHookModulePrefs` 支持的类型只有 `String`、`Int`、`Float`、`Long`、`Boolean`,请传入支持的类型。
|
||||||
|
|
||||||
!> `IllegalStateException` HookParam args is empty
|
!> `IllegalStateException` HookParam Method args index must be >= 0
|
||||||
|
|
||||||
<b>异常原因</b>
|
<b>异常原因</b>
|
||||||
|
|
||||||
在 `HookParam` 中调用 `firstArgs` 或 `lastArgs` 但原始 `param` 数组为空。
|
在 `HookParam` 中调用 `args().last()` 但是目标 `param` 为空或 `args` 中的 `index` 设置了小于 0 的数值。
|
||||||
|
|
||||||
> 示例如下
|
> 示例如下
|
||||||
|
|
||||||
@@ -450,17 +450,17 @@ class MainActivity : AppCompatActivity() {
|
|||||||
injectMember {
|
injectMember {
|
||||||
// ...
|
// ...
|
||||||
afterHook {
|
afterHook {
|
||||||
// 调用了此变量
|
// 假设 param 是空的
|
||||||
firstArgs...
|
args().last()...
|
||||||
// 调用了此变量
|
// 设置了小于 0 的 index
|
||||||
lastArgs...
|
args(index = -5)...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>解决方案</b>
|
<b>解决方案</b>
|
||||||
|
|
||||||
请确认你 Hook 的目标方法、构造方法的方法参数数量是否不为空,否则你无法使用此功能。
|
请确认你 Hook 的目标方法、构造方法的方法参数数量是否不为空,且不能对 `args` 的下标设置小于 0 的数值。
|
||||||
|
|
||||||
!> `IllegalStateException` HookParam instance got null! Is this a static member?
|
!> `IllegalStateException` HookParam instance got null! Is this a static member?
|
||||||
|
|
||||||
|
@@ -48,20 +48,6 @@ class HookParam(private val createrInstance: YukiHookCreater, private val wrappe
|
|||||||
*/
|
*/
|
||||||
val args get() = wrapper.args ?: arrayOf(0)
|
val args get() = wrapper.args ?: arrayOf(0)
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前 Hook 对象 [method] or [constructor] 的参数对象数组第一位
|
|
||||||
* @return [Any] or null
|
|
||||||
* @throws IllegalStateException 如果数组为空
|
|
||||||
*/
|
|
||||||
val firstArgs get() = if (args.isNotEmpty()) args[0] else error("HookParam args is empty")
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前 Hook 对象 [method] or [constructor] 的参数对象数组最后一位
|
|
||||||
* @return [Any] or null
|
|
||||||
* @throws IllegalStateException 如果数组为空
|
|
||||||
*/
|
|
||||||
val lastArgs get() = if (args.isNotEmpty()) args[args.lastIndex] else error("HookParam args is empty")
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前 Hook 实例的对象
|
* 获取当前 Hook 实例的对象
|
||||||
*
|
*
|
||||||
@@ -102,18 +88,10 @@ class HookParam(private val createrInstance: YukiHookCreater, private val wrappe
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前 Hook 对象 [method] or [constructor] 的参数对象数组第一位 [T]
|
* 获取当前 Hook 对象的 [method] or [constructor] 的返回值 [T]
|
||||||
* @return [T] or null
|
* @return [T] or null
|
||||||
* @throws IllegalStateException 如果数组为空
|
|
||||||
*/
|
*/
|
||||||
inline fun <reified T> firstArgs() = firstArgs as? T?
|
inline fun <reified T> result() = result as? T?
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前 Hook 对象 [method] or [constructor] 的参数对象数组最后一位 [T]
|
|
||||||
* @return [T] or null
|
|
||||||
* @throws IllegalStateException 如果数组为空
|
|
||||||
*/
|
|
||||||
inline fun <reified T> lastArgs() = lastArgs as? T?
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前 Hook 实例的对象 [T]
|
* 获取当前 Hook 实例的对象 [T]
|
||||||
@@ -122,12 +100,18 @@ class HookParam(private val createrInstance: YukiHookCreater, private val wrappe
|
|||||||
*/
|
*/
|
||||||
inline fun <reified T> instance() = instance as? T? ?: error("HookParam instance cannot cast to ${T::class.java.name}")
|
inline fun <reified T> instance() = instance as? T? ?: error("HookParam instance cannot cast to ${T::class.java.name}")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前 Hook 对象的 [method] or [constructor] 的参数数组下标实例化类
|
||||||
|
* @return [ArgsIndexCondition]
|
||||||
|
*/
|
||||||
|
fun args() = ArgsIndexCondition()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前 Hook 对象的 [method] or [constructor] 的参数实例化对象类
|
* 获取当前 Hook 对象的 [method] or [constructor] 的参数实例化对象类
|
||||||
* @param index 参数对象数组下标 - 默认是 0
|
* @param index 参数对象数组下标
|
||||||
* @return [ArgsModifyer]
|
* @return [ArgsModifyer]
|
||||||
*/
|
*/
|
||||||
fun args(index: Int = 0) = ArgsModifyer(index)
|
fun args(index: Int) = ArgsModifyer(index)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行原始 [Member]
|
* 执行原始 [Member]
|
||||||
@@ -165,8 +149,30 @@ class HookParam(private val createrInstance: YukiHookCreater, private val wrappe
|
|||||||
result = null
|
result = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对方法参数的数组下标进行实例化类
|
||||||
|
*
|
||||||
|
* - ❗请使用第一个 [args] 方法来获取 [ArgsIndexCondition]
|
||||||
|
*/
|
||||||
|
inner class ArgsIndexCondition {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前 Hook 对象的 [method] or [constructor] 的参数数组第一位
|
||||||
|
* @return [ArgsModifyer]
|
||||||
|
*/
|
||||||
|
fun first() = args(index = 0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前 Hook 对象的 [method] or [constructor] 的参数数组最后一位
|
||||||
|
* @return [ArgsModifyer]
|
||||||
|
*/
|
||||||
|
fun last() = args(index = args.lastIndex)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对方法参数的修改进行实例化类
|
* 对方法参数的修改进行实例化类
|
||||||
|
*
|
||||||
|
* - ❗请使用第二个 [args] 方法来获取 [ArgsModifyer]
|
||||||
* @param index 参数对象数组下标
|
* @param index 参数对象数组下标
|
||||||
*/
|
*/
|
||||||
inner class ArgsModifyer(private val index: Int) {
|
inner class ArgsModifyer(private val index: Int) {
|
||||||
@@ -271,6 +277,7 @@ class HookParam(private val createrInstance: YukiHookCreater, private val wrappe
|
|||||||
* @throws IllegalStateException 如果目标方法参数对象数组为空或 [index] 下标不存在
|
* @throws IllegalStateException 如果目标方法参数对象数组为空或 [index] 下标不存在
|
||||||
*/
|
*/
|
||||||
fun <T> set(any: T?) {
|
fun <T> set(any: T?) {
|
||||||
|
if (index < 0) error("HookParam Method args index must be >= 0")
|
||||||
if (args.isEmpty()) error("HookParam Method args is empty, mabe not has args")
|
if (args.isEmpty()) error("HookParam Method args is empty, mabe not has args")
|
||||||
if (index > args.lastIndex) error("HookParam Method args index out of bounds, max is ${args.lastIndex}")
|
if (index > args.lastIndex) error("HookParam Method args index out of bounds, max is ${args.lastIndex}")
|
||||||
wrapper.setArgs(index, any)
|
wrapper.setArgs(index, any)
|
||||||
|
Reference in New Issue
Block a user