-
Notifications
You must be signed in to change notification settings - Fork 7
/
variable_match.py
80 lines (63 loc) · 2.53 KB
/
variable_match.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
import os
import sqlite3
matches = open('deobf/matches.txt', 'r').readlines()
conn_clean = sqlite3.connect('tmp/clean_structs.db')
cursor_clean = conn_clean.cursor()
conn_obf = sqlite3.connect('tmp/obf_structs.db')
cursor_obf = conn_obf.cursor()
current_pos = 0
var_matches = []
for l in matches:
print(str(round((current_pos / len(matches)) * 100, 4)) + "%", end="\r")
obf_classname = l.split("/")[0].strip()
clean_classname = l.split("/")[1].strip()
row_obf = cursor_obf.execute("SELECT * FROM symbols WHERE name='%s'" % obf_classname).fetchone()
row_clean = cursor_clean.execute("SELECT * FROM symbols WHERE name='%s'" % clean_classname).fetchone()
try:
if row_obf[1] is not None:
struct_obf_fields = row_obf[1].split(',')
struct_obf_fields.pop(0)
else:
struct_obf_fields = None
if row_obf[2] is not None:
struct_obf_staticfields = row_obf[2].split(',')
struct_obf_staticfields.pop(0)
else:
struct_obf_staticfields = None
if row_clean[1] is not None:
struct_clean_fields = row_clean[1].split(',')
struct_clean_fields.pop(0)
else:
struct_clean_fields = None
if row_clean[2] is not None:
struct_clean_staticfields = row_clean[2].split(',')
struct_clean_staticfields.pop(0)
else:
struct_clean_staticfields = None
if struct_clean_fields is None and struct_clean_staticfields is None:
continue
if struct_obf_fields is None and struct_obf_staticfields is None:
continue
except:
continue
try:
for index, obf_field in enumerate(struct_obf_fields):
try:
obf_varname = obf_field.split(" ")[-1]
clean_varname = struct_clean_fields[index].split(" ")[-1]
obf_varname = obf_varname.replace(";", "").replace("*", "")
clean_varname = clean_varname.replace(";", "").replace("*", "")
if obf_varname != clean_varname and '_' not in obf_varname and '_' not in clean_varname:
var_matches.append((obf_varname, clean_varname))
except:
continue
except:
continue
current_pos += 1
conn_obf.close()
conn_clean.close()
f = open('deobf/matches.txt', 'a')
f.write("//start variable matches")
for (obfname, cleanname) in var_matches:
f.write(obfname + "/" + cleanname + "\n")
print("Generated all variable name matches")