mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-01 16:25:31 +08:00
...
This commit is contained in:
@@ -36,13 +36,15 @@ import com.highcapable.yukihookapi.hook.xposed.YukiHookModuleStatus
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private var a = "没更改的变量"
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
// for test
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle("Hook 方法返回值测试")
|
||||
.setMessage(test() + "\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
|
||||
.setMessage(test() + "\n变量:$a\n模块是否已激活:${YukiHookModuleStatus.isActive()}")
|
||||
.setPositiveButton("下一个") { _, _ ->
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle("Hook 方法参数测试")
|
||||
|
@@ -33,6 +33,7 @@ import com.highcapable.yukihookapi.demo.BuildConfig
|
||||
import com.highcapable.yukihookapi.demo.InjectTest
|
||||
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
|
||||
|
||||
class MainHooker : YukiBaseHooker() {
|
||||
@@ -40,6 +41,18 @@ class MainHooker : YukiBaseHooker() {
|
||||
override fun onHook() =
|
||||
loadApp(name = BuildConfig.APPLICATION_ID) {
|
||||
MainActivity::class.java.hook {
|
||||
injectMember {
|
||||
method {
|
||||
name = "onCreate"
|
||||
param(BundleClass)
|
||||
beforeHook {
|
||||
field {
|
||||
name = "a"
|
||||
type = StringType
|
||||
}.set(instance, "这段文字被修改成功了")
|
||||
}
|
||||
}
|
||||
}
|
||||
injectMember {
|
||||
method {
|
||||
name = "test"
|
||||
|
@@ -53,6 +53,18 @@ class MainInjecter : YukiHookXposedInitProxy {
|
||||
encase(BuildConfig.APPLICATION_ID) {
|
||||
loadApp(name = BuildConfig.APPLICATION_ID) {
|
||||
MainActivity::class.java.hook {
|
||||
injectMember {
|
||||
method {
|
||||
name = "onCreate"
|
||||
param(BundleClass)
|
||||
beforeHook {
|
||||
field {
|
||||
name = "a"
|
||||
type = StringType
|
||||
}.set(instance, "这段文字被修改成功了")
|
||||
}
|
||||
}
|
||||
}
|
||||
injectMember {
|
||||
method {
|
||||
name = "test"
|
||||
|
@@ -153,7 +153,7 @@ class YukiHookCreater(private val packageParam: PackageParam, val hookClass: Cla
|
||||
* @param initiate 方法体
|
||||
* @return [FieldFinder.Result]
|
||||
*/
|
||||
fun field(initiate: FieldFinder.() -> Unit) =
|
||||
fun HookParam.field(initiate: FieldFinder.() -> Unit) =
|
||||
try {
|
||||
FieldFinder().apply(initiate).find()
|
||||
} catch (e: Throwable) {
|
||||
@@ -161,7 +161,7 @@ class YukiHookCreater(private val packageParam: PackageParam, val hookClass: Cla
|
||||
onNoSuchMemberCallback?.invoke(e)
|
||||
onFailureCallback?.invoke(e)
|
||||
if (onNoSuchMemberCallback == null && onFailureCallback == null) onHookFailureMsg(e)
|
||||
null
|
||||
FieldFinder().Result()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -372,6 +372,13 @@ class YukiHookCreater(private val packageParam: PackageParam, val hookClass: Cla
|
||||
*/
|
||||
inner class Result {
|
||||
|
||||
/**
|
||||
* 设置变量实例
|
||||
* @param instance 变量所在的实例对象 - 如果是静态可不填 - 默认 null
|
||||
* @param any 设置的实例内容
|
||||
*/
|
||||
fun set(instance: Any? = null, any: Any?) = fieldInstance?.set(instance, any)
|
||||
|
||||
/**
|
||||
* 得到变量实例
|
||||
* @param instance 变量所在的实例对象 - 如果是静态可不填 - 默认 null
|
||||
|
Reference in New Issue
Block a user