Skip to content

Commit 1eda35f

Browse files
committed
perf: detectHiddenMethod
1 parent 6d2e477 commit 1eda35f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

app/src/main/kotlin/li/songe/gkd/shizuku/ShizukuApi.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import li.songe.gkd.util.toast
2323
import rikka.shizuku.Shizuku
2424
import rikka.shizuku.ShizukuBinderWrapper
2525
import rikka.shizuku.SystemServiceHelper
26+
import java.lang.reflect.Method
2627

2728
inline fun <T> safeInvokeMethod(
2829
block: () -> T
@@ -43,11 +44,16 @@ fun getStubService(name: String, condition: Boolean): ShizukuBinderWrapper? {
4344
return ShizukuBinderWrapper(service)
4445
}
4546

47+
private fun Method.simpleString(): String {
48+
return "${name}(${parameterTypes.joinToString(",") { it.name }}):${returnType.name}"
49+
}
50+
4651
fun Class<*>.detectHiddenMethod(
4752
methodName: String,
4853
vararg args: Pair<Int, List<Class<*>>>,
4954
): Int {
50-
declaredMethods.forEach { method ->
55+
val methodsVal = methods
56+
methodsVal.forEach { method ->
5157
if (method.name == methodName) {
5258
val types = method.parameterTypes.toList()
5359
args.forEach { (value, argTypes) ->
@@ -57,7 +63,13 @@ fun Class<*>.detectHiddenMethod(
5763
}
5864
}
5965
}
60-
throw NoSuchMethodException()
66+
val result = methodsVal.filter { it.name == methodName }
67+
if (result.isEmpty()) {
68+
throw NoSuchMethodException("${name}::${methodName} not found")
69+
} else {
70+
LogUtils.d("detectHiddenMethod", *result.map { it.simpleString() }.toTypedArray())
71+
throw NoSuchMethodException("${name}::${methodName} not match")
72+
}
6173
}
6274

6375
class ShizukuContext(

0 commit comments

Comments
 (0)