如何在iOS7(越狱)中获取SpringBoard的任务端口? [英] How to get task port of SpringBoard in iOS7 (Jailbroken)?

查看:178
本文介绍了如何在iOS7(越狱)中获取SpringBoard的任务端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们可以使用contextIdAtPositiontaskPortOfContextId来获取前顶部应用程序的mach_port_t,但是在某些应用程序中时,我们不能使用contextIdAtPosition来获取SpringBoard的上下文ID( (在背景中),那么我们如何获得SpringBoardmach_port_t?谢谢!

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!

推荐答案

根据 http://theiphonewiki.com/wiki//System/Library/LaunchDaemons/com.apple.SpringBoard.plist ,SpringBoard提供了很多服务.其中两个可能(或可能不)符合您的兴趣:

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;
}

输出:

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

这篇关于如何在iOS7(越狱)中获取SpringBoard的任务端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆