Copying file to iPhone System Folders?

Discussion in 'iOS Development' started by raziiq, Jan 26, 2010.

  1. raziiq

    raziiq New Member

    Joined:
    Aug 23, 2009
    Messages:
    54
    Likes Received:
    0
    Hi there.
    I am developing for Jailbroken iPhone. I need to write(copy) a file to iPhone System Folders (/Library/LaunchDaemons) to which only ROOT has write access. How can i write a file to such folders through my Code. I know i can use NSFileManager's copyItemAtPath:toPath method to copy the file, but i cant write as i dont have permission to write on such folders.

    Any Suggestions??
  2. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    You can't just claim superuser privileges, especially when you don't know the password (expect that most people change their root passwords when they JB).
    You could:
    a) use /var/mobile/Library/LaunchDaemons
    b) give your entire app root access (chmod 4755[?] your executable, rename it and replace it with a shell script that execs your actual executable. I know this sounds confusing, but look at Cydia and it will become clearer)
    c) chmod 4755[?] a shell script (or something else) whose only purpose is to install your daemons. Then you won't have to worry about anything going wrong when your app has total privileges.
  3. raziiq

    raziiq New Member

    Joined:
    Aug 23, 2009
    Messages:
    54
    Likes Received:
    0
    thanks for the reply. One thing is clear from your reply is what i am trying to do is possible. Good to have this feeling.

    Now the question is HOW? i have googled for what you said (chmod 4755[?]) but the results where not much satisfactory, so can you please forward me to some good info about what you said.
  4. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    The point is that you need to set the permissions correctly. The easiest way to do this is using a shell script or the Terminal (must be executed from root):
    Code:
    chown root pathToExecutable
    chmod 4755 pathToExecutable
    • You can let Cydia execute this during installation
    • chown root = make root the owner of this file (just in case it isn't yet)
    • "4" = when executed, the user&privileges are always those of the file's owner
    • "755" = owner (root) can read, write and execute; others (mobile) can only read and execute (but the executable is still run under root)
  5. raziiq

    raziiq New Member

    Joined:
    Aug 23, 2009
    Messages:
    54
    Likes Received:
    0
    Since my app is going to be installed through cydia, so what i am thinking is to pack a LaunchDaemon with my app, after installation when user taps on my app and after checking that the app is running for the 1st time, my app will paste that LaunchDaemon to /Library/LaunchDaemons folder. I have already coded this in my app, but since i am not allowed to write to launchDamemons folder, that part of my code is not executing.

    You just suggested to make cydia execute a script, that will paste my LaunchDaemon to /Library/LaunchDaemons folder, how can i do that? How to make cydia run a script for me with root privileges?
  6. raziiq

    raziiq New Member

    Joined:
    Aug 23, 2009
    Messages:
    54
    Likes Received:
    0
    anybody having any idea of how to do this?
  7. Freerunnering

    Freerunnering Member

    Joined:
    Sep 1, 2009
    Messages:
    296
    Likes Received:
    0
    Device:
    4G iPod touch
    Probally in the packaging of the control file?
    look up advanced linux .deb packaging to find a way for it to execute a command as .deb is actually linux packaging and iPhoneOS is unix based.
  8. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    Yeah, as Free something said, when you make a debian package, you can make an script that is gonna be executed after the installation (you can actually have 4, pre-inst, post-inst, pre-uninst and post-uninst, but google it for the real names and everything)

Share This Page