问题描述
我试图写文件到设备的根分区。这是一个越狱应用程序,所以它被安装在/应用程序。使用 NSFileManager
写入根文件系统时,写入失败,并且出现Permission Denied错误。 好像我的应用程序没有以root身份运行。它被安装在/ Applications中。我的应用程序如何成为root?
确实,应用程序必须以root身份运行才能访问非移动目录。在与Optimo和Saurik讨论之后,我终于找到了获得root权限的正确方法。
$ b
- 在main()函数中添加
setuid(0);
和setgid(0);
- 正常构建应用程序。
- 在应用程序包中创建可执行文件的副本。打开原始的可执行文件并用下面的脚本替换它的内容:
$ $ $
$ b $ {dir}/ COPIED_EXECUTABLE_NAME$ @
在iOS上直接启动根应用程序失败。因此,我们用启动根可执行文件的脚本来替换应用程序的主要可执行文件。
-
在终端中,导航到应用程序包。
-
chmod 0775
原始可执行文件和chmod 6775
复制的可执行文件。 - 将应用程序包复制到/ Applications应用程序。重新启动SpringBoard,你应该很好走。如果应用程序没有启动,则重复步骤5& 6在设备上。
I am trying to write file to the root partition of the device. It is a Jailbreak app so it is installed in /Applications. When writing to the root filesystem using NSFileManager
the write fails with a "Permission Denied" error.
It seems like my app is not running as root. It is installed in /Applications though. How can my app become root?
It is true, the app has to run as root to access non mobile directories. After discussing this with Optimo and Saurik I finally found the right way to get root privileges.
- In the main() function add
setuid(0);
andsetgid(0);
- Build the app normally.
- Create a copy of the executable file in the app bundle.
Open the original executable file and replace its content with this script:
#!/bin/bash dir=$(dirname "$0") exec "${dir}"/COPIED_EXECUTABLE_NAME "$@"
Directly launching a root app fails on iOS. Therefore we replace the app's main executable with a script that launches the root executable.
In terminal, navigate to the app bundle.
chmod 0775
the original executable file andchmod 6775
the copied executable file.
- Copy the app bundle to /Applications to a device. Restart SpringBoard and you should be good to go. If the app doesn't launch then repeat step 5 & 6 on the device.
这篇关于在iOS上为NSFileManager获得root权限(越狱)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!