gpt4 book ai didi

ios - 入侵 MFMessageComposeViewController

转载 作者:可可西里 更新时间:2023-11-01 03:31:14 39 4
gpt4 key购买 nike

我知道这在实际应用中是不允许的,这有利于用户的隐私和安全。但出于纯粹的学术目的,我试图在不显示 MessageComposer UI 的情况下发送消息。

MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];

if([MFMessageComposeViewController canSendText]) {
picker.recipients = [NSArray arrayWithObject:@"1234"];
picker.body = @"Hello";
[picker performSelector:@selector(smsComposeControllerSendStarted:) withObject:[UIButton buttonWithType:UIButtonTypeCustom]];
}

结果什么也没有发生。甚至不是控制台上的失败异常。我也没有在 SMS 应用程序上看到一条消息。我发消息的人也没有收到。

可以在这里找到 MFMessageComposeViewController 的 iVar 和方法列表。

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

我编写了一个快速代码来验证这些项目是否实际存在于 MFMessageComposeViewController 中。
uint varCount = 0;
Class cls= [MFMessageComposeViewController class];
Ivar *vars = class_copyIvarList(cls, &varCount);

for (uint i = 0; i < varCount; i++) {
Ivar var = vars[i];
const char* name = ivar_getName(var);
const char* typeEncoding = ivar_getTypeEncoding(var);
printf("iVar%i------------> %s\n",i+1,name);
}
free(vars);

Method *imps = class_copyMethodList(cls, &varCount);
for (uint i = 0; i < varCount; i++) {
SEL sel = method_getName(imps[i]);
printf("Method%i------------> %s\n",i+1,[(NSStringFromSelector(sel)) UTF8String]);
}

它产生以下输出:
iVar1------------> _messageComposeDelegate
iVar2------------> _recipients
iVar3------------> _body
iVar4------------> _subject
iVar5------------> _mutableAttachmentURLs
iVar6------------> _currentAttachedVideoCount
iVar7------------> _currentAttachedAudioCount
iVar8------------> _currentAttachedImageCount
iVar9------------> _temporaryAttachmentURLs
iVar10------------> _attachments
Method1------------> disableUserAttachments
Method2------------> setCurrentAttachedVideoCount:
Method3------------> setCurrentAttachedAudioCount:
Method4------------> setCurrentAttachedImageCount:
Method5------------> _MIMETypeForURL:
Method6------------> _isVideoMIMEType:
Method7------------> _isAudioMIMEType:
Method8------------> _isImageMIMEType:
Method9------------> mutableAttachmentURLs
Method10------------> _contentTypeForMIMEType:
Method11------------> _updateAttachmentCountForAttachmentURL:
Method12------------> _buildAttachmentInfoForAttachmentURL:andAlternameFilename:
Method13------------> temporaryAttachmentURLs
Method14------------> canAddAttachmentURL:
Method15------------> addAttachmentData:withAlternateFilename:
Method16------------> _setCanEditRecipients:
Method17------------> messageComposeDelegate
Method18------------> setMutableAttachmentURLs:
Method19------------> currentAttachedVideoCount
Method20------------> currentAttachedAudioCount
Method21------------> currentAttachedImageCount
Method22------------> setTemporaryAttachmentURLs:
Method23------------> dealloc
Method24------------> viewWillAppear:
Method25------------> initWithNibName:bundle:
Method26------------> automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers
Method27------------> setModalPresentationStyle:
Method28------------> body
Method29------------> setSubject:
Method30------------> subject
Method31------------> setMessageComposeDelegate:
Method32------------> setBody:
Method33------------> addAttachmentURL:withAlternateFilename:
Method34------------> addAttachmentData:typeIdentifier:filename:
Method35------------> attachmentURLs
Method36------------> attachments
Method37------------> recipients
Method38------------> smsComposeControllerCancelled:
Method39------------> smsComposeControllerSendStarted:
Method40------------> setRecipients:

在我看来 smsComposeControllerSendStarted:方法可能更像是一个委托(delegate),而不是启动消息发送的实际函数。在上面的方法列表中,没有一个方法签名看起来更接近 sendMessage:或类似于实际发送消息的函数的东西。

我的问题是:

1) 真的是这样吗 MFMessageComposeViewController在引擎盖下。或者它是否有一些无法通过运行时函数访问的类集群?

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

任何想法将不胜感激。

谢谢。

最佳答案

MFMessageComposeViewController用途 CKSMSComposeController作为私有(private)的实际 UI ChatKit.framework它使用了一大堆其他类( CKSMSComposeQueuingRemoteViewControllerProxyCKSMSComposeRemoteViewControllerCKSMSComposeViewServiceController ),包括 XPC 接口(interface) XPCProxy<CKSMSCompose> .

更新 1

在阅读了 quellish 评论后,我发现了这个 http://oleb.net/blog/2012/10/remote-view-controllers-in-ios-6/看起来像 MFMessageComposeViewController和类似的类为它们的目的启动另一个进程。这些进程是 XPC 服务,它们实现了某些协议(protocol),您的应用程序通过这些协议(protocol)与它们进行通信。这些流程都签署了所有必需的权利。大概 /Applications/MessagesViewService.app/MessagesViewService是实际发送短信的内容。这个二进制文件是用 com.apple.messages.composeclient 签名的这是发送带有 this 的消息所必需的我在 ChatKit.framework 中找到的代码。我认为有一种方法可以手动与该 XPC 服务通信以发送短信,但这会很困难。不是你可以用 class-dump 和类似的简单工具来鬼混的东西,这些工具并没有真正给你很多信息。

更新 2

我已经设法弄明白了。我已经扔掉了所有的助手类,所有没有真正与 XPC 服务通信的 UI 东西。剩下的就足以显示 SMS View Controller 并向 XPC 服务发送一些方法,而不会有任何阻碍。

当我们显示短信撰写 UI 时 iOS 确实启动 /Applications/MessagesViewService.app/MessagesViewService过程。这就是 XPC 服务。你可以在你的应用程序显示它时尝试杀死它 - 你会得到黑屏,这意味着它是正确的。
CKSMSComposeRemoteViewController是显示 SMS UI 的 View Controller 。它是 _UIRemoteViewController 的子类类(class)。基本上,它管理我们的应用程序和在其他进程中的 XPC 服务中运行的实际 UI 之间的连接。这是我如何在我的 -(void)viewDidLoad 中获取它的实例方法

_UIAsyncInvocation* cancelationInvocation = 
[CKSMSComposeRemoveViewController requestViewController:@"CKSMSComposeViewServiceController"
fromServiceWithBundleIdentifier:@"com.apple.mobilesms.compose"
connectionHandler:
^(CKSMSComposeRemoteViewController* obj, NSError* error){
smsViewController = obj;
[smsViewController setDelegate:self];

smsViewControllerProxy = [smsViewController serviceViewControllerProxy];
}];
smsViewController是一个远程 View Controller 实例。 smsViewControllerProxyXPCProxy<CKSMSCompose>实现 CKSMSComposeViewServiceProtocol 的实例协议(protocol) - 方法调用将被转发到 XPC 服务。 XPCProxy并没有真正实现这些方法。它实现了 forwardInvocation:方法以便将调用转发到 XPC 连接。
_UIAsyncInvocation , 查看 ivar 名称 cancelationInvocation , 用于取消 XPC 消息。它仅在 CKSMSComposeController viewServiceDidTerminateWithError: 中被调用方法。

这是我显示 Controller 的方式:
[self presentViewController:smsViewController animated:YES completion:NULL];

您可能已经注意到 [smsViewController setDelegate:self] .代表必须执行 CKSMSComposeRemoteViewControllerDelegate协议(protocol)或应用程序将因异常(无法识别的选择器)而崩溃。这是我实现的:
-(void)smsComposeControllerAppeared
{
}

-(void)smsComposeControllerCancelled
{
}

-(void)smsComposeControllerDataInserted
{
}

这足以开始了。

这是我们如何向远程 View Controller 发送消息:
[smsViewControllerProxy insertTextPart:@"Some text"];

这会将文本插入 SMS 文本字段并拨打 smsComposeControllerDataInserted委托(delegate)方法。

考虑到所有这些,我不再认为我们可以在没有 UI 的情况下发送 SMS 消息。实际的 UI 正在另一个进程中运行,我们无法对其进行任何控制。我们可以设置一些字段,仅此而已。我希望有办法,但事实是,难怪我们不能。 iOS 6 中引入了远程 View 来解决这个确切的安全问题 - 在 iOS 5 上有一种无需用户许可就可以发送短信的方法,一些 AppStore 应用程序做到了这一点。所以给苹果点赞。

更新 3

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

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

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

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

关于ios - 入侵 MFMessageComposeViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22653828/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com