Fix allMethods hooking replace bug

This commit is contained in:
2022-03-30 13:40:48 +08:00
parent cc8dbb8995
commit e895759172
5 changed files with 73 additions and 5 deletions

View File

@@ -47,6 +47,10 @@ class MainActivity : AppCompatActivity() {
appDemoFourthText.text = getRegularText(string = "Have fun day") appDemoFourthText.text = getRegularText(string = "Have fun day")
appDemoFifthText.text = getDataText() appDemoFifthText.text = getDataText()
appDemoSixthText.text = getArray(arrayOf("apple", "banana")).let { "${it[0]}, ${it[1]}" } appDemoSixthText.text = getArray(arrayOf("apple", "banana")).let { "${it[0]}, ${it[1]}" }
appDemoSeventhText.text = Main().getTestResultFirst()
appDemoEighthText.text = Main().getTestResultFirst(string = "Find something interesting")
appDemoNinthText.text = Main().getTestResultLast()
appDemoTenthText.text = Main().getTestResultLast(string = "This is the last sentence")
appDemoButton.setOnClickListener { toast() } appDemoButton.setOnClickListener { toast() }
} }
} }

View File

@@ -27,7 +27,15 @@
*/ */
package com.highcapable.yukihookapi.demo_app.utils package com.highcapable.yukihookapi.demo_app.utils
class Main(private val string: String) { class Main(private val string: String = "") {
fun getString() = string fun getString() = string
fun getTestResultFirst() = "The world is beautiful"
fun getTestResultFirst(string: String) = string
fun getTestResultLast() = "The world is fantastic"
fun getTestResultLast(string: String) = string
} }

View File

@@ -40,7 +40,31 @@
android:textSize="20sp" /> android:textSize="20sp" />
<TextView <TextView
android:id="@+id/app_demo_fifth_text" android:id="@+id/app_demo_seventh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
<TextView
android:id="@+id/app_demo_eighth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
<TextView
android:id="@+id/app_demo_ninth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
<TextView
android:id="@+id/app_demo_tenth_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="15dp" android:layout_marginBottom="15dp"
@@ -55,6 +79,14 @@
android:text="sample" android:text="sample"
android:textSize="20sp" /> android:textSize="20sp" />
<TextView
android:id="@+id/app_demo_fifth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="20sp" />
<Button <Button
android:id="@+id/app_demo_button" android:id="@+id/app_demo_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -154,6 +154,18 @@ class HookEntry : YukiHookXposedInitProxy {
args().set("I am hook constructor param") args().set("I am hook constructor param")
} }
} }
// 注入要 Hook 的方法
injectMember {
allMethods(name = "getTestResultFirst")
// 执行替换 Hook
replaceTo("I am hook all methods first")
}
// 注入要 Hook 的方法
injectMember {
allMethods(name = "getTestResultLast")
// 执行替换 Hook
replaceTo("I am hook all methods last")
}
} }
} }
} }

View File

@@ -170,6 +170,10 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl
/** /**
* 查找并 Hook [hookClass] 中指定 [name] 的全部方法 * 查找并 Hook [hookClass] 中指定 [name] 的全部方法
* *
* 在同一个 [injectMember] 中
*
* 你只能使用一次 [allMethods]、[allConstructors]、[method]、[constructor] 方法 - 否则结果会被替换
*
* - ❗警告:无法准确处理每个方法的返回值和 param - 建议使用 [method] 对每个方法单独 Hook * - ❗警告:无法准确处理每个方法的返回值和 param - 建议使用 [method] 对每个方法单独 Hook
* *
* - ❗如果 [hookClass] 中没有方法可能会发生错误 * - ❗如果 [hookClass] 中没有方法可能会发生错误
@@ -184,6 +188,10 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl
/** /**
* 查找并 Hook [hookClass] 中的全部构造方法 * 查找并 Hook [hookClass] 中的全部构造方法
* *
* 在同一个 [injectMember] 中
*
* 你只能使用一次 [allMethods]、[allConstructors]、[method]、[constructor] 方法 - 否则结果会被替换
*
* - ❗警告:无法准确处理每个构造方法的 param - 建议使用 [constructor] 对每个构造方法单独 Hook * - ❗警告:无法准确处理每个构造方法的 param - 建议使用 [constructor] 对每个构造方法单独 Hook
* *
* - ❗如果 [hookClass] 中没有构造方法可能会发生错误 * - ❗如果 [hookClass] 中没有构造方法可能会发生错误
@@ -197,7 +205,9 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl
/** /**
* 查找 [hookClass] 需要 Hook 的方法 * 查找 [hookClass] 需要 Hook 的方法
* *
* 你只能使用一次 [method] 或 [constructor] 方法 - 否则结果会被替换 * 在同一个 [injectMember] 中
*
* 你只能使用一次 [allMethods]、[allConstructors]、[method]、[constructor] 方法 - 否则结果会被替换
* @param initiate 方法体 * @param initiate 方法体
* @return [MethodFinder.Result] * @return [MethodFinder.Result]
*/ */
@@ -213,7 +223,9 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl
/** /**
* 查找 [hookClass] 需要 Hook 的构造方法 * 查找 [hookClass] 需要 Hook 的构造方法
* *
* 你只能使用一次 [method] 或 [constructor] 方法 - 否则结果会被替换 * 在同一个 [injectMember] 中
*
* 你只能使用一次 [allMethods]、[allConstructors]、[method]、[constructor] 方法 - 否则结果会被替换
* @param initiate 方法体 * @param initiate 方法体
* @return [ConstructorFinder.Result] * @return [ConstructorFinder.Result]
*/ */
@@ -493,7 +505,7 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl
*/ */
internal val isNotIgnoredNoSuchMemberFailure get() = onNoSuchMemberFailureCallback == null && isNotIgnoredHookingFailure internal val isNotIgnoredNoSuchMemberFailure get() = onNoSuchMemberFailureCallback == null && isNotIgnoredHookingFailure
override fun toString() = "${hookClass.name}$member$tag#YukiHookAPI" override fun toString() = "${hookClass.name}$allMethodsName$member$hookAllMembers$tag#YukiHookAPI"
/** /**
* 监听 Hook 结果实现类 * 监听 Hook 结果实现类