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

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

问题描述

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

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.

我的应用似乎没有以 root 身份运行.虽然它安装在/Applications 中.我的应用如何成为 root 用户?

It seems like my app is not running as root. It is installed in /Applications though. How can my app become root?

推荐答案

确实,应用程序必须以 root 身份运行才能访问非移动目录.在与 Optimo 和 Saurik 讨论后,我终于找到了获得 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. 在 main() 函数中添加 setuid(0);setgid(0);
  2. 正常构建应用.
  3. 在应用程序包中创建可执行文件的副本.
  4. 打开原始可执行文件并用这个脚本替换其内容:

  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 "$@"

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

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.

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

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