This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
logfilter.py
70 lines (58 loc) · 1.8 KB
/
logfilter.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
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# The Original Code is ADBFuzz.
#
# The Initial Developer of the Original Code is Christian Holler (decoder).
#
# Contributors:
# Christian Holler <[email protected]> (Original Developer)
#
# ***** END LICENSE BLOCK *****
import threading
import subprocess
class LogFilter(threading.Thread):
def __init__(self, config, triager, logProcess, logFile):
self.config = config
self.triager = triager
self.logProcess = logProcess
self.logFile = logFile
self.eof = False
# Thread initialization stuff
self.stdout = None
self.stderr = None
threading.Thread.__init__(self)
# We need this to know when to terminate
self._stop = threading.Event()
def run(self):
if self.logFile == None:
logFileFd = None
else:
logFileFd = open(self.logFile, 'w')
# Loop until we get aborted, hit EOF or find something interesting
while not self._stop.isSet():
line = self.logProcess.stdout.readline()
if (len(line) == 0):
self.eof = True
break
if logFileFd == None:
# Output to stdout
print line.strip()
else:
# Store to file first
logFileFd.write(line)
# Now check if it has something interesting (e.g. assertion)
line = line.strip()
if self.triager.checkLine(line):
break
if logFileFd != None:
logFileFd.close()
return
def terminate(self):
self._stop.set()
if __name__ == "__main__":
raise Exception("This module cannot run standalone, but is used by ADBFuzz")