1

I want to hook methods of class MPIncomingPhoneCallController in iOS 5 to do something when a call comes. I use

Class _$MPIncomingPhoneCallController = objc_getClass("MPIncomingPhoneCallController");

MSHookMessage(_$MPIncomingPhoneCallController, 
              @selector(updateLCDWithName:label:breakPoint:), 
             (IMP) &Hook_LCD, 
             "pre_");

to hook updateLCDWithName:label:breakPoint:, but it failed.

How can I do this?

Nate
  • 31,017
  • 13
  • 83
  • 207
dustdn
  • 418
  • 2
  • 6
  • 18
  • you don't hook Classes. You hook methods or functions. I suggest you google a bit and look for tutorials on how to use MobileSubstrate, but first learn more about the basics of programming. PS: here you got to use objc_getMetaClass() – YllierDev May 07 '12 at 05:10
  • @YllierDev Yes, you are right,I hook functions.But first I have to get the class. objc_getMetaClass() is used to hook class method while objc_getClass is used to hook othe methods. – dustdn May 07 '12 at 05:20
  • 1
    objc_getClass is used for instance methods. Sorry for the confusion, I don't know how I thought that you wanted to hook a class method. Anyhow, I'm assuming that you are trying to hook that one while your tweak is injected into SpringBoard. You have to know that this class is in a plugin for SpringBoard which is loaded quite late. So you can only hook it once that plugin has been loaded. – YllierDev May 07 '12 at 05:32
  • @YllierDev As it is loaded late so I get nil? [link](http://stackoverflow.com/a/8842239/965442) Vertex mentioned iEnhancer there, I googled but find little info useful. Can you give me some guides? Thanks. – dustdn May 07 '12 at 05:50
  • I am sorry, but maybe nil is not the reason. I test others and they are also nil but methods are hooked. I will test more and sorry for this. – dustdn May 07 '12 at 07:13
  • @Vertex,Loko Can you give me some help on hooking methods of classes under SpringBoardPlugins ? Thanks – dustdn May 13 '12 at 11:22
  • I don't know when SpringBoard is loading the plugins, you'll have to apply the hooks after the plugins have been loaded – YllierDev May 14 '12 at 15:54
  • If you're open to *other* ways to simply detect when an incoming call arrives, other than MS hooking, then [have a look at this related question and answer](http://stackoverflow.com/a/14765396/119114). – Nate Feb 24 '13 at 22:14

1 Answers1

1

Class you are trying to hook is located in IncomingCall.serviceBundle which gets loaded in SpringBoard only when there is incoming call. To determine when it's actually loaded you need to hook SBPluginManager loadPluginBundle:. Wait until loaded bundle is com.apple.mobilephone.incomingcall. Only then you can hook what you want.

creker
  • 9,400
  • 1
  • 30
  • 47