[core] Check cast before returning from hooker (#696)

This commit is contained in:
LoveSy 2021-05-30 15:18:13 +08:00 committed by GitHub
parent efa42a4eb0
commit a694d2bc73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 5 deletions

View File

@ -20,17 +20,17 @@
package de.robv.android.xposed;
import java.lang.reflect.Executable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
public class LspHooker {
private final XposedBridge.AdditionalHookInfo additionalInfo;
private final Member method;
private final Executable method;
private final Method backup;
public LspHooker(XposedBridge.AdditionalHookInfo info, Member origin, Method backup) {
public LspHooker(XposedBridge.AdditionalHookInfo info, Executable origin, Method backup) {
this.additionalInfo = info;
this.method = origin;
this.backup = backup;
@ -118,8 +118,15 @@ public class LspHooker {
// return
if (param.hasThrowable())
throw param.getThrowable();
else
return param.getResult();
else {
var result = param.getResult();
if (method instanceof Method) {
var returnType = ((Method) method).getReturnType();
if (!returnType.isPrimitive())
return returnType.cast(result);
}
return result;
}
}
}