FORUMS
Remove All Ads from XDA

Hooking extended class but getting child class

7,800 posts
Thanks Meter: 5,330
 
By elesbb, Senior Member on 23rd May 2018, 07:14 PM
Post Reply Email Thread
So, I hook a method inside class B, all is well. However, when I type
Code:
param.thisObject.getClass().getName()
it does not show "B" it instead shows "A".

Class A is a class that extends class B.

But why is
Code:
param.thisObeject()
of type class "A" instead of "B"?

How can I get an object of class "B" so I can call methods specific to that class?

Also, the method I would like to call is private, but I get a "MethodNotFound" exception in xposed.
 
 
23rd May 2018, 10:05 PM |#2  
Ibuprophen's Avatar
Recognized Contributor
Flag Upstate New York
Thanks Meter: 5,955
 
Donate to Me
More
Quote:
Originally Posted by elesbb

So, I hook a method inside class B, all is well...

I've never developed a Module before but, I believe that you should be able to obtain some member guidance within the following thread.

https://forum.xda-developers.com/sho....php?t=2709324

Good Luck!


~~~~~~~~~~~~~~~
I DO NOT provide support via PM unless asked/requested by myself. PLEASE keep it in the threads where everyone can share.
24th May 2018, 07:08 AM |#3  
C3C076's Avatar
Recognized Contributor
Flag Bratislava
Thanks Meter: 23,591
 
Donate to Me
More
Quote:
Originally Posted by elesbb

So, I hook a method inside class B, all is well. However, when I type

Code:
param.thisObject.getClass().getName()
it does not show "B" it instead shows "A".
How can I get an object of class "B" so I can call methods specific to that class?

You can safely call methods that are defined within parent class B using derived instance A as long as those methods are not private to class B.
If they are private to class B you have to use a different approach. E.g.:
1) Get method of class B explicitly using classB.getDeclaredMethod() and set it to accessible
2) call method.invoke(param.thisObject, params...) where param.thisObject is instance of derived A
The Following User Says Thank You to C3C076 For This Useful Post: [ View ] Gift C3C076 Ad-Free
25th May 2018, 02:53 PM |#4  
elesbb's Avatar
OP Senior Member
Thanks Meter: 5,330
 
Donate to Me
More
Quote:
Originally Posted by C3C076

You can safely call methods that are defined within parent class B using derived instance A as long as those methods are not private to class B.
If they are private to class B you have to use a different approach. E.g.:
1) Get method of class B explicitly using classB.getDeclaredMethod() and set it to accessible
2) call method.invoke(param.thisObject, params...) where param.thisObject is instance of derived A

Ahh yes. Thank you. For some reason I thought Xposed took care of this automatically when calling XposedHelpers.callMethod() but apparently not. Thank you very much!
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes