Gaining root permissions on iOS for NSFileManager (Jailbreak)
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.
- In the main() function add
setuid(0);
andsetgid(0);
- Build the app normally.
- Create a copy of the executable file in the app bundle.
-
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.
In terminal, navigate to the app bundle.
-
chmod 0775
the original executable file andchmod 6775
the copied executable file.
- 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.