KyuubiRan / EzXHelper

A library to make Xposed modules development easily.
https://KyuubiRan.github.io/EzXHelper/
Apache License 2.0
373 stars 47 forks source link

Can EzXHelper or Xposed be used to call the superclass version of a hooked method? #22

Open DavidBerdik opened 1 year ago

DavidBerdik commented 1 year ago

I have a scenario in which I want to hook a method in a class that is extended from another class. Under certain conditions, I want to override the hooked method in the extended class and have it instead execute the original method. Basically I want to do the Xposed/EzXHelper equivalent of calling super.myHookedMethod(). Is there a way to do this?

I tried using XposedHelpers.callMethod(XposedHelpers.getSurroundingThis(param.thisObject), "myHookedMethod") and XposedHelpers.callMethod(param.thisObject, "super.myHookedMethod") but neither has worked. Is there any way to achieve this?

keta1 commented 1 year ago

XposedBridge#invokeOriginalMethod (Member method, Object thisObject, Object[] args)

DavidBerdik commented 1 year ago

Doesn't this just call the method of the class you're in?

https://api.xposed.info/reference/de/robv/android/xposed/XposedBridge.html#invokeOriginalMethod(java.lang.reflect.Member,%20java.lang.Object,%20java.lang.Object[])

teble commented 1 year ago

Are you looking for java.lang.invoke.MethodHandle? it can call obj.super.method()

cinit commented 1 year ago

For invoking a super method (aka. invoke-super), you can use JNIEnv::CallNonvirtual<Type>Method. Note that MethodHandle is added in API 26.

DavidBerdik commented 1 year ago

@teble I'm honestly not sure if java.lang.invoke.MethodHandle is what I'm looking for, but it kind of sounds like it might be based on what I'm reading. Can I use callMethod() with obj.super then?

DavidBerdik commented 1 year ago

@cinit I'm not sure I understand this.