docs: update api-example, example, move-to-new-api, reflection

This commit is contained in:
2023-10-02 22:41:35 +08:00
parent 3ca7f4b017
commit ea86a2b60a
8 changed files with 34 additions and 118 deletions

View File

@@ -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.

View File

@@ -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 {
// ...
}
}

View File

@@ -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.
}

View File

@@ -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"