Reputation: 542
I've an iPhone 5s jailbroken on ios 7.1.2 and I would like to make a tweak that would launch some command line through button pressed action. So for this I've several questions:
I've read that it's possible to launch command line through NSTask in mac os x applications but I've also read that NSTask is unavailable in ios. So how could I do for launching several command line on user action ?
I need admin rights for some commands, if I place my app in /Applications/ , I'll automatically have admin rights that's true ? So no need to call su binary etc ... ?
I'm new to ios and jailbreak development so if I've told silly things correct me ! Thanks in advance
Upvotes: 1
Views: 2518
Reputation: 542
Thanks to others members and some search, I've found the answers to the 2 questions:
(Big thanks to @Nate for this repply), it's possible to use NSTask in ios by importing the header file into the application project. The syntax is the same as the use in mac os x application but you can find some help here
An app placed into /Applications/ haven't the admin rights. For doing this, you have to:
1) In the main() function add setuid(0);
and setgid(0);
2) Build the app normally.
3) If you build an app named HelloWorld, Xcode will create a
HelloWorld.app directory, with a file named HelloWorld inside it, which
is executable. Rename this executable to, for example, MobileHelloWorld
4) Once you ve done that, create a new file in the HelloWorld.app
directory called HelloWorld
, 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.
5) In terminal, navigate to the app bundle.
6) chmod 0775
the original executable file and chmod 6775
the copied
executable file.
7) 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.
For this questions, all credits goes to (again :P) @Nate (here) and @JonasG (here)
Upvotes: 1