mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
Modify change contains function from reflects to symbolName in NameConditions (conflict commit)
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
package com.highcapable.yukihookapi.hook.core.finder.tools
|
||||
|
||||
import com.highcapable.yukihookapi.hook.core.finder.base.data.BaseRulesData
|
||||
import com.highcapable.yukihookapi.hook.core.finder.classes.data.ClassRulesData
|
||||
import com.highcapable.yukihookapi.hook.core.finder.members.data.ConstructorRulesData
|
||||
import com.highcapable.yukihookapi.hook.core.finder.members.data.FieldRulesData
|
||||
import com.highcapable.yukihookapi.hook.core.finder.members.data.MemberRulesData
|
||||
@@ -107,7 +108,7 @@ internal object ReflectionTool {
|
||||
val iLType = type?.let(matchIndex) { e -> declares.filter { e == it.type }.lastIndex } ?: -1
|
||||
val iLName = name.takeIf(matchIndex) { it.isNotBlank() }?.let { e -> declares.filter { e == it.name }.lastIndex } ?: -1
|
||||
val iLModify = modifiers?.let(matchIndex) { e -> declares.filter { e.contains(it) }.lastIndex } ?: -1
|
||||
val iLNameCds = nameConditions?.let(matchIndex) { e -> declares.filter { e.contains(it) }.lastIndex } ?: -1
|
||||
val iLNameCds = nameConditions?.let(matchIndex) { e -> declares.filter { e.contains(it.name) }.lastIndex } ?: -1
|
||||
declares.forEachIndexed { index, instance ->
|
||||
conditions {
|
||||
type?.also {
|
||||
@@ -129,7 +130,7 @@ internal object ReflectionTool {
|
||||
})
|
||||
}
|
||||
nameConditions?.also {
|
||||
and(it.contains(instance).let { hold ->
|
||||
and(it.contains(instance.name).let { hold ->
|
||||
if (hold) iNameCds++
|
||||
hold && matchIndex.compare(iNameCds, iLNameCds)
|
||||
})
|
||||
@@ -174,7 +175,7 @@ internal object ReflectionTool {
|
||||
val iLParamTypes = paramTypes?.let(matchIndex) { e -> declares.filter { paramTypesEq(e, it.parameterTypes) }.lastIndex } ?: -1
|
||||
val iLName = name.takeIf(matchIndex) { it.isNotBlank() }?.let { e -> declares.filter { e == it.name }.lastIndex } ?: -1
|
||||
val iLModify = modifiers?.let(matchIndex) { e -> declares.filter { e.contains(it) }.lastIndex } ?: -1
|
||||
val iLNameCds = nameConditions?.let(matchIndex) { e -> declares.filter { e.contains(it) }.lastIndex } ?: -1
|
||||
val iLNameCds = nameConditions?.let(matchIndex) { e -> declares.filter { e.contains(it.name) }.lastIndex } ?: -1
|
||||
declares.forEachIndexed { index, instance ->
|
||||
conditions {
|
||||
name.takeIf { it.isNotBlank() }?.also {
|
||||
@@ -220,7 +221,7 @@ internal object ReflectionTool {
|
||||
})
|
||||
}
|
||||
nameConditions?.also {
|
||||
and(it.contains(instance).let { hold ->
|
||||
and(it.contains(instance.name).let { hold ->
|
||||
if (hold) iNameCds++
|
||||
hold && matchIndex.compare(iNameCds, iLNameCds)
|
||||
})
|
||||
@@ -331,6 +332,7 @@ internal object ReflectionTool {
|
||||
is FieldRulesData -> isInitialize.not()
|
||||
is MethodRulesData -> isInitialize.not()
|
||||
is ConstructorRulesData -> isInitialize.not()
|
||||
is ClassRulesData -> isInitialize.not()
|
||||
else -> true
|
||||
}.takeIf { it }?.also { error("You must set a condition when finding a $objectName") }
|
||||
return result(this)
|
||||
|
@@ -319,20 +319,13 @@ class NameConditions @PublishedApi internal constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 对比 [Class]、[Member] 类型是否符合条件
|
||||
* @param reflects 实例 - 只支持 [Class]、[Method]、[Field]
|
||||
* @param isUseSimple 是否使用 [Class.getSimpleName] - 只支持 [Class] - 默认否
|
||||
* 对比 [Class]、[Member] 名称是否符合条件
|
||||
* @param symbolName 符号名称 - 可以使用 [Class.getName]、[Class.getSimpleName]、[Field.getName]、[Method.getName] 获取
|
||||
* @return [Boolean] 是否符合条件
|
||||
*/
|
||||
@PublishedApi
|
||||
internal fun contains(reflects: Any, isUseSimple: Boolean = false): Boolean {
|
||||
internal fun contains(symbolName: String): Boolean {
|
||||
var conditions = true
|
||||
when (reflects) {
|
||||
is Class<*> -> if (isUseSimple) reflects.simpleName else reflects.name
|
||||
is Method -> reflects.name
|
||||
is Field -> reflects.name
|
||||
else -> ""
|
||||
}.also { symbolName ->
|
||||
if (isThisSynthetic0) conditions = conditions && symbolName == "this$0"
|
||||
if (isOnlySymbols) conditions = conditions && symbolName.matches("[*,.:~`'\"|/\\\\?!^()\\[\\]{}%@#$&\\-_+=<>]+".toRegex())
|
||||
if (isOnlyLetters) conditions = conditions && symbolName.matches("[a-zA-Z]+".toRegex())
|
||||
@@ -349,7 +342,6 @@ class NameConditions @PublishedApi internal constructor() {
|
||||
cdsLength.takeIf { it >= 0 }?.also { conditions = conditions && symbolName.length == it }
|
||||
cdsLengthRange.takeIf { it.isEmpty().not() }?.also { conditions = conditions && symbolName.length in it }
|
||||
cdsLengthConditions?.also { conditions = conditions && it(symbolName.length) }
|
||||
}
|
||||
return conditions
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user