[英]Blocking incoming sms in iOS 7
I want to write a tweak for jailbroken devices that blocks messages from a phone number(in iOS 7). 我想为越狱设备编写一项调整措施,以阻止来自电话号码的消息(在iOS 7中)。 First I used the second answer of creker in this link for writing the tweak. 首先,我在此链接中使用了creker的第二个答案来编写调整项。 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: 和我的plist文件:
<?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! 主要的问题是loadServiceBundle
永远不会被钩住,我的函数也永远不会被调用! If I install the tweak on the iPhone, nothing happens when mobile has incoming sms and message alert comes. 如果我在iPhone上安装了调整功能,则当手机收到短信并且出现消息提示时,什么也不会发生。 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? 我本人认为问题是我正在为iOS 7编写程序,但问题是针对iOS6。如果问题是这样,您能告诉我该怎么做吗?
Another question that I have is in the loadServiceBundle
method. 我的另一个问题是在loadServiceBundle
方法中。 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. 我很高兴告诉我代码中是否还有其他问题。
com.apple.imservice.sms
. 您的捆绑包ID错误,应该是com.apple.imservice.sms
。 I've posted SMS service directory path ( /System/Library/Messages/PlugIns/SMS.imservice/
). 我已经发布了SMS服务目录路径( /System/Library/Messages/PlugIns/SMS.imservice/
)。 In there you can find Info.plist
which contains bundle id of the plugin - com.apple.imservice.sms
. 在其中可以找到Info.plist
,其中包含插件的包ID- com.apple.imservice.sms
。 IMDService -(void)loadServiceBundle
, without arguments. 是IMDService -(void)loadServiceBundle
,不带参数。 Then you can use [[self bundle] bundleIdentifier]
to get bundle id. 然后,您可以使用[[self bundle] bundleIdentifier]
获取捆绑包ID。 Also, don't forget to call original implementation of loadServiceBundle
before you hook _processReceivedMessage:
or even check for bundle id. 另外,不要忘了在钩上_processReceivedMessage:
之前甚至调用loadServiceBundle
原始实现_processReceivedMessage:
甚至检查包ID。 Original implementation actually loads the plugin, so calling it should be the first thing you do. 原始实现实际上会加载该插件,因此调用它应该是您要做的第一件事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.