Question

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.

Was it helpful?

Solution

  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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top