11

I am trying to write an app that runs in the background and injects touches to the springboard or other apps. I understand that I will be using private APIs and structures. The app is an enterprise app and does not need to be approved for the AppStore.

I am using the GSEvent structure as suggested by KennyTM with some minor modifications for IOS 5/6. I am able to send touch events and other events to the Springboard by sending GSSystemEvents.

I need to be able to send similar events to other applications as well, but I am not able to find the port for the front most application.

Is there a way to get the port for the application that is upfront and running so that I can send my GSEvents to the app?

It would be nice if someone can point me to examples or show me how I can get the purple port of the front most app.

Thanks!

1 Answer 1

12

UPDATE: I haven't tested this on ios7.

I happen to work on the exact same requirement before.

To get the purple port, you can use GSCopyPurpleNamedPort() with the bundle Id as an argument.

If you need to simulate touch on SpringBoard, use GSGetPurpleSystemEventPort.

With this below code, you should be able to get the port and use it to inject touch system wide.

#import <dlfcn.h>
// Framework Paths
#define SBSERVPATH  "/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices"
-(mach_port_t)getFrontMostAppPort
{
    bool locked;
    bool passcode;
    mach_port_t *port;
    void *lib = dlopen(SBSERVPATH, RTLD_LAZY);
    int (*SBSSpringBoardServerPort)() = dlsym(lib, "SBSSpringBoardServerPort");
    void* (*SBGetScreenLockStatus)(mach_port_t* port, bool *lockStatus, bool *passcodeEnabled) = dlsym(lib, "SBGetScreenLockStatus");
    port = (mach_port_t *)SBSSpringBoardServerPort();
    dlclose(lib);
    SBGetScreenLockStatus(port, &locked, &passcode);
    void *(*SBFrontmostApplicationDisplayIdentifier)(mach_port_t *port, char *result) = dlsym(lib, "SBFrontmostApplicationDisplayIdentifier");
    char appId[256];
    memset(appId, 0, sizeof(appId));
    SBFrontmostApplicationDisplayIdentifier(port, appId);
    NSString * frontmostApp=[NSString stringWithFormat:@"%s",appId];
    if([frontmostApp length] == 0 || locked)
        return GSGetPurpleSystemEventPort();
    else
        return GSCopyPurpleNamedPort(appId);
}

I've tested...this works fine on iOS 5 and 6. You might not need the lock part if you don't inject when the lock screen shows up. Hope this helps.

4
  • 1
    Great..!! Worked like a charm..!!
    – Apurv
    Commented Apr 24, 2013 at 6:52
  • Sorry, I haven't tested it on ios7 yet.
    – pt2121
    Commented Oct 7, 2013 at 18:13
  • Please find some way for ios 7 Commented Feb 13, 2014 at 11:48
  • 1
    Plz if someone have an idea to get work on ios7 try to post it. Commented Nov 17, 2014 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.