From ea86a2b60a8216b41b87a2744f77fde88b787714 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Mon, 2 Oct 2023 22:41:35 +0800 Subject: [PATCH] docs: update api-example, example, move-to-new-api, reflection --- .../src/en/api/special-features/reflection.md | 16 +-------- docs-source/src/en/config/api-example.md | 24 ++++++------- docs-source/src/en/guide/example.md | 34 ++----------------- docs-source/src/en/guide/move-to-new-api.md | 2 +- .../zh-cn/api/special-features/reflection.md | 16 +-------- docs-source/src/zh-cn/config/api-example.md | 24 ++++++------- docs-source/src/zh-cn/guide/example.md | 34 ++----------------- .../src/zh-cn/guide/move-to-new-api.md | 2 +- 8 files changed, 34 insertions(+), 118 deletions(-) diff --git a/docs-source/src/en/api/special-features/reflection.md b/docs-source/src/en/api/special-features/reflection.md index d1787df0..cf5ac87a 100644 --- a/docs-source/src/en/api/special-features/reflection.md +++ b/docs-source/src/en/api/special-features/reflection.md @@ -1578,15 +1578,7 @@ For more functions, please refer to [VariousClass](../public/com/highcapable/yuk If it is used when creating a Hook, it can be more convenient, and it can also automatically intercept the exception that `Class` cannot be found. -> The following example - -```kotlin -findClass("com.demo.ATest", "com.demo.BTest").hook { - // Your code here. -} -``` - -You can also define this `Class` as a constant type to use. +You can define this `Class` as a constant type to use. > The following example @@ -1599,12 +1591,6 @@ ABTestClass.hook { } ``` -::: tip - -For more functions, please refer to the [PackageParam.findClass](../public/com/highcapable/yukihookapi/hook/param/PackageParam#findclass-method) method. - -::: - ### Calling Generics In the process of reflection, we may encounter generic problems. diff --git a/docs-source/src/en/config/api-example.md b/docs-source/src/en/config/api-example.md index 69b1c731..85dfc677 100644 --- a/docs-source/src/en/config/api-example.md +++ b/docs-source/src/en/config/api-example.md @@ -51,7 +51,7 @@ The `encase` method can be created in the `onHook` method using two schemes. ```kotlin YukiHookAPI.encase { loadApp(name = "com.example.demo") { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } } @@ -63,7 +63,7 @@ YukiHookAPI.encase { ```kotlin encase { loadApp(name = "com.example.demo") { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } } @@ -120,12 +120,12 @@ object CustomHooker : YukiBaseHooker() { override fun onHook() { loadApp(name = "com.example.demo1") { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } } loadApp(name = "com.example.demo2") { - findClass(name = "$packageName.CustomClass").hook { + "$packageName.CustomClass".toClass().hook { // Your code here. } } @@ -148,7 +148,7 @@ object HookEntry : IYukiHookXposedInit { object ChildCustomHooker : YukiBaseHooker() { override fun onHook() { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } } @@ -163,7 +163,7 @@ You can use the `loadHooker` method to load another Hooker in multiple layers in object FirstHooker : YukiBaseHooker() { override fun onHook() { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } loadHooker(SecondHooker) @@ -235,7 +235,7 @@ In `YukiHookAPI`, these functions **are seamless**. ```kotlin encase { loadApp(name = "com.example.demo") { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } // Create a Resources Hook (fixed usage) @@ -262,7 +262,7 @@ encase { } } loadApp(name = "com.example.demo") { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } // Create a Resources Hook in the app @@ -299,7 +299,7 @@ Below are two **error** examples. ```kotlin encase { // Wrong usage, can't start Hook directly - findClass(name = "com.example.demo.DemoClass").hook { + "com.example.demo.DemoClass".toClass().hook { // ... } // Wrong usage, can't start Hook directly @@ -329,7 +329,7 @@ object CustomHooker : YukiBaseHooker() { override fun onHook() { // Wrong method of use // Because there is no judgment object in the outer layer, you cannot start Hook directly - findClass(name = "com.example.demo.DemoClass").hook { + "com.example.demo.DemoClass".toClass().hook { // ... } } @@ -357,7 +357,7 @@ encase { loadApp(/** name parameter optional */) { loadHooker(CustomHooker) // ✅ Correct usage, Hook in app scope - findClass(name = "com.example.demo.DemoClass").hook { + "com.example.demo.DemoClass".toClass().hook { // ... } // ✅ Correct usage, Hook in app scope @@ -384,7 +384,7 @@ object CustomHooker : YukiBaseHooker() { // ✅ The correct method of use, since there is no judgment object in the outer layer // it is necessary to judge the scope of the app before performing Hook loadApp(/** name parameter optional */) { - findClass(name = "com.example.demo.DemoClass").hook { + "com.example.demo.DemoClass".toClass().hook { // ... } } diff --git a/docs-source/src/en/guide/example.md b/docs-source/src/en/guide/example.md index 94b1562c..ee13bec1 100644 --- a/docs-source/src/en/guide/example.md +++ b/docs-source/src/en/guide/example.md @@ -138,14 +138,14 @@ loadApp(name = "com.android.browser") { } ``` -For the `Class` that does not exist in the current project, you can use the `stub` method or the `findClass` method to get the class that needs to be hooked. +For the `Class` that does not exist in the current project, you can use the `stub` method or the `String.toClass(...)` method to get the class that needs to be hooked. For example, I want to get `com.example.demo.TestClass`. > The following example ```kotlin -findClass(name = "com.example.demo.TestClass").hook { +"com.example.demo.TestClass".toClass().hook { injectMember { // Your code here. } @@ -157,35 +157,7 @@ If `com.example.demo` is the app you want to hook, then the writing method can b > The following example ```kotlin -findClass(name = "$packageName.TestClass").hook { - injectMember { - // Your code here. - } -} -``` - -Some people may have started to say that `findClass` is a bit cumbersome in some scenarios. - -Because some people may have the following needs. - -> The following example - -```kotlin -const val TestClass = "com.example.demo.TestClass" - -TestClass.hook { - injectMember { - // Your code here. - } -} -``` - -That's okay, you can also create a Hook directly using the string class name. - -> The following example - -```kotlin -"$packageName.TestClass".hook { +"$packageName.TestClass".toClass().hook { injectMember { // Your code here. } diff --git a/docs-source/src/en/guide/move-to-new-api.md b/docs-source/src/en/guide/move-to-new-api.md index 5763f619..7ed7e1fd 100644 --- a/docs-source/src/en/guide/move-to-new-api.md +++ b/docs-source/src/en/guide/move-to-new-api.md @@ -30,7 +30,7 @@ override fun onHook() = encase { // Hook specified app loadApp(name = "com.demo.test") { // Class Hook - findClass("com.demo.test.TestClass").hook { + "com.demo.test.TestClass".toClass().hook { injectMember { method { name = "test" diff --git a/docs-source/src/zh-cn/api/special-features/reflection.md b/docs-source/src/zh-cn/api/special-features/reflection.md index 9df2ceda..86a917a3 100644 --- a/docs-source/src/zh-cn/api/special-features/reflection.md +++ b/docs-source/src/zh-cn/api/special-features/reflection.md @@ -1525,15 +1525,7 @@ VariousClass("com.demo.ATest", "com.demo.BTest").toClass().method { 若在创建 Hook 的时候使用,可以更加方便,还可以自动拦截找不到 `Class` 的异常。 -> 示例如下 - -```kotlin -findClass("com.demo.ATest", "com.demo.BTest").hook { - // Your code here. -} -``` - -你还可以把这个 `Class` 定义为一个常量类型来使用。 +你可以把这个 `Class` 定义为一个常量类型来使用。 > 示例如下 @@ -1546,12 +1538,6 @@ ABTestClass.hook { } ``` -::: tip - -更多功能请参考 [PackageParam.findClass](../public/com/highcapable/yukihookapi/hook/param/PackageParam#findclass-method) 方法。 - -::: - ### 调用泛型 在反射过程中,我们可能会遇到泛型问题,在泛型的反射处理上,`YukiHookAPI` 同样提供了一个可在任意地方使用的语法糖。 diff --git a/docs-source/src/zh-cn/config/api-example.md b/docs-source/src/zh-cn/config/api-example.md index 647fc159..566ec451 100644 --- a/docs-source/src/zh-cn/config/api-example.md +++ b/docs-source/src/zh-cn/config/api-example.md @@ -51,7 +51,7 @@ fun encase(initiate: PackageParam.() -> Unit) ```kotlin YukiHookAPI.encase { loadApp(name = "com.example.demo") { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } } @@ -63,7 +63,7 @@ YukiHookAPI.encase { ```kotlin encase { loadApp(name = "com.example.demo") { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } } @@ -120,12 +120,12 @@ object CustomHooker : YukiBaseHooker() { override fun onHook() { loadApp(name = "com.example.demo1") { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } } loadApp(name = "com.example.demo2") { - findClass(name = "$packageName.CustomClass").hook { + "$packageName.CustomClass".toClass().hook { // Your code here. } } @@ -148,7 +148,7 @@ object HookEntry : IYukiHookXposedInit { object ChildCustomHooker : YukiBaseHooker() { override fun onHook() { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } } @@ -163,7 +163,7 @@ object ChildCustomHooker : YukiBaseHooker() { object FirstHooker : YukiBaseHooker() { override fun onHook() { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } loadHooker(SecondHooker) @@ -233,7 +233,7 @@ encase { ```kotlin encase { loadApp(name = "com.example.demo") { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } // 创建一个 Resources Hook (固定用法) @@ -260,7 +260,7 @@ encase { } } loadApp(name = "com.example.demo") { - findClass(name = "$packageName.DemoClass").hook { + "$packageName.DemoClass".toClass().hook { // Your code here. } // 在 APP 中创建 Resources Hook @@ -296,7 +296,7 @@ encase { ```kotlin encase { // 错误的使用方法,不能直接开始 Hook - findClass(name = "com.example.demo.DemoClass").hook { + "com.example.demo.DemoClass".toClass().hook { // ... } // 错误的使用方法,不能直接开始 Hook @@ -325,7 +325,7 @@ object CustomHooker : YukiBaseHooker() { override fun onHook() { // 错误的使用方法,由于外层没有任何判断对象,不能直接开始 Hook - findClass(name = "com.example.demo.DemoClass").hook { + "com.example.demo.DemoClass".toClass().hook { // ... } } @@ -353,7 +353,7 @@ encase { loadApp(/** name 参数可选 */) { loadHooker(CustomHooker) // ✅ 正确的使用方法,在 APP 作用域内 Hook - findClass(name = "com.example.demo.DemoClass").hook { + "com.example.demo.DemoClass".toClass().hook { // ... } // ✅ 正确的使用方法,在 APP 作用域内 Hook @@ -379,7 +379,7 @@ object CustomHooker : YukiBaseHooker() { override fun onHook() { // ✅ 正确的使用方法,由于外层没有任何判断对象,需要判断 APP 作用域后再进行 Hook loadApp(/** name 参数可选 */) { - findClass(name = "com.example.demo.DemoClass").hook { + "com.example.demo.DemoClass".toClass().hook { // ... } } diff --git a/docs-source/src/zh-cn/guide/example.md b/docs-source/src/zh-cn/guide/example.md index c7bffd04..f2db847b 100644 --- a/docs-source/src/zh-cn/guide/example.md +++ b/docs-source/src/zh-cn/guide/example.md @@ -138,14 +138,14 @@ loadApp(name = "com.android.browser") { } ``` -对于当前项目下没有的 `Class`,你可以使用 `stub` 方式或 `findClass` 方法来得到需要 Hook 的类。 +对于当前项目下没有的 `Class`,你可以使用 `stub` 方式或 `String.toClass(...)` 方法来得到需要 Hook 的类。 比如,我要得到 `com.example.demo.TestClass`。 > 示例如下 ```kotlin -findClass(name = "com.example.demo.TestClass").hook { +"com.example.demo.TestClass".toClass().hook { injectMember { // Your code here. } @@ -157,35 +157,7 @@ findClass(name = "com.example.demo.TestClass").hook { > 示例如下 ```kotlin -findClass(name = "$packageName.TestClass").hook { - injectMember { - // Your code here. - } -} -``` - -到这里有些同学可能就开始说了,在某些场景下 `findClass` 显得有些繁琐。 - -因为可能有些同学有如下需求。 - -> 示例如下 - -```kotlin -const val TestClass = "com.example.demo.TestClass" - -TestClass.hook { - injectMember { - // Your code here. - } -} -``` - -没关系,你还可以使用字符串类名直接创建一个 Hook。 - -> 示例如下 - -```kotlin -"$packageName.TestClass".hook { +"$packageName.TestClass".toClass().hook { injectMember { // Your code here. } diff --git a/docs-source/src/zh-cn/guide/move-to-new-api.md b/docs-source/src/zh-cn/guide/move-to-new-api.md index 73420599..ec02449b 100644 --- a/docs-source/src/zh-cn/guide/move-to-new-api.md +++ b/docs-source/src/zh-cn/guide/move-to-new-api.md @@ -30,7 +30,7 @@ override fun onHook() = encase { // Hook 指定的 APP loadApp(name = "com.demo.test") { // Class Hook - findClass("com.demo.test.TestClass").hook { + "com.demo.test.TestClass".toClass().hook { injectMember { method { name = "test"