From d8091684f7da57c04b7ce782f0fd5020cc80b006 Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Tue, 8 Feb 2022 21:35:13 +0800 Subject: [PATCH] ... --- .../yukihookapi/demo/InjectNoParamTest.kt | 46 +++++++++++++++++++ .../yukihookapi/demo/MainActivity.kt | 13 ++++-- .../demo/hook/inject/MainInjecter.kt | 16 +++++-- .../yukihookapi/hook/core/YukiHookCreater.kt | 2 +- 4 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/com/highcapable/yukihookapi/demo/InjectNoParamTest.kt diff --git a/app/src/main/java/com/highcapable/yukihookapi/demo/InjectNoParamTest.kt b/app/src/main/java/com/highcapable/yukihookapi/demo/InjectNoParamTest.kt new file mode 100644 index 00000000..d74c942f --- /dev/null +++ b/app/src/main/java/com/highcapable/yukihookapi/demo/InjectNoParamTest.kt @@ -0,0 +1,46 @@ +/** + * MIT License + * + * Copyright (C) 2022 HighCapable + * + * This file is part of YukiHookAPI. + * + * 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 2022/2/8. + */ +package com.highcapable.yukihookapi.demo + +import androidx.annotation.Keep + +// for test +@Keep +class InjectNoParamTest { + + @Keep + private var test = "没有" + + init { + test = "没修改的变量" + } + + // for test + @Keep + fun getString() = test +} \ No newline at end of file diff --git a/app/src/main/java/com/highcapable/yukihookapi/demo/MainActivity.kt b/app/src/main/java/com/highcapable/yukihookapi/demo/MainActivity.kt index f4780ba5..13c2c92f 100644 --- a/app/src/main/java/com/highcapable/yukihookapi/demo/MainActivity.kt +++ b/app/src/main/java/com/highcapable/yukihookapi/demo/MainActivity.kt @@ -63,10 +63,15 @@ class MainActivity : AppCompatActivity() { .setMessage(InjectLucky().getString() + "\n" + InjectLucky(string = "没更改的文字").getString() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}") .setPositiveButton("下一个") { _, _ -> AlertDialog.Builder(this) - .setTitle("Hook 构造方法测试(名称)") - .setMessage(InjectTestName("文字没更改").getString() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}") - .setPositiveButton("完成") { _, _ -> toast() } - .show() + .setTitle("Hook 构造方法测试(无参)") + .setMessage(InjectNoParamTest().getString() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}") + .setPositiveButton("下一个") { _, _ -> + AlertDialog.Builder(this) + .setTitle("Hook 构造方法测试(名称)") + .setMessage(InjectTestName("文字没更改").getString() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}") + .setPositiveButton("完成") { _, _ -> toast() } + .show() + }.show() }.show() }.show() }.show() diff --git a/app/src/main/java/com/highcapable/yukihookapi/demo/hook/inject/MainInjecter.kt b/app/src/main/java/com/highcapable/yukihookapi/demo/hook/inject/MainInjecter.kt index 444f7c3a..04998bbb 100644 --- a/app/src/main/java/com/highcapable/yukihookapi/demo/hook/inject/MainInjecter.kt +++ b/app/src/main/java/com/highcapable/yukihookapi/demo/hook/inject/MainInjecter.kt @@ -33,10 +33,7 @@ import android.app.AlertDialog import android.widget.Toast import com.highcapable.yukihookapi.YukiHookAPI import com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed -import com.highcapable.yukihookapi.demo.BuildConfig -import com.highcapable.yukihookapi.demo.InjectLucky -import com.highcapable.yukihookapi.demo.InjectTest -import com.highcapable.yukihookapi.demo.MainActivity +import com.highcapable.yukihookapi.demo.* import com.highcapable.yukihookapi.hook.factory.encase import com.highcapable.yukihookapi.hook.factory.findMethod import com.highcapable.yukihookapi.hook.type.ActivityClass @@ -124,6 +121,17 @@ class MainInjecter : YukiHookXposedInitProxy { beforeHook { args().set("构造方法已被 Hook 成功") } } } + InjectNoParamTest::class.java.hook { + injectMember { + constructor() + afterHook { + field { + name = "test" + type = StringType + }.set(instance, "内容被改掉了") + } + } + } findClass(name = "$packageName.InjectTestName").hook { injectMember { constructor { param(StringType) } diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiHookCreater.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiHookCreater.kt index 2d79042c..21ec9e00 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiHookCreater.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiHookCreater.kt @@ -176,7 +176,7 @@ class YukiHookCreater(private val packageParam: PackageParam, val hookClass: Cla * @param initiate 方法体 * @return [ConstructorFinder.Result] */ - fun constructor(initiate: ConstructorFinder.() -> Unit): ConstructorFinder.Result { + fun constructor(initiate: ConstructorFinder.() -> Unit = {}): ConstructorFinder.Result { hookAllMembers = HookAllMembers.HOOK_NONE isHookMemberSetup = true return ConstructorFinder(hookInstance = this, hookClass).apply(initiate).build()