Xcode怎么给自己开发的应用签task_for_pid-allow(或:Xcode怎么调试自己开发的命令行工具?)

一个测试的项目,给自己的应用签task_for_pid-allow。
在工程中创建了pidTest.entitlements,如下图:


ViewController.m中代码非常简单,如下:

#import <Foundation/NSProcessInfo.h>
#import <mach-o/dyld_images.h>

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
   
    kern_return_t    rc;
    mach_port_t    task;
    int pid;
    
    pid =  [[NSProcessInfo processInfo] processIdentifier];//获取进程的id,即平常使用ps -e | grep xxx得到的进程端口号
    rc = task_for_pid(mach_task_self(), pid, &task);
    
    if (rc) { 
        fprintf (stderr, "task_for_pid() failed with error %d - %s\n", rc, mach_error_string(rc)); 
        exit(1); 
    }
    printf ("RC %d - Task: %d\n",rc, task);
}

但是Xcode无法编译通过,提示如下:

Showing All Messages
:-1: Automatic signing is unable to resolve an issue with the “get_pid” target’s entitlements. Automatic signing can’t add the task_for_pid-allow entitlements to your provisioning profile. Switch to manual signing and resolve the issue by downloading a matching provisioning profile from the developer website. Alternatively, to continue using automatic signing, remove these entitlements from your entitlements file and their associated functionality from your code. (in target ‘get_pid’)

其中重点是Automatic signing can’t add the task_for_pid-allow entitlements to your provisioning profile,以及Switch to manual signing。

我不认为这个Entitlements你有权利签?

不是,你拿自己进程的mach task为什么要task for pid???

mach_task_self() 返回的直接就是本进程的mach task啊?

这样的话,那task_for_pid(mach_task_self(), pid, &task)中的pid,可能是其他进程的pid。
弄这个的最终目的,是要调试自己开发的命令行工具

1 个赞

正常开发肯定不可能给你这个权限啊。你能随便 task_for_pid成功就能随便篡改机器上除了内核以外的任何进程了

你只能用theos那套开发相关工具然后pseudo sign

1 个赞

如果用theos这套工具的话,可以进行命令行工具调试吗

看了theos相关的,好像是make package,然后用签名工具签名?再安装到手机上。这样虽然可以签名,但无法调试。
不知道其他人开发命令行工具的时候怎么调试,难道用printf大法吗 :paw_prints:

1 个赞

参考不越狱可以砸壳了可以解决。
翻译叫“通灵纸”漏洞?作者说就算没有iOS背景或者漏洞利用背景的人,也能理解这个。
原理是构建特定的xml签名文件,利用系统4个模块对xml文件的解析不同,导致上层看不到,但是底层检测到是有权限的。