Xposed: how to block a method call

4.5k Views Asked by At

I'm using Xposed to do some method hooking (for now, just for learning). I've manged to hook the method SendTextMessage (android.telephony.SmsManager), i can do some things before the call and after the call of the method, so my question is, can i do something in the before that will cause the original method not be called?

Thanks,

3

There are 3 best solutions below

1
On BEST ANSWER

Use this somewhere in a "before" hook to prevent call to original method

param.setResult(null);

(In a "after" hook it only changes result of original method because it was executed yet)

0
On

You can use XC_MethodReplacement instead of XC_MethodHook to replace a call.

0
On

There's comments in the source code that say the way to prevent a method call is to call MethodHookParam#setThrowable(Throwable) to prevent the function from being called. So take the param passed to beforeHookedMethod and call param.setThrowable(Throwable t)

Note that Throwable is just the super class for all errors and exceptions in Java, so you should just be able to use Exception or Error as your Throwable.

(https://github.com/rovo89/XposedBridge/blob/13c9918eb449a4b851740c5e380057d6f0d23bd5/src/de/robv/android/xposed/XC_MethodHook.java)