Match original Xposed

This commit is contained in:
LoveSy 2021-01-28 01:08:09 +08:00
parent d3a5b282cb
commit 715a25d0bd
2 changed files with 25 additions and 24 deletions

View File

@ -74,13 +74,7 @@ public final class DynamicBridge {
if (hooker == null) { if (hooker == null) {
throw new IllegalStateException("method not hooked, cannot call original method."); throw new IllegalStateException("method not hooked, cannot call original method.");
} }
try { return hooker.callBackup(thisObject, args);
return hooker.callBackup(thisObject, args);
} catch (IllegalAccessException e) {
throw e;
} catch (Throwable e) {
throw new InvocationTargetException(e);
}
} }
} }

View File

@ -18,29 +18,32 @@ public class LspHooker {
this.backup = backup; this.backup = backup;
} }
public Object callBackup(Object thisObject, Object[] args) throws Throwable { public Object callBackup(Object thisObject, Object[] args) throws InvocationTargetException, IllegalAccessException {
try { if (args == null) {
if (args == null) { args = new Object[0];
args = new Object[0]; }
} if (Modifier.isStatic(method.getModifiers())) {
if (Modifier.isStatic(method.getModifiers())) { return backup.invoke(null, args);
return backup.invoke(null, args); } else {
} else { Object[] newArgs = new Object[args.length + 1];
Object[] newArgs = new Object[args.length + 1]; newArgs[0] = thisObject;
newArgs[0] = thisObject; System.arraycopy(args, 0, newArgs, 1, args.length);
System.arraycopy(args, 0, newArgs, 1, args.length); return backup.invoke(null, newArgs);
return backup.invoke(null, newArgs);
}
} catch (InvocationTargetException ite) {
throw ite.getCause();
} }
} }
@SuppressWarnings({"unused", "RedundantSuppression"}) @SuppressWarnings({"unused", "RedundantSuppression"})
public Object handleHookedMethod(Object[] args) throws Throwable { public Object handleHookedMethod(Object[] args) throws Throwable {
if (disableHooks) {
try {
return backup.invoke(null, args);
} catch (InvocationTargetException ite) {
throw ite.getCause();
}
}
Object[] callbacksSnapshot = additionalInfo.callbacks.getSnapshot(); Object[] callbacksSnapshot = additionalInfo.callbacks.getSnapshot();
final int callbacksLength = callbacksSnapshot.length; final int callbacksLength = callbacksSnapshot.length;
if (disableHooks || callbacksLength == 0) { if (callbacksLength == 0) {
try { try {
return backup.invoke(null, args); return backup.invoke(null, args);
} catch (InvocationTargetException ite) { } catch (InvocationTargetException ite) {
@ -84,7 +87,11 @@ public class LspHooker {
// call original method if not requested otherwise // call original method if not requested otherwise
if (!param.returnEarly) { if (!param.returnEarly) {
param.setResult(callBackup(param.thisObject, param.args)); try {
param.setResult(callBackup(param.thisObject, param.args));
} catch (InvocationTargetException e) {
param.setThrowable(e.getCause());
}
} }
// call "after method" callbacks // call "after method" callbacks