mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
...
This commit is contained in:
@@ -29,20 +29,12 @@
|
|||||||
|
|
||||||
package com.highcapable.yukihookapi.demo.hook.inject
|
package com.highcapable.yukihookapi.demo.hook.inject
|
||||||
|
|
||||||
import android.app.AlertDialog
|
|
||||||
import android.widget.Toast
|
|
||||||
import com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed
|
import com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed
|
||||||
import com.highcapable.yukihookapi.demo.BuildConfig
|
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.MainHooker
|
||||||
import com.highcapable.yukihookapi.demo.hook.SecondHooker
|
import com.highcapable.yukihookapi.demo.hook.SecondHooker
|
||||||
import com.highcapable.yukihookapi.hook.factory.encase
|
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.proxy.YukiHookXposedInitProxy
|
||||||
import com.highcapable.yukihookapi.hook.type.ActivityClass
|
|
||||||
import com.highcapable.yukihookapi.hook.type.BundleClass
|
|
||||||
import com.highcapable.yukihookapi.hook.type.StringType
|
|
||||||
|
|
||||||
// for test
|
// for test
|
||||||
@InjectYukiHookWithXposed
|
@InjectYukiHookWithXposed
|
||||||
@@ -50,65 +42,65 @@ class MainInjecter : YukiHookXposedInitProxy {
|
|||||||
|
|
||||||
override fun onHook() {
|
override fun onHook() {
|
||||||
// 方案 1
|
// 方案 1
|
||||||
// encase(BuildConfig.APPLICATION_ID, MainHooker(), SecondHooker())
|
encase(BuildConfig.APPLICATION_ID, MainHooker(), SecondHooker())
|
||||||
// 方案 2
|
// 方案 2
|
||||||
encase(BuildConfig.APPLICATION_ID) {
|
// encase(BuildConfig.APPLICATION_ID) {
|
||||||
loadApp(name = BuildConfig.APPLICATION_ID) {
|
// loadApp(name = BuildConfig.APPLICATION_ID) {
|
||||||
MainActivity::class.java.hook {
|
// MainActivity::class.java.hook {
|
||||||
injectMember {
|
// injectMember {
|
||||||
method {
|
// method {
|
||||||
name = "test"
|
// name = "test"
|
||||||
returnType = StringType
|
// returnType = StringType
|
||||||
}
|
// }
|
||||||
replaceTo("这段文字已被 Hook 成功")
|
// replaceTo("这段文字已被 Hook 成功")
|
||||||
}
|
// }
|
||||||
injectMember {
|
// injectMember {
|
||||||
method {
|
// method {
|
||||||
name = "test"
|
// name = "test"
|
||||||
param(StringType)
|
// param(StringType)
|
||||||
returnType = StringType
|
// returnType = StringType
|
||||||
}
|
// }
|
||||||
beforeHook { args().set("方法参数已被 Hook 成功") }
|
// beforeHook { args().set("方法参数已被 Hook 成功") }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
InjectTest::class.java.hook {
|
// InjectTest::class.java.hook {
|
||||||
injectMember {
|
// injectMember {
|
||||||
constructor { param(StringType) }
|
// constructor { param(StringType) }
|
||||||
beforeHook { args().set("构造方法已被 Hook 成功") }
|
// beforeHook { args().set("构造方法已被 Hook 成功") }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
findClass(name = "$packageName.InjectTestName").hook {
|
// findClass(name = "$packageName.InjectTestName").hook {
|
||||||
injectMember {
|
// injectMember {
|
||||||
constructor { param(StringType) }
|
// constructor { param(StringType) }
|
||||||
beforeHook { args().set("构造方法已被 Hook 成功 [2]") }
|
// beforeHook { args().set("构造方法已被 Hook 成功 [2]") }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
loadApp(name = "com.android.browser") {
|
// loadApp(name = "com.android.browser") {
|
||||||
ActivityClass.hook {
|
// ActivityClass.hook {
|
||||||
injectMember {
|
// injectMember {
|
||||||
method {
|
// method {
|
||||||
name = "onCreate"
|
// name = "onCreate"
|
||||||
param(BundleClass)
|
// param(BundleClass)
|
||||||
}
|
// }
|
||||||
afterHook {
|
// afterHook {
|
||||||
AlertDialog.Builder(instance())
|
// AlertDialog.Builder(instance())
|
||||||
.setCancelable(false)
|
// .setCancelable(false)
|
||||||
.setTitle("测试 Hook")
|
// .setTitle("测试 Hook")
|
||||||
.setMessage("Hook 已成功")
|
// .setMessage("Hook 已成功")
|
||||||
.setPositiveButton("OK") { _, _ ->
|
// .setPositiveButton("OK") { _, _ ->
|
||||||
Toast.makeText(instance(), "Hook Success", Toast.LENGTH_SHORT).show()
|
// Toast.makeText(instance(), "Hook Success", Toast.LENGTH_SHORT).show()
|
||||||
}.show()
|
// }.show()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
injectMember {
|
// injectMember {
|
||||||
member = hookClass.findMethod(name = "onStart")
|
// member = hookClass.findMethod(name = "onStart")
|
||||||
afterHook {
|
// afterHook {
|
||||||
Toast.makeText(instance(), "手动 Hook", Toast.LENGTH_SHORT).show()
|
// Toast.makeText(instance(), "手动 Hook", Toast.LENGTH_SHORT).show()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user