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

流过昼夜 提交于 2019-12-23 05:12:08

问题


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!


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/21660397/how-to-get-task-port-of-springboard-in-ios7-jailbroken

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