TODO: 增加描述
import os, sys, datetime, time
def save_file(content):
filename = "out" + datetime.datetime.now().strftime('%Y%m%d%H%M%S.log')
fp_out = open(filename, 'w+')
fp_out.write(content)
fp_out.close()
def read_file(argv):
if len(argv) != 4:
print("parameter error")
os._exit(0)
input_file = argv[1]
if argv[2].find('0x') < 0:
start_address = int(argv[2])
else:
start_address = int(sys.argv[2], 16)
if argv[3].find('0x') < 0:
read_size = int(argv[3])
else:
read_size = int(sys.argv[3], 16)
fp_in = open(input_file, 'r')
fp_in.seek(start_address, 0)
text = fp_in.read(read_size)
save_file(text)
fp_in.close()
print("dump OK")
os._exit(0)
if __name__ == "__main__":
try:
read_file(sys.argv)
finally:
print "exception catched"
os._exit(0)
命令:
python main.py ~/customer/coolkit/err.bin 64 0x38
第三个和第四个参数, 十六进制和十进制均可.