1

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

Synny
  • 542
  • 1
  • 4
  • 18
  • I don't do much jailbroken development but I'm pretty certain there is no way of opening a commend line on a jailbroken device. I'm not 100% on this and will stand correct otherwise. – Popeye Sep 30 '14 at 12:51
  • Sorry but I'm pretty sure it's possible ^^ I've seen several cydia apps that, for example, zip a folder, copy a file... Without command line, It wouldn't be possible no ? – Synny Sep 30 '14 at 13:04
  • 2
    No, apps on jailbroken devices do not automatically run as root. They still run as `mobile`. – nobody Sep 30 '14 at 13:12
  • 1
    @AndrewMedico thanks for the info, for launching an app as root I've found this useful guide http://stackoverflow.com/questions/16892795/how-to-gain-root-privileges-for-ios-app so I've answered my second question myself... But I'm not able to find an answer for the first ! Do you know something about this ? – Synny Sep 30 '14 at 13:40
  • @Synny Zipping and copying a file can be done without the need for command line. Everything I have found in relation to launching command line is all to do with `NSTask` on Mac everything else points to it can't be done. Though I still hold I am not 100% on this but from what I have read online I am pretty confident that it can't be done. I will stand corrected though if someone says otherwise. – Popeye Sep 30 '14 at 13:49
  • @Popeye Sorry for what I've told, you're right concerning copy a file etc (thanks google !)... I've also read that it "could" be possible if I copy NSTask.h into my application folder. With this it would be possible no ? – Synny Sep 30 '14 at 14:02
  • @Synny Would it work by just copying the `NSTask.h` file wouldn't you need the `NSTask.m` file as well? Best of luck getting it to work though. – Popeye Sep 30 '14 at 14:10
  • @Popeye Apparently there is no need to have NSTask.m into project bundle. For the moment I can't go on my dev device so I can't test it, I would come back to you in 2-3 days to tell if it's work ;) – Synny Sep 30 '14 at 14:18
  • 1
    NSTask definitely is available (but private) on iOS. See [this answer for a sample](http://stackoverflow.com/a/18754179/119114) – Nate Sep 30 '14 at 23:58
  • @Nate That's what I've found ! A big big thanks for the confirmation ! For the NSData part, I can print the output of my several commands line into a .log (localized for example into /var/mobile/Documents) thaht's true ? – Synny Oct 01 '14 at 07:51

1 Answers1

1

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)

Community
  • 1
  • 1
Synny
  • 542
  • 1
  • 4
  • 18