iOS-私有API与runtime

简介:

有朋友在做类似iTool的功能,跟我聊起来,这几天闲,就写了一个demo,不是正经做这个,还很粗略,具体干货诸位等这位朋友自己发文吧。

DEMO

https://github.com/liulishuo/testAppList

思路

iOS9白名单的上限是50个,如果想绕过这个限制,扫描系统中所有app的状态,只有使用私有API,需要用到的类有两个:LSApplicationWorkspace、LSApplicationProxy,知道类的名字我们就可以依靠runtime得到这个类,以及这个类的所有方法,OC的方法望文生义,接下来就可以慢慢尝试。

实现

  • 得到LSApplicationWorkspace、LSApplicationProxy

1
2
Class LSApplicationWorkspace_class = objc_getClass( "LSApplicationWorkspace" );
Class LSApplicationProxy_class = object_getClass(@ "LSApplicationProxy" );

得到类的所有方法与成员变量(编程小翁)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//获取不到成员变量
  int count = 0;
  Ivar *members = class_copyIvarList([LSApplicationProxy_class class], &count);   for  (int i = 0 ; i < count; i++) {
      Ivar  var  = members[i];      const char *memberName = ivar_getName( var );      const char *memberType = ivar_getTypeEncoding( var );
      NSLog(@ "%s: %s" ,memberType,memberName);
  }
  
  NSLog(@ "count: %d" ,count);   //获取不到有用的方法
  count = 0;
  Method *memberMethods = class_copyMethodList(LSApplicationProxy_class, &count);   for  (int i = 0; i < count; i++) {
      SEL name = method_getName(memberMethods[i]);
      NSString *methodName = [NSString stringWithCString:sel_getName(name) encoding:NSUTF8StringEncoding];
      NSLog(@ "member method:%@" , methodName);
  }
  
  NSLog(@ "count: %d" ,count);

因为函数class_copyIvarList、class_copyMethodList有时不能返回有用的结果,所以我们使用class-dump(有朋友反映xcode7的库导不出来,大家用源码自己build一个吧),导出类的头文件。

导出MobileCoreServices.framework的所有头文件:

1
class-dump -H /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/MobileCoreServices.framework  -o /Users/credit/Desktop/header004

-o后面是输出路径 改成你需要的。

02.png

MobileCoreServices.framework的所有头文件

03.png

LSApplicationProxy

04.png

LSApplicationWorkspace

  • 得到app列表

虽然没有注释,但是我们可以猜到这个方法应该可以得到app列表

1
- (id)allApplications;

但是他是实例方法,我们先要拿到一个LSApplicationWorkspace实例

1
+ (id)defaultWorkspace;

代码如下

1
2
NSObject* workspace = [LSApplicationWorkspace_class performSelector:@selector(defaultWorkspace)];
NSArray *appList = [workspace performSelector:@selector(allApplications)];
  • 遍历app列表

applist里的每一个元素都是LSApplicationProxy 比对其头文件,把对应的属性打印出来研究,

属性略多,不想自己写的朋友,请看我的demo

05.png

遍历数组

06.png

YY

07.png

微信

注意groupContainers数组的内容,我们可以拿到group id,可不可以拿到公共存储区的数据呢?

1
2
NSUserDefaults *share = [[NSUserDefaults alloc] initWithSuiteName:@ "group.com.tencent.xin" ];
NSLog(@ "%@" ,share.dictionaryRepresentation);

然而并没有,那有没有共享数据的目录呢?

1
NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@ "group.com.tencent.xin" ];

返回值为nil

app不在group.com.tencent.xin这个组内,咱的冒牌货强写是无效的,因为这个标识符已经被正品占用了。

001.png

App Groups

还有什么好玩的? 试试这个

1
[workspace performSelector:@selector(uninstallApplication:withOptions:) withObject:@ "XXX"  withObject:nil];

workspace 是LSApplicationWorkspace实例,@"XXX"这里填你获取到的applicationIdentifier

模拟器可以正常卸载app,真机不行。

更多API,大家可以自己尝试一下。

目录
相关文章
|
6月前
|
API iOS开发
iOS面试关于runtime
iOS面试关于runtime
56 0
|
7月前
|
Java API
Java之API详解之Runtime的详细解析
Java之API详解之Runtime的详细解析
94 0
Java之API详解之Runtime的详细解析
|
文字识别 API iOS开发
iOS小技能:iOS13 证件扫描 & 文字识别API
1. 应用场景:证件扫描、文字识别 2. 原理:利用iOS13 VNDocumentCameraViewController的证件扫描和VNRecognizeTextRequest文字识别功能进行实现
231 0
iOS小技能:iOS13 证件扫描 & 文字识别API
|
3月前
|
缓存 JSON API
IOS网络编程:什么是 RESTful API?如何使用 RESTful 风格设计 API?
IOS网络编程:什么是 RESTful API?如何使用 RESTful 风格设计 API?
42 3
|
5月前
|
Java API
常用API——Math,System,Object,Runtime
常用API——Math,System,Object,Runtime
|
7月前
|
API
15-iOS之Runtime常用API以及使用
15-iOS之Runtime常用API以及使用
54 0
|
10月前
|
小程序 API Android开发
小程序获取WIFI的API(IOS conncetWifi()自动跳转设置页)
小程序获取WIFI的API(IOS conncetWifi()自动跳转设置页)
262 0
|
编译器 iOS开发
iOS Runtime详细介绍及实战使用(二)
iOS Runtime详细介绍及实战使用
 iOS Runtime详细介绍及实战使用(二)
|
API iOS开发
iOS Runtime详细介绍及实战使用(一)
iOS Runtime详细介绍及实战使用
|
Java API
Java中常用API总结(3)—— Runtime类(含实例解读)
Runtime类所在包为java.lang包,因此在使用的时候不需要进行导包;并且Runtime类被public修饰了,因此该类是可以被继承的
153 0
Java中常用API总结(3)—— Runtime类(含实例解读)