0

我已经按照这个答案Blocking incomming sms in ios 7。问题是它阻止了每条消息及其通知。其次,当我发送除此号码 +923139303006 以外的消息时,它会不断调用 _processReceivedMessage_hooked 方法。

我将 OpenDev 与 Xcode 5、iOS 7.x 一起使用。

#include <logos/logos.h>
#import <substrate.h>
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <libkern/OSAtomic.h>
#import "CoreTelephony.h"


id(*_processReceivedMessage_orig)(id, SEL, CTMessage*) = NULL;
id _processReceivedMessage_hooked(id self, SEL _cmd, CTMessage* msg);



@class IMDService; 
static void (*_logos_orig$_ungrouped$IMDService$loadServiceBundle)(IMDService*, SEL); static void _logos_method$_ungrouped$IMDService$loadServiceBundle(IMDService*, SEL); 



static void _logos_method$_ungrouped$IMDService$loadServiceBundle(IMDService* self, SEL _cmd) {

    _logos_orig$_ungrouped$IMDService$loadServiceBundle(self, _cmd);

    NSBundle *bundle =[NSBundle mainBundle];

     NSLog(@"bundle identifier %@ ***** ",[bundle bundleIdentifier]);

//    if ([[bundle bundleIdentifier] isEqualToString:@"com.apple.imservice.sms"] && [bundle isLoaded])
//    {  
        NSLog(@"Hoooking  ***** ");
        MSHookMessageEx(objc_getClass("SMSServiceSession"),
                        @selector(_processReceivedMessage:),
                        (IMP)_processReceivedMessage_hooked,
                        (IMP*)&_processReceivedMessage_orig);
//    }

}


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

CTMessagePart *itmes = [[msg items] objectAtIndex:0];

NSString* msgtxt = [[NSString alloc] initWithData:itmes.data encoding:NSASCIIStringEncoding];


NSLog(@"message %@ ****",msgtxt);

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

}

static __attribute__((constructor)) void _logosLocalInit() {
{
    Class _logos_class$_ungrouped$IMDService = objc_getClass("IMDService");
    MSHookMessageEx(_logos_class$_ungrouped$IMDService, @selector(loadServiceBundle), (IMP)&_logos_method$_ungrouped$IMDService$loadServiceBundle, (IMP*)&_logos_orig$_ungrouped$IMDService$loadServiceBundle);
}
}

这是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>
4

1 回答 1

1

尝试取消注释if ([[bundle bundleIdentifier] isEqualToString:@"com.apple.imservice.sms"] && [bundle isLoaded])检查。

原因被loadServiceBundle多次调用 - 有几个 imagent 插件。每次它被称为你钩子_processReceivedMessage:一次又一次地重写你以前的钩子。因为这一切都发生在单个图像进程中,所以原始_processReceivedMessage:实现将丢失。结果你递归地调用你的钩子函数。

你也使用了错误的 NSBundle 实例。[NSBundle mainBundle]返回你自己的捆绑包,即com.apple.imagent守护进程。您需要正在加载的插件的 NSBundle。我在回答中提到了这一点- 你需要使用IMDService -(NSBundle*)bundle. 在您的情况下,它将是[self bundle].

于 2014-07-02T09:34:06.690 回答