def async_get_funcs(file_name, use_ghidra=True): if use_ghidra: ret_list = gh.get_function_information(file_name) else: ret_list = fh.get_function_information(file_name) for func in ret_list: func['file_name'] = file_name return ret_list
def get_sparse_file_data(file_name): info = get_function_information(file_name) #arg_info = get_arg_funcs(file_item) #trimmed = trim_funcs(arg_info) if info: trimmed = trim_funcs(info, file_name=file_name) else: trimmed = [] return trimmed
def get_vulnerabilities(file_name, ld_path): print("[+] Getting argument functions") if use_ghidra: arg_funcs = fh.get_function_information(file_name) else: arg_funcs = fh.get_arg_funcs(file_name) for func in arg_funcs: func['file_name'] = file_name arg_funcs = fix_functions(arg_funcs) #arg_funcs = [x for x in arg_funcs if 'mtd_write_firmware' in x['name']] print("[+] Analyzing {} functions".format(len(arg_funcs))) return get_bugs_from_functions(arg_funcs, ld_path)
def test(): parser = argparse.ArgumentParser() parser.add_argument("File") args = parser.parse_args() info = fh.get_function_information(args.File) #info = fh.get_arg_funcs(args.File) info = trim_funcs(info, args.File) vect, func_sparse = funcs_to_sparse(info) transformer = Normalizer().fit(func_sparse) func_sparse = transformer.transform(func_sparse) #svd = TruncatedSVD(random_state=2) svd = TruncatedSVD(n_components=5, n_iter=7, random_state=42) func_sparse = svd.fit_transform(func_sparse) scores = [] clust_count = [] for x in range(2, 20): result = KMeans(n_clusters=x, random_state=2).fit(func_sparse) score = silhouette_score(func_sparse, result.labels_, metric="cosine") scores.append(score) clust_count.append(x) print("Clusters {:<3} | Silhoette Score : {}".format(x, score)) plt.plot(clust_count, scores) plt.xlabel("Cluster Centroid Count") plt.ylabel("Silhoette Score") plt.grid = True plt.show() pass