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
|
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.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.ConstructorRulesData
|
||||||
import com.highcapable.yukihookapi.hook.core.finder.members.data.FieldRulesData
|
import com.highcapable.yukihookapi.hook.core.finder.members.data.FieldRulesData
|
||||||
import com.highcapable.yukihookapi.hook.core.finder.members.data.MemberRulesData
|
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 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 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 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 ->
|
declares.forEachIndexed { index, instance ->
|
||||||
conditions {
|
conditions {
|
||||||
type?.also {
|
type?.also {
|
||||||
@@ -129,7 +130,7 @@ internal object ReflectionTool {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
nameConditions?.also {
|
nameConditions?.also {
|
||||||
and(it.contains(instance).let { hold ->
|
and(it.contains(instance.name).let { hold ->
|
||||||
if (hold) iNameCds++
|
if (hold) iNameCds++
|
||||||
hold && matchIndex.compare(iNameCds, iLNameCds)
|
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 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 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 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 ->
|
declares.forEachIndexed { index, instance ->
|
||||||
conditions {
|
conditions {
|
||||||
name.takeIf { it.isNotBlank() }?.also {
|
name.takeIf { it.isNotBlank() }?.also {
|
||||||
@@ -220,7 +221,7 @@ internal object ReflectionTool {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
nameConditions?.also {
|
nameConditions?.also {
|
||||||
and(it.contains(instance).let { hold ->
|
and(it.contains(instance.name).let { hold ->
|
||||||
if (hold) iNameCds++
|
if (hold) iNameCds++
|
||||||
hold && matchIndex.compare(iNameCds, iLNameCds)
|
hold && matchIndex.compare(iNameCds, iLNameCds)
|
||||||
})
|
})
|
||||||
@@ -331,6 +332,7 @@ internal object ReflectionTool {
|
|||||||
is FieldRulesData -> isInitialize.not()
|
is FieldRulesData -> isInitialize.not()
|
||||||
is MethodRulesData -> isInitialize.not()
|
is MethodRulesData -> isInitialize.not()
|
||||||
is ConstructorRulesData -> isInitialize.not()
|
is ConstructorRulesData -> isInitialize.not()
|
||||||
|
is ClassRulesData -> isInitialize.not()
|
||||||
else -> true
|
else -> true
|
||||||
}.takeIf { it }?.also { error("You must set a condition when finding a $objectName") }
|
}.takeIf { it }?.also { error("You must set a condition when finding a $objectName") }
|
||||||
return result(this)
|
return result(this)
|
||||||
|
@@ -319,37 +319,29 @@ class NameConditions @PublishedApi internal constructor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对比 [Class]、[Member] 类型是否符合条件
|
* 对比 [Class]、[Member] 名称是否符合条件
|
||||||
* @param reflects 实例 - 只支持 [Class]、[Method]、[Field]
|
* @param symbolName 符号名称 - 可以使用 [Class.getName]、[Class.getSimpleName]、[Field.getName]、[Method.getName] 获取
|
||||||
* @param isUseSimple 是否使用 [Class.getSimpleName] - 只支持 [Class] - 默认否
|
|
||||||
* @return [Boolean] 是否符合条件
|
* @return [Boolean] 是否符合条件
|
||||||
*/
|
*/
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal fun contains(reflects: Any, isUseSimple: Boolean = false): Boolean {
|
internal fun contains(symbolName: String): Boolean {
|
||||||
var conditions = true
|
var conditions = true
|
||||||
when (reflects) {
|
if (isThisSynthetic0) conditions = conditions && symbolName == "this$0"
|
||||||
is Class<*> -> if (isUseSimple) reflects.simpleName else reflects.name
|
if (isOnlySymbols) conditions = conditions && symbolName.matches("[*,.:~`'\"|/\\\\?!^()\\[\\]{}%@#$&\\-_+=<>]+".toRegex())
|
||||||
is Method -> reflects.name
|
if (isOnlyLetters) conditions = conditions && symbolName.matches("[a-zA-Z]+".toRegex())
|
||||||
is Field -> reflects.name
|
if (isOnlyNumbers) conditions = conditions && symbolName.matches("[0-9]+".toRegex())
|
||||||
else -> ""
|
if (isOnlyLettersNumbers) conditions = conditions && symbolName.matches("[a-zA-Z0-9]+".toRegex())
|
||||||
}.also { symbolName ->
|
if (isOnlyLowercase) conditions = conditions && symbolName.matches("[a-z]+".toRegex())
|
||||||
if (isThisSynthetic0) conditions = conditions && symbolName == "this$0"
|
if (isOnlyUppercase) conditions = conditions && symbolName.matches("[A-Z]+".toRegex())
|
||||||
if (isOnlySymbols) conditions = conditions && symbolName.matches("[*,.:~`'\"|/\\\\?!^()\\[\\]{}%@#$&\\-_+=<>]+".toRegex())
|
cdsEqualsOfs.takeIf { it.isNotEmpty() }?.also { conditions = conditions && it.any { e -> symbolName.equals(e.first, e.second) } }
|
||||||
if (isOnlyLetters) conditions = conditions && symbolName.matches("[a-zA-Z]+".toRegex())
|
cdsStartsWiths.takeIf { it.isNotEmpty() }
|
||||||
if (isOnlyNumbers) conditions = conditions && symbolName.matches("[0-9]+".toRegex())
|
?.also { conditions = conditions && it.any { e -> symbolName.startsWith(e.first, e.second, e.third) } }
|
||||||
if (isOnlyLettersNumbers) conditions = conditions && symbolName.matches("[a-zA-Z0-9]+".toRegex())
|
cdsEndsWiths.takeIf { it.isNotEmpty() }?.also { conditions = conditions && it.any { e -> symbolName.endsWith(e.first, e.second) } }
|
||||||
if (isOnlyLowercase) conditions = conditions && symbolName.matches("[a-z]+".toRegex())
|
cdsContains.takeIf { it.isNotEmpty() }?.also { conditions = conditions && it.any { e -> symbolName.contains(e.first, e.second) } }
|
||||||
if (isOnlyUppercase) conditions = conditions && symbolName.matches("[A-Z]+".toRegex())
|
cdsMatches.takeIf { it.isNotEmpty() }?.also { conditions = conditions && it.any { e -> symbolName.matches(e) } }
|
||||||
cdsEqualsOfs.takeIf { it.isNotEmpty() }?.also { conditions = conditions && it.any { e -> symbolName.equals(e.first, e.second) } }
|
cdsLength.takeIf { it >= 0 }?.also { conditions = conditions && symbolName.length == it }
|
||||||
cdsStartsWiths.takeIf { it.isNotEmpty() }
|
cdsLengthRange.takeIf { it.isEmpty().not() }?.also { conditions = conditions && symbolName.length in it }
|
||||||
?.also { conditions = conditions && it.any { e -> symbolName.startsWith(e.first, e.second, e.third) } }
|
cdsLengthConditions?.also { conditions = conditions && it(symbolName.length) }
|
||||||
cdsEndsWiths.takeIf { it.isNotEmpty() }?.also { conditions = conditions && it.any { e -> symbolName.endsWith(e.first, e.second) } }
|
|
||||||
cdsContains.takeIf { it.isNotEmpty() }?.also { conditions = conditions && it.any { e -> symbolName.contains(e.first, e.second) } }
|
|
||||||
cdsMatches.takeIf { it.isNotEmpty() }?.also { conditions = conditions && it.any { e -> symbolName.matches(e) } }
|
|
||||||
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
|
return conditions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user