Fix when the hook classSet is null,stop finding any member

This commit is contained in:
2022-04-01 13:58:18 +08:00
parent c7fb5370a2
commit 5931ff570f
3 changed files with 22 additions and 16 deletions

View File

@@ -125,7 +125,6 @@ class ConstructorFinder(
/**
* 得到构造方法
* @return [Constructor]
* @throws IllegalStateException 如果 [classSet] 为 null
* @throws NoSuchMethodError 如果找不到构造方法
*/
private val result get() = ReflectionTool.findConstructor(classSet, index, modifiers, paramCount, paramTypes)
@@ -148,11 +147,13 @@ class ConstructorFinder(
*/
@DoNotUseMethod
override fun build(isBind: Boolean) = try {
runBlocking {
isBindToHooker = isBind
setInstance(isBind, result)
}.result { onHookLogMsg(msg = "Find Constructor [${memberInstance}] takes ${it}ms [${hookTag}]") }
Result()
if (classSet != null) {
runBlocking {
isBindToHooker = isBind
setInstance(isBind, result)
}.result { onHookLogMsg(msg = "Find Constructor [${memberInstance}] takes ${it}ms [${hookTag}]") }
Result()
} else Result(isNoSuch = true, Throwable("classSet is null"))
} catch (e: Throwable) {
onFailureMsg(throwable = e)
Result(isNoSuch = true, e)
@@ -196,6 +197,7 @@ class ConstructorFinder(
*/
@DoNotUseMethod
internal fun build() {
if (classSet == null) return
if (remedyPlans.isNotEmpty()) run {
var isFindSuccess = false
var lastError: Throwable? = null

View File

@@ -110,10 +110,12 @@ class FieldFinder(
*/
@DoNotUseMethod
override fun build(isBind: Boolean) = try {
runBlocking {
memberInstance = ReflectionTool.findField(classSet, index, name, modifiers, type)
}.result { onHookLogMsg(msg = "Find Field [${memberInstance}] takes ${it}ms [${hookTag}]") }
Result()
if (classSet != null) {
runBlocking {
memberInstance = ReflectionTool.findField(classSet, index, name, modifiers, type)
}.result { onHookLogMsg(msg = "Find Field [${memberInstance}] takes ${it}ms [${hookTag}]") }
Result()
} else Result(isNoSuch = true, Throwable("classSet is null"))
} catch (e: Throwable) {
Thread {
SystemClock.sleep(10)

View File

@@ -139,7 +139,6 @@ class MethodFinder(
/**
* 得到方法
* @return [Method]
* @throws IllegalStateException 如果 [classSet] 为 null
* @throws NoSuchMethodError 如果找不到方法
*/
private val result get() = ReflectionTool.findMethod(classSet, index, name, modifiers, returnType, paramCount, paramTypes)
@@ -163,11 +162,13 @@ class MethodFinder(
*/
@DoNotUseMethod
override fun build(isBind: Boolean) = try {
runBlocking {
isBindToHooker = isBind
setInstance(isBind, result)
}.result { onHookLogMsg(msg = "Find Method [${memberInstance}] takes ${it}ms [${hookTag}]") }
Result()
if (classSet != null) {
runBlocking {
isBindToHooker = isBind
setInstance(isBind, result)
}.result { onHookLogMsg(msg = "Find Method [${memberInstance}] takes ${it}ms [${hookTag}]") }
Result()
} else Result(isNoSuch = true, Throwable("classSet is null"))
} catch (e: Throwable) {
onFailureMsg(throwable = e)
Result(isNoSuch = true, e)
@@ -212,6 +213,7 @@ class MethodFinder(
*/
@DoNotUseMethod
internal fun build() {
if (classSet == null) return
if (remedyPlans.isNotEmpty()) run {
var isFindSuccess = false
var lastError: Throwable? = null