-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathConfig.py
113 lines (95 loc) · 3.56 KB
/
Config.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
from Context import Context
import cPickle as pickle
import pdb
class Config:
def __init__(self, config_path, config_type, matchtype):
self.fp = open(config_path, 'r')
self.callgraph = None
self.feature_db = None
self.funcontex = None
self.Contextls = {}
self.testset = {}
self.testcontextls = {}
self.src_db = {}
self.dst_db = {}
self.matchtype = matchtype
self.obtainConfig(config_path)
self.matchall_preparing()
def obtainConfig(self, config_path):
for entry in self.fp:
if 'src' in entry:
if 'srcfunc' in entry:
self.srcfunc = entry.split(":= ")[1].split("\n")[0]
if 'srcname' in entry:
self.srcname = entry.split(":= ")[1].split("\n")[0]
if 'srcdir' in entry:
self.srcdir = entry.split(":= ")[1].split("\n")[0]
self.src_db['name'] = self.srcname
if "dst" in entry:
if 'dstfunc' in entry:
self.dstfunc = entry.split(":= ")[1].split("\n")[0]
if 'dstname' in entry:
self.dstname = entry.split(":= ")[1].split("\n")[0]
if 'dstdir' in entry:
self.dstdir = entry.split(":= ")[1].split("\n")[0]
self.dst_db['name'] = self.dstname
if 'depth' in entry:
self.depth = int(entry.split(":= ")[1].split("\n")[0])
if 'type' in entry:
self.type = entry.split(":= ")[1].split("\n")[0]
def matchall_preparing(self):
feature_db_path = self.srcdir + self.srcname + '.dugs'
func_dug_db = pickle.load(open(feature_db_path, 'r'))
self.src_db['dugs'] = func_dug_db
feature_db_path = self.srcdir + self.srcname + '.func_seqs'
func_dug_db = pickle.load(open(feature_db_path, 'r'))
self.src_db['seqs'] = func_dug_db
#callgraph_path = self.srcdir + self.srcname + '.callgraph'
#callgraph = pickle.load(open(callgraph_path, 'r'))
#self.src_db['callgraph'] = callgraph
self.src_db['type'] = self.type
self.src_db['depth'] = self.depth
## dst feature extractions
feature_db_path = self.dstdir + self.dstname + '.dugs'
func_dug_db = pickle.load(open(feature_db_path, 'r'))
self.dst_db['dugs'] = func_dug_db
feature_db_path = self.dstdir + self.dstname + '.func_seqs'
func_dug_db = pickle.load(open(feature_db_path, 'r'))
self.dst_db['seqs'] = func_dug_db
#callgraph_path = self.dstdir + self.dstname + '.callgraph'
#callgraph = pickle.load(open(callgraph_path, 'r'))
#self.dst_db['callgraph'] = callgraph
'''
if self.matchtype == 'start':
self.gen_callgraphlets()
testcontextls_path = self.srcdir + self.srcname + '.graphlets'
self.testcontextls = pickle.load(open(testcontextls_path, 'r'))
testcontextls_path = self.srcdir + self.srcname + '.graphlets'
self.testcontextls = pickle.load(open(testcontextls_path, 'r'))
self.dst_db['type'] = self.type
self.dst_db['depth'] = self.depth
'''
def gen_callgraphlets(self):
# for src callgraphlets
self.src_graphlets = {}
test_context_path = self.srcdir + self.srcname + '.graphlets'
src_callgraph = self.src_db['callgraph']
type_ = self.src_db['type']
depth = self.src_db['depth']
i = 0
for node in src_callgraph:
print str(i*1.0/len(src_callgraph))
i += 1
src_context = Context(node, src_callgraph, depth, type_)
self.src_graphlets[node] = src_context
pickle.dump(self.src_graphlets, open(test_context_path, 'wb'))
self.dst_graphlets = {}
test_context_path = self.dstdir + self.dstname + '.contextls'
dst_callgraph = self.dst_db['callgraph']
i = 0
for node in dst_callgraph:
print str(i*1.0/len(src_callgraph))
i += 1
dst_context = Context(node, dst_callgraph, depth, type_)
self.dst_graphlets[node] = dst_context
pickle.dump(self.dst_graphlets, open(test_context_path, 'wb'))