Search code examples
iosjailbreaktweak

Which method from which header is called when making a phone call in iOS?


I'm developing a tweak through logos template from ios open dev, but I've been looking around all header files in existing frameworks and I'm not finding the correct header which have method that's called after someone make a phone call ? Does any one know which it is ? I'm trying to do something like "AskToCall" which is available in Cydia that prompts an UIAlertView when a phone call is made, exactly when green button is pressed.

Thank you!


Solution

  • 1) First you need to link against private framework CoreTelephony: in your logos project's Makefile make sure you include yourprojectname_PRIVATE_FRAMEWORKS = CoreTelephony. Also make sure your MobileSubstrate .plist file filters "com.apple.mobilephone"

    2) The phone application on iPhone uses CoreTelephony's CTCallDialWithID function to make calls. You can simply hook the function and do your thing instead.

    #import "substrate.h" // for MSHookFunction definition
    
    extern "C" void CTCallDialWithID(NSString *numberToDial); // function declaration
    
    static void (*original_CTCallDialWithID)(NSString *numberToDial); //define a function pointer on which you'll assign the original call later
    
    static void replaced_CTCallDialWithID(NSString *numberToDial){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Verify New Call" message:[NSString stringWithFormat:@"Are you sure you want to call %@",numberToDial]
                             delegate:YOUR_OBJECT cancelButtonTitle:@"No" otherButtonTitles:@"Yes,please",nil];
        [alert show];
        [alert release];
    }
    

    In your constructor :

    %ctor{
          %init();
          MSHookFunction((void *)CTCallDialWithID,(void *)replaced_CTCallDialWithID,(void **)&original_CTCallDialWithID);
          // Replace original function implementation with your replaced_ one.
    
    }
    

    To actually dial the number eventually (e.g. in your alertview's delegate.) after you've replaced the function implementation, use

    CTCallDial(NSString *number);
    

    because CTCallDialWithID expects {...} parameters and will not function correctly.

    Note that this is a global hook in Phone.app for CTCallDialWithID (i works for all outgoing calls , including tapping a recent call to dial it, or a favorite, etc.

    If you simply need a hook for just when pressing the Call button:

    %hook DialerController
    -(void)_callButtonPressed:(id)pressed{
    
       UIView *dialerView=MSHookIvar<UIView *>(self,"_dialerView");
       UILabel *lcd=MSHookIvar<UILabel *>(dialerView,"_lcd");
       NSString *numberToBeDialed=[lcd text];
    
      // do your thing with the number in here.
    }
    %end
    

    I noticed you mentioned you found this method earlier and didn't work. It probably didn't work for you because you're not injecting in MobilePhone.app.

    Your .plist file in your theos project should look like:

    Filter = { Bundles = ("com.apple.mobilephone");};