越狱状态下不同进程下的Tweak和App如何通信?

已在论坛查到的方式有如下4种,

  • socket,包括原生socket和websocket
  • xpc,iOS下不会使用
  • 通知
    • 其中通知可以发送和接收,但经过反复测试不能携带参数,需要配合本地文件存储或者剪切板等完成通信
//App 发送
   CFDictionaryRef cfdic = (__bridge CFDictionaryRef)dict;
   
   NSLog(@"%@", cfdic);
   
   const void *tkeys[1] = { @"testKey" };
   const void *tvalues[1] = { @"testValue" };
   CFDictionaryRef userInfo = CFDictionaryCreate(NULL, tkeys, tvalues, 1, NULL, NULL);
   
   CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("OpenAPP"), NULL, userInfo, kCFNotificationPostToAllSessions);
// tweak 注册
   CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL,
                                   &OpenAPPNotificationReceivedCallback, CFSTR("OpenAPP"), NULL,
                                   CFNotificationSuspensionBehaviorDeliverImmediately);

// tweak收到通知的回调
   static void OpenAPPNotificationReceivedCallback(CFNotificationCenterRef center,
                                               void *observer, CFStringRef name,
                                               const void *object, CFDictionaryRef
                                               userInfo)
   {
       #error  这里始终收不到 userInfo

   }

  • 所以想通过通知配合本地文件存贮内容,频繁读取文件.不够优雅

  • 所以想问下各位大佬,不同进程下的Tweak和App如何优雅的双向通信

1 个赞

你漏了一个重要信息,tweak和App是不是同一个进程?

不同进程下,APP是自己的App,Tweak是用来hook SpringBoard的tweak

如果是沙盒App跟SpringBoard通信,我印象需要rocketbootstrap,搜搜看

是root权限的App在/Applications目录下

这种我还没试过,你可以试试rocketbootstrap方案

好的.谢谢

试了下rocketbootstrap

得到的结论是:

一:Root权限的App 和普通沙盒App 都可以通过CPDistributedMessagingCenter向SpringBoard发送消息,

二:但是没有办法从SpringBoard发送消息到Root权限的App或者普通的沙盒App.也就是只能单向通信

所以想问下有没有可以双向通信的办法

SpringBoard可以借助rocketbootstrap向App发消息吗?我记得以前做过,是可以的啊

CPDistributedMessagingCenter 这种是不可以的,您是用的什么方式发的

通知是可以双向成功发送

// 客户端   发送
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string =@"要发送的json数据<加密后的>";
CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("notification.identifier"), NULL, NULL, 0);


//服务端 接收
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL,
                                    &Callback, CFSTR("notification.identifier"), NULL,
                                    CFNotificationSuspensionBehaviorDeliverImmediately);
//接收后的回调
static void Callback(CFNotificationCenterRef center,
                     void *observer,
                     CFStringRef name,
                     const void *object,
                     CFDictionaryRef userInfo)
{
    // ...
    NSLog(@"%@",userInfo);
    NSLog(@"%@",name);
    NSLog(@"客户端收到通知");
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
 得到      pasteboard.string;
//解密数据
}

缺陷是userinfo无法传值 可以暂时先配合剪切板,互相通信

@snakeninny 能帮助解答下吗?目前用的iPhone13.4.1的系统,Tweak检测A程序,然后将信息通过Tweak传递给B程序,已经让B程序后台保活了,能收到Tweak发出的通知,但是获取不到剪切板上的内容,这个怎么解决那?能吧.x文件弄到B程序直接检测A程序吗,B程序需要回头展示界面,不能单单写个插件吧?

读写文件也行

读写文件都能访问是吧,一个是tweak插件,一个是用来展示的app,文件写到那个目录下那?有其他方式可以直接和你聊聊吗,我的QQ1276422345

别在一棵树上吊死啊,我记得app都可以给springboard发消息,收到返回数据是没有问题的,写个定时器就可以达到目的

谢谢,目前已经解决,通过把数据存在一个文件,另一个app也访问这个文件,存的文件路径是/var/mobile/Library/Preferences/,感谢各位热心帮助解答

感谢,已经用你说的方法解决