import json from tqdm import tqdm if __name__ == '__main__': mal_file_name = './malware_result.jsonl' ben_file_name = './benign-result.jsonl' fil = open(mal_file_name, mode='r') fun_name_dict = {} for item in tqdm(fil): item = json.loads(item) item_fun_list = item['function_names'] for fun_name in item_fun_list: if fun_name_dict.get(fun_name) is not None: fun_name_dict[fun_name] += 1 else: fun_name_dict[fun_name] = 1 fil = open(mal_file_name, mode='r') for item in tqdm(fil): item = json.loads(item) item_fun_list = item['function_names'] for fun_name in item_fun_list: if fun_name_dict.get(fun_name) is not None: fun_name_dict[fun_name] += 1 else: fun_name_dict[fun_name] = 1 with open('./res.jsonl', 'w') as file: for key, value in fun_name_dict.items(): temp = {"f_name": key, "count": value} file.write(json.dumps(temp) + '\n')