forked from yhryyq/cfgtool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassifier_javac.py
executable file
·68 lines (53 loc) · 1.83 KB
/
classifier_javac.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
import re
import os
class State():
def __init__(self, id, signature, next=None):
self.id = id
self.signature = signature
self.next = []
if next != None:
self.next.append(next)
def AddNext(self, next):
self.next.append(next)
def Match(self, String):
if len(self.signature) == 0:
return True
# print ("\tMatchState=>", self.signature, " -> ", String, ":", len (String))
if re.search(self.signature, String) != None:
return True
else:
return False
class classifier():
def __init__(self,fileType):
self.filetype = fileType.split()
self.States = []
def creatCPYClassifier(self):
S0 = State (0, "JNIEXPORT")
self.AddState(S0)
# def printStates(self):
# for state in self.States:
# print(state.id)
def AddState(self, state):
self.States.append(state)
def Match(self, File):
if not os.path.exists(File):
return False, ""
StateStack = self.States
if len(StateStack) == 0:
return False, ""
Ext = os.path.splitext(File)[-1].lower()
if Ext not in self.filetype:
return False, ""
with open(File, "r", encoding="utf8", errors="ignore") as sf:
for line in sf:
if len(line) < 4:
continue
for state in StateStack:
isMatch = state.Match(line)
if isMatch == False:
continue
if len(state.next) == 0:
return True, str(state.id)
for next in state.next:
StateStack.append(next)
return False,""