With the Android SDK, I can run a process as a superuser by invoking su
and then running my code. How can I do the same on iOS?
Here's what I use on Android:
// Elevate to root
Process localProcess = Runtime.getRuntime().exec( "su");
// Now run some command as root
DataOutputStream localDataOutputStream = new DataOutputStream( localProcess.getOutputStream());
localDataOutputStream.writeBytes( "chmod 666 file.name\n");
localDataOutputStream.writeBytes( "exit\n");
localDataOutputStream.flush();
I've tried the following C commands, but I receive an error stating that my password is incorrect.
system( "ls -l /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist"); // read start permissions
system( "sudo -s alpine | chmod 666 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist"); // trying change permissions
system( "ls -l /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist"); // read changes
The log looks like this:
-rw-r--r-- 1 root wheel 7813 Dec 16 10:47 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist
chmod: changing permissions of `/System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist': Operation not permitted
We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:
#1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility.
Password:
-rw-r--r-- 1 root wheel 7813 Dec 16 10:47 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist
How can I programmatically run any script with root permissions on iOS? I'm looking for an answer that will work on jailbroken devices, but would be happy with something that also works on stock devices, if that's possible.