ios – 黑客入侵MFMessageComposeViewController

前端之家收集整理的这篇文章主要介绍了ios – 黑客入侵MFMessageComposeViewController前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我知道在真正的应用程序中不允许这样做,有利于用户的隐私和安全.但是出于纯粹的学术目的,我试图发送消息而不像这样呈现MessageComposer UI.
  1. MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
  2.  
  3. if([MFMessageComposeViewController canSendText]) {
  4. picker.recipients = [NSArray arrayWithObject:@"1234"];
  5. picker.body = @"Hello";
  6. [picker performSelector:@selector(smsComposeControllerSendStarted:) withObject:[UIButton buttonWithType:UIButtonTypeCustom]];
  7. }

结果没有任何结果.甚至在控制台上都没有失败异常.我都没有在短信应用上看到消息.我发送邮件的人也没有得到它.

可以在这里找到iMars和MFMessageComposeViewController方法的列表.

https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/MessageUI.framework/MFMessageComposeViewController.h

我写了一个快速代码来验证这些是否是MFMessageComposeViewController中实际存在的项目.

  1. uint varCount = 0;
  2. Class cls= [MFMessageComposeViewController class];
  3. Ivar *vars = class_copyIvarList(cls,&varCount);
  4.  
  5. for (uint i = 0; i < varCount; i++) {
  6. Ivar var = vars[i];
  7. const char* name = ivar_getName(var);
  8. const char* typeEncoding = ivar_getTypeEncoding(var);
  9. printf("iVar%i------------> %s\n",i+1,name);
  10. }
  11. free(vars);
  12.  
  13. Method *imps = class_copyMethodList(cls,&varCount);
  14. for (uint i = 0; i < varCount; i++) {
  15. SEL sel = method_getName(imps[i]);
  16. printf("Method%i------------> %s\n",[(NSStringFromSelector(sel)) UTF8String]);
  17. }

它产生以下输出

  1. iVar1------------> _messageComposeDelegate
  2. iVar2------------> _recipients
  3. iVar3------------> _body
  4. iVar4------------> _subject
  5. iVar5------------> _mutableAttachmentURLs
  6. iVar6------------> _currentAttachedVideoCount
  7. iVar7------------> _currentAttachedAudioCount
  8. iVar8------------> _currentAttachedImageCount
  9. iVar9------------> _temporaryAttachmentURLs
  10. iVar10------------> _attachments
  11. Method1------------> disableUserAttachments
  12. Method2------------> setCurrentAttachedVideoCount:
  13. Method3------------> setCurrentAttachedAudioCount:
  14. Method4------------> setCurrentAttachedImageCount:
  15. Method5------------> _MIMETypeForURL:
  16. Method6------------> _isVideoMIMEType:
  17. Method7------------> _isAudioMIMEType:
  18. Method8------------> _isImageMIMEType:
  19. Method9------------> mutableAttachmentURLs
  20. Method10------------> _contentTypeForMIMEType:
  21. Method11------------> _updateAttachmentCountForAttachmentURL:
  22. Method12------------> _buildAttachmentInfoForAttachmentURL:andAlternameFilename:
  23. Method13------------> temporaryAttachmentURLs
  24. Method14------------> canAddAttachmentURL:
  25. Method15------------> addAttachmentData:withAlternateFilename:
  26. Method16------------> _setCanEditRecipients:
  27. Method17------------> messageComposeDelegate
  28. Method18------------> setMutableAttachmentURLs:
  29. Method19------------> currentAttachedVideoCount
  30. Method20------------> currentAttachedAudioCount
  31. Method21------------> currentAttachedImageCount
  32. Method22------------> setTemporaryAttachmentURLs:
  33. Method23------------> dealloc
  34. Method24------------> viewWillAppear:
  35. Method25------------> initWithNibName:bundle:
  36. Method26------------> automaticallyForwardAppearanceAndRotationMethodstochildViewControllers
  37. Method27------------> setModalPresentationStyle:
  38. Method28------------> body
  39. Method29------------> setSubject:
  40. Method30------------> subject
  41. Method31------------> setMessageComposeDelegate:
  42. Method32------------> setBody:
  43. Method33------------> addAttachmentURL:withAlternateFilename:
  44. Method34------------> addAttachmentData:typeIdentifier:filename:
  45. Method35------------> attachmentURLs
  46. Method36------------> attachments
  47. Method37------------> recipients
  48. Method38------------> smsComposeControllerCancelled:
  49. Method39------------> smsComposeControllerSendStarted:
  50. Method40------------> setRecipients:

在我看来,smsComposeControllerSendStarted:方法可能比启动消息发送的实际函数更多的是委托.在上面的方法列表中,没有一个方法签名看起来更接近sendMessage:或类似于实际发送消息的函数.

我的问题是:

1)所有真正的MFMessageComposeViewController都在幕后.或者它是否有一些无法通过运行时函数访问的类集群?

2)如何找出实际的messageSend方法及其实现的类?

任何想法将不胜感激.

谢谢.

解决方法

内部MFMessageComposeViewController使用CKSMSComposeController作为私人ChatKit.framework的实际UI,它使用一大堆其他类(CKSMSComposeQueuingRemoteViewControllerProxy,CKSMSComposeRemoteViewController,CKSMSComposeViewServiceController),包括XPC接口XPCProxy< CKSMSCompose>.

更新1

在阅读了quellish评论后我发现这个http://oleb.net/blog/2012/10/remote-view-controllers-in-ios-6/看起来像MFMessageComposeViewController和类似的类为他们的目的启动另一个过程.这些进程是XPC服务,它们实现了应用程序与之通信的特定协议.这些流程使用所有必需的权利进行签名.可能/Applications/MessagesViewService.app/MessagesViewService实际上是发送短信的.这个二进制文件是用com.apple.messages.composeclient签名的,这是为了发送我在ChatKit.framework中找到的this代码所必需的.我认为有一种方法可以手动与该XPC服务进行通信以发送短信,但这将很困难.你不能用类转储和类似的简单工具来搞错,这些工具并没有给你太多的信息.

更新2

我已经成功了解了这一点.我扔掉了所有帮助程序类,所有UI内容都没有真正与XPC服务通信.剩下的就足以显示SMS视图控制器并将一些方法发送到XPC服务而不会有任何障碍.

当我们显示SMS组合UI时,iOS确实会启动/Applications/MessagesViewService.app/MessagesViewService进程.这是XPC服务.您可以尝试在应用程序显示时杀死它 – 您将获得黑屏,这意味着它是正确的.

CKSMSComposeRemoteViewController是显示SMS UI的视图控制器.它是_UIRemoteViewController类的子类.基本上,它管理我们的应用程序与在其他进程中在XPC服务中运行的实际UI之间的连接.这是我如何在我的 – (void)viewDidLoad方法获取它的实例

  1. _UIAsyncInvocation* cancelationInvocation =
  2. [CKSMSComposeRemoveViewController requestViewController:@"CKSMSComposeViewServiceController"
  3. fromServiceWithBundleIdentifier:@"com.apple.mobilesms.compose"
  4. connectionHandler:
  5. ^(CKSMSComposeRemoteViewController* obj,NSError* error){
  6. smsViewController = obj;
  7. [smsViewController setDelegate:self];
  8.  
  9. smsViewControllerProxy = [smsViewController serviceViewControllerProxy];
  10. }];

smsViewController是一个远程视图控制器实例. smsViewControllerProxy是XPCProxy< CKSMSCompose>实现CKSMSComposeViewServiceProtocol协议的实例 – 方法调用将被转发到XPC服务. XPCProxy并没有真正实现这些方法.它实现了forwardInvocation:方法,以便将调用转发到XPC连接.

_UIAsyncInvocation,查看ivar名称cancelationInvocation,用于取消XPC消息.它仅在CKSMSComposeController viewServiceDidTerminateWithError:方法调用.

以下是我显示控制器的方法

  1. [self presentViewController:smsViewController animated:YES completion:NULL];

您可能注意到[smsViewController setDelegate:self].委托必须实现CKSMSComposeRemoteViewControllerDelegate协议或应用程序将崩溃异常(无法识别的选择器).这是我实施的:

  1. -(void)smsComposeControllerAppeared
  2. {
  3. }
  4.  
  5. -(void)smsComposeControllerCancelled
  6. {
  7. }
  8.  
  9. -(void)smsComposeControllerDataInserted
  10. {
  11. }

这足以让你走了.

以下是我们如何向远程视图控制器发送消息:

  1. [smsViewControllerProxy insertTextPart:@"Some text"];

这会将文本插入SMS文本字段并调用smsComposeControllerDataInserted委托方法.

考虑到所有这些,我不再认为我们可以在没有UI的情况下发送短信.实际UI正在另一个进程中运行,我们对它没有任何控制权.我们可以设置一些字段,但就是这样.我希望有一种方法,但事实是,难怪我们做不到.在iOS 6中引入了远程视图来解决这个确切的安全问题 – 在iOS 5上,有一种方法可以在没有用户许可的情况下发送SMS,而一些AppStore应用就是这样做的.所以对Apple赞不绝口.

更新3

我设法在我们与SMS UI交互时转储正在发送的XPC消息.关于日志格式的几句话.第一行 – 拦截消息的地方.它是函数名称或Incoming事件,这意味着它是来自服务的传入消息.连接名称只是XPC连接名称.消息是XPC消息字典内容.消息数据 – 一些XPC消息包含“d” – >“r”键的二进制数据.它是一个序列化的二进制属性列表,无法使用NSPropertyListSerialization反序列化 – 它采用了一些新的格式.相反,你需要使用来自Foundation.framework的NSXPCDecoder – (id)_initWithRootXPCObject:(xpc_object_t).现在转储:

SMS UI正在呈现http://pastebin.com/NVEpujSh

按下“发送”按钮后的SMS UI http://pastebin.com/BYXd2djF

编辑SMS字段时会发送和接收消息,但它们仅对应于UI事件.例如,谁成为第一响应者,那些并不能真正说明SMS UI中发生了什么的东西.

猜你在找的iOS相关文章