From 11e1beca3a0c4d9b880f33f4c6e1f1f1dbeba8e1 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Thu, 8 Sep 2022 04:39:00 +0800 Subject: [PATCH] Added length function in NameConditions --- docs/api/public/NameConditions.md | 18 +++++++++++++ .../hook/core/finder/type/NameConditions.kt | 26 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/docs/api/public/NameConditions.md b/docs/api/public/NameConditions.md index 80bdd8de..8bbd8d61 100644 --- a/docs/api/public/NameConditions.md +++ b/docs/api/public/NameConditions.md @@ -88,6 +88,24 @@ fun matches(regex: Regex) > 正则字符匹配。 +### length *- method* + +```kotlin +fun length(num: Int) +``` + +```kotlin +fun length(numRange: IntRange) +``` + +**变更记录** + +`v1.0.93` `新增` + +**功能描述** + +> 字符长度与范围匹配。 + ### thisSynthetic0 *- method* ```kotlin diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/type/NameConditions.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/type/NameConditions.kt index ce0dc235..0b2f3463 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/type/NameConditions.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/type/NameConditions.kt @@ -55,6 +55,12 @@ class NameConditions @PublishedApi internal constructor() { /** 正则字符匹配条件 */ private var cdsMatches: Regex? = null + /** 字符长度匹配条件 */ + private var cdsLength = -1 + + /** 字符长度范围匹配条件 */ + private var cdsLengthRange = IntRange.EMPTY + /** 标识为匿名类的主类调用对象条件 */ private var isThisSynthetic0 = false @@ -143,6 +149,22 @@ class NameConditions @PublishedApi internal constructor() { cdsMatches = regex } + /** + * 字符长度匹配 + * @param num 预期的长度 + */ + fun length(num: Int) { + cdsLength = num + } + + /** + * 字符长度范围匹配 + * @param numRange 预期的长度范围 + */ + fun length(numRange: IntRange) { + cdsLengthRange = numRange + } + /** * 标识为匿名类的主类调用对象 * @@ -247,6 +269,8 @@ class NameConditions @PublishedApi internal constructor() { if (cdsEndsWith != null) cdsEndsWith?.apply { conditions = conditions && it.endsWith(first, second) } if (cdsContains != null) cdsContains?.apply { conditions = conditions && it.contains(first, second) } if (cdsMatches != null) cdsMatches?.apply { conditions = conditions && it.matches(regex = this) } + if (cdsLength >= 0) conditions = conditions && it.length == cdsLength + if (cdsLengthRange != IntRange.EMPTY) conditions = conditions && it.length in cdsLengthRange } return conditions } @@ -265,6 +289,8 @@ class NameConditions @PublishedApi internal constructor() { if (cdsEndsWith != null) cdsEndsWith?.apply { conditions += " " } if (cdsContains != null) cdsContains?.apply { conditions += " " } if (cdsMatches != null) cdsMatches?.apply { conditions += " " } + if (cdsLength >= 0) conditions += " " + if (cdsLengthRange != IntRange.EMPTY) conditions += " " return "[${conditions.trim()}]" } } \ No newline at end of file