[Q] how to hook an overloaded method

Search This thread

tonyzzp

Member
Nov 13, 2011
19
0
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

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
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

Member
Nov 13, 2011
19
0
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

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
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.
 
  • Like
Reactions: tonyzzp

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    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.