From 18312577848306866f6afe4ddfb77024d95daf88 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Fri, 20 Jan 2023 23:52:59 +0800 Subject: [PATCH] Update api-example documentation --- docs-source/src/en/config/api-example.md | 29 ++++++++++++++++++++- docs-source/src/zh-cn/config/api-example.md | 27 ++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/docs-source/src/en/config/api-example.md b/docs-source/src/en/config/api-example.md index 1866bd20..004cae85 100644 --- a/docs-source/src/en/config/api-example.md +++ b/docs-source/src/en/config/api-example.md @@ -105,7 +105,7 @@ object CustomHooker : YukiBaseHooker() { } ``` -Child Hooker **recommended** singleton `object` creation, you can also use `class` but not recommended. +Child Hooker **recommended** to use singleton `object` to create, you can also use `class` but it is generally not recommended. ::: warning @@ -195,6 +195,33 @@ object HookEntry : IYukiHookXposedInit { } ``` +#### Special Case + +As we mentioned above, it is generally not recommended to use `class` to create child Hookers, but there is a special case where it may still be necessary to keep your Hooker supporting multiple instantiations. + +There is a rare possibility that there are multiple package names in a process. + +In this case, when `YukiHookAPI` finds that the child Hooker is a singleton, it will ignore it and print a warning message. + +```: no-line-numbers +This Hooker "HOOKER" is singleton or reused, but the current process has multiple package name "NAME", the original is "NAME" +Make sure your Hooker supports multiple instances for this situation +The process with package name "NAME" will be ignored +``` + +In this case, we only need to modify `object` to `class` or determine the package name during loading and then load the child Hooker. + +For example, in the above cases, the following forms can be used to load. + +> The following example + +```kotlin +encase { + // Assume this is the app package name and child Hooker you need to load + loadApp("com.example.demo", YourCustomHooker) +} +``` + ### Expansion Features If your current Hook Framework supports and enables the Resources Hook feature, you can now create Resources Hooks directly in `encase`. diff --git a/docs-source/src/zh-cn/config/api-example.md b/docs-source/src/zh-cn/config/api-example.md index dedb86aa..960d07ac 100644 --- a/docs-source/src/zh-cn/config/api-example.md +++ b/docs-source/src/zh-cn/config/api-example.md @@ -105,7 +105,7 @@ object CustomHooker : YukiBaseHooker() { } ``` -子 Hooker **建议使用**单例 `object` 创建,你也可以使用 `class` 但不推荐。 +子 Hooker **建议使用**单例 `object` 创建,你也可以使用 `class` 但一般情况下不推荐。 ::: warning @@ -195,6 +195,31 @@ object HookEntry : IYukiHookXposedInit { } ``` +#### 特殊情况 + +上面我们说到,在一般情况下不推荐使用 `class` 创建子 Hooker,但是有一种特殊情况,它可能依然需要保持你的 Hooker 支持多例。 + +有极少的可能性会出现在一个进程中存在多个包名的情况,这种情况下,`YukiHookAPI` 发现子 Hooker 为单例时,将会忽略并打印一条警告信息。 + +```:no-line-numbers +This Hooker "HOOKER" is singleton or reused, but the current process has multiple package name "NAME", the original is "NAME" +Make sure your Hooker supports multiple instances for this situation +The process with package name "NAME" will be ignored +``` + +遇到这种情况时,我们只需要修改 `object` 为 `class` 或者在装载时判断包名后再装载子 Hooker。 + +例如以上情况中可使用以下形式来装载。 + +> 示例如下 + +```kotlin +encase { + // 假设这个就是你需要装载的 APP 包名和子 Hooker + loadApp("com.example.demo", YourCustomHooker) +} +``` + ### 扩展特性 如果你当前使用的 Hook Framework 支持并启用了资源钩子(Resources Hook)功能,你现在可以直接在 `encase` 中创建 Resources Hook。