Blocking incoming sms in iOS 7

我怕爱的太早我们不能终老 提交于 2019-12-08 02:27:35

问题


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.


回答1:


  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.


来源:https://stackoverflow.com/questions/22989967/blocking-incoming-sms-in-ios-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!