iOS【 ASO项目使用的技术】之 Inter process Communication

2021-03-24 16:04:16 浏览数 (1)

前言

原文:

https://blog.csdn.net/z929118967/article/details/77981259

These are some of the existing methods to implement IPC on iOS:

  • [URL Scheme]
  • Keychain

https://blog.csdn.net/z929118967/article/details/78195794

  • [UIDocumentInteractionController]
  • 利用socket进行本地通信

https://blog.csdn.net/z929118967/article/details/109616038

  • [Mach Ports]
  • Pasteboard

iOS 逆向:Tweak的开发例子【发红包】使用tweak和lua脚本结合进行实现https://blog.csdn.net/z929118967/article/details/76914272

代码语言:javascript复制
 UIPasteboard* pasteboard = [UIPasteboard generalPasteboard]; 
 [pasteboard setString:@"A1"];
//使用tweak和lua脚本结合进行实现
//1、tweak侧的功能是hookapp的原生功能
//2、lua 是实现模拟用户点击
//3、通信通过剪切板:tweak 通过剪切板和lua脚本进行通信
//其实后面我继续研究,把lua侧的功能全部用tweak实现了。 这里分享的是一个思路。



  • [AppleEvents & AppleScript]
  • [Distributed Objects]
  • XPC

https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingXPCServices.html

  • Notifications

http://iphonedevwiki.net/index.php/Notifications

  • libobjcipc

http://iphonedevwiki.net/index.php/Libobjcipc

  • LightMessaging

https://github.com/rpetrich/LightMessaging

Community Libraries

  • 1、RocketBootstrap:Service registration and lookup system for iOS
  • 2、OBJCIPC :High-level API for hosting services inside apps (by Alan Yip/a1anyip)
  • 3、LightMessaging:Header-only library for simple IPC

本文重点讲解RocketBootstrap的两种包装方式:CFMessagePort、CPDistributedMessagingCenter

I 、librocketbootstrap

iOS ASO【Inter process Communication】之去掉rocketbootstrap的Depends依赖

  • RocketBootstrap4Inter_process_Communication
  • feature

1、Uses iOS7’s security model: Privileged processes can register, any process can look up 2、Works with existing mach-based IPC mechanisms 3、Similar to Apple’s bootstrap APIs: bootstrap_look_up becomes rocketbootstrap_look_up bootstrap_register becomes rocketbootstrap_register 4、Easy to use wrappers for CFMessagePort and CPDistributedMessagingCenter(todo: XPC) 5、Bring your own security model by using audit_token_to_au32 to know who’s calling 6、Requires package dependency, commonly installed on users’ devices

1.0 获取librocketbootstrap :

-Install this from Cydia 直接搜索rocketbootstrap安装即可

代码语言:javascript复制
iPhone:/var/log root# ls -l /usr/lib/librocketbootstrap.dylib
-rwxr-xr-x 1 root wheel 221776 Feb  6  2017 /usr/lib/librocketbootstrap.dylib*

/Library/LaunchDaemons/com.rpetrich.rocketbootstrapd.plist
/usr/libexec/rocketd
launchctl load  /Library/LaunchDaemons/com.rpetrich.rocketbootstrapd.plist
launchctl unload /Library/LaunchDaemons/com.rpetrich.rocketbootstrapd.plist


1.1 CFMessagePort

  • registerMsgCenter 基本可以解决双向通信;例子:避免重启其他进程从sb获取源地址信息的变更。守护进行都可以注册成为服务
代码语言:javascript复制
  (kern_return_t)rockettest_messageport_server
{
    static CFMessagePortRef messagePort;//
    if (messagePort)
        return 0;
    messagePort = CFMessagePortCreateLocal(kCFAllocatorDefault, CFSTR("rockettest_messageport"), messagePortCallback, NULL, NULL);//CFSTR("rockettest_messageport")即server key,
    CFRunLoopSourceRef source = CFMessagePortCreateRunLoopSource(kCFAllocatorDefault, messagePort, 0);
    CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes);
    CFRunLoopAddSource(CFRunLoopGetCurrent(), source, (CFStringRef)UITrackingRunLoopMode);
    return rocketbootstrap_cfmessageportexposelocal(messagePort);
}
typedef CFDataRef (*CFMessagePortCallBack)(CFMessagePortRef local, SInt32 msgid, CFDataRef data, void *info);
//回调的定义
static CFDataRef messagePortCallback(CFMessagePortRef local, SInt32 msgid, CFDataRef data, void *info)
{
    NSLog(@"rockettest_messageport_server: received %@", data);
    return CFDataCreate(kCFAllocatorDefault, (const UInt8 *)"bootstrap", 9);
}

  • CFMessagePort: Only supports synchronous use

0 人点赞