forked from ucam-cl-dtg/LibID
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseObfresult.py
More file actions
85 lines (50 loc) · 1.66 KB
/
parseObfresult.py
File metadata and controls
85 lines (50 loc) · 1.66 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
#!/usr/bin/env python
# coding=utf-8
import os
import json
oriPath = "./outputs/rmv/"
fileList = os.listdir(oriPath)
app_dict = {}
for app in fileList:
appPath = os.path.join(oriPath,app)
libList = []
f = open(appPath)
load_dict = json.load(f)
run_time = load_dict['time']
appName = load_dict['appID']+".apk"
libs = load_dict['libraries']
cmd = "echo {0},{1}>>{2}".format(appName,str(run_time),"rmv_Time.csv")
os.system(cmd)
if len(libs)>0:
for lib in libs:
libName = lib['name']
if libName not in libList:
libList.append(libName)
app_dict[appName] = libList
cmd = "echo {0},{1}>>{2}".format(appName,",".join(libList),"rmv_TestResult.csv")
os.system(cmd)
else:
app_dict[appName] = []
cmd = "echo {0}:{1}>>{2}".format(appName,"","rmv_TestResult.csv")
# os.system(cmd)
gtPath = "/home/zhanxian/workspace/LibDetection/LibID/outputs/obf/GroundTruth/obf_ground_truth.csv"
gtf=open(gtPath)
lines = gtf.readlines()
gtf.close()
gt_dict = {}
for line in lines:
line = line.replace("\n","")
segs = line.split(",")
app = segs[0]
del(segs[0])
libs = segs
gt_dict[app]=libs
for app in app_dict:
if app in gt_dict.keys():
test_libs = app_dict[app]
gt_libs = gt_dict[app]
intersec = list(set(test_libs).intersection(set(gt_libs)))
rate = len(intersec)*1.0/len(gt_libs)
cmd = "echo {0},{1},{2},{3}>>{4}".format(app,len(intersec),len(gt_libs),rate,"rmv_result.csv")
os.system(cmd)
print ("all work is done!")