add BinToMem_CLI.exe source file

Signed-off-by: liangkangnan <liangkangnan@163.com>
pull/1/head
liangkangnan 2019-12-08 18:42:15 +08:00
parent 2788fb395e
commit e162e68385
1 changed files with 44 additions and 0 deletions

44
tools/BinToMem_CLI.py Normal file
View File

@ -0,0 +1,44 @@
import sys
import os
def bin_to_mem(infile, outfile):
binfile = open(infile, 'rb')
binfile_content = binfile.read(os.path.getsize(infile))
datafile = open(outfile, 'w')
index = 0
b0 = 0
b1 = 0
b2 = 0
b3 = 0
for b in binfile_content:
if index == 0:
b0 = b
index = index + 1
elif index == 1:
b1 = b
index = index + 1
elif index == 2:
b2 = b
index = index + 1
elif index == 3:
b3 = b
index = 0
array = []
array.append(b3)
array.append(b2)
array.append(b1)
array.append(b0)
datafile.write(bytearray(array).hex() + '\n')
binfile.close()
datafile.close()
if __name__ == '__main__':
if len(sys.argv) == 3:
bin_to_mem(sys.argv[1], sys.argv[2])
else:
print('Usage: %s binfile datafile' % sys.argv[0], sys.argv[1], sys.argv[2])