From 1ffa0fab4fc096593e1941162c42a5646ed0f8f9 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Tue, 3 Oct 2023 01:59:55 +0800 Subject: [PATCH] refactor: merge opt-in api to new annotations --- .../hook/core/YukiMemberHookCreator.md | 2 +- .../xposed/channel/YukiHookDataChannel.md | 2 +- .../hook/core/YukiMemberHookCreator.md | 2 +- .../xposed/channel/YukiHookDataChannel.md | 2 +- .../hook/core/YukiMemberHookCreator.kt | 6 +-- .../annotation/DangerousHookOperation.kt} | 30 +++------------ .../xposed/channel/YukiHookDataChannel.kt | 6 +-- .../annotation/SendTooLargeChannelData.kt | 37 +++++++++++++++++++ 8 files changed, 53 insertions(+), 34 deletions(-) rename yukihookapi-core/src/main/java/com/highcapable/yukihookapi/{annotation/CauseProblemsApi.kt => hook/core/annotation/DangerousHookOperation.kt} (62%) create mode 100644 yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/xposed/channel/annotation/SendTooLargeChannelData.kt diff --git a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.md b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.md index 392bdf4c..aad42df5 100644 --- a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.md +++ b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.md @@ -170,7 +170,7 @@ fun useDangerousOperation(option: String) 请在 `option` 中键入 `Yes do as I say!` 代表你同意允许所有危险行为。 -你还需要在整个调用域中声明注解 `CauseProblemsApi` 以消除警告。 +你还需要在整个调用域中声明注解 `DangerousHookOperation` 以消除警告。 若你只需要 Hook `ClassLoader` 的 `loadClass` 方法,请参考 [ClassLoader.onLoadClass](../factory/ReflectionFactory#classloader-onloadclass-ext-method)。 diff --git a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.md b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.md index 529021d9..d365a8af 100644 --- a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.md +++ b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.md @@ -142,7 +142,7 @@ fun allowSendTooLargeData(): NameSpace 仅会在每次调用时生效,下一次没有调用此方法则此功能将被自动关闭。 -你还需要在整个调用域中声明注解 `CauseProblemsApi` 以消除警告。 +你还需要在整个调用域中声明注解 `SendTooLargeChannelData` 以消除警告。 ::: danger diff --git a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.md b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.md index 23942af4..2ff99f5e 100644 --- a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.md +++ b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.md @@ -162,7 +162,7 @@ fun useDangerousOperation(option: String) 请在 `option` 中键入 `Yes do as I say!` 代表你同意允许所有危险行为。 -你还需要在整个调用域中声明注解 `CauseProblemsApi` 以消除警告。 +你还需要在整个调用域中声明注解 `DangerousHookOperation` 以消除警告。 若你只需要 Hook `ClassLoader` 的 `loadClass` 方法,请参考 [ClassLoader.onLoadClass](../factory/ReflectionFactory#classloader-onloadclass-ext-method)。 diff --git a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.md b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.md index 34b68098..ffa4442b 100644 --- a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.md +++ b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.md @@ -134,7 +134,7 @@ fun allowSendTooLargeData(): NameSpace 仅会在每次调用时生效,下一次没有调用此方法则此功能将被自动关闭。 -你还需要在整个调用域中声明注解 `CauseProblemsApi` 以消除警告。 +你还需要在整个调用域中声明注解 `SendTooLargeChannelData` 以消除警告。 ::: danger diff --git a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.kt b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.kt index 80d83d25..c413e7d9 100644 --- a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.kt +++ b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.kt @@ -30,8 +30,8 @@ package com.highcapable.yukihookapi.hook.core import com.highcapable.yukihookapi.YukiHookAPI -import com.highcapable.yukihookapi.annotation.CauseProblemsApi import com.highcapable.yukihookapi.hook.bean.HookClass +import com.highcapable.yukihookapi.hook.core.annotation.DangerousHookOperation import com.highcapable.yukihookapi.hook.core.api.compat.HookApiCategoryHelper import com.highcapable.yukihookapi.hook.core.api.helper.YukiHookHelper import com.highcapable.yukihookapi.hook.core.api.priority.YukiHookPriority @@ -140,12 +140,12 @@ class YukiMemberHookCreator internal constructor(private val packageParam: Packa * * 请在 [option] 中键入 "Yes do as I say!" 代表你同意允许所有危险行为 * - * 你还需要在整个调用域中声明注解 [CauseProblemsApi] 以消除警告 + * 你还需要在整个调用域中声明注解 [DangerousHookOperation] 以消除警告 * * - 若你不知道允许此功能会带来何种后果 - 请勿使用 * @param option 操作选项内容 */ - @CauseProblemsApi + @DangerousHookOperation fun useDangerousOperation(option: String) { hookOption = option } diff --git a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/annotation/CauseProblemsApi.kt b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/annotation/DangerousHookOperation.kt similarity index 62% rename from yukihookapi-core/src/main/java/com/highcapable/yukihookapi/annotation/CauseProblemsApi.kt rename to yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/annotation/DangerousHookOperation.kt index 12a87568..cd066cd6 100644 --- a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/annotation/CauseProblemsApi.kt +++ b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/annotation/DangerousHookOperation.kt @@ -23,33 +23,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * - * This file is created by fankes on 2022/4/3. + * This file is created by fankes on 2023/10/3. */ -@file:Suppress("unused") +package com.highcapable.yukihookapi.hook.core.annotation -package com.highcapable.yukihookapi.annotation - -@RequiresOptIn(level = RequiresOptIn.Level.WARNING) +@RequiresOptIn(message = "允许 Hook 过程中的所有危险行为可能导致意料之外的情况发生", level = RequiresOptIn.Level.WARNING) @MustBeDocumented -@Target( - AnnotationTarget.CLASS, - AnnotationTarget.CONSTRUCTOR, - AnnotationTarget.FUNCTION, - AnnotationTarget.ANNOTATION_CLASS, - AnnotationTarget.PROPERTY, - AnnotationTarget.FIELD, - AnnotationTarget.LOCAL_VARIABLE, - AnnotationTarget.VALUE_PARAMETER, - AnnotationTarget.PROPERTY_GETTER, - AnnotationTarget.PROPERTY_SETTER, - AnnotationTarget.TYPEALIAS -) +@Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.BINARY) /** - * - 标记为不规范使用可能会引发问题的 API - * - * 此功能用于规范代码调用域 - 非调用域内的 API 将会在 IDE 中显示警告 - * - * 此功能除继承和接口外不应该在这里被调用 + * 标记需要 [RequiresOptIn] 的功能 */ -annotation class CauseProblemsApi \ No newline at end of file +annotation class DangerousHookOperation \ No newline at end of file diff --git a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.kt b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.kt index 231e101b..4b4af8ed 100644 --- a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.kt +++ b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.kt @@ -44,12 +44,12 @@ import android.os.Parcel import android.os.Parcelable import android.os.TransactionTooLargeException import com.highcapable.yukihookapi.YukiHookAPI -import com.highcapable.yukihookapi.annotation.CauseProblemsApi import com.highcapable.yukihookapi.hook.log.YLog import com.highcapable.yukihookapi.hook.log.data.YLogData import com.highcapable.yukihookapi.hook.utils.factory.RandomSeed import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication import com.highcapable.yukihookapi.hook.xposed.bridge.YukiXposedModule +import com.highcapable.yukihookapi.hook.xposed.channel.annotation.SendTooLargeChannelData import com.highcapable.yukihookapi.hook.xposed.channel.data.ChannelData import com.highcapable.yukihookapi.hook.xposed.channel.data.wrapper.ChannelDataWrapper import com.highcapable.yukihookapi.hook.xposed.channel.priority.ChannelPriority @@ -343,12 +343,12 @@ class YukiHookDataChannel private constructor() { * * 仅会在每次调用时生效 - 下一次没有调用此方法则此功能将被自动关闭 * - * 你还需要在整个调用域中声明注解 [CauseProblemsApi] 以消除警告 + * 你还需要在整个调用域中声明注解 [SendTooLargeChannelData] 以消除警告 * * - 若你不知道允许此功能会带来何种后果 - 请勿使用 * @return [NameSpace] */ - @CauseProblemsApi + @SendTooLargeChannelData fun allowSendTooLargeData(): NameSpace { isAllowSendTooLargeData = true return this diff --git a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/xposed/channel/annotation/SendTooLargeChannelData.kt b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/xposed/channel/annotation/SendTooLargeChannelData.kt new file mode 100644 index 00000000..c14c24c4 --- /dev/null +++ b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/xposed/channel/annotation/SendTooLargeChannelData.kt @@ -0,0 +1,37 @@ +/* + * YukiHookAPI - An efficient Hook API and Xposed Module solution built in Kotlin. + * Copyright (C) 2019-2023 HighCapable + * https://github.com/fankes/YukiHookAPI + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * This file is created by fankes on 2023/10/3. + */ +package com.highcapable.yukihookapi.hook.xposed.channel.annotation + +@RequiresOptIn(message = "这是一个危险的操作,允许发送过大的数据可能导致宿主或模块崩溃", level = RequiresOptIn.Level.WARNING) +@MustBeDocumented +@Target(AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.BINARY) +/** + * 标记需要 [RequiresOptIn] 的功能 + */ +annotation class SendTooLargeChannelData \ No newline at end of file