在 iOS 上获取 NSFileManager 的 root 权限(越狱)

发布于 2024-12-10 23:07:22 字数 197 浏览 5 评论 0原文

我正在尝试将文件写入设备的根分区。它是一个越狱应用程序,因此安装在/Applications 中。使用 NSFileManager 写入根文件系统时,写入失败并出现“权限被拒绝”错误。

看来我的应用程序没有以 root 身份运行。但它安装在 /Applications 中。我的应用程序如何成为root?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舟遥客 2024-12-17 23:07:22

确实,应用程序必须以 root 身份运行才能访问非移动目录。经过与 Optimo 和 Saurik 讨论后,我终于找到了获得 root 权限的正确方法。

  1. 在 main() 函数中添加 setuid(0);setgid(0);
  2. 正常构建应用程序。
  3. 在应用程序包中创建可执行文件的副本。
  4. 打开原始可执行文件并将其内容替换为以下脚本:

    <前><代码>#!/bin/bash
    目录=$(目录名“$0”)
    执行“${dir}”/COPIED_EXECUTABLE_NAME“$@”

    在 iOS 上直接启动根应用程序失败。因此,我们将应用程序的主可执行文件替换为启动根可执行文件的脚本。

  5. 在终端中,导航到应用程序包。

  6. chmod 0775 原始可执行文件和 chmod 6775 复制的可执行文件。
  7. 将应用程序包复制到设备的 /Applications。重新启动 SpringBoard,您应该就可以开始了。如果应用程序未启动,则重复步骤 5 和 5。 6 在设备上。

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.

  1. In the main() function add setuid(0); and setgid(0);
  2. Build the app normally.
  3. Create a copy of the executable file in the app bundle.
  4. 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.

  5. In terminal, navigate to the app bundle.

  6. chmod 0775 the original executable file and chmod 6775 the copied executable file.
  7. 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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文