From ed00d92096e0bff9553344c7cae21b1a286885fd Mon Sep 17 00:00:00 2001 From: ywx1293154 Date: Fri, 12 Jan 2024 01:34:48 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=B0=86=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E4=BF=A1=E6=81=AF=E8=BD=ACjson=E7=9A=84=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- llvm_test_script/checksec/check.py | 82 +++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 24 deletions(-) mode change 100755 => 100644 llvm_test_script/checksec/check.py diff --git a/llvm_test_script/checksec/check.py b/llvm_test_script/checksec/check.py old mode 100755 new mode 100644 index 97910ac..2a7e91e --- a/llvm_test_script/checksec/check.py +++ b/llvm_test_script/checksec/check.py @@ -3,6 +3,8 @@ import os import time import datetime import argparse +import sys +sys.path.append('./third_party') import jinja2 CHECK_TRUE = 'true' @@ -12,7 +14,7 @@ CHECK_FAILED = 'failed' CHECK_ITEM_NUM = 11 class GenerateReport: - def _generate_failed_files_report(self, output_path, failed_file_list): + def _generate_failed_files_html_report(self, output_path, failed_file_list): env = jinja2.Environment(loader = jinja2.FileSystemLoader('./templates')) template = env.get_template('failed_files_template.html') data = { @@ -22,7 +24,7 @@ class GenerateReport: with open(output_path + 'failed files list.html', 'w', encoding='utf-8') as failed_file: failed_file.write(document) - def _generate_total_files_report(self, output_path, total_file_info): + def _generate_total_files_html_report(self, output_path, total_file_info): env = jinja2.Environment(loader = jinja2.FileSystemLoader('./templates')) template = env.get_template('total_files_template.html') data = { @@ -32,7 +34,7 @@ class GenerateReport: with open(output_path + 'total file list.html', 'w', encoding='utf-8') as total_file: total_file.write(document) - def _generate_summary_report(self, output_path, check_items, summary_data, total_file_info): + def _generate_summary_html_report(self, output_path, check_items, summary_data, total_file_info): env = jinja2.Environment(loader = jinja2.FileSystemLoader('./templates')) template = env.get_template('index_files_template.html') data = { @@ -43,6 +45,33 @@ class GenerateReport: document = template.render(data) with open(output_path +"Index.html", 'w', encoding='utf-8') as index_html_file: index_html_file.write(document) + def _generate_failed_files_json_report(self, output_path, failed_file_list): + data = { + 'check_file_list' : failed_file_list + } + json_str = json.dumps(data,indent=1) + with open(output_path+'check_file_list.json', 'w' ,encoding='utf-8') as json_file: + json_file.write(json_str) + def _generate_total_files_json_report(self, output_path, total_file_info): + data = { + 'total_file_info' : total_file_info + } + json_str =json.dumps(data,indent=1) + with open(output_path+'total_file_list.json', 'w' ,encoding ='utf-8') as json_file: + json_file.write(json_str) + def _generate_summary_json_report(self, output_path, check_items, summary_data, total_file_info): + summary_data_dict = summary_data.__dict__ + check_items_dict = {} + for i in check_items: + check_items_dict[i._name] = i.__dict__ + data = { + 'summary_data' : summary_data_dict, + 'total_file_info' : total_file_info, + 'check_items' : check_items_dict, + } + json_str = json.dumps(data ,indent=1) + with open(output_path+'Index.json', 'w',encoding='utf-8') as json_file: + json_file.write(json_str) class CheckItemData: def __init__(self, name, do_check = CHECK_FALSE, check_flag = None): @@ -70,7 +99,7 @@ class CheckData: def _check_security(self, check_file_path, root_dir, check_items, summary_data, file_name_list, total_file_info): with open(check_file_path) as check_file: check_file_data = json.load(check_file) - for file_path in check_file_data['check_file_path']: + for file_path in check_file_data['check_file_path']: check_path = root_dir + file_path if not os.path.exists(check_path): print("check error: check file is not exist") @@ -105,7 +134,7 @@ class CheckData: check_items[i]._failed_list.append(file_info['filename']) else: check_items[i]._passed_list.append(file_info['filename']) - + def _generate_failed_files_data(self, check_items, summary_data, file_name_list, failed_file_list): for file_name in file_name_list: file_info = {} @@ -123,7 +152,7 @@ class CheckData: file_info[check_item._name] = CHECK_PASS if CHECK_FAILED in file_info.values(): failed_file_list.append(file_info) - summary_data._check_file_list_num = len(failed_file_list) + summary_data._check_file_list_num = len(failed_file_list) class HtmlTitle: _start_time = 0 @@ -140,7 +169,7 @@ def generate_failed_list(failed_file_list): with open('failed_list.txt', 'w') as txt_file: for failed_file_info in failed_file_list: txt_file.write(str(failed_file_info) + '\n') - + def get_file_size(file_size): if file_size < 1024: return str(round(file_size, 2)) + 'B' @@ -204,57 +233,57 @@ def add_parse(): required = True, type = str, help='output path to save the report') - + parser.add_argument( '--relro', type = str, help = 'set relro expected value and compare actual value with expected value') - + parser.add_argument( '--nx', type = str, help = 'set nx expected value and compare actual value with expected value') - + parser.add_argument( '--rpath', type = str, help = 'set rpath expected value and compare actual value with expected value') - + parser.add_argument( '--canary', type = str, help = 'set canary expected value and compare actual value with expected value') - + parser.add_argument( '--pie', type = str, help = 'set pie expected value and compare actual value with expected value') - + parser.add_argument( '--symbols', type = str, help = 'set symbols expected value and compare actual value with expected value') - + parser.add_argument( '--fortity', type = str, help = 'set fortity expected value and compare actual value with expected value') - + parser.add_argument( '--safestack', type = str, help = 'set safestack expected value and compare actual value with expected value') - + parser.add_argument( '--Clang_Cfi', type = str, help = 'set Clang-Cfi expected value and compare actual value with expected value') - + parser.add_argument( '--fortified', type = str, help = 'set fortified expected value and compare actual value with expected value') - + parser.add_argument( '--fortifiable', type = str, @@ -272,8 +301,8 @@ def main(): if root_dir[-1] == '/': root_dir = root_dir[:-1] check_data = CheckData() - check_items = [check_data._relro_check, check_data._canary_check, check_data._nx_check, check_data._pie_check, - check_data._clangcfi_check, check_data._clang_safestack_check, check_data._rpath_check, check_data._symbols_check, + check_items = [check_data._relro_check, check_data._canary_check, check_data._nx_check, check_data._pie_check, + check_data._clangcfi_check, check_data._clang_safestack_check, check_data._rpath_check, check_data._symbols_check, check_data._fortify_check, check_data._fortified_check, check_data._fortifiable_check] update_attributes(args, check_items) file_name_list = [] @@ -288,10 +317,15 @@ def main(): summary_data._execution_time = str(run_time) + 's' report = GenerateReport() - report._generate_summary_report(output_path, check_items, summary_data, total_file_info) - report._generate_total_files_report(output_path, total_file_info) - report._generate_failed_files_report(output_path, failed_file_list) + report._generate_summary_html_report(output_path, check_items, summary_data, total_file_info) + report._generate_total_files_html_report(output_path, total_file_info) + report._generate_failed_files_html_report(output_path, failed_file_list) + + report._generate_summary_json_report(output_path, check_items, summary_data, total_file_info) + report._generate_total_files_json_report(output_path, total_file_info) + report._generate_failed_files_json_report(output_path, failed_file_list) + generate_failed_list(failed_file_list) if __name__ == '__main__': - main() \ No newline at end of file + main() -- Gitee From 8edbd13922d37e9b6ccd355829054cae323feb6b Mon Sep 17 00:00:00 2001 From: yinwei <10306648+qq2235349717@user.noreply.gitee.com> Date: Fri, 12 Jan 2024 01:50:13 +0000 Subject: [PATCH 2/2] update llvm_test_script/checksec/check.py. Signed-off-by: yinwei <10306648+qq2235349717@user.noreply.gitee.com> --- llvm_test_script/checksec/check.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/llvm_test_script/checksec/check.py b/llvm_test_script/checksec/check.py index 2a7e91e..0b87bce 100644 --- a/llvm_test_script/checksec/check.py +++ b/llvm_test_script/checksec/check.py @@ -3,8 +3,6 @@ import os import time import datetime import argparse -import sys -sys.path.append('./third_party') import jinja2 CHECK_TRUE = 'true' -- Gitee