美文网首页
Hex编码的文件进行解码

Hex编码的文件进行解码

作者: CentForever | 来源:发表于2021-01-03 10:36 被阅读0次

Hex编码的文件进行解码

import sys
import os
import binascii



def ParseFile(_file, _outfile):
    outfile = open(_outfile,"wb")
    fp = open(_file, "rb")
    while True:  
        line = fp.readline()  
        if line:  
            pass    # do something here
            outfile.write(binascii.a2b_hex(line.strip().encode('utf8'))
            print('*******************************')
        else:  
            break
    outfile.close()
    fp.close()
    
def main(args):
    global lastseq

    if 1==len(args):
        if os.path.isdir(args[0]):
            filelist = glob.glob(args[0] + "/*.Hlog")
            for filepath in filelist:
                lastseq = 0
                ParseFile(filepath, filepath+".log")
        else: ParseFile(args[0], args[0]+".log")    
    elif 2==len(args):
        ParseFile(args[0], args[1])    
    else: 
        filelist = glob.glob("*.Hlog")
        for filepath in filelist:
            lastseq = 0
            ParseFile(filepath, filepath+".log")

if __name__ == "__main__":
    main(sys.argv[1:])

相关文章

网友评论

      本文标题:Hex编码的文件进行解码

      本文链接:https://www.haomeiwen.com/subject/kiognktx.html