本文介绍了越狱iOS 7中的短信拦截的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have followed this answer Blocking incomming sms in ios 7. The problem is it blocks every message and its notification. Secondly it continuously call _processReceivedMessage_hooked method when I send message other then this number +923139303006.

我正在使用OpenDev和Xcode 5,iOS 7.x。

I'm using OpenDev with 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>


推荐答案

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

Try uncommenting if ([[bundle bundleIdentifier] isEqualToString:@"com.apple.imservice.sms"] && [bundle isLoaded]) check.

原因是多次调用 loadServiceBundle - 有几个imagent插件。每次调用时你都会一次又一次地挂钩 _processReceivedMessage:重写你以前的钩子。因为它全部发生在单个imagent过程中,原始 _processReceivedMessage:实现将丢失。因此,您递归调用您的钩子函数。

The reason is loadServiceBundle is called multiple times - there're several imagent plugins. Every time it's called you hook _processReceivedMessage: again and again rewriting your previous hooks. Because it all happens inside a single imagent process original _processReceivedMessage: implementation will be lost. As a result you recursively call your hooked function.

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

Also you using wrong NSBundle instance. [NSBundle mainBundle] returns you bundle of yourself i.e. com.apple.imagent daemon. You need NSBundle of the plugin being loaded. I covered that in my answer - you need to use IMDService -(NSBundle*)bundle. In your case, it will be [self bundle].

这篇关于越狱iOS 7中的短信拦截的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 00:31