1#!/usr/bin/env python 2# -*- coding:utf-8 -*- 3# 4# Copyright (c) 2021 Huawei Device Co., Ltd. 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18import re 19 20 21class RunResult(): 22 SUCCESS = 0 23 24 RUN_ENV_ERROR = -1 25 RUN_NO_DEVICE_ERROR = -2 26 RUN_CONFIG_FORMAT_ERROR = -3 27 RUN_CONFIG_FORMAT_NOCOLON_ERROR = -4 28 RUN_FUZZER_BIN_NOT_FOUND_ERROR = -5 29 RUN_CONNECT_ERROR = -6 30 RUN_EXEC_ERROR = -7 31 RUN_CONFIG_DICT_ERROR = -8 32 RUN_LINK_ERROR = -9 33 34 35 def __init__(self, code, data): 36 self.code = code 37 self.data = data 38 self.payload = {} 39 40 self.crash_info = { 41 "run_times": 0, 42 "log": "", 43 "project": "", 44 "speed": 0, 45 "summary": "No vulnerable", 46 "command_log": "", 47 "vulnerable": False, 48 "backtrace": "", 49 "cov": 0, 50 "libscov": {}, 51 "report_progress": 0 52 } 53 54 55 def get_log(self): 56 return "code :{}, msg: {}".format(self.code, self.data) 57 58 @staticmethod 59 def filter_log(log_str): 60 ansi_escape = re.compile(r''' 61 \x1B 62 (?: 63 [@-Z\\-_] 64 | 65 \[ 66 [0-?]* 67 [ -/]* 68 [@-~] 69 ) 70 ''', re.VERBOSE) 71 result = ansi_escape.sub('', log_str) 72 return result 73 74 def analysis(self, result, outdir): 75 pass 76 77 def write_analysis_result(self, analysis_ressult_path, html_format=True): 78 with open(analysis_ressult_path, "wb") as f: 79 if html_format: 80 f.write(RunResult.filter_log(render_detail(self.crash_info))) 81 else: 82 f.write(RunResult.filter_log(self.crash_info["backtrace"])) 83 84 85if __name__ == "__main__": 86 cmd_log = "" 87 res_obj = RunResult(0, "OK") 88 res_obj.analysis(cmd_log, "../../../out/") 89 print(res_obj.crash_info) 90 91