MalGraph/samples/funCount.py

32 lines
1.0 KiB
Python
Raw Normal View History

2023-12-28 17:01:36 +08:00
import json
from tqdm import tqdm
if __name__ == '__main__':
2024-01-05 14:30:45 +08:00
mal_file_name = './malware_result.jsonl'
ben_file_name = './benign-result.jsonl'
fil = open(mal_file_name, mode='r')
2023-12-28 17:01:36 +08:00
fun_name_dict = {}
2024-01-05 14:30:45 +08:00
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')
2023-12-28 17:01:36 +08:00
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
2024-01-05 14:30:45 +08:00
with open('./res.jsonl', 'w') as file:
for key, value in fun_name_dict.items():
temp = {"f_name": key, "count": value}
2023-12-28 17:01:36 +08:00
file.write(json.dumps(temp) + '\n')