Gaining root permissions on iOS for NSFileManager (Jailbreak)

一个人想着一个人 提交于 2019-11-26 00:48:07

问题


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?


回答1:


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.


来源:https://stackoverflow.com/questions/7841344/gaining-root-permissions-on-ios-for-nsfilemanager-jailbreak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!