Skip to content

Commit 7479987

Browse files
committed
Minor fixes
1 parent 83bcda1 commit 7479987

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

xposed/src/main/kotlin/org/matrix/vector/impl/hooks/BaseInvoker.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.github.libxposed.api.XposedInterface.CtorInvoker
44
import io.github.libxposed.api.XposedInterface.Invoker
55
import java.lang.reflect.Constructor
66
import java.lang.reflect.Executable
7+
import java.lang.reflect.InvocationTargetException
78
import java.lang.reflect.Method
89
import org.matrix.vector.impl.di.VectorBootstrap
910
import org.matrix.vector.nativebridge.HookBridge
@@ -28,7 +29,11 @@ internal abstract class BaseInvoker<T : Invoker<T, U>, U : Executable>(
2829
protected fun proceedInvocation(thisObject: Any?, args: Array<out Any?>): Any? {
2930
return when (val currentType = type) {
3031
is Invoker.Type.Origin -> {
31-
HookBridge.invokeOriginalMethod(executable, thisObject, *args)
32+
try {
33+
HookBridge.invokeOriginalMethod(executable, thisObject, args)
34+
} catch (e: InvocationTargetException) {
35+
throw e.cause ?: e
36+
}
3237
}
3338
is Invoker.Type.Chain -> {
3439
val snapshots =

xposed/src/main/kotlin/org/matrix/vector/impl/hooks/VectorChain.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ class VectorChain(
8686
t: Throwable,
8787
record: VectorHookRecord,
8888
nextChain: VectorChain,
89-
currentThis: Any,
90-
currentArgs: Array<Any?>,
89+
recoverThis: Any,
90+
recoverArgs: Array<Any?>,
9191
): Any? {
9292
if (record.exceptionMode == ExceptionMode.PASSTHROUGH) {
9393
throw t
@@ -97,9 +97,9 @@ class VectorChain(
9797
Log.e("VectorChain", "Hooker threw exception: ${record.hooker.javaClass.name}", t)
9898

9999
if (!nextChain.proceedCalled) {
100-
// Crash occurred BEFORE proceed(). Skip this hooker entirely and drive the chain
101-
// manually.
102-
return nextChain.proceedWith(currentThis, currentArgs)
100+
// Crash occurred BEFORE proceed().
101+
// Skip this hooker entirely and drive the chain manually.
102+
return nextChain.proceedWith(recoverThis, recoverArgs)
103103
} else {
104104
// Crash occurred AFTER proceed(). Swallow the module's crash and return the real
105105
// downstream state.

xposed/src/main/kotlin/org/matrix/vector/impl/hooks/VectorNativeHooker.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,17 @@ class VectorNativeHooker<T : Executable>(private val method: T) {
9898
val result = rootChain.proceed()
9999

100100
// Type safety validation before returning to C++
101-
if (
102-
returnType != null &&
103-
!returnType.isPrimitive &&
104-
result != null &&
105-
!HookBridge.instanceOf(result, returnType)
106-
) {
107-
throw ClassCastException(
108-
"Return value's type from hook callback does not match the hooked method"
109-
)
101+
if (returnType != null && returnType != Void.TYPE) {
102+
if (result == null && returnType.isPrimitive) {
103+
throw NullPointerException(
104+
"Hook returned null for a primitive return type: $method"
105+
)
106+
}
107+
if (result != null && HookBridge.instanceOf(result, returnType)) {
108+
throw ClassCastException(
109+
"Hook return type mismatch. Expected ${returnType.name}, got ${result.javaClass.name}"
110+
)
111+
}
110112
}
111113

112114
return result

0 commit comments

Comments
 (0)