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:])
网友评论