-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiOS_private.py
107 lines (87 loc) · 3.26 KB
/
iOS_private.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#coding=utf-8
'''
Created on 2015年10月27日
iOS private api检查入口
@author: hzwangzhiwei
'''
import os
from dump import otool_utils
from api import app_utils, api_utils
from db import api_dbs
def get_executable_path(ipa_path, pid):
'''
info: unzip ipa, get execute app path
'''
if not os.path.exists(ipa_path):
#不存在,返回检查结果为空值
return False
cur_dir = os.getcwd()
dest = os.path.join(cur_dir, 'tmp/' + pid)
if not os.path.exists(dest):
os.mkdir(dest)
print dest
app_path = app_utils.unzip_ipa(ipa_path, dest) #解压ipa,获得xxx.app目录路径
app = app_utils.get_executable_file(app_path)
return app
def check_private_api(app, pid):
#print app
strings = app_utils.get_app_strings(app, pid) #一般是app中的一些可打印文本
#app中的私有库和公有库 .framework
private, public = otool_utils.otool_app(app)
app_varibles = app_utils.get_app_variables(app, pid)
left = strings - app_varibles #去除一些关键字,剩余app中的一些关键词
api_set = api_dbs.get_framework_private_apis() #数据库中的私有api
print 'private length:', len(api_set)
inter_api = api_utils.intersection_list_and_api(left, api_set) # app中的api和数据库中的私有api取交集,获得app中的私有api关键字数据
app_methods = app_utils.get_app_methods(app, pid) #app中的方法名
app_apis = []
for m in app_methods:
class_name = m["class"] if m["class"] != "ctype" else 'cur_app'
method_list = m["methods"]
m_type = m["type"]
for m in method_list:
tmp_api = {}
tmp_api['api_name'] = m
tmp_api['class_name'] = class_name
tmp_api['type'] = m_type
#tmp_api['header_file'] = ''
#tmp_api['sdk'] = ''
#tmp_api['framework'] = ''
app_apis.append(tmp_api)
methods_in_app = api_utils.intersection_api(app_apis, inter_api) #app中的私有方法
methods_not_in_app = inter_api# inter_method - methods_in_app # 不在app中的私有方法
return methods_in_app, methods_not_in_app, private
def check_architectures(app):
arcs = app_utils.check_architectures(app)
return arcs
if __name__ == '__main__':
ipa_path = "/Users/summer-wj/code/svn/ljsg_for_netease_20150928_resign.ipa"
# cur_dir = os.getcwd()
# dest = os.path.join(cur_dir, 'tmp')
# app_path = app_utils.unzip_ipa(ipa_path, dest)
# print app_path
private_1 = open("tmp/private_1.txt", "w")
private_2 = open("tmp/private_2.txt", "w")
#将strings内容输出到文件中
pid = app_utils.get_unique_str()
app = get_executable_path(ipa_path, pid)
print app
arcs = check_architectures(app)
print arcs
a, b, c = check_private_api(app, pid)
print "=" * 50
print len(a), "Private Methods in App:"
print "*" * 50
for aa in a:
print aa
print >>private_1, aa
print "=" * 50
print len(b), "Private Methods not in App, May in Framework Used:"
print "*" * 50
for bb in b:
print >>private_2, bb
print "=" * 50
print len(c), "Private Framework in App:"
print "*" * 50
#for cc in c:
# print cc