mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
...
This commit is contained in:
@@ -37,15 +37,15 @@ import com.highcapable.yukihookapi.hook.type.BundleClass
|
|||||||
class HookMain : YukiHookInitializeProxy {
|
class HookMain : YukiHookInitializeProxy {
|
||||||
|
|
||||||
override fun onHook() = encase {
|
override fun onHook() = encase {
|
||||||
optApp(name = "com.highcapable.yukihookapi.demo") {
|
loadApp(name = "com.highcapable.yukihookapi.demo") {
|
||||||
classOf(name = "$packageName.MainActivity").hook {
|
loadClass(name = "$packageName.MainActivity").hook {
|
||||||
grabMember = hookClass.methodOf(name = "hello")
|
grabMember = hookClass.loadMethod(name = "hello")
|
||||||
replaceTo(any = "这是一段 Hook 的文字内容")
|
replaceTo(any = "这是一段 Hook 的文字内容")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
optApp(name = "com.android.browser") {
|
loadApp(name = "com.android.browser") {
|
||||||
ActivityClass.hook {
|
ActivityClass.hook {
|
||||||
grabMember = hookClass.methodOf(name = "onCreate", BundleClass)
|
grabMember = hookClass.loadMethod(name = "onCreate", BundleClass)
|
||||||
afterHook {
|
afterHook {
|
||||||
Toast.makeText(thisAny as Activity, "Hook Success", Toast.LENGTH_SHORT).show()
|
Toast.makeText(thisAny as Activity, "Hook Success", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
@@ -81,11 +81,11 @@ class PackageParam(
|
|||||||
val isFirstApplication get() = instance?.isFirstApplication ?: true
|
val isFirstApplication get() = instance?.isFirstApplication ?: true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook 指定包名的 APP
|
* 装载并 Hook 指定包名的 APP
|
||||||
* @param name 包名
|
* @param name 包名
|
||||||
* @param initiate 方法体
|
* @param initiate 方法体
|
||||||
*/
|
*/
|
||||||
fun optApp(name: String, initiate: PackageParam.() -> Unit) {
|
fun loadApp(name: String, initiate: PackageParam.() -> Unit) {
|
||||||
if (packageName == name) initiate(this)
|
if (packageName == name) initiate(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ class PackageParam(
|
|||||||
* @return [Class]
|
* @return [Class]
|
||||||
* @throws NoClassDefFoundError 如果找不到类会报错
|
* @throws NoClassDefFoundError 如果找不到类会报错
|
||||||
*/
|
*/
|
||||||
fun classOf(name: String): Class<*> = appClassLoader.loadClass(name)
|
fun loadClass(name: String): Class<*> = appClassLoader.loadClass(name)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找目标方法
|
* 查找目标方法
|
||||||
@@ -104,7 +104,7 @@ class PackageParam(
|
|||||||
* @return [Method]
|
* @return [Method]
|
||||||
* @throws NoSuchMethodError 如果找不到方法会报错
|
* @throws NoSuchMethodError 如果找不到方法会报错
|
||||||
*/
|
*/
|
||||||
fun Class<*>.methodOf(name: String, vararg params: Class<*>): Method =
|
fun Class<*>.loadMethod(name: String, vararg params: Class<*>): Method =
|
||||||
getDeclaredMethod(name, *params).apply { isAccessible = true }
|
getDeclaredMethod(name, *params).apply { isAccessible = true }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,7 +113,7 @@ class PackageParam(
|
|||||||
* @return [Constructor]
|
* @return [Constructor]
|
||||||
* @throws NoSuchMethodError 如果找不到方法会报错
|
* @throws NoSuchMethodError 如果找不到方法会报错
|
||||||
*/
|
*/
|
||||||
fun Class<*>.constructorOf(vararg params: Class<*>): Constructor<*> =
|
fun Class<*>.loadConstructor(vararg params: Class<*>): Constructor<*> =
|
||||||
getDeclaredConstructor(*params).apply { isAccessible = true }
|
getDeclaredConstructor(*params).apply { isAccessible = true }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user