-
Notifications
You must be signed in to change notification settings - Fork 10
/
parse.py
88 lines (73 loc) · 2.66 KB
/
parse.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
#coding=utf8
import os
import sys
import re
SystemTextSimple = ["AppDelegate", "package", "preload", "main", "ENTER", "BACKGROUND", "EVENT", "FOREGROUND",
"cocos", "android", "core", "cancel", "touch", "armature", "Bone", "path", "error",
"module", "loading", "from", "file", "loaders", "strlogpath", "vector", "login", "insert",
"game", "update", "share", "directory", "clean"]
def get_sign(folder_path):
first_file, second_file = None, None
for file in os.listdir(folder_path):
full_path = os.path.join(folder_path, file)
if os.path.isfile(full_path):
if not first_file:
first_file = full_path
elif not second_file:
second_file = full_path
else:
break
print "use file %s and %s to get sign." %(first_file.replace(folder_path, ""),
second_file.replace(folder_path, ""))
guess_sign1 = ""
with open(first_file, "rb") as file_obj:
guess_sign1 = file_obj.read(20)
file_obj.close()
guess_sign2 = ""
with open(second_file, "rb") as file_obj:
guess_sign2 = file_obj.read(20)
file_obj.close()
sign = ""
for i in range(20):
if guess_sign1[i] == guess_sign2[i]:
sign = sign + guess_sign1[i]
else:
break
return sign
def get_key_contain(so_path, sign):
may_contain = None
with open(so_path, "rb") as file_obj:
buffer_cache = file_obj.read(1024*1024)
while buffer_cache:
index = buffer_cache.find(sign)
if index != -1:
may_contain = buffer_cache[index-100:index+110]
break
buffer_cache = file_obj.read(1024*1024)
return may_contain
def parse_key_simple(key):
if len(key) <= 3:
return False
global SystemText
for text in SystemTextSimple:
if key.upper().find(text.upper()) != -1:
return False
return True
def get_guess_key_list(may_contain):
may_contain = re.sub(r"[^a-zA-Z0-9 ]", " ", may_contain)
may_contain = re.sub(r" [ ]+", " ", may_contain)
may_list = may_contain.split(" ")
may_list = filter(parse_key_simple, may_list)
return may_list
def get_key_list(sign, so_path):
print "sign: " + sign
may_contain = get_key_contain(so_path, sign)
if not may_contain:
print "not found plain sign."
return []
print "here is the text may contain key: \n%s\n" %(may_contain)
key_list = get_guess_key_list(may_contain)
key_list.remove(sign)
return key_list
if __name__ == "__main__":
pass