mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
...
This commit is contained in:
@@ -29,17 +29,12 @@
|
|||||||
|
|
||||||
package com.highcapable.yukihookapi.demo.hook
|
package com.highcapable.yukihookapi.demo.hook
|
||||||
|
|
||||||
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.InjectTest
|
||||||
import com.highcapable.yukihookapi.demo.MainActivity
|
import com.highcapable.yukihookapi.demo.MainActivity
|
||||||
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
|
import com.highcapable.yukihookapi.hook.type.StringType
|
||||||
|
|
||||||
@InjectYukiHookWithXposed
|
@InjectYukiHookWithXposed
|
||||||
@@ -72,37 +67,8 @@ class HookMain : YukiHookXposedInitProxy {
|
|||||||
beforeHook { args().set("构造方法已被 Hook 成功") }
|
beforeHook { args().set("构造方法已被 Hook 成功") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
findClass(name = "$packageName.InjectTestName").hook {
|
loadHooker(hooker = HookSecond())
|
||||||
injectMember {
|
|
||||||
constructor { param(StringType) }
|
|
||||||
beforeHook { args().set("构造方法已被 Hook 成功 [2]") }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
loadApp(name = "com.android.browser") {
|
|
||||||
ActivityClass.hook {
|
|
||||||
injectMember {
|
|
||||||
method {
|
|
||||||
name = "onCreate"
|
|
||||||
param(BundleClass)
|
|
||||||
}
|
|
||||||
afterHook {
|
|
||||||
AlertDialog.Builder(instance())
|
|
||||||
.setCancelable(false)
|
|
||||||
.setTitle("测试 Hook")
|
|
||||||
.setMessage("Hook 已成功")
|
|
||||||
.setPositiveButton("OK") { _, _ ->
|
|
||||||
Toast.makeText(instance(), "Hook Success", Toast.LENGTH_SHORT).show()
|
|
||||||
}.show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
injectMember {
|
|
||||||
member = hookClass.findMethod(name = "onStart")
|
|
||||||
afterHook {
|
|
||||||
Toast.makeText(instance(), "手动 Hook", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
loadApp(name = "com.android.browser", hooker = HookThird())
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* 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/3.
|
||||||
|
*/
|
||||||
|
package com.highcapable.yukihookapi.demo.hook
|
||||||
|
|
||||||
|
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
|
||||||
|
import com.highcapable.yukihookapi.hook.type.StringType
|
||||||
|
|
||||||
|
// for test
|
||||||
|
class HookSecond : YukiBaseHooker() {
|
||||||
|
|
||||||
|
override fun onHook() =
|
||||||
|
findClass(name = "$packageName.InjectTestName").hook {
|
||||||
|
injectMember {
|
||||||
|
constructor { param(StringType) }
|
||||||
|
beforeHook { args().set("构造方法已被 Hook 成功 [2]") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,64 @@
|
|||||||
|
/**
|
||||||
|
* 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/3.
|
||||||
|
*/
|
||||||
|
package com.highcapable.yukihookapi.demo.hook
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.widget.Toast
|
||||||
|
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
|
||||||
|
import com.highcapable.yukihookapi.hook.factory.findMethod
|
||||||
|
import com.highcapable.yukihookapi.hook.type.ActivityClass
|
||||||
|
import com.highcapable.yukihookapi.hook.type.BundleClass
|
||||||
|
|
||||||
|
// for test
|
||||||
|
class HookThird : YukiBaseHooker() {
|
||||||
|
|
||||||
|
override fun onHook() =
|
||||||
|
ActivityClass.hook {
|
||||||
|
injectMember {
|
||||||
|
method {
|
||||||
|
name = "onCreate"
|
||||||
|
param(BundleClass)
|
||||||
|
}
|
||||||
|
afterHook {
|
||||||
|
AlertDialog.Builder(instance())
|
||||||
|
.setCancelable(false)
|
||||||
|
.setTitle("测试 Hook")
|
||||||
|
.setMessage("Hook 已成功")
|
||||||
|
.setPositiveButton("OK") { _, _ ->
|
||||||
|
Toast.makeText(instance(), "Hook Success", Toast.LENGTH_SHORT).show()
|
||||||
|
}.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
injectMember {
|
||||||
|
member = hookClass.findMethod(name = "onStart")
|
||||||
|
afterHook {
|
||||||
|
Toast.makeText(instance(), "手动 Hook", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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/3.
|
||||||
|
*/
|
||||||
|
package com.highcapable.yukihookapi.hook.entity
|
||||||
|
|
||||||
|
import com.highcapable.yukihookapi.hook.proxy.YukiHookXposedInitProxy
|
||||||
|
import com.highcapable.yukihookapi.param.PackageParam
|
||||||
|
|
||||||
|
/**
|
||||||
|
* YukiHook 的子类实现
|
||||||
|
*
|
||||||
|
* 你可以在 [YukiHookXposedInitProxy] 的 [YukiHookXposedInitProxy.onHook] 中实现如下用法
|
||||||
|
*
|
||||||
|
* 调用 [PackageParam.loadApp] loadApp(name = "包名", hooker = 继承于此类的自定义 Hooker)
|
||||||
|
*
|
||||||
|
* 详情请参考 https://github.com/fankes/YukiHookAPI/wiki
|
||||||
|
*/
|
||||||
|
abstract class YukiBaseHooker : PackageParam() {
|
||||||
|
|
||||||
|
/** 子类 Hook 开始 */
|
||||||
|
abstract fun onHook()
|
||||||
|
}
|
@@ -31,6 +31,7 @@ package com.highcapable.yukihookapi.param
|
|||||||
|
|
||||||
import android.content.pm.ApplicationInfo
|
import android.content.pm.ApplicationInfo
|
||||||
import com.highcapable.yukihookapi.hook.core.YukiHookCreater
|
import com.highcapable.yukihookapi.hook.core.YukiHookCreater
|
||||||
|
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
|
||||||
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +43,7 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage
|
|||||||
* @param baseParam 对接 Xposed API 的 [XC_LoadPackage.LoadPackageParam] - 默认空
|
* @param baseParam 对接 Xposed API 的 [XC_LoadPackage.LoadPackageParam] - 默认空
|
||||||
* @param customParam 自定义装载类 - 默认空
|
* @param customParam 自定义装载类 - 默认空
|
||||||
*/
|
*/
|
||||||
class PackageParam(
|
open class PackageParam(
|
||||||
private val baseParam: XC_LoadPackage.LoadPackageParam? = null,
|
private val baseParam: XC_LoadPackage.LoadPackageParam? = null,
|
||||||
private val customParam: CustomParam? = null
|
private val customParam: CustomParam? = null
|
||||||
) {
|
) {
|
||||||
@@ -93,6 +94,21 @@ class PackageParam(
|
|||||||
if (packageName == name) initiate(this)
|
if (packageName == name) initiate(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 装载并 Hook 指定包名的 APP
|
||||||
|
* @param name 包名
|
||||||
|
* @param hooker Hook 子类
|
||||||
|
*/
|
||||||
|
fun loadApp(name: String, hooker: YukiBaseHooker) {
|
||||||
|
if (packageName == name) hooker.onHook()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 装载 Hook 子类
|
||||||
|
* @param hooker Hook 子类
|
||||||
|
*/
|
||||||
|
fun loadHooker(hooker: YukiBaseHooker) = hooker.onHook()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将目标 [Class] 绑定到 [appClassLoader]
|
* 将目标 [Class] 绑定到 [appClassLoader]
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user