Detect and send iMessages on iOS 8

The following contents are taken from iOS App Reverse Engineering

Create tweak project “iOSREMadridMessenger”

    snakeninnys-MacBook:Code snakeninny$ /opt/theos/bin/nic.pl
    NIC 2.0 - New Instance Creator
    ------------------------------
      [1.] iphone/application
      [2.] iphone/cydget
      [3.] iphone/framework
      [4.] iphone/library
      [5.] iphone/notification_center_widget
      [6.] iphone/preference_bundle
      [7.] iphone/sbsettingstoggle
      [8.] iphone/tool
      [9.] iphone/tweak
      [10.] iphone/xpc_service
    Choose a Template (required): 9
    Project Name (required): iOSREMadridMessenger
    Package Name [com.yourcompany.iosremadridmessenger]: com.iosre.iosremadridmessenger
    Author/Maintainer Name [snakeninny]: snakeninny
    [iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]: com.apple.MobileSMS
    [iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]: MobileSMS
    Instantiating iphone/tweak in iosremadridmessenger/...
    Done.

Compose iOSREMadridMessenger.h

@interface IDSIDQueryController
+ (instancetype)sharedInstance;
- (NSDictionary *)_currentIDStatusForDestinations:(NSArray *)arg1 service:(NSString *)arg2 listenerID:(NSString *)arg3;
@end

@interface IMServiceImpl : NSObject
+ (instancetype)iMessageService;
@end

@class IMHandle;

@interface IMAccount : NSObject
- (IMHandle *)imHandleWithID:(NSString *)arg1 alreadyCanonical:(BOOL)arg2;
@end

@interface IMAccountController : NSObject
+ (instancetype)sharedInstance;
- (IMAccount *)__ck_defaultAccountForService:(IMServiceImpl *)arg1;
@end

@interface IMMessage : NSObject
+ (instancetype)instantMessageWithText:(NSAttributedString *)arg1 flags:(unsigned long long)arg2;
@end

@interface IMChat : NSObject
- (void)sendMessage:(IMMessage *)arg1;
@end

@interface IMChatRegistry : NSObject
+ (instancetype)sharedInstance;
- (IMChat *)chatForIMHandle:(IMHandle *)arg1;
@end

Edit Tweak.xm

#import "iOSREMadridMessenger.h"

%hook SMSApplication
%new
- (int)madridStatusForAddress:(NSString *)address
{
	NSString *formattedAddress = nil;
	if ([address rangeOfString:@"@"].location != NSNotFound) formattedAddress = [@"mailto:" stringByAppendingString:address];
	else formattedAddress = [@"tel:" stringByAppendingString:address];
	NSDictionary *status = [[IDSIDQueryController sharedInstance] _currentIDStatusForDestinations:@[formattedAddress] service:@"com.apple.madrid" listenerID:@"__kIMChatServiceForSendingIDSQueryControllerListenerID"];
	return [status[formattedAddress] intValue];
}

%new
- (void)sendMadridMessageToAddress:(NSString *)address withText:(NSString *)text
{
	IMServiceImpl *service = [IMServiceImpl iMessageService];
	IMAccount *account = [[IMAccountController sharedInstance] __ck_defaultAccountForService:service];
	IMHandle *handle = [account imHandleWithID:address alreadyCanonical:NO];
	IMChat *chat = [[IMChatRegistry sharedInstance] chatForIMHandle:handle];
	NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:text];
	IMMessage *message = [IMMessage instantMessageWithText:attributedString flags:1048581];
	[chat sendMessage:message];
	[attributedString release];
}
%end

Edit Makefile

THEOS_DEVICE_IP = iOSIP
ARCHS = armv7 arm64
TARGET = iphone:latest:8.0

include theos/makefiles/common.mk

TWEAK_NAME = iOSREMadridMessenger
iOSREMadridMessenger_FILES = Tweak.xm
iOSREMadridMessenger_PRIVATE_FRAMEWORKS = IDS ChatKit IMCore

include $(THEOS_MAKE_PATH)/tweak.mk

after-install::
	install.exec "killall -9 MobileSMS"

Edit control

Package: com.iosre.iosremadridmessenger
Name: iOSREMadridMessenger
Depends: mobilesubstrate, firmware (>= 8.0)
Version: 1.0
Architecture: iphoneos-arm
Description: Detect and send iMessage example
Maintainer: snakeninny
Author: snakeninny
Section: Tweaks
Homepage: http://bbs.iosre.com

You know how to compile and install the tweak. After that test if with Cycript:

FunMaker-5:~ root# cycript -p MobileSMS
cy# [UIApp madridStatusForAddress:@"snakeninny@icloud.com"]
1
cy# [UIApp sendMadridMessageToAddress:@"snakeninny@icloud.com" withText:@"Sent from iOSREMadridMessenger"]

And we’re done :wink: Here’s how it looks:

The book explains everything in details, please stay tuned and check it out! Cheers!

3 个赞

What does IDS do?

IDSIDQueryController comes from IDS, which functions as the iMessage detector

1 个赞

cy# [UIApp madridStatusForAddress:@“snakeninny@icloud.com”]
Error: unrecognized selector madridStatusForAddress: sent to object 0x16d45da0
这是什么情况

tweak安装了吗?

已经安装了,之前还做过实验可以用

是注入到MobileSMS里去了吗?

嘻嘻,多谢狗神提醒,忘记看前面了!