-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathxclangspec_generator.py
More file actions
executable file
·91 lines (77 loc) · 2.76 KB
/
xclangspec_generator.py
File metadata and controls
executable file
·91 lines (77 loc) · 2.76 KB
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
'''
#
# Run with python3
# Script that generates the Logos xclangspec
#
# xclangspec_generator is a script created by pr0crustes (https://github.com/pr0crustes)
# that is provided as it is, without any warranty.
# pr0crustes @ 2018 - all rights reserved.
#
'''
import os
global_new_keywords = [
"// Start Logos Keywords",
"%group",
"%hook",
"%new",
"%subclass",
"%property",
"%end",
"%config",
"%hookf",
"%ctor",
"%dtor",
"%init",
"%class",
"%c",
"%orig",
"%log",
"// End Logos Keywords",
"// Start Other Keywords",
"NSLog",
"NSString",
"NSInteger",
"NSObject",
"// End Other Keywords"
]
global_ident1 = "Words = ("
global_ident2 = "Chars = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_\";"
global_ident3 = "StartChars = \"@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_\";"
class XClangGenerator(object):
def __init__(self):
self.objc_spec_file = "/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/ObjectiveC.xclangspec"
self.objc_spec_content = []
self.new_lines = []
def __get_loaded_file(self):
print("Reading File...")
for line in open(self.objc_spec_file, 'r'):
if line.strip() and not line.strip().startswith("/"):
self.objc_spec_content.append(line)
def __get_parsed_file(self):
print("Parsing File...")
for i in range(len(self.objc_spec_content)):
line = self.objc_spec_content[i].replace("objc", "logos")
self.new_lines.append(line)
if global_ident1 in line and i > 3 and global_ident2 in self.objc_spec_content[i-1] and global_ident3 in self.objc_spec_content[i-2]:
print("Inserting Logos Keywords Into New File...")
for new_word in global_new_keywords:
if new_word.strip().startswith("//"):
self.new_lines.append("\t\t\t\t" + new_word + "\n")
else:
self.new_lines.append("\t\t\t\t\"" + new_word + "\",\n")
def __save_file(self):
print("Saving New File...")
with open("Logos.xclangspec", "w") as file:
file.write("// Logos xclangspec was generated by spec_gen\n")
file.write("// Script made by pr0crustes\n")
for line in self.new_lines:
file.write(line)
def execute(self):
self.__get_loaded_file()
self.__get_parsed_file()
self.__save_file()
print("XClangSpec Generator was successfully runned.")
if __name__ == '__main__':
os.rename("/opt/MonkeyDev/Logos-Xcode/src/Logos.xc", "/opt/MonkeyDev/Logos-Xcode/src/Logos.xclangspec")
gen = XClangGenerator()
gen.execute()