mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-10 04:24:21 +08:00
docs: update example, reflection
This commit is contained in:
@@ -78,6 +78,54 @@ For more functions, please refer to [classOf](../public/com/highcapable/yukihook
|
||||
|
||||
:::
|
||||
|
||||
### Lazy Loading
|
||||
|
||||
Suppose we want to get a `Class` that cannot be called directly, but we do not need this `Class` immediately.
|
||||
|
||||
At this time, you can use `lazyClass` to complete this function.
|
||||
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
// Lazy loading of this Class
|
||||
// If you are currently in a PackageParam environment, then you do not need to consider ClassLoader
|
||||
val instance by lazyClass("com.demo.Test")
|
||||
// Customize the ClassLoader where the Class is located
|
||||
val customClassLoader: ClassLoader? = ... // Assume this is your ClassLoader
|
||||
val instance by lazyClass("com.demo.Test") { customClassLoader }
|
||||
// Call this Class at the appropriate time
|
||||
instance.method {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
If the current `Class` does not exist, using the above method will throw an exception.
|
||||
|
||||
If you are not sure whether `Class` exists, you can refer to the following solution.
|
||||
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
// Lazy loading of this Class
|
||||
// If you are currently in a PackageParam environment, then you do not need to consider ClassLoader
|
||||
// If not available, the result will be null but no exception will be thrown
|
||||
val instance by lazyClassOrNull("com.demo.Test")
|
||||
// Customize the ClassLoader where the Class is located
|
||||
val customClassLoader: ClassLoader? = ... // Assume this is your ClassLoader
|
||||
// If not available, the result will be null but no exception will be thrown
|
||||
val instance by lazyClassOrNull("com.demo.Test") { customClassLoader }
|
||||
// Call this Class at the appropriate time
|
||||
instance?.method {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
::: tip
|
||||
|
||||
For more functions, please refer to [lazyClass](../public/com/highcapable/yukihookapi/hook/factory/ReflectionFactory#lazyclass-method), [lazyClassOrNull](../public/com/highcapable/yukihookapi/hook/factory/ReflectionFactory#lazyclassornull-method), [PackageParam → lazyClass](../public/com/highcapable/yukihookapi/hook/param/PackageParam#lazyclass-method), [PackageParam → lazyClassOrNull](../public/com/highcapable/yukihookapi/hook/param/PackageParam#lazyclassornull-method) methods.
|
||||
|
||||
:::
|
||||
|
||||
### Existential Judgment
|
||||
|
||||
Suppose we want to determine whether a `Class` exists.
|
||||
|
@@ -157,7 +157,7 @@ For example, I want to get `com.example.demo.TestClass`.
|
||||
.method {
|
||||
// Your code here.
|
||||
}.hook {
|
||||
// Your code here.
|
||||
// Your code here.
|
||||
}
|
||||
```
|
||||
|
||||
@@ -170,10 +170,30 @@ If `com.example.demo` is the app you want to hook, then the writing method can b
|
||||
.method {
|
||||
// Your code here.
|
||||
}.hook {
|
||||
// Your code here.
|
||||
// Your code here.
|
||||
}
|
||||
```
|
||||
|
||||
If this `Class` is not immediately available, you can use `lazyClass(...)` to define it.
|
||||
|
||||
> The following example
|
||||
|
||||
Define `TestClass`.
|
||||
|
||||
```kotlin
|
||||
val TestClass by lazyClass("com.example.demo.TestClass")
|
||||
```
|
||||
|
||||
Use it when appropriate.
|
||||
|
||||
```kotlin
|
||||
TestClass.method {
|
||||
// Your code here.
|
||||
}.hook {
|
||||
// Your code here.
|
||||
}
|
||||
```
|
||||
|
||||
::: tip
|
||||
|
||||
For more functions, please refer to [MemberHookCreator](../api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator#memberhookcreator-class).
|
||||
@@ -568,6 +588,18 @@ override fun onHook() = encase {
|
||||
}
|
||||
```
|
||||
|
||||
You can also abbreviate the `hook { ... }` method body when you only need a Hook callback event.
|
||||
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
ActivityClass.method {
|
||||
// Your code here.
|
||||
}.hook().after {
|
||||
// Your code here.
|
||||
}
|
||||
```
|
||||
|
||||
## Xposed Module Status
|
||||
|
||||
Usually, the developer of the Xposed Module will choose to read the activation information of the current Xposed Module to better show the user the effective status of the current function.
|
||||
|
Reference in New Issue
Block a user