refactor: merge opt-in api to new annotations

This commit is contained in:
2023-10-03 01:59:55 +08:00
parent 71203cd9bf
commit 1ffa0fab4f
8 changed files with 53 additions and 34 deletions

View File

@@ -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)。

View File

@@ -142,7 +142,7 @@ fun allowSendTooLargeData(): NameSpace
仅会在每次调用时生效,下一次没有调用此方法则此功能将被自动关闭。
你还需要在整个调用域中声明注解 `CauseProblemsApi` 以消除警告。
你还需要在整个调用域中声明注解 `SendTooLargeChannelData` 以消除警告。
::: danger

View File

@@ -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)。

View File

@@ -134,7 +134,7 @@ fun allowSendTooLargeData(): NameSpace
仅会在每次调用时生效,下一次没有调用此方法则此功能将被自动关闭。
你还需要在整个调用域中声明注解 `CauseProblemsApi` 以消除警告。
你还需要在整个调用域中声明注解 `SendTooLargeChannelData` 以消除警告。
::: danger

View File

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

View File

@@ -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
annotation class DangerousHookOperation

View File

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

View File

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