This commit is contained in:
2022-02-05 05:21:43 +08:00
parent e6bfc181de
commit 6a6715268f
11 changed files with 175 additions and 28 deletions

View File

@@ -30,6 +30,12 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/debug/kotlin")
kotlin.srcDir("build/generated/ksp/release/kotlin")
}
}
}
dependencies {

View File

@@ -1 +1 @@
com.highcapable.yukihookapi.demo.InjectTest_YukiHookXposedInit
com.highcapable.yukihookapi.demo.hook.inject.MainInjecter_YukiHookXposedInit

View File

@@ -30,6 +30,7 @@
package com.highcapable.yukihookapi.demo
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.highcapable.yukihookapi.hook.xposed.YukiHookModuleStatus
@@ -48,7 +49,7 @@ class MainActivity : AppCompatActivity() {
.setPositiveButton("下一个") { _, _ ->
AlertDialog.Builder(this)
.setTitle("Hook 方法参数测试")
.setMessage(test("这是没有更改的文字") + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
.setMessage(test("这是没有更改的文字") + "\n${a(content = "这是原文")}\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
.setPositiveButton("下一个") { _, _ ->
AlertDialog.Builder(this)
.setTitle("Hook 构造方法测试(stub)")
@@ -57,13 +58,19 @@ class MainActivity : AppCompatActivity() {
AlertDialog.Builder(this)
.setTitle("Hook 构造方法测试(名称)")
.setMessage(InjectTestName("文字没更改").getString() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
.setPositiveButton("完成", null)
.setPositiveButton("完成") { _, _ -> toast() }
.show()
}.show()
}.show()
}.show()
}
// for test
private fun toast() = Toast.makeText(this, "我弹出来了,没有 Hook", Toast.LENGTH_SHORT).show()
// for test
private fun a(content1: String = "前缀", content: String) = "$content1${content}_后面加了一段文字"
// for test
private fun test() = "正常显示的一行文字"

View File

@@ -35,6 +35,7 @@ import com.highcapable.yukihookapi.demo.MainActivity
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
import com.highcapable.yukihookapi.hook.type.BundleClass
import com.highcapable.yukihookapi.hook.type.StringType
import com.highcapable.yukihookapi.hook.type.UnitType
// for test
class MainHooker : YukiBaseHooker() {
@@ -54,6 +55,24 @@ class MainHooker : YukiBaseHooker() {
}.set(instance, "这段文字被修改成功了")
}
}
injectMember {
method {
name = "toast"
returnType = UnitType
}
intercept()
}
injectMember {
method {
name = "a"
param(StringType, StringType)
returnType = StringType
}
beforeHook {
args(index = 0).set("改了前面的")
args(index = 1).set("改了后面的")
}
}
injectMember {
method {
name = "test"

View File

@@ -31,28 +31,30 @@ package com.highcapable.yukihookapi.demo.hook.inject
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.InjectTest
import com.highcapable.yukihookapi.demo.MainActivity
import com.highcapable.yukihookapi.demo.hook.MainHooker
import com.highcapable.yukihookapi.demo.hook.SecondHooker
import com.highcapable.yukihookapi.hook.factory.encase
import com.highcapable.yukihookapi.hook.factory.findMethod
import com.highcapable.yukihookapi.hook.proxy.YukiHookXposedInitProxy
import com.highcapable.yukihookapi.hook.type.ActivityClass
import com.highcapable.yukihookapi.hook.type.BundleClass
import com.highcapable.yukihookapi.hook.type.StringType
import com.highcapable.yukihookapi.hook.type.UnitType
// for test
@InjectYukiHookWithXposed
class MainInjecter : YukiHookXposedInitProxy {
override fun onHook() {
// 设置模式
YukiHookAPI.isDebug = true
// 方案 1
encase(MainHooker(), SecondHooker())
// encase(MainHooker(), SecondHooker())
// 方案 2
encase(BuildConfig.APPLICATION_ID) {
encase {
loadApp(name = BuildConfig.APPLICATION_ID) {
MainActivity::class.java.hook {
injectMember {
@@ -67,6 +69,24 @@ class MainInjecter : YukiHookXposedInitProxy {
}.set(instance, "这段文字被修改成功了")
}
}
injectMember {
method {
name = "toast"
returnType = UnitType
}
intercept()
}
injectMember {
method {
name = "a"
param(StringType, StringType)
returnType = StringType
}
beforeHook {
args(index = 0).set("改了前面的")
args(index = 1).set("改了后面的")
}
}
injectMember {
method {
name = "test"