Modify change to new conditions to fix Members may probably has a finding bug in ReflectionTool

This commit is contained in:
2022-09-08 04:01:35 +08:00
parent 600b02f308
commit e09d3282f0

View File

@@ -33,6 +33,7 @@ import com.highcapable.yukihookapi.hook.core.finder.members.data.MethodRulesData
import com.highcapable.yukihookapi.hook.factory.hasExtends import com.highcapable.yukihookapi.hook.factory.hasExtends
import com.highcapable.yukihookapi.hook.store.ReflectsCacheStore import com.highcapable.yukihookapi.hook.store.ReflectsCacheStore
import com.highcapable.yukihookapi.hook.type.defined.UndefinedType import com.highcapable.yukihookapi.hook.type.defined.UndefinedType
import com.highcapable.yukihookapi.hook.utils.conditions
import com.highcapable.yukihookapi.hook.xposed.bridge.YukiHookBridge import com.highcapable.yukihookapi.hook.xposed.bridge.YukiHookBridge
import com.highcapable.yukihookapi.hook.xposed.bridge.factory.YukiHookHelper import com.highcapable.yukihookapi.hook.xposed.bridge.factory.YukiHookHelper
import com.highcapable.yukihookapi.hook.xposed.parasitic.AppParasitics import com.highcapable.yukihookapi.hook.xposed.parasitic.AppParasitics
@@ -118,11 +119,11 @@ internal object ReflectionTool {
if (rulesData.modifiers != null && matchIndex != null) filter { rulesData.modifiers!!.contains(it) }.lastIndex else -1 if (rulesData.modifiers != null && matchIndex != null) filter { rulesData.modifiers!!.contains(it) }.lastIndex else -1
val nameCdsLastIndex = val nameCdsLastIndex =
if (rulesData.nameConditions != null && matchIndex != null) filter { rulesData.nameConditions!!.contains(it) }.lastIndex else -1 if (rulesData.nameConditions != null && matchIndex != null) filter { rulesData.nameConditions!!.contains(it) }.lastIndex else -1
forEachIndexed { p, it -> forEachIndexed { p, instance ->
var isMatched = false var isMatched = false
var conditions = true rulesData.conditions {
if (rulesData.type != null) value.type?.also { e ->
conditions = (rulesData.type == it.type).let { and((e == instance.type).let {
if (it) typeIndex++ if (it) typeIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -130,9 +131,10 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (typeLastIndex - typeIndex) && matchIndex.second) || abs(matchIndex.first) == (typeLastIndex - typeIndex) && matchIndex.second) ||
(typeLastIndex == typeIndex && matchIndex.second.not())) (typeLastIndex == typeIndex && matchIndex.second.not()))
})
} }
if (rulesData.name.isNotBlank()) value.name.takeIf { it.isNotBlank() }?.also { e ->
conditions = (conditions && rulesData.name == it.name).let { and((e == instance.name).let {
if (it) nameIndex++ if (it) nameIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -140,9 +142,10 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (nameLastIndex - nameIndex) && matchIndex.second) || abs(matchIndex.first) == (nameLastIndex - nameIndex) && matchIndex.second) ||
(nameLastIndex == nameIndex && matchIndex.second.not())) (nameLastIndex == nameIndex && matchIndex.second.not()))
})
} }
if (rulesData.modifiers != null) value.modifiers?.also { e ->
conditions = (conditions && rulesData.modifiers!!.contains(it)).let { and(e.contains(instance).let {
if (it) modifyIndex++ if (it) modifyIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -150,9 +153,10 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (modifyLastIndex - modifyIndex) && matchIndex.second) || abs(matchIndex.first) == (modifyLastIndex - modifyIndex) && matchIndex.second) ||
(modifyLastIndex == modifyIndex && matchIndex.second.not())) (modifyLastIndex == modifyIndex && matchIndex.second.not()))
})
} }
if (rulesData.nameConditions != null) value.nameConditions?.also { e ->
conditions = (conditions && rulesData.nameConditions!!.contains(it)).let { and(e.contains(instance).let {
if (it) nameCdsIndex++ if (it) nameCdsIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -160,12 +164,14 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (nameCdsLastIndex - nameCdsIndex) && matchIndex.second) || abs(matchIndex.first) == (nameCdsLastIndex - nameCdsIndex) && matchIndex.second) ||
(nameCdsLastIndex == nameCdsIndex && matchIndex.second.not())) (nameCdsLastIndex == nameCdsIndex && matchIndex.second.not()))
})
} }
if (orderIndex != null) conditions = orderIndex?.also {
(conditions && ((orderIndex.first >= 0 && orderIndex.first == p && orderIndex.second) || and(((it.first >= 0 && it.first == p && it.second) ||
(orderIndex.first < 0 && abs(orderIndex.first) == (lastIndex - p) && orderIndex.second) || (it.first < 0 && abs(it.first) == (lastIndex - p) && it.second) ||
(lastIndex == p && orderIndex.second.not()))).also { isMatched = true } (lastIndex == p && it.second.not())).also { isMatched = true })
if (conditions && isMatched) fields.add(it.apply { isAccessible = true }) }
}.finally { if (isMatched) fields.add(instance.apply { isAccessible = true }) }
} }
} ?: error("Can't find this Field [${rulesData.name}] because classSet is null") } ?: error("Can't find this Field [${rulesData.name}] because classSet is null")
fields.takeIf { it.isNotEmpty() }?.also { ReflectsCacheStore.putFields(hashCode, fields) } fields.takeIf { it.isNotEmpty() }?.also { ReflectsCacheStore.putFields(hashCode, fields) }
@@ -248,11 +254,11 @@ internal object ReflectionTool {
if (rulesData.modifiers != null && matchIndex != null) filter { rulesData.modifiers!!.contains(it) }.lastIndex else -1 if (rulesData.modifiers != null && matchIndex != null) filter { rulesData.modifiers!!.contains(it) }.lastIndex else -1
val nameCdsLastIndex = val nameCdsLastIndex =
if (rulesData.nameConditions != null && matchIndex != null) filter { rulesData.nameConditions!!.contains(it) }.lastIndex else -1 if (rulesData.nameConditions != null && matchIndex != null) filter { rulesData.nameConditions!!.contains(it) }.lastIndex else -1
forEachIndexed { p, it -> forEachIndexed { p, instance ->
var isMatched = false var isMatched = false
var conditions = true rulesData.conditions {
if (rulesData.name.isNotBlank()) value.name.takeIf { it.isNotBlank() }?.also { e ->
conditions = (rulesData.name == it.name).let { and((e == instance.name).let {
if (it) nameIndex++ if (it) nameIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -260,9 +266,10 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (nameLastIndex - nameIndex) && matchIndex.second) || abs(matchIndex.first) == (nameLastIndex - nameIndex) && matchIndex.second) ||
(nameLastIndex == nameIndex && matchIndex.second.not())) (nameLastIndex == nameIndex && matchIndex.second.not()))
})
} }
if (rulesData.returnType != null) value.returnType?.also { e ->
conditions = (conditions && rulesData.returnType == it.returnType).let { and((e == instance.returnType).let {
if (it) returnTypeIndex++ if (it) returnTypeIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -270,9 +277,10 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (returnTypeLastIndex - returnTypeIndex) && matchIndex.second) || abs(matchIndex.first) == (returnTypeLastIndex - returnTypeIndex) && matchIndex.second) ||
(returnTypeLastIndex == returnTypeIndex && matchIndex.second.not())) (returnTypeLastIndex == returnTypeIndex && matchIndex.second.not()))
})
} }
if (rulesData.paramCount >= 0) value.paramCount.takeIf { it >= 0 }?.also { e ->
conditions = (conditions && it.parameterTypes.size == rulesData.paramCount).let { and((instance.parameterTypes.size == e).let {
if (it) paramCountIndex++ if (it) paramCountIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -280,9 +288,10 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (paramCountLastIndex - paramCountIndex) && matchIndex.second) || abs(matchIndex.first) == (paramCountLastIndex - paramCountIndex) && matchIndex.second) ||
(paramCountLastIndex == paramCountIndex && matchIndex.second.not())) (paramCountLastIndex == paramCountIndex && matchIndex.second.not()))
})
} }
if (rulesData.paramCountRange.isEmpty().not()) value.paramCountRange.takeIf { it.isEmpty().not() }?.also { e ->
conditions = (conditions && it.parameterTypes.size in rulesData.paramCountRange).let { and((instance.parameterTypes.size in e).let {
if (it) paramCountRangeIndex++ if (it) paramCountRangeIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -290,9 +299,10 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (paramCountRangeLastIndex - paramCountRangeIndex) && matchIndex.second) || abs(matchIndex.first) == (paramCountRangeLastIndex - paramCountRangeIndex) && matchIndex.second) ||
(paramCountRangeLastIndex == paramCountRangeIndex && matchIndex.second.not())) (paramCountRangeLastIndex == paramCountRangeIndex && matchIndex.second.not()))
})
} }
if (rulesData.paramTypes != null) value.paramTypes?.also { e ->
conditions = (conditions && arrayContentsEq(rulesData.paramTypes, it.parameterTypes)).let { and(arrayContentsEq(e, instance.parameterTypes).let {
if (it) paramTypeIndex++ if (it) paramTypeIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -300,9 +310,10 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (paramTypeLastIndex - paramTypeIndex) && matchIndex.second) || abs(matchIndex.first) == (paramTypeLastIndex - paramTypeIndex) && matchIndex.second) ||
(paramTypeLastIndex == paramTypeIndex && matchIndex.second.not())) (paramTypeLastIndex == paramTypeIndex && matchIndex.second.not()))
})
} }
if (rulesData.modifiers != null) value.modifiers?.also { e ->
conditions = (conditions && rulesData.modifiers!!.contains(it)).let { and(e.contains(instance).let {
if (it) modifyIndex++ if (it) modifyIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -310,9 +321,10 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (modifyLastIndex - modifyIndex) && matchIndex.second) || abs(matchIndex.first) == (modifyLastIndex - modifyIndex) && matchIndex.second) ||
(modifyLastIndex == modifyIndex && matchIndex.second.not())) (modifyLastIndex == modifyIndex && matchIndex.second.not()))
})
} }
if (rulesData.nameConditions != null) value.nameConditions?.also { e ->
conditions = (conditions && rulesData.nameConditions!!.contains(it)).let { and(e.contains(instance).let {
if (it) nameCdsIndex++ if (it) nameCdsIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -320,12 +332,14 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (nameCdsLastIndex - nameCdsIndex) && matchIndex.second) || abs(matchIndex.first) == (nameCdsLastIndex - nameCdsIndex) && matchIndex.second) ||
(nameCdsLastIndex == nameCdsIndex && matchIndex.second.not())) (nameCdsLastIndex == nameCdsIndex && matchIndex.second.not()))
})
} }
if (orderIndex != null) conditions = orderIndex?.also {
(conditions && ((orderIndex.first >= 0 && orderIndex.first == p && orderIndex.second) || and(((it.first >= 0 && it.first == p && it.second) ||
(orderIndex.first < 0 && abs(orderIndex.first) == (lastIndex - p) && orderIndex.second) || (it.first < 0 && abs(it.first) == (lastIndex - p) && it.second) ||
(lastIndex == p && orderIndex.second.not()))).also { isMatched = true } (lastIndex == p && it.second.not())).also { isMatched = true })
if (conditions && isMatched) methods.add(it.apply { isAccessible = true }) }
}.finally { if (isMatched) methods.add(instance.apply { isAccessible = true }) }
} }
} ?: error("Can't find this Method [${rulesData.name}] because classSet is null") } ?: error("Can't find this Method [${rulesData.name}] because classSet is null")
methods.takeIf { it.isNotEmpty() }?.also { ReflectsCacheStore.putMethods(hashCode, methods) } methods.takeIf { it.isNotEmpty() }?.also { ReflectsCacheStore.putMethods(hashCode, methods) }
@@ -399,11 +413,11 @@ internal object ReflectionTool {
filter { arrayContentsEq(rulesData.paramTypes, it.parameterTypes) }.lastIndex else -1 filter { arrayContentsEq(rulesData.paramTypes, it.parameterTypes) }.lastIndex else -1
val modifyLastIndex = val modifyLastIndex =
if (rulesData.modifiers != null && matchIndex != null) filter { rulesData.modifiers!!.contains(it) }.lastIndex else -1 if (rulesData.modifiers != null && matchIndex != null) filter { rulesData.modifiers!!.contains(it) }.lastIndex else -1
forEachIndexed { p, it -> forEachIndexed { p, instance ->
var isMatched = false var isMatched = false
var conditions = true rulesData.conditions {
if (rulesData.paramCount >= 0) value.paramCount.takeIf { it >= 0 }?.also { e ->
conditions = (it.parameterTypes.size == rulesData.paramCount).let { and((instance.parameterTypes.size == e).let {
if (it) paramCountIndex++ if (it) paramCountIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -411,9 +425,10 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (paramCountLastIndex - paramCountIndex) && matchIndex.second) || abs(matchIndex.first) == (paramCountLastIndex - paramCountIndex) && matchIndex.second) ||
(paramCountLastIndex == paramCountIndex && matchIndex.second.not())) (paramCountLastIndex == paramCountIndex && matchIndex.second.not()))
})
} }
if (rulesData.paramCountRange.isEmpty().not()) value.paramCountRange.takeIf { it.isEmpty().not() }?.also { e ->
conditions = (conditions && it.parameterTypes.size in rulesData.paramCountRange).let { and((instance.parameterTypes.size in e).let {
if (it) paramCountRangeIndex++ if (it) paramCountRangeIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -421,9 +436,10 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (paramCountRangeLastIndex - paramCountRangeIndex) && matchIndex.second) || abs(matchIndex.first) == (paramCountRangeLastIndex - paramCountRangeIndex) && matchIndex.second) ||
(paramCountRangeLastIndex == paramCountRangeIndex && matchIndex.second.not())) (paramCountRangeLastIndex == paramCountRangeIndex && matchIndex.second.not()))
})
} }
if (rulesData.paramTypes != null) value.paramTypes?.also { e ->
conditions = (conditions && arrayContentsEq(rulesData.paramTypes, it.parameterTypes)).let { and(arrayContentsEq(e, instance.parameterTypes).let {
if (it) paramTypeIndex++ if (it) paramTypeIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -431,9 +447,10 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (paramTypeLastIndex - paramTypeIndex) && matchIndex.second) || abs(matchIndex.first) == (paramTypeLastIndex - paramTypeIndex) && matchIndex.second) ||
(paramTypeLastIndex == paramTypeIndex && matchIndex.second.not())) (paramTypeLastIndex == paramTypeIndex && matchIndex.second.not()))
})
} }
if (rulesData.modifiers != null) value.modifiers?.also { e ->
conditions = (conditions && rulesData.modifiers!!.contains(it)).let { and(e.contains(instance).let {
if (it) modifyIndex++ if (it) modifyIndex++
isMatched = true isMatched = true
it && (matchIndex == null || it && (matchIndex == null ||
@@ -441,12 +458,14 @@ internal object ReflectionTool {
(matchIndex.first < 0 && (matchIndex.first < 0 &&
abs(matchIndex.first) == (modifyLastIndex - modifyIndex) && matchIndex.second) || abs(matchIndex.first) == (modifyLastIndex - modifyIndex) && matchIndex.second) ||
(modifyLastIndex == modifyIndex && matchIndex.second.not())) (modifyLastIndex == modifyIndex && matchIndex.second.not()))
})
} }
if (orderIndex != null) conditions = orderIndex?.also {
(conditions && ((orderIndex.first >= 0 && orderIndex.first == p && orderIndex.second) || and(((it.first >= 0 && it.first == p && it.second) ||
(orderIndex.first < 0 && abs(orderIndex.first) == (lastIndex - p) && orderIndex.second) || (it.first < 0 && abs(it.first) == (lastIndex - p) && it.second) ||
(lastIndex == p && orderIndex.second.not()))).also { isMatched = true } (lastIndex == p && it.second.not())).also { isMatched = true })
if (conditions && isMatched) constructors.add(it.apply { isAccessible = true }) }
}.finally { if (isMatched) constructors.add(instance.apply { isAccessible = true }) }
} }
} ?: error("Can't find this Constructor because classSet is null") } ?: error("Can't find this Constructor because classSet is null")
return constructors.takeIf { it.isNotEmpty() }?.also { ReflectsCacheStore.putConstructors(hashCode, constructors) } return constructors.takeIf { it.isNotEmpty() }?.also { ReflectsCacheStore.putConstructors(hashCode, constructors) }