3

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,

hardartcore
  • 16,886
  • 12
  • 75
  • 101
Sharas
  • 1,985
  • 3
  • 20
  • 43

3 Answers3

8

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)

defim
  • 456
  • 6
  • 9
  • If you set result to null, what is returned as a result after the method wasn't executed. I mean if you call say if(blockedMethod()) {}, then what happens to the if-clause? – JohnyTex Oct 19 '20 at 08:52
2

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

Bugster
  • 1,475
  • 1
  • 12
  • 17
-1

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)

samGbos
  • 867
  • 1
  • 6
  • 13