I'm currently building an app for jailbroken device, and I need root privileges for my app so that I can perform some tasks ask root. I found a related question : Gaining root permissions on iOS for NSFileManager (Jailbreak). But I am really new to iOS, I don't understand and unable to complete task from step 4. Can anyone make it more detail please?
1 Answers
What step 4 is telling you:
Open the original executable file and delete its contents (the contents are now stored in the previously copied and renamed binary).
is simply that you have moved the executable file for your app to a new filename, and you should replace it with a script with the name of the original executable.
Example
If you build an app named HelloWorld, Xcode will create a
HelloWorld.app
directory, with a file namedHelloWorld
inside it, which is executable.The answer you link to suggests basically renaming the executable to something like
MobileHelloWorld
.Once you've done that, create a new file in the
HelloWorld.app
directory calledHelloWorld
, and edit it with a text editor to give it this content:
#!/bin/bash
dir=$(dirname "$0")
exec "${dir}"/MobileHelloWorld "$@"
That script will then be run when you tap the app's icon, because in the app's Info.plist file, the name of the executable is
<key>CFBundleExecutable</key>
<string>HelloWorld</string>
and HelloWorld
is now a shell script, which invokes MobileHelloWorld
, the renamed binary executable file.

- 31,017
- 13
- 83
- 207
-
Thanks you so much, this is detail enough for me to follow. But when should we do this task? In main() ? – Vibol Jun 03 '13 at 09:10
-
1No. You do this manually. You build your Xcode project, without code signing. After the Xcode build finishes, you have an output product that contains the `HelloWorld.app` directory, and the `HelloWorld` executable inside of it. You need to then open up a shell terminal on your Mac, and perform the steps as listed in the answer you linked to. You rename the executable file that Xcode built. You create a new shell script file as I show above, and name that file `HelloWorld`. You edit the file permissions using `chmod` at the command line, just as the other answer describes. All by hand. – Nate Jun 03 '13 at 09:14
-
OMG, this is why I don't understand the answer, I was thinking of doing it programmatically in my app, that's totally wrong. Well, thanks for spending time for this newbie ! – Vibol Jun 03 '13 at 09:23
-
We're all newbies at some point :). By the way, the `setuid(0)` call in that answer **is supposed to be in your actual app's code**. The other stuff is manual work to be done after you build, but before you install and run on the device. – Nate Jun 03 '13 at 09:25