__author__ = 'ASUS'

from creatAsm.getFileOpcode import *
from creatAsm.getNgramOpcode import *
import csv
def creatNgramcsv(filename,pathdir,srcpath):
    filepath = srcpath + '/' + filename
    #print ('生成的asm文件位置：',filepath)
    ops = getOpcodeSequence(filepath)
    countered_dict = getOpcodeNgram(ops,3)
    keys = countered_dict.keys()
    count = 0
    for key in keys:
        count += countered_dict[key]
    keys = countered_dict.keys()
    path = pathdir + '/' + filename.split('.')[0] + '.csv'
    with open(path,'w',newline='') as file:
        writer = csv.writer(file)
        writer.writerow([count])
        for key in keys:
            count += countered_dict[key]
            writer.writerow([list(key)[0],list(key)[1],list(key)[2],countered_dict[key]])