Added index Field find feature and fix hook not work bug

This commit is contained in:
2022-04-01 15:45:14 +08:00
parent 5931ff570f
commit bf3a754b67
4 changed files with 32 additions and 10 deletions

View File

@@ -101,7 +101,8 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl
if (YukiHookAPI.hasXposedBridge.not()) return Result()
if (hookMembers.isEmpty()) error("Hook Members is empty,hook aborted")
else Thread {
SystemClock.sleep(10)
/** 延迟使得方法取到返回值 */
SystemClock.sleep(1)
if (isDisableCreaterRunHook.not() && hookClass.instance != null) hookMembers.forEach { it.hook() }
if (isDisableCreaterRunHook.not() && hookClass.instance == null)
if (onHookClassNotFoundFailureCallback == null)

View File

@@ -58,6 +58,8 @@ class FieldFinder(
*
* - 设置后将筛选 [Class.getDeclaredFields] 的数组下标
*
* - ❗若你同时设置了 [type] 将仅过滤类型为 [type] 的数组下标
*
* - ❗受到字节码顺序影响 - 请勿完全依赖于此功能
*
* 若 index 小于零则忽略此条件 (等于 -2 为取最后一个)
@@ -80,12 +82,20 @@ class FieldFinder(
*/
var type: Class<*>? = null
/** 设置 [Field] 在当前类中的位置为首位 */
/**
* 设置 [Field] 在当前类中的位置为首位
*
* - ❗若你同时设置了 [type] 将仅过滤类型为 [type] 的数组下标
*/
fun firstIndex() {
index = 0
}
/** 设置 [Field] 在当前类中的位置为末位 */
/**
* 设置 [Field] 在当前类中的位置为末位
*
* - ❗若你同时设置了 [type] 将仅过滤类型为 [type] 的数组下标
*/
fun lastIndex() {
index = -2
}
@@ -118,7 +128,8 @@ class FieldFinder(
} else Result(isNoSuch = true, Throwable("classSet is null"))
} catch (e: Throwable) {
Thread {
SystemClock.sleep(10)
/** 延迟使得方法取到返回值 */
SystemClock.sleep(1)
onFailureMsg(msg = "NoSuchField happend in [$classSet] [${hookTag}]", throwable = e)
}.start()
Result(isNoSuch = true, e)

View File

@@ -78,7 +78,8 @@ abstract class BaseFinder(
fun print() = yLoggerE(msg = "NoSuch$tag happend in [$classSet] $msg [${hookTag}]", e = throwable)
if (isAlwaysPrint) print()
else Thread {
SystemClock.sleep(10)
/** 延迟使得方法取到返回值 */
SystemClock.sleep(1)
if (isNotIgnoredNoSuchMemberFailure && !isUsingRemedyPlan && !isShutErrorPrinting) print()
}.start()
}

View File

@@ -58,11 +58,11 @@ internal object ReflectionTool {
return MemberCacheStore.findField(hashCode) ?: let {
var field: Field? = null
classSet?.declaredFields?.apply {
forEachIndexed { p, it ->
filter { type == null || type == it.type }.takeIf { it.isNotEmpty() }?.forEachIndexed { p, it ->
var isMatched = false
var conditions = true
if (type != null) isMatched = true
if (name.isNotBlank()) conditions = (name == it.name).also { isMatched = true }
if (type != null) conditions = (conditions && it.type == type).also { isMatched = true }
if (modifiers != null) conditions = (conditions && modifiers.contains(it)).also { isMatched = true }
if (index == -2) conditions = (conditions && p == lastIndex).also { isMatched = true }
if (index >= 0) conditions = (conditions && p == index).also { isMatched = true }
@@ -75,7 +75,10 @@ internal object ReflectionTool {
field?.also { MemberCacheStore.putField(hashCode, field) }
?: throw NoSuchFieldError(
"Can't find this Field --> " +
"index:[${index.takeIf { it >= 0 } ?: "unspecified"}] " +
"index:[${
index.takeIf { it >= 0 || it == -2 }?.toString()
?.replace(oldValue = "-2", newValue = "last") ?: "unspecified"
}] " +
"name:[${name.takeIf { it.isNotBlank() } ?: "unspecified"}] " +
"type:[${type ?: "unspecified"}] " +
"modifiers:${modifiers ?: "[]"} " +
@@ -131,7 +134,10 @@ internal object ReflectionTool {
method?.also { MemberCacheStore.putMethod(hashCode, method) }
?: throw NoSuchMethodError(
"Can't find this Method --> " +
"index:[${index.takeIf { it >= 0 } ?: "unspecified"}] " +
"index:[${
index.takeIf { it >= 0 || it == -2 }
?.toString()?.replace(oldValue = "-2", newValue = "last") ?: "unspecified"
}] " +
"name:[${name.takeIf { it.isNotBlank() } ?: "unspecified"}] " +
"paramCount:[${paramCount.takeIf { it >= 0 } ?: "unspecified"}] " +
"paramTypes:[${paramTypes.typeOfString()}] " +
@@ -184,7 +190,10 @@ internal object ReflectionTool {
?: throw NoSuchMethodError(
"Can't find this Constructor --> " +
"index:[${index.takeIf { it >= 0 } ?: "unspecified"}] " +
"paramCount:[${paramCount.takeIf { it >= 0 } ?: "unspecified"}] " +
"paramCount:[${
paramCount.takeIf { it >= 0 || it == -2 }
?.toString()?.replace(oldValue = "-2", newValue = "last") ?: "unspecified"
}] " +
"paramTypes:[${paramTypes.typeOfString()}] " +
"modifiers:${modifiers ?: "[]"} " +
"in Class [$classSet] " +