如何在iOS上使用root权限运行子程序?

使用Android SDK,我可以通过调用su然后运行我的代码来以超级用户身份运行进程。 我怎么能在iOS上做同样的事情?

以下是我在Android上使用的内容:

 // Elevate to root Process localProcess = Runtime.getRuntime().exec( "su"); // Now run some command as root DataOutputStream localDataOutputStream = new DataOutputStream( localProcess.getOutputStream()); localDataOutputStream.writeBytes( "chmod 666 file.name\n"); localDataOutputStream.writeBytes( "exit\n"); localDataOutputStream.flush(); 

我已经尝试了下面的C命令,但是收到一个错误,指出我的密码不正确。

 system( "ls -l /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist"); // read start permissions system( "sudo -s alpine | chmod 666 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist"); // trying change permissions system( "ls -l /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist"); // read changes 

日志看起来像这样:

-rw-r – r– 1个根轮7813 Dec 16 10:47 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist

chmod:更改`/System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist'的权限:操作不允许

我们相信您已经收到本地系统pipe理员的通常演讲。 它通常归结为这三件事情:

 #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. 

密码:

-rw-r – r– 1个根轮7813 Dec 16 10:47 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist

我如何以编程方式在iOS上以root权限运行任何脚本? 我正在寻找一个可以在越狱设备上工作的答案,但是如果可能的话,我们也会对在股票设备上也能使用的东西感到满意。

IOS的一个主要function是沙盒,这意味着应用程序驻留在自己的文件系统中,而其他应用程序不可见。 你想做什么违背IOS的安全devise。

如果您需要做的是允许一组应用程序相互交谈并共享数据,则可以通过共享的文档types,导出的UTI和DocumentInteraction类来执行此操作,

你的sudo命令格式不正确:

 sudo -s alpine | chmod 666 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist 

这被解释为:

 sudo -s <sudo-command> | <non-sudo-command> 

这是试图用sudo运行alpine命令,并将其输出pipe道输出到chmod ,这是没有道理的。 由于chmod不以root身份运行,因此会输出:

 chmod: changing permissions of `/System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist': Operation not permitted We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. 

而且由于sudo没有提供密码( -S参数),所以通过输出提示input密码:

 Password: 

我想你打算这样做:

 echo <password> | sudo -S <command> 

我相信你打算使用alpine作为密码,然后将是:

 echo 'alpine' | sudo -S chmod 666 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist 

有关sudo的更多信息,请参见man(8) sudo