在iOS上为NSFileManager获得root权限(越狱) [英] Gaining root permissions on iOS for NSFileManager (Jailbreak)

查看:278
本文介绍了在iOS上为NSFileManager获得root权限(越狱)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写文件到设备的根分区。这是一个越狱应用程序,所以它被安装在/应用程序。使用 NSFileManager 写入根文件系统时,写入失败,并且出现Permission Denied错误。



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

解决方案

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


  1. 在main()函数中添加 setuid(0); setgid(0);

  2. 正常构建应用程序。

  3. 在应用程序包中创建可执行文件的副本。打开原始的可执行文件并用下面的脚本替换它的内容:



    $ $ $








    $ b $ {dir}/ COPIED_EXECUTABLE_NAME$ @

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

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


  5. chmod 0775 原始可执行文件和 chmod 6775 复制的可执行文件。

  6. 将应用程序包复制到/ 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.

  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.

这篇关于在iOS上为NSFileManager获得root权限(越狱)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆