Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,809,359 Members 39,641 Now Online
XDA Developers Android and Mobile Development Forum

[Q] how to hook an overloaded method

Tip us?
 
tonyzzp
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 18
Join Date: Nov 2011
Question [Q] how to hook an overloaded method

I want to develop a permission manage program.

but how can i hook the method startActivity?

it has
startActivity(Intent)
startActivity(Intent,Bundle)
startActivityForResult(Intent,int)
startActivityFromChild(Activity,Intent)
.....

and other overload method.
which one should i hook?

if I hook all the methods,when startAcitivyt(Intent) is called, and all the methods are called too.

but if I only hook startActivity(Intent), when the startAcivity(Intent,Bundle) is called,i will not catch it.

please help me.thanks.
 
GermainZ
Old
#2  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,397
Posts: 5,476
Join Date: Aug 2012
Look at the source code, startActivity(Intent) will call startActivity(Intent, Bundle) so you only need to hook the latter. This may vary between different Android versions so you'll also want to check that.

In general you can also define a hook then use that for multiple methods. For example:
Code:
ZC_MethodHook hook = new XC_MethodHook(...);
findAndHookMethod (someClass, "someMethod", Argument.class, AnotherArgument.class, hook);
"someMethod", Argument.class, hook);
 
tonyzzp
Old
#3  
Junior Member - OP
Thanks Meter 0
Posts: 18
Join Date: Nov 2011
Quote:
Originally Posted by GermainZ View Post
Look at the source code, startActivity(Intent) will call startActivity(Intent, Bundle) so you only need to hook the latter. This may vary between different Android versions so you'll also want to check that.

In general you can also define a hook then use that for multiple methods. For example:
Code:
ZC_MethodHook hook = new XC_MethodHook(...);
findAndHookMethod (someClass, "someMethod", Argument.class, AnotherArgument.class, hook);
"someMethod", Argument.class, hook);
but there is a problem.
if the two methods are:

void methodA(){
//some code ..
methodA(0);
}

void methodA(int a){
//...
}

if i hook methodA(int) and prevent it from running. when methodA() is called, the "some code" will execute,but then stop.
 
GermainZ
Old
#4  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,397
Posts: 5,476
Join Date: Aug 2012
Quote:
Originally Posted by tonyzzp View Post
but there is a problem.
if the two methods are:

void methodA(){
//some code ..
methodA(0);
}

void methodA(int a){
//...
}

if i hook methodA(int) and prevent it from running. when methodA() is called, the "some code" will execute,but then stop.
This isn't the case for startActivity - again, look at the source code.

I'm not sure what you're asking here, to be honest. Of course, you *can* hook both methods (or even all of them using hookAllMethods, but be careful about argument when you do that), but in startActivity's case that seems unnecessary.
The Following User Says Thank You to GermainZ For This Useful Post: [ Click to Expand ]
Tags
develop, hook, method, overload
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes