2

I want to write a tweak for jailbroken devices that blocks messages from a phone number(in iOS 7). First I used the second answer of creker in this link for writing the tweak. Here is my code:

#import <substrate.h>
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <libkern/OSAtomic.h>
#import "CTMessage.h"
#import "CTMessageCenter.h"

id(*_processReceivedMessage_orig)(id, SEL, CTMessage*) = NULL;
id _processReceivedMessage_hooked(id self, SEL _cmd, CTMessage* msg);
%hook IMDService
-(void)loadServiceBundle:(NSBundle*)bundle
{    
    if ([[bundle bundleIdentifier] isEqualToString:@"com.apple.SMSPlugin"] && [bundle isLoaded]) // not sure if the bundle identifier is correct!
    {  
        MSHookMessageEx(objc_getClass("SMSServiceSession"),
                        @selector(_processReceivedMessage:),
                        (IMP)_processReceivedMessage_hooked,
                        (IMP*)&_processReceivedMessage_orig);
    }
}
%end

id _processReceivedMessage_hooked(id self, SEL _cmd, CTMessage* msg)
{
    NSObject<CTMessageAddress>* phonenumber = [msg sender];
    NSString *senderNumber = (NSString*) [phonenumber canonicalFormat]; // sender number

    if ([senderNumber isEqualToString:@"+012345678910"])
        [[CTMessageCenter sharedMessageCenter] acknowledgeIncomingMessageWithId:[msg messageId]];
    else
         return _processReceivedMessage_orig(self, _cmd, msg);
}

and my plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Filter</key>
    <dict>
        <key>Bundles</key>
        <array>
            <string>com.apple.imagent</string>
        </array>
    </dict>
</dict>
</plist>

The main problem is that loadServiceBundle never gets hooked and my function never gets called! If I install the tweak on the iPhone, nothing happens when mobile has incoming sms and message alert comes. I myself think that the problem is I’m writing for iOS 7 but the question is for iOS 6. If the problem is this, could you tell what should I have to do?

Another question that I have is in the loadServiceBundle method. As you can see in the written code, I don’t exactly know which bundle identifier should I filter. Please tell me if I’ve chosen the right bundle identifier.

I would be glad to tell me if I have any other problems in my code.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3519705
  • 105
  • 9

1 Answers1

0
  1. My solution works on iOS 7
  2. Your bundle id is wrong, it should be com.apple.imservice.sms. I've posted SMS service directory path (/System/Library/Messages/PlugIns/SMS.imservice/). In there you can find Info.plist which contains bundle id of the plugin - com.apple.imservice.sms.
  3. You are hooking the wrong method. It's IMDService -(void)loadServiceBundle, without arguments. Then you can use [[self bundle] bundleIdentifier] to get bundle id. Also, don't forget to call original implementation of loadServiceBundle before you hook _processReceivedMessage: or even check for bundle id. Original implementation actually loads the plugin, so calling it should be the first thing you do.
creker
  • 9,400
  • 1
  • 30
  • 47
  • Thank u for the answer.I did what you said but i don't no why I can't hook `IMDService -(void)loadServiceBundle`. Still nothing happens when a message comes.Iv'e also added the tweaks plist file but i thinks its correct. – user3519705 Apr 10 '14 at 20:49
  • I found my problem. For hooking `(void)loadServiceBundle`, after copying the files, you have to reboot the phone. I myself only respringed the iPhone so `loadServiceBundle` wasn't ever called. After rebooting the iPhone, the tweak works perfectly! – user3519705 Apr 14 '14 at 07:48
  • Respring only restarts the SpringBoard so it required and will help only in case of SpringBoard tweaks. In your case you are hooking `com.apple.imagent` daemon. Instead of restarting an iPhone you could restart `com.apple.imagent`. You could do this by executing in terminal `launchctl stop com.apple.imagent`. That's how I install my tweak. – creker Apr 14 '14 at 08:03
  • @user3519705 Could you please guide me how to build tweak from this question code. I m using iOSOpenDev with Xcode 5 and iOS 7. Thanks – Ahad Khan Jun 26 '14 at 11:41
  • I have implemented but the problem is its block all messages and their notifications. – Ahad Khan Jun 30 '14 at 10:36
  • Let's continue discussion here http://stackoverflow.com/questions/16219799/block-sms-on-ios6/18915532#18915532 Where my original answer is. – creker Jun 30 '14 at 10:44
  • @AhadKhan The code works fine and I'm using it (thanks to creker). Are you sure about the `if ([senderNumber isEqualToString:@"+012345678910"])` line? Try logging and see what happens to the code. – user3519705 Jun 30 '14 at 13:01
  • I have already tried this... if this if blocks executes everything is fine. But when I send message from another number than else part executes and it start calling it self recursively. Here in else block it supposed to be calling original method but it call itself recursively. – Ahad Khan Jul 01 '14 at 05:20
  • @user3519705 How could I call original method because its get stuck in recursive call. This continuously executing else part when I send message from another number. Where its supposed to show notification and message should be appeared in SMS, I don't know where I m lacking. – Ahad Khan Jul 02 '14 at 05:37
  • @AhadKhan, you should post your code (add it to your question) - include everything from CydiaSubstrate calls to actual hooks. I use pretty much the same code as in the question above apart from return value - `_processReceivedMessage:` doesn't return anything. – creker Jul 02 '14 at 06:51
  • @creker many thanks for your cooperation. I have posted my code here is link of question. http://stackoverflow.com/questions/24525639/sms-interception-in-jailbreak-ios-7 – Ahad Khan Jul 02 '14 at 07:49