Suge
Suge

Reputation: 2897

How to get task port of SpringBoard in iOS7 (Jailbroken)?

I know we can use contextIdAtPosition and taskPortOfContextId to get the mach_port_t of the front top app, but when inside some app, we can not use contextIdAtPosition to get the context id of SpringBoard (it's at background), so how can we get the mach_port_t of SpringBoard? Thank you!

Upvotes: 0

Views: 1553

Answers (2)

Nick X
Nick X

Reputation: 186

according to http://theiphonewiki.com/wiki//System/Library/LaunchDaemons/com.apple.SpringBoard.plist, the SpringBoard has exposed a lot of services. two of them might (or might not) be of your interests:

  • "com.apple.iohideventsystem"
  • "com.apple.springboard"

Here is the sample code to query the ports by service names.

#include <mach/mach.h>
#include "bootstrap.h"
#include <stdio.h>
#include <stdlib.h>

#define CHECK_MACH_ERROR(a) do {kern_return_t rr = (a); if ((rr) != KERN_SUCCESS) \
{ printf("Mach error %x (%s) on line %d of file %s\n", (rr), mach_error_string((rr)), __LINE__, __FILE__); abort(); } } while (0)

int main(int argc, char **argv, char **envp) 
{
  mach_port_t bp = MACH_PORT_NULL;
  mach_port_t sp = MACH_PORT_NULL;

  kern_return_t err = task_get_bootstrap_port(mach_task_self(), &bp);
  CHECK_MACH_ERROR(err);
  printf("bp:%d\n", bp);

  err = bootstrap_look_up(bp, "com.apple.iohideventsystem", &sp);
  CHECK_MACH_ERROR(err);
  printf("iohideventsystem:%d\n", sp);

  err = bootstrap_look_up(bp, "com.apple.springboard", &sp);
  CHECK_MACH_ERROR(err);
  printf("springboard:%d\n", sp);

  // need to deallocate ports before exit

  return 0;
}

The output:

my-iPad:~ root# /usr/bin/port_query 
bp:519
iohideventsystem:4099
springboard:4355

Upvotes: 1

Victor Ronin
Victor Ronin

Reputation: 23268

There is a SpringboardService framework.

It has a function SBSSpringBoardServerPort() which returns Springboard mach port.

Note: Each application may have multiple mach ports, so I am not sure that it's one which you need.

Upvotes: 1

Related Questions