iOS 6.x open command line on jailbreak

試著忘記壹切 提交于 2019-11-27 09:10:18
Nate

Update:

It looks like the original /usr/bin/open has been updated for iOS 6 on Cydia, so I recommend you try that first.


Original Answer:

I miss open, too! But, until it gets updated for iOS 6, you can just build your own non-graphical app (just a main program, not a UIApplicationMain()) and do the same thing yourself.

I'll skip over parsing command line arguments from int main(int argc, char *argv[], but once you know the Bundle Id (CFBundleIdentifier) of the app you want to open, open the SpringBoardServices private framework, and use it to launch the app:

#include <dlfcn.h>
#define SBSERVPATH "/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices"

-(void) openApp: (NSString*) bundleId {

    // the SpringboardServices.framework private framework can launch apps,
    //  so we open it dynamically and find SBSLaunchApplicationWithIdentifier()
    void* sbServices = dlopen(SBSERVPATH, RTLD_LAZY);
    int (*SBSLaunchApplicationWithIdentifier)(CFStringRef identifier, Boolean suspended) = dlsym(sbServices, "SBSLaunchApplicationWithIdentifier");
    int result = SBSLaunchApplicationWithIdentifier((__bridge CFStringRef)bundleId, false);
    dlclose(sbServices);
}

This code requires the com.apple.springboard.launchapplications entitlement for your command line program to use it successfully, as the mobile user. See here for adding an entitlement. You'd need an entitlements.xml file for your executable, like this:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>com.apple.springboard.launchapplications</key>
        <true/>
    </dict>
</plist>

And then sign it with

ldid -Sentitlements.xml MyCommandLineTool

Note: I haven't tested this, but this answer states that an alternative to using entitlements is to run the command as root.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!