Welcome to the iFans Forums Create Your Account or Ask a Question Answers in 5 minutes - no registration required!

[CoreTelephony]CTTelephonyCenterRemoveObserver

Discussion in 'iOS Development' started by Jeepston, Aug 18, 2009.

  1. Jeepston

    Jeepston New Member

    Joined:
    May 17, 2009
    Messages:
    45
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    Continuing collecting info on SMS functions in 3.0....

    In order to react on incoming SMS, we need to add our own observer for correspondent notification (btw, in 3.0 those notifications are kCTMessageReceivedNotification and kCKSMSRecordReceivedNotification). Also, if we want not only to react on SMS, but to completely intercept it, we need to remove system observers (which is the title of current thread). And this procedure, for some reason, is the cause of some obstacles.

    In 2.0 it was enough to inject this code into SBTelephonyManager init merhod:

    [OBJC]void *ct = CTTelephonyCenterGetDefault();
    CTTelephonyCenterRemoveObserver(ct, SBTelephonyManager,kCTSMSMessageReceivedNotification,NULL); [/OBJC]

    It appears, that this is not enough for 3.0. Removing observers from SBTelephonyManager for both notifications does not give needed result. I have also tried to inject into [SBSMSManager init] this removal functions:

    [OBJC]CTTelephonyCenterRemoveObserver(ct, _SBSMSManager,kCKSMSRecordReceivedNotification,NULL);
    CTTelephonyCenterRemoveObserver(ct, _SBSMSManager,kCTMessageReceivedNotification,NULL);[/OBJC]

    And still - no result. So, apparently, I am missing some observer(s) in other classes. And I am stuck figuring out what are those classes. Does anyone have experience in dealing with this in 3.0? :confused:

    Any help, information and hints will be greatly appreciated.
  2. Jeepston

    Jeepston New Member

    Joined:
    May 17, 2009
    Messages:
    45
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    Here is the solution:

    To process SMS before your device does, you need to inject code into _receiedMessage:replace method of CKSMSService.

    Code:

    in the declaration:

    [OBJC]
    #import "CKSMSService.h"[/OBJC]

    in main():

    [OBJC]Class $CKSMSService = objc_getClass("CKSMSService");
    _CKSMSService$_receivedMessage$replace$ = MSHookMessage($CKSMSService, @selector(_receivedMessage:replace:), &$CKSMSService$_receivedMessage$replace$);[/OBJC]

    function with injected code:

    [OBJC]
    HOOK(CKSMSService, _receivedMessage$replace$, void, struct __CKSMSRecord *msg, BOOL isReplace)
    {
    // do whatever you need with CKSMSRecord
    ...........
    // if needed - call original method:
    CALL_ORIG(CKSMSService, _receivedMessage$replace$, msg, isReplace);
    }[/OBJC]

    Also you need to get two headers (e.g. from here: http://seriot.ch/blog.php?article=20090316): CKSMSService.h and CKService.h

    In order to compile, write

    [OBJC]#import "CKService.h"[/OBJC]

    on top of CKSMSService.h and comment out all lines where you'll get compiler errors.

    P.S. This code is based on SkylarEC's template for MS dylibs (http://www.ifans.com/forums/showthread.php?t=163185)
  3. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,492
    Likes Received:
    0
    Device:
    iPhone 4 (Black)
    Your code tags all turned into PHP code.....

    Just thought I'd say
  4. Jeepston

    Jeepston New Member

    Joined:
    May 17, 2009
    Messages:
    45
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    I like highlighting of php code :) . Plain
    Code:
     doesn't highlight at all, just saves the formatting
  5. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,492
    Likes Received:
    0
    Device:
    iPhone 4 (Black)
    [OBJC] Tag does syntax highlighting though......

    But whatever :)
  6. Jeepston

    Jeepston New Member

    Joined:
    May 17, 2009
    Messages:
    45
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    I didn't know about its existence. It's not on the control panel %)
  7. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,652
    Likes Received:
    122
    If you give me a list of standard CT functions, etc, I can have them added to the OBJC syntax highlighter.

    Also, I thought I had stickied the announcement of OBJC tags. Apparently I didn't. My bad.
  8. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,341
    Likes Received:
    55
    I admire you and cyanidepoison's work on reversing CoreTelephony. You guys should write up a page on it on the iPhone Wiki (theiphonewiki.com) if there isn't already an updated page.
  9. voidptr

    voidptr New Member

    Joined:
    Oct 29, 2009
    Messages:
    1
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    Hi All,

    I'm trying to build a Springboard plugin with Mobile Substrate to process incoming SMS.
    I'm using "CKSMSRecordText(void*, __CKSMSRecord*)" to get the SMS text.
    But when I link objects files I get a linker error.

    "Undefined symbols:
    "CKSMSCopyText(void*, __CKSMSRecord*)", referenced from:
    "$CKSMSService$_receivedMessage$replace$(CKSMSService*,objc_selector*,__CKSMSRecord*,signed char) in
    SpringBoardHook.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status"

    I've added ChatKit Framework on my makefile

    -F"/toolchain/sys/System/Library/PrivateFrameworks"
    -framework ChatKit

    Do you know what i'm doing wrong? Could you help me with this issue?
    Thank you very much in advance.
  10. skewlboy

    skewlboy New Member

    Joined:
    Dec 25, 2009
    Messages:
    3
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    Intercepting sending messages just requires hooking the sendMessage in CKSMSService, just thought I'd add :)

Share This Page