-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathiterheaders.py
118 lines (107 loc) · 4.75 KB
/
iterheaders.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
108
109
110
111
112
113
114
115
116
117
118
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2014 Arming lee <[email protected]>
#
# Distributed under terms of the MIT license.
"""
iterate header files in Frameworks
"""
import os
import subprocess
def public_framework_headers():
"""
get all public frameworks' header files(documented)
Args:
Returns:
[('UIKit.framework', 'UIWindow.h',
'/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIWindow.h')]
"""
def iterate_dir(framework, prefix, path):
files = []
for f in os.listdir(path):
if os.path.isfile(os.path.join(path, f)):
files.append((framework, prefix+f, os.path.join(path, f)))
elif os.path.isdir(os.path.join(path, f)):
files += iterate_dir(framework, prefix+f+"/", os.path.join(path, f))
return files
allpaths = []
path = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/Frameworks/"
#import pdb
#pdb.set_trace()
for framework in os.listdir(path):
if framework.endswith(".framework"):
header_path = path + framework +"/Headers/"
if os.path.exists(header_path):
#for header in os.listdir(header_path):
# file_path = header_path + header
# allpaths.append((framework, header, file_path))
allpaths += iterate_dir(framework, "", os.path.join(path, header_path))
return allpaths
#print len(allpaths)
def public_include_headers():
"""
get all the header files in .../usr/include/objc/
Args:
Returns:
[('/usr/include/objc', 'NSObject.h',
'/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/include/objc/NSObject.h')]
"""
allpaths = []
path = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/include/objc/"
for header in os.listdir(path):
allpaths.append(("/usr/include/objc", header, path + header))
return allpaths
def class_dump_framework():
"""
class-dump public framework
Todo:
iterate all the files and directories, to find the mach-o files. We can accomplish this with "file -b xxx"
"""
cur_dir = os.getcwd()
#path = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/Frameworks/"
path = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/PrivateFrameworks/"
dump_cmd = "/usr/local/bin/class-dump -H %s -o %s"
for framework in os.listdir(path):
if framework.endswith(".framework"):
#cmd = dump_cmd%(os.path.join(path, framework), os.path.join(os.path.join(cur_dir, "pub-headers"), framework))
cmd = dump_cmd%(os.path.join(path, framework), os.path.join(os.path.join(cur_dir, "pri-headers"), framework))
ret = subprocess.call(cmd.split())
if ret != 0:
print framework
def public_dump_headers():
"""
get all public frameworks' header files(documented)
Args:
Returns:
[('UIKit.framework', 'UIWindow.h',
'/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIWindow.h')]
"""
def iterate_dir(framework, prefix, path):
files = []
for f in os.listdir(path):
if os.path.isfile(os.path.join(path, f)):
files.append((framework, prefix+f, os.path.join(path, f)))
elif os.path.isdir(os.path.join(path, f)):
files += iterate_dir(framework, prefix+f+"/", os.path.join(path, f))
return files
allpaths = []
path = os.path.join(os.getcwd(), "pub-headers")
#import pdb
#pdb.set_trace()
for framework in os.listdir(path):
if framework.endswith(".framework"):
header_path = os.path.join(path, framework)
if os.path.exists(header_path):
#for header in os.listdir(header_path):
# file_path = header_path + header
# allpaths.append((framework, header, file_path))
allpaths += iterate_dir(framework, "", header_path)
return allpaths
#print len(allpaths)
if __name__ == "__main__":
#print public_framework_headers()
#print public_include_headers()
class_dump_framework()
pass