import os
import shutil
import json

SOURCE_DIR = 'I:/mwreports/malware/analyses'

dirs = os.listdir(SOURCE_DIR)
print(dirs)

fopen = open('dic_pku.json','r')
dic = eval(fopen.read())
fopen.close()

for idx, dir in enumerate(dirs):
    print(idx, len(dirs))
    fopen = open(os.path.join(SOURCE_DIR, dir, 'reports/report.json'), 'r')
    try:
        new_dict = json.load(fopen)
    except:
        print('打开json失败')
        continue
    # target = new_dict['target']
    md5 = new_dict['target']['file']['md5']
    label = dic[md5]['name'].split('.')[0]
    # dir = os.path.join(SOURCE_DIR, dir)
    if label == None:
        label = 'None'
    dic[md5]['sub_dir'] = dir

fwrite = open('dic_pku_add.json', 'w')
fwrite.write(str(dic))
fwrite.close()