From c02b658362547625042fcca98f3aa6d985eeddfb Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Fri, 25 Mar 2022 01:43:44 +0800 Subject: [PATCH] Add new function --- .../hook/core/finder/FieldFinder.kt | 2 - .../yukihookapi/hook/param/HookParam.kt | 76 +++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt index 5e533e5b..c92fc3ee 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt @@ -206,8 +206,6 @@ class FieldFinder( /** * 得到变量的 [Any] 实例 - * - * - ❗请确认目标变量的类型 - 发生错误会返回默认值 * @param instance 变量所在的实例对象 - 如果是静态可不填 - 默认 null * @return [Any] or null */ diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/param/HookParam.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/param/HookParam.kt index 22422648..7c7e5006 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/param/HookParam.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/param/HookParam.kt @@ -97,6 +97,20 @@ class HookParam(private val wrapper: HookParamWrapper) { wrapper.result = value } + /** + * 获取当前 Hook 对象 [method] or [constructor] 的参数对象数组第一位 [T] + * @return [T] or null + * @throws IllegalStateException 如果数组为空 + */ + inline fun firstArgs() = firstArgs as? T? + + /** + * 获取当前 Hook 对象 [method] or [constructor] 的参数对象数组最后一位 [T] + * @return [T] or null + * @throws IllegalStateException 如果数组为空 + */ + inline fun lastArgs() = lastArgs as? T? + /** * 获取当前 Hook 实例的对象 [T] * @return [T] @@ -153,6 +167,68 @@ class HookParam(private val wrapper: HookParamWrapper) { */ inner class ArgsModifyer(private val index: Int) { + /** + * 得到方法参数的实例对象 [T] + * @return [T] or null + */ + fun of() = runCatching { args[index] as? T? }.getOrNull() + + /** + * 得到方法参数的实例对象 [Int] + * + * - ❗请确认目标参数的类型 - 发生错误会返回默认值 + * @return [Int] 取不到返回 0 + */ + fun ofInt() = of() ?: 0 + + /** + * 得到方法参数的实例对象 [Long] + * + * - ❗请确认目标参数的类型 - 发生错误会返回默认值 + * @return [Long] 取不到返回 0L + */ + fun ofLong() = of() ?: 0L + + /** + * 得到方法参数的实例对象 [Short] + * + * - ❗请确认目标参数的类型 - 发生错误会返回默认值 + * @return [Short] 取不到返回 0 + */ + fun ofShort() = of() ?: 0 + + /** + * 得到方法参数的实例对象 [Double] + * + * - ❗请确认目标参数的类型 - 发生错误会返回默认值 + * @return [Double] 取不到返回 0.0 + */ + fun ofDouble() = of() ?: 0.0 + + /** + * 得到方法参数的实例对象 [Float] + * + * - ❗请确认目标参数的类型 - 发生错误会返回默认值 + * @return [Float] 取不到返回 0f + */ + fun ofFloat() = of() ?: 0f + + /** + * 得到方法参数的实例对象 [String] + * + * - ❗请确认目标参数的类型 - 发生错误会返回默认值 + * @return [String] 取不到返回 "" + */ + fun ofString() = of() ?: "" + + /** + * 得到方法参数的实例对象 [Boolean] + * + * - ❗请确认目标参数的类型 - 发生错误会返回默认值 + * @return [Boolean] 取不到返回 false + */ + fun ofBoolean() = of() ?: false + /** * 设置方法参数的实例对象 * @param any 实例对象