Implement constructor invocation APIs in LSPosedContext (#533)
Unlike the existing `newInstance` variants which allocate and return a new object, these new APIs execute constructor logic on an existing, pre-allocated instance (`thisObject`). This separation of allocation and initialization allows for invoking original or super constructors within hook callbacks where the object reference is already established. The implementation leverages the existing JNI `HookBridge` methods, as `invokeOriginalMethod` and `invokeSpecialMethod` already support void-return signatures required for constructor execution. Co-authored-by: frknkrc44 <krc440002@gmail.com>
This commit is contained in:
parent
aed70305b9
commit
ea71745430
|
|
@ -210,10 +210,16 @@ public class LSPosedContext implements XposedInterface {
|
|||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object invokeOrigin(@NonNull Method method, @Nullable Object thisObject, Object[] args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException {
|
||||
public Object invokeOrigin(@NonNull Method method, @Nullable Object thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException {
|
||||
return HookBridge.invokeOriginalMethod(method, thisObject, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void invokeOrigin(@NonNull Constructor<T> constructor, @NonNull T thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException {
|
||||
// The bridge returns an Object (null for void/constructors), which we discard.
|
||||
HookBridge.invokeOriginalMethod(constructor, thisObject, args);
|
||||
}
|
||||
|
||||
private static char getTypeShorty(Class<?> type) {
|
||||
if (type == int.class) {
|
||||
return 'I';
|
||||
|
|
@ -257,6 +263,11 @@ public class LSPosedContext implements XposedInterface {
|
|||
return HookBridge.invokeSpecialMethod(method, getExecutableShorty(method), method.getDeclaringClass(), thisObject, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void invokeSpecial(@NonNull Constructor<T> constructor, @NonNull T thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException {
|
||||
HookBridge.invokeSpecialMethod(constructor, getExecutableShorty(constructor), constructor.getDeclaringClass(), thisObject, args);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T> T newInstanceOrigin(@NonNull Constructor<T> constructor, Object... args) throws InvocationTargetException, IllegalAccessException, InstantiationException {
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 54582730315ba4a3d7cfaf9baf9d23c419e07006
|
||||
Subproject commit 55efdf9d159195261d7326e9e125965a90025a12
|
||||
Loading…
Reference in New Issue