在 iOS 上为 NSFileManager 获得 root 权限(越狱)

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

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

问题描述

我正在尝试将文件写入设备的根分区.这是一个越狱应用程序,因此它安装在/Applications 中.使用 NSFileManager 写入根文件系统时,写入失败并出现 Permission Denied" 错误.

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 权限(越狱)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 iOS 上为 NSFileManager 获得 root 权限(越狱)

基础教程推荐