IOS Jailbreak How do intercept SMS / Text Messages
Asked Answered
D

3

12

I'm currently trying to write an application that intercepts text messages and reacts depending on the content of that message. I tried to hook into _receivedMessage:(struct __CKSMSRecord *)message replace:(BOOL)replace method in the CKSMSService class but this seems not do get called at all.

Could someone please tell me what function/class i have to hook in? I need to intercept the text message before it gets displayed and stored into the database. I'm on IOS 5.0.1.

Any help is truly appreciated.

Doucette answered 30/12, 2011 at 15:1 Comment(1)
If your interested in this question why not support the Area 51 proposal for a jail-breaking Stack Exchange siteWarmup
T
10

This code snippet should intercept SMS messages- You can extend it for other kinds of notifications. Will work on iOS 5.0.1 as well. Does not work with iMessages though. Link with CoreTelephony framework (there are bunch of private headers there which you'd can class-dump)

#include <dlfcn.h>

#define CORETELPATH "/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony"
id(*CTTelephonyCenterGetDefault)();

void (*CTTelephonyCenterAddObserver) (id,id,CFNotificationCallback,NSString*,void*,int);


static void telephonyEventCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
    NSString *notifyname=(NSString *)name;
    if ([notifyname isEqualToString:@"kCTMessageReceivedNotification"])//received SMS
    {
        NSLog(@" SMS Notification Received :kCTMessageReceivedNotification");
        // Do blocking here. 
    }
}

-(void) registerCallback {

 void *handle = dlopen(CORETELPATH, RTLD_LAZY);
    CTTelephonyCenterGetDefault = dlsym(handle, "CTTelephonyCenterGetDefault");
    CTTelephonyCenterAddObserver = dlsym(handle,"CTTelephonyCenterAddObserver");
    dlclose(handle);
    id ct = CTTelephonyCenterGetDefault();

    CTTelephonyCenterAddObserver(
                                 ct, 
                                 NULL, 
                                 telephonyEventCallback,
                                 NULL,
                                 NULL,
                                 CFNotificationSuspensionBehaviorDeliverImmediately);
}
Tallowy answered 12/1, 2012 at 16:10 Comment(4)
How do you see the private headers and class-dump them?Curtin
Hi @Tallowy , do you know how to block the messages after the notification is received ?Assembly
Is there any alternative to do that. I am using Coretelephony.h header file. Can I implement sms notifications using this header.Tophole
I m using iOS 7.0.6 with Xcode 5. I have implemented this code and It gives me notification on received SMS but do not give me SMS content.Tophole
C
1

Although the poster already accepted rajagp's answer, I'm pretty sure it doesn't do what the question actually asked, on iOS 5. For iOS 5, I'm no longer seeing the message content anymore, although I do get notified that there is a new message.

So, what I did is take rajagp's notification handler for kCTMessageReceivedNotification, and inside it, use the code posted here to actually get the content of the text message, from the SMS database.

Cynthea answered 14/6, 2012 at 6:53 Comment(0)
R
0

This still works on iOS 7, but I found that you need a slight delay after receiving the kCTMessageReceivedNotification notification. Else you will miss the SMS just received. I use a delay of 0.1 sec, with a [self performSelector .. afterDelay:0.1];

Runion answered 15/2, 2016 at 22:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.