-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
189 lines (173 loc) · 5.19 KB
/
test.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import re
def match(line:str,cmd:str):
if not cmd:
return True
contains=[]
ends=[]
greater=[]
print("cmd=",cmd)
notcmd=re.search("not\((.*)\)",cmd)
if notcmd:
notcmd=notcmd.groups()[0]
print("notcmd=",notcmd)
cmd=cmd.replace("not("+notcmd+")","")
# input("pause")
case=cmd.split("&")
print("case=",case)
for c in case:
if c.startswith("contains="):
contains.append(c.split("\"")[-1])
if c.startswith("ends="):
ends.append(c.split("\"")[-1])
if c.startswith("greater="):
greater.append(c.split("\"")[-1])
result=True
for con in contains:
if con in line:
result=True
else:
return False
for end in ends:
if line.endswith(end):
result=True
else:
return False
for gre in greater:
if line>gre:
result=True
else:
return False
if notcmd:
notresult=not match(line,notcmd)
print("1",notresult)
print("2",result)
result=result and notresult
print("3",result)
return result
cmd="contains=\"hello\"¬(not(contains=\"world\"))"
# notcmd=re.search("not\((.*)\)",cmd)
# print(notcmd.groups()[0])
line="hello worl"
# print(line.split("\""))
print(match(line,cmd))
# contains="hello"¬()
# with open("searchtest.txt","r") as f:
# for line in f.readlines():
# line=line.strip()
# import re
# class filter:
# def init(self,cmd:str):
# self.cmd=cmd
# self.contains=[]
# self.ends=[]
# self.greater=[]
# def parse(self):
# # cases=self.cmd.split("&")
# result=re.match("not(*)",self.cmd)
# for c in cases:
# if c.startswith("contains="):
# self.contains.append(c.split("\"")[-2])
# if c.startswith("ends="):
# self.ends.append(c.split("\"")[-2])
# if c.startswith("greater="):
# self.greater.append(c.split("\"")[-2])
# # if c.startswith("not"):
# # case=c.split("(")[-1].split("=")[0]
# # keyword=c.split("\"")[-2]
# # if case=="ends":
# # self.ends[1].append(keyword)
# # if case=="contains":
# # self.contains[1].append(keyword)
# # if case=="greater":
# # self.greater[1].append(keyword)
# def match(self,line:str):
# result=False
# for con in self.contains:
# if con in line:
# result=True
# else:
# return False
# for end in self.ends:
# if line.endswith(end):
# result=True
# else:
# return False
# for gre in self.greater:
# if line>gre:
# result=True
# else:
# return False
# contains="hello"¬()
# with open("searchtest.txt","r") as f:
# for line in f.readlines():
# line=line.strip()
# def GetCategory(txtfile:str,ApiList:list):
# #两个特殊的类android.manifest类属于security;而android.R属于UI
# cataccord={
# "io":[]\
# ,"net":[]\
# ,"device":[]\
# ,"location":[]\
# ,"UI":[]\
# ,"hardware":[]\
# ,"app":[]\
# ,"multimedia":[]\
# ,"security":[]\
# ,"base":[]
# }
# category={
# "io":[]\
# ,"net":[]\
# ,"device":[]\
# ,"location":[]\
# ,"UI":[]\
# ,"hardware":[]\
# ,"app":[]\
# ,"multimedia":[]\
# ,"security":[]\
# ,"base":[]
# }
# # from sklearn import svm
# # from sklearn import datasets
# # iris=datasets.load_iris()
# # digits = datasets.load_digits()
# # clf = svm.SVC(gamma=0.001,C=100.)#模型和参数
# # clf.fit(digits.data[:-1], digits.target[:-1])#传递训练集给fit函数并进行学习
# # print(digits.data[-1:])
# # print(clf.predict(digits.data[-1:]))
# from sklearn.manifold import TSNE
# import numpy
# from sklearn import datasets
# import os
# testdir="D:\workplace\main\libdetector\\test"
# datadic={}
# data=[]
# labels=[]
# floor=3
# for file in os.listdir(testdir):
# with open(testdir+"\\"+file,"r") as f:
# for line in f.readlines():
# line=line.strip()
# if int(line[-1])==floor:
# path=line.split(":")[0]+":"+line.split(":")[1]
# tmp=[]
# for i in line.split(":")[-1].split(","):
# tmp.append(int(i))
# data.append(tmp)
# datadic[path]=tmp
# label=""
# for i in range(1,floor+1):
# label=path.split("\\")[-i]+"\\"+label
# labels.append(path)
# for i in labels:
# if "org\\apache\\http" in i:
# print(i)
# if i in datadic.keys():
# print(datadic[i])
# # npdata=numpy.array(data)
# # tsne = TSNE(n_components=2, init='pca', random_state=0)
# # result=tsne.fit_transform(npdata)
# # import matplotlib.pyplot as plt
# # for node in result:
# # plt.plot(node[0],node[1],color='b',marker='o',markersize=10)
# # plt.show()