-
Notifications
You must be signed in to change notification settings - Fork 7
/
generate_hashtable.py
40 lines (31 loc) · 1.29 KB
/
generate_hashtable.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
import sqlite3
import hashlib
classname_file = open("tmp/unmatched_clean.txt", "r")
classnames = classname_file.readlines()
conn_clean = sqlite3.connect('tmp/clean_structs.db')
cursor_clean = conn_clean.cursor()
conn_hash = sqlite3.connect('tmp/hashtable.db')
cursor_hash = conn_hash.cursor()
cursor_hash.execute('''CREATE TABLE hashes (hash text, name text)''')
current_pos = 0
for classname in classnames:
print(str(round((current_pos / len(classnames)) * 100, 4)) + "%", end="\r")
classname = classname.strip()
row = cursor_clean.execute("SELECT * FROM symbols WHERE name='%s'" % classname).fetchone()
fields_length = 0
static_fields_length = 0
if row[1] is not None:
struct_fields = row[1].split(',')
struct_fields.pop(0)
fields_length = len(struct_fields)
else:
struct_fields = None
if row[2] is not None:
struct_staticfields = row[2].split(',')
struct_staticfields.pop(0)
static_fields_length = len(struct_staticfields)
else:
struct_staticfields = None
cursor_hash.execute("INSERT INTO hashes VALUES (\'" + str(hashlib.sha1(bytes(str(fields_length) + '_' + str(static_fields_length), encoding='utf8')).hexdigest()) + "\', \'" + classname + "\')")
current_pos += 1
print("Generated hashtabel")