forked from mozilla/ADBFuzz
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtriage.py
115 lines (91 loc) · 3.34 KB
/
triage.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
# ***** 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 subprocess
import time
import shutil
import os
import signal
import sys
import re
from detectors import AssertionDetector, CrashDetector
from mail import Mailer
class Triager:
def __init__(self, config):
self.config = config
if self.config.useMail:
self.mailer = Mailer(config)
self.assertDetector = AssertionDetector(self.config.knownPath)
self.crashDetector = CrashDetector(self.config.knownPath)
self.androidLogLinefilter = lambda x: re.sub('^[^:]+: ', '', x)
def process(self, issueUUID, miniDump, systemLog, websockLog):
print "Triaging crash..."
# Read Android system log
systemLogFile = open(systemLog)
# Check if we got aborted or crashed
aborted = self.assertDetector.hasFatalAssertion(
systemLogFile,
verbose=True,
lineFilter=self.androidLogLinefilter
)
# Reopen file
systemLogFile.close()
systemLogFile = open(systemLog)
# Check if the syslog file contains an interesting assertion.
# The lambda removes the Android syslog tags before matching
assertions = self.assertDetector.scanFileAssertions(
systemLogFile,
verbose=True,
ignoreKnownAssertions=True,
lineFilter=self.androidLogLinefilter
)
hasNewAssertion = len(assertions) > 0
systemLogFile.close()
if miniDump == None and not hasNewAssertion:
print "Error: No minidump available but also no assertions detected!"
return
isNewCrash = (miniDump != None)
crashFunction = "Unknown"
issueDesc = "Unknown"
if miniDump != None:
# Obtain symbolized crash trace to check crash signature
trace = miniDump.getSymbolizedCrashTrace()
if (len(trace) > 0):
crashFunction = trace[0][1]
issueDesc = "Crashed at " + crashFunction
isNewCrash = not self.crashDetector.isKnownCrashSignature(crashFunction)
# Also check first frame (some functions are blacklisted here)
if (isNewCrash and len(trace) > 1):
isNewCrash = not self.crashDetector.isKnownCrashSignature(trace[1][1])
# Use the last assertion as issue description
if hasNewAssertion:
issueDesc = assertions[len(assertions)-1]
print issueDesc
if hasNewAssertion or (not aborted and isNewCrash):
print "Found new issue, check " + websockLog + " to reproduce"
if self.config.useMail:
self.mailer.notify(issueUUID, issueDesc, miniDump)
else:
# Delete files if not in debug mode
if not self.config.debug:
if miniDump != None:
miniDump.cleanup()
os.remove(systemLog)
os.remove(websockLog)
return
def checkLine(self, line):
return self.assertDetector.scanLineAssertions(self.androidLogLinefilter(line))
if __name__ == "__main__":
raise Exception("This module cannot run standalone, but is used by ADBFuzz")