Skip to content

Commit d6db892

Browse files
committed
docs: update move-to-new-api
1 parent 7f97ad7 commit d6db892

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

docs-source/src/en/guide/move-to-new-api.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,50 @@ override fun replaceHookedMethod(param: MethodHookParam) = null
260260
:::
261261
::::
262262

263+
### Notes on Migrating XposedHelpers
264+
265+
The reflection functionality provided in `YukiHookAPI` differs from the reflection functionality of `XposedHelpers`.
266+
267+
Here is a guide to avoid common pitfalls.
268+
269+
Methods like `XposedHelpers.callMethod` and `XposedHelpers.callStaticMethod` automatically search and invoke all public methods (including those in superclasses), which is a feature of native Java reflection. In contrast, the reflection solution provided by `YukiHookAPI` first searches and then calls, and by default, the search process does not automatically look for methods in superclasses.
270+
271+
For example, class `A` inherits from `B`, and `B` has a public method `test`, while `A` does not.
272+
273+
```java
274+
public class B {
275+
public void test(String a) {
276+
// ...
277+
}
278+
}
279+
280+
public class A extends B {
281+
// ...
282+
}
283+
```
284+
285+
Usage with `XposedHelpers`.
286+
287+
```kotlin
288+
val instance: A = ...
289+
XposedHelpers.callMethod(instance, "test", "some string")
290+
```
291+
292+
Usage with `YukiHookAPI`.
293+
294+
```kotlin
295+
val instance: A = ...
296+
instance.current().method {
297+
name = "test"
298+
// Note that you need to add this search condition to ensure it searches for methods in superclasses.
299+
superClass()
300+
}.call("some string")
301+
// Or directly call the superClass() method.
302+
instance.current().superClass()?.method {
303+
name = "test"
304+
}?.call("some string")
305+
```
306+
263307
## Migrate More Functions Related to Hook API
264308

265309
`YukiHookAPI` is a brand new Hook API, which is fundamentally different from other Hook APIs, you can refer to [API Document](../api/home) and [Special Features](../api/special-features/reflection) to determine some functional Migration and use.

docs-source/src/zh-cn/guide/move-to-new-api.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,49 @@ override fun replaceHookedMethod(param: MethodHookParam) = null
260260
:::
261261
::::
262262

263+
### 迁移 XposedHelpers 注意事项
264+
265+
`YukiHookAPI` 中提供的反射功能与 `XposedHelpers` 的反射功能有所不同,这里提供一个误区指引。
266+
267+
`XposedHelpers.callMethod``XposedHelpers.callStaticMethod` 等方法自动查找的方法会自动调用所有公开的方法 (包括 `super` 超类),这是 Java 原生反射的特性,
268+
`YukiHookAPI` 提供的反射方案为先反射查找再调用,而查找过程默认不会自动查找 `super` 超类的方法。
269+
270+
例如,类 `A` 继承于 `B``B` 中存在公开的方法 `test`,而 `A` 中并不存在。
271+
272+
```java
273+
public class B {
274+
public void test(String a) {
275+
// ...
276+
}
277+
}
278+
279+
public class A extends B {
280+
// ...
281+
}
282+
```
283+
284+
此时 `XposedHelpers` 的用法。
285+
286+
```kotlin
287+
val instance: A = ...
288+
XposedHelpers.callMethod(instance, "test", "some string")
289+
```
290+
291+
`YukiHookAPI` 的用法。
292+
293+
```kotlin
294+
val instance: A = ...
295+
instance.current().method {
296+
name = "test"
297+
// 请注意,这里需要添加此查找条件以确保其会查找超类的方法
298+
superClass()
299+
}.call("some string")
300+
// 或者直接调用 superClass() 方法
301+
instance.current().superClass()?.method {
302+
name = "test"
303+
}?.call("some string")
304+
```
305+
263306
## 迁移更多有关 Hook API 的功能
264307

265308
`YukiHookAPI` 是一套全新的 Hook API,与其它 Hook API 存在着本质区别,你可以参考 [API 文档](../api/home) 以及 [特色功能](../api/special-features/reflection) 来决定一些功能性的迁移和使用。

0 commit comments

Comments
 (0)