def __lines(self, analyzer1_info: AnalyzerInfo, analyzer2_info: AnalyzerInfo, used_comparison=None): result_comparison = Comparison() self.__subproc_comparison_init(result_comparison, analyzer1_info, analyzer2_info) if not result_comparison.check_both_FileInfo_format(): return -1 # FileInfo actions BEGIN for file_info_an1 in analyzer1_info.info: file_info_an2 = analyzer2_info.search_by_file(file_info_an1.file) if isinstance(file_info_an2, int) and file_info_an2 == -1: continue for error_info_an1_ind in range(len(file_info_an1.errors)): for error_info_an2_ind in range(len(file_info_an2.errors)): if self.__subproc_lines_check_intersect( file_info_an1[error_info_an1_ind].lines, file_info_an2[error_info_an2_ind].lines, self.heuristic_params["distance"]): self.__subproc_result_comparison_binding_create( result_comparison, file_info_an1, file_info_an2, error_info_an1_ind, error_info_an2_ind) # FileInfo actions END result_comparison.stat_matrix_fill_by_bindings() return result_comparison
def __reaching_defs(self, analyzer1_info: AnalyzerInfo, analyzer2_info: AnalyzerInfo, used_comparison=None): result_comparison = Comparison() self.__subproc_comparison_init(result_comparison, analyzer1_info, analyzer2_info) if not result_comparison.check_both_FileInfo_format(): return -1 for file_info_an1 in analyzer1_info: file_info_an2 = analyzer2_info.search_by_file(file_info_an1.file) if isinstance(file_info_an2, int) and file_info_an2 == -1: continue cursor = create_cursor(file_info_an1.file) for error_an1_ind, error_an1 in enumerate(file_info_an1): var_er_an1 = self.__subproc_get_msg_leak_var( error_an1, analyzer1_info.analyzer_name) if var_er_an1 is None: continue line_er_an1 = error_an1.main_line cursor_er_an1 = reaching_var_def_by_line( cursor, var_er_an1, line_er_an1) for error_an2_ind, error_an2 in enumerate(file_info_an2): var_er_an2 = self.__subproc_get_msg_leak_var( error_an2, analyzer2_info.analyzer_name) if var_er_an2 is None: continue line_er_an2 = error_an2.main_line cursor_er_an2 = reaching_var_def_by_line( cursor, var_er_an2, line_er_an2) if cursor_er_an1 is None or cursor_er_an2 is None: continue if cursor_er_an2 == cursor_er_an1: self.__subproc_result_comparison_binding_create( result_comparison, file_info_an1, file_info_an2, error_an1_ind, error_an2_ind) result_comparison.stat_matrix_fill_by_bindings() return result_comparison
def __funcs(self, analyzer1_info: AnalyzerInfo, analyzer2_info: AnalyzerInfo, used_comparison=None): # TODO: fully implement and debug def __subproc_same_func_in_file_check(cursor: cl.Cursor, error_an1, error_an2): for child in cursor.get_children(): if child.kind == cl.CursorKind.FUNCTION_DECL: if child.extent.start.line <= error_an1.main_line <= child.extent.end.line and \ child.extent.start.line <= error_an2.main_line <= child.extent.end.line: return True result_comparison = Comparison() self.__subproc_comparison_init(result_comparison, analyzer1_info, analyzer2_info) if not result_comparison.check_both_FileInfo_format(): return -1 for file_info_an1 in analyzer1_info: file_info_an2 = analyzer2_info.search_by_file(file_info_an1.file) if isinstance(file_info_an2, int) and file_info_an2 == -1: continue cursor = create_cursor(file_info_an1.file) for error_info_an1_ind, error_an1 in enumerate(file_info_an1): for error_info_an2_ind, error_an2 in enumerate(file_info_an2): if __subproc_same_func_in_file_check( cursor, error_an1, error_an2): self.__subproc_result_comparison_binding_create( result_comparison, file_info_an1, file_info_an2, error_info_an1_ind, error_info_an2_ind) result_comparison.stat_matrix_fill_by_bindings() return result_comparison
def __files(self, analyzer1_info: AnalyzerInfo, analyzer2_info: AnalyzerInfo, used_comparison=None): result_comparison = Comparison() self.__subproc_comparison_init(result_comparison, analyzer1_info, analyzer2_info) if not result_comparison.check_both_FileInfo_format(): return -1 for file_info_an1 in analyzer1_info: #if file_info_an1.file == "/home/nick/C/testcases/CWE401_Memory_Leak/s01/CWE401_Memory_Leak__char_calloc_21.c": # print("HEH") file_info_an2 = analyzer2_info.search_by_file(file_info_an1.file) if isinstance(file_info_an2, int) and file_info_an2 == -1: continue for error_an1_ind, error_an1 in enumerate(file_info_an1): var_er_an1 = self.__subproc_get_msg_leak_var( error_an1, analyzer1_info.analyzer_name) for error_an2_ind, error_an2 in enumerate(file_info_an2): var_er_an2 = self.__subproc_get_msg_leak_var( error_an2, analyzer2_info.analyzer_name) if var_er_an1 == var_er_an2: self.__subproc_result_comparison_binding_create( result_comparison, file_info_an1, file_info_an2, error_an1_ind, error_an2_ind) result_comparison.stat_matrix_fill_by_bindings() return result_comparison
# Internal imports from projectLib.Comparison import Comparison from ProjectConfig import * juliet_res_dir = xml_source_path["juliet"] svace_res_dir = xml_source_path["svace"] cwe_num_list = cwe_num_list comparison = Comparison() comparison.load_comparison(comp_results_path["standard"], 2) comparison.print_comparison()
from projectLib.Comparison import Comparison from ProjectConfig import * comparison = Comparison() comparison.load_comparison(comp_results_path["standard"], 0) comparison.generate_svres_for_both(svres_gen_path["standard"], project_name_par="C", project_src_dir_par="/home/nick/C", ind=0)
def __syntax_construct(self, analyzer1_info: AnalyzerInfo, analyzer2_info: AnalyzerInfo, used_comparison=None): # SUBPROCEDURES BEGIN def __subfunc_search(node: clang.cindex.Cursor, lst: list): if node.kind in self.heuristic_params["statement_list"]: trace_unit = [] trace_unit.append(node.location.line) sub_stmts = list(node.get_children()) for el in sub_stmts: trace_unit.append(el.location.line) lst.append(trace_unit) for c in node.get_children(): __subfunc_search(c, lst) return # SUBPROCEDURES END result_comparison = Comparison() self.__subproc_comparison_init(result_comparison, analyzer1_info, analyzer2_info) if not result_comparison.check_both_FileInfo_format(): return -1 # FileInfo actions BEGIN for file_info_an1 in analyzer1_info: file_info_an2 = analyzer2_info.search_by_file(file_info_an1.file) if isinstance(file_info_an2, int) and file_info_an2 == -1: continue index = clang.cindex.Index.create() translation_unit = index.parse( file_info_an1.file, args=[self.heuristic_params["c++_version"]]) cursor = translation_unit.cursor syntax_constr_line_list = [] __subfunc_search(cursor, syntax_constr_line_list) for error_info_an1_ind in range(len(file_info_an1.errors)): for error_info_an2_ind in range(len(file_info_an2.errors)): if file_info_an1[error_info_an1_ind].type in self.heuristic_params["analyzer1_warn_types_list"] and \ file_info_an2[error_info_an2_ind].type in self.heuristic_params["analyzer2_warn_types_list"]: for statement_lines in syntax_constr_line_list: if self.__subproc_lines_check_intersect(file_info_an1[error_info_an1_ind].lines, statement_lines, 0) and \ self.__subproc_lines_check_intersect(file_info_an2[error_info_an2_ind].lines, statement_lines, 0): self.__subproc_result_comparison_binding_create( result_comparison, file_info_an1, file_info_an2, error_info_an1_ind, error_info_an2_ind) # FileInfo actions END result_comparison.stat_matrix_fill_by_bindings() return result_comparison
######################## comparison1 = Heuristic("reaching_defs", {}).\ compare_info_with_heuristic(copy.deepcopy(svace_info), copy.deepcopy(juliet_info)) ######################## comparison1.save_comparison(comp_results_path["standard"], 0) comparison2.save_comparison(comp_results_path["standard"], 1) print("COMPARISON GENERATION PART END") # COMPARISON GENERATION PART END # COMPARISON LOADING PART START print("COMPARISON LOADING PART START") comparison1 = Comparison() comparison2 = Comparison() comparison1.load_comparison(comp_results_path["standard"], 0) comparison2.load_comparison(comp_results_path["standard"], 1) print("COMPARISON LOADING PART END") # COMPARISON LOADING PART END # COMPARISON UNION INTERSECTION SUBSTRACTION PART BEGIN print("COMPARISON UNION INTERSECTION SUBSTRACTION PART BEGIN") print("COMPARISON 1") comparison1.group_comparison(type_groups["svace"], type_groups["juliet"]).print_comparison() print("COMPARISON 2") comparison2.group_comparison(type_groups["svace"],
from projectLib.Comparison import Comparison from ProjectConfig import * from projectLib.Heuristic import Heuristic # LINES GENERATION PART START print("COMPARISON GENERATION PART START") svace_info = AnalyzerInfo() svace_info.load_info(info_path["svace"], info_ind=1) juliet_info = AnalyzerInfo() juliet_info.load_info(info_path["juliet"], info_ind=1) comparison_lines = Heuristic("lines", {"distance": 0}).\ compare_info_with_heuristic(dc(svace_info), dc(juliet_info)) comparison_reaching_defs = Comparison() comparison_reaching_defs.load_comparison(comp_results_path["standard"], 3) comparison_union = comparison_reaching_defs.comparison_union(comparison_lines) comparison_lines.print_comparison() comparison_union.print_comparison() comparison_union.save_comparison(comp_results_path["standard"], 4) print("COMPARISON GENERATION PART END") print("SVRES GENERATION PART BEGIN") comparison_union.generate_svres_for_both( svres_gen_path["standard"], project_name_par=code_project_name,
# Internal imports from projectLib.Comparison import Comparison from ProjectConfig import * comparison = Comparison() comparison.load_comparison(comp_results_path["standard"], 0) comparison.group_comparison(type_groups["svace"], type_groups["juliet"]).print_comparison() comparison.analyze_comparison_buffer_overflow() comparison.print_comparison() comparison.group_comparison(type_groups["svace"], type_groups["juliet"]).print_comparison() comparison.save_comparison(res_dir=comp_results_path["standard"], comparison_id=5)
# Internal imports from projectLib.AnalyzerInfo import AnalyzerInfo from projectLib.Comparison import Comparison from ProjectConfig import * from projectLib.Heuristic import Heuristic # LINES GENERATION PART START print("COMPARISON GENERATION PART START") svace_info = AnalyzerInfo() svace_info.load_info(info_path["svace"], info_ind=0) juliet_info = AnalyzerInfo() juliet_info.load_info(info_path["juliet"], info_ind=0) comparison_initital = Comparison() comparison_initital.load_comparison(comp_results_path["standard"], 1) comparison = Heuristic("vars", {"type_groups": type_groups}).\ compare_info_with_heuristic(used_comparison=comparison_initital) comparison_initital.save_comparison(comp_results_path["standard"], 2) print("COMPARISON GENERATION PART END") print("SVRES GENERATION PART BEGIN") comparison_initital.generate_svres_for_both( svres_gen_path["standard"], project_name_par=code_project_name, project_src_dir_par=code_project_source_path, ind=2)