Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Q] how to hook an overloaded method

OP tonyzzp

20th June 2014, 03:47 AM   |  #1  
OP Junior Member
Thanks Meter: 0
 
19 posts
Join Date:Joined: Nov 2011
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.
20th June 2014, 08:55 AM   |  #2  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,332
 
5,910 posts
Join Date:Joined: Aug 2012
More
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);
23rd June 2014, 04:18 AM   |  #3  
OP Junior Member
Thanks Meter: 0
 
19 posts
Join Date:Joined: Nov 2011
Quote:
Originally Posted by GermainZ

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.
23rd June 2014, 04:43 AM   |  #4  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,332
 
5,910 posts
Join Date:Joined: Aug 2012
More
Quote:
Originally Posted by tonyzzp

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: [ View ]
Post Reply Subscribe to Thread

Tags
develop, hook, method, overload
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes