mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
Added some sample in documentation
This commit is contained in:
@@ -212,7 +212,7 @@ fun members(vararg member: Member?)
|
|||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
injectMember {
|
injectMember {
|
||||||
members(instanceClass.getMethod("test", StringType))
|
members(instanceClass.getDeclaredMethod("test", StringType))
|
||||||
beforeHook {}
|
beforeHook {}
|
||||||
afterHook {}
|
afterHook {}
|
||||||
}
|
}
|
||||||
@@ -225,9 +225,9 @@ injectMember {
|
|||||||
```kotlin
|
```kotlin
|
||||||
injectMember {
|
injectMember {
|
||||||
members(
|
members(
|
||||||
instanceClass.getMethod("test1", StringType),
|
instanceClass.getDeclaredMethod("test1", StringType),
|
||||||
instanceClass.getMethod("test2", StringType),
|
instanceClass.getDeclaredMethod("test2", StringType),
|
||||||
instanceClass.getMethod("test3", StringType)
|
instanceClass.getDeclaredMethod("test3", StringType)
|
||||||
)
|
)
|
||||||
beforeHook {}
|
beforeHook {}
|
||||||
afterHook {}
|
afterHook {}
|
||||||
@@ -306,6 +306,25 @@ injectMember {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
若想 Hook 当前查询 `method { ... }` 条件的全部结果,你只需要在最后加入 `all` 即可。
|
||||||
|
|
||||||
|
> 示例如下
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
injectMember {
|
||||||
|
method {
|
||||||
|
name = "test"
|
||||||
|
paramCount(1..5)
|
||||||
|
}.all()
|
||||||
|
beforeHook {}
|
||||||
|
afterHook {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
此时 `beforeHook` 与 `afterHook` 会在每个查询到的结果中多次回调 Hook 方法体。
|
||||||
|
|
||||||
|
!> 若没有 `all`,默认只会 Hook 当前条件查询到的数组下标结果第一位。
|
||||||
|
|
||||||
#### constructor *- method*
|
#### constructor *- method*
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
@@ -338,6 +357,22 @@ injectMember {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
若想 Hook 当前查询 `constructor { ... }` 条件的全部结果,你只需要在最后加入 `all` 即可。
|
||||||
|
|
||||||
|
> 示例如下
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
injectMember {
|
||||||
|
constructor { paramCount(1..5) }.all()
|
||||||
|
beforeHook {}
|
||||||
|
afterHook {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
此时 `beforeHook` 与 `afterHook` 会在每个查询到的结果中多次回调 Hook 方法体。
|
||||||
|
|
||||||
|
!> 若没有 `all`,默认只会 Hook 当前条件查询到的数组下标结果第一位。
|
||||||
|
|
||||||
#### HookParam.field *- i-ext-method*
|
#### HookParam.field *- i-ext-method*
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
@@ -354,7 +389,7 @@ inline fun HookParam.field(initiate: FieldCondition): FieldFinder.Result
|
|||||||
|
|
||||||
**功能描述**
|
**功能描述**
|
||||||
|
|
||||||
> 使用当前 `hookClass` 查找并得到 `Field`。
|
> 使用当前 `instanceClass` 查找并得到 `Field`。
|
||||||
|
|
||||||
**功能示例**
|
**功能示例**
|
||||||
|
|
||||||
@@ -370,6 +405,7 @@ injectMember {
|
|||||||
returnType = UnitType
|
returnType = UnitType
|
||||||
}
|
}
|
||||||
afterHook {
|
afterHook {
|
||||||
|
// 这里不需要再调用 instanceClass.field 进行查询
|
||||||
field {
|
field {
|
||||||
name = "isSweet"
|
name = "isSweet"
|
||||||
type = BooleanType
|
type = BooleanType
|
||||||
@@ -394,7 +430,7 @@ inline fun HookParam.method(initiate: MethodCondition): MethodFinder.Result
|
|||||||
|
|
||||||
**功能描述**
|
**功能描述**
|
||||||
|
|
||||||
> 使用当前 `hookClass` 查找并得到方法。
|
> 使用当前 `instanceClass` 查找并得到方法。
|
||||||
|
|
||||||
#### HookParam.constructor *- i-ext-method*
|
#### HookParam.constructor *- i-ext-method*
|
||||||
|
|
||||||
@@ -412,7 +448,7 @@ inline fun HookParam.constructor(initiate: ConstructorCondition): ConstructorFin
|
|||||||
|
|
||||||
**功能描述**
|
**功能描述**
|
||||||
|
|
||||||
> 使用当前 `hookClass` 查找并得到构造方法。
|
> 使用当前 `instanceClass` 查找并得到构造方法。
|
||||||
|
|
||||||
#### HookParam.injectMember *- i-ext-method*
|
#### HookParam.injectMember *- i-ext-method*
|
||||||
|
|
||||||
|
@@ -192,6 +192,8 @@ TestClass.hook {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
更多功能请参考 [MemberHookCreater](api/document?id=memberhookcreater-class)。
|
||||||
|
|
||||||
### Hook Zygote
|
### Hook Zygote
|
||||||
|
|
||||||
在 APP 启动时,新的进程被 fork 后的第一个事件 `initZygote`。
|
在 APP 启动时,新的进程被 fork 后的第一个事件 `initZygote`。
|
||||||
@@ -219,6 +221,8 @@ loadZygote {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
!> 在 `loadZygote` 中进行的功能十分有限,几乎很少的情况下需要用到 `loadZygote` 方法。
|
||||||
|
|
||||||
### Hook 系统框架
|
### Hook 系统框架
|
||||||
|
|
||||||
在 `YukiHookAPI` 中,Hook 系统框架的实现非常简单。
|
在 `YukiHookAPI` 中,Hook 系统框架的实现非常简单。
|
||||||
@@ -240,7 +244,7 @@ loadSystem {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
!> `loadZygote` 与 `loadSystem` 有直接性区别,`loadZygote` 会在 `initZygote` 中装载,系统框架被视为一个单独的 APP 而存在,若要 Hook 系统框架,请使用 `loadSystem`。
|
!> `loadZygote` 与 `loadSystem` 有直接性区别,`loadZygote` 会在 `initZygote` 中装载,系统框架被视为 `loadApp(name = "android")` 而存在,若要 Hook 系统框架,可直接使用 `loadSystem`。
|
||||||
|
|
||||||
### Hook Resources
|
### Hook Resources
|
||||||
|
|
||||||
@@ -408,6 +412,8 @@ method {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
更多功能请参考 [MemberHookCreater.Result](api/document?id=result-class) 与 [ResourcesHookCreater.Result](api/document?id=result-class-2)。
|
||||||
|
|
||||||
这里介绍了可能发生的常见异常,若要了解更多请参考 [API 异常处理](config/api-exception.md)。
|
这里介绍了可能发生的常见异常,若要了解更多请参考 [API 异常处理](config/api-exception.md)。
|
||||||
|
|
||||||
### 抛出异常
|
### 抛出异常
|
||||||
@@ -485,7 +491,7 @@ injectMember {
|
|||||||
|
|
||||||
!> 为了保证 Hook 调用域与宿主内调用域相互隔离,异常只有在 `beforeHook` 与 `afterHook` 回调方法体中才能抛给宿主。
|
!> 为了保证 Hook 调用域与宿主内调用域相互隔离,异常只有在 `beforeHook` 与 `afterHook` 回调方法体中才能抛给宿主。
|
||||||
|
|
||||||
更多功能请参考 [HookCallback](api/document?id=hookcallback-class)。
|
更多功能请参考 [Throwable.throwToApp](api/document?id=throwablethrowtoapp-i-ext-method) 与 [HookCallback](api/document?id=hookcallback-class)。
|
||||||
|
|
||||||
## 状态监听
|
## 状态监听
|
||||||
|
|
||||||
@@ -538,7 +544,7 @@ loadApp(name = "com.android.phone") {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
详细用法可 [点击这里](api/document?id=loadapp-method) 进行查看。
|
更多功能请参考 [loadApp](api/document?id=loadapp-method)。
|
||||||
|
|
||||||
### 多个进程
|
### 多个进程
|
||||||
|
|
||||||
@@ -555,7 +561,7 @@ withProcess(name = "$packageName:tool") {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
详细用法可 [点击这里](api/document?id=withprocess-method) 进行查看。
|
更多功能请参考 [withProcess](api/document?id=withprocess-method)。
|
||||||
|
|
||||||
## 写法优化
|
## 写法优化
|
||||||
|
|
||||||
@@ -609,9 +615,11 @@ if(YukiHookAPI.Status.isModuleActive) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
若要了解更多可 [点击这里](api/document?id=status-object) 进行查看。
|
更多功能请参考 [YukiHookAPI.Status](api/document?id=status-object)。
|
||||||
|
|
||||||
!> 新版本的 API 修改了激活逻辑判断方式,现在你可以在模块与 Hook APP (宿主) 中同时使用此 API。
|
!> 若模块激活判断中包含太极、无极中的激活状态,就必须将模块的 `Application` 继承于 `ModuleApplication` 或直接使用 `ModuleApplication`。
|
||||||
|
|
||||||
|
!> `1.0.91` 版本后的 API 修改了激活逻辑判断方式,现在你可以在模块与 Hook APP (宿主) 中同时使用此 API。
|
||||||
|
|
||||||
!> 需要确保 `YukiHookAPI.Configs.isEnableHookModuleStatus` 是启用状态。
|
!> 需要确保 `YukiHookAPI.Configs.isEnableHookModuleStatus` 是启用状态。
|
||||||
|
|
||||||
|
@@ -761,6 +761,59 @@ Test::class.java.method {
|
|||||||
|
|
||||||
!> 特别注意使用了 `RemedyPlan` 的方法查询结果不能再使用 `get` 的方式得到方法实例,应当使用 `wait` 方法。
|
!> 特别注意使用了 `RemedyPlan` 的方法查询结果不能再使用 `get` 的方式得到方法实例,应当使用 `wait` 方法。
|
||||||
|
|
||||||
|
另外,你还可以在使用 [多重查询](guide/special-feature?id=多重查询) 的情况下继续使用 `RemedyPlan`。
|
||||||
|
|
||||||
|
> 示例如下
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
// 假设这就是这个 Class 的实例
|
||||||
|
val instance = Test()
|
||||||
|
// 使用 YukiHookAPI 调用并执行
|
||||||
|
Test::class.java.method {
|
||||||
|
name = "doTask"
|
||||||
|
emptyParam()
|
||||||
|
}.remedys {
|
||||||
|
method {
|
||||||
|
name = "doTask"
|
||||||
|
paramCount(0..1)
|
||||||
|
}.onFind {
|
||||||
|
// 可在这里实现找到的逻辑
|
||||||
|
}
|
||||||
|
method {
|
||||||
|
name = "doTask"
|
||||||
|
paramCount(1..2)
|
||||||
|
}.onFind {
|
||||||
|
// 可在这里实现找到的逻辑
|
||||||
|
}
|
||||||
|
}.waitAll(instance) {
|
||||||
|
// 得到方法的结果
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
以当前 `Class` 举例,若 [多重查询](guide/special-feature?id=多重查询) 结合 `RemedyPlan` 在创建 Hook 的时候使用,你需要稍微改变一下用法。
|
||||||
|
|
||||||
|
> 示例如下
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
injectMember {
|
||||||
|
method {
|
||||||
|
name = "doTask"
|
||||||
|
emptyParam()
|
||||||
|
}.remedys {
|
||||||
|
method {
|
||||||
|
name = "doTask"
|
||||||
|
paramCount(0..1)
|
||||||
|
}
|
||||||
|
method {
|
||||||
|
name = "doTask"
|
||||||
|
paramCount(1..2)
|
||||||
|
}
|
||||||
|
}.all()
|
||||||
|
beforeHook {}
|
||||||
|
afterHook {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
更多用法可参考 [Method RemedyPlan](api/document?id=remedyplan-class)、[Constructor RemedyPlan](api/document?id=remedyplan-class-1)、[Field RemedyPlan](api/document?id=remedyplan-class-2)。
|
更多用法可参考 [Method RemedyPlan](api/document?id=remedyplan-class)、[Constructor RemedyPlan](api/document?id=remedyplan-class-1)、[Field RemedyPlan](api/document?id=remedyplan-class-2)。
|
||||||
|
|
||||||
### 相对匹配
|
### 相对匹配
|
||||||
|
Reference in New Issue
Block a user