iOS-私有API与runtime
2016-06-30 11:37
459 查看
序
有朋友在做类似iTool的功能,跟我聊起来,这几天闲,就写了一个demo,不是正经做这个,还很粗略,具体干货诸位等这位朋友自己发文吧。DEMO
https://github.com/liulishuo/testAppList思路
iOS9白名单的上限是50个,如果想绕过这个限制,扫描系统中所有app的状态,只有使用私有API,需要用到的类有两个:LSApplicationWorkspace、LSApplicationProxy,知道类的名字我们就可以依靠runtime得到这个类,以及这个类的所有方法,OC的方法望文生义,接下来就可以慢慢尝试。实现
得到LSApplicationWorkspace、LSApplicationProxyClass LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace"); Class LSApplicationProxy_class = object_getClass(@"LSApplicationProxy");
得到类的所有方法与成员变量(编程小翁)
//获取不到成员变量 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的所有头文件:
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后面是输出路径 改成你需要的。
MobileCoreServices.framework的所有头文件
LSApplicationProxy
LSApplicationWorkspace
得到app列表
虽然没有注释,但是我们可以猜到这个方法应该可以得到app列表
- (id)allApplications;
但是他是实例方法,我们先要拿到一个LSApplicationWorkspace实例
+ (id)defaultWorkspace;
代码如下
NSObject* workspace = [LSApplicationWorkspace_class performSelector:@selector(defaultWorkspace)]; NSArray *appList = [workspace performSelector:@selector(allApplications)];
遍历app列表
applist里的每一个元素都是LSApplicationProxy 比对其头文件,把对应的属性打印出来研究,
属性略多,不想自己写的朋友,请看我的demo
遍历数组
YY
微信
末
注意groupContainers数组的内容,我们可以拿到group id,可不可以拿到公共存储区的数据呢?NSUserDefaults *share = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.tencent.xin"]; NSLog(@"%@",share.dictionaryRepresentation);
然而并没有,那有没有共享数据的目录呢?
NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.tencent.xin"];
返回值为nil
app不在group.com.tencent.xin这个组内,咱的冒牌货强写是无效的,因为这个标识符已经被正品占用了。
App Groups
还有什么好玩的? 试试这个
[workspace performSelector:@selector(uninstallApplication:withOptions:) withObject:@"XXX" withObject:nil];
workspace 是LSApplicationWorkspace实例,@"XXX"这里填你获取到的applicationIdentifier
模拟器可以正常卸载app,真机不行。
更多API,大家可以自己尝试一下。
文/cocoa(简书作者)
原文链接:http://www.jianshu.com/p/6167b9ce7af8
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用开发中AFNetworking库的常用HTTP操作方法小结
- iOS应用中UISearchDisplayController搜索效果的用法
- iOS App开发中的UISegmentedControl分段组件用法总结
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- iOS中UIAlertView警告框组件的使用教程
- 浅析iOS应用开发中线程间的通信与线程安全问题
- iOS中的UIKeyboard键盘视图使用方法小结
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法