SMS Interception in Jailbreak iOS 7

故事扮演 提交于 2019-12-08 13:41:37

问题


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.

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);
}
}

here is 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>

回答1:


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

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.

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].



来源:https://stackoverflow.com/questions/24525639/sms-interception-in-jailbreak-ios-7

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