2015-08-22 15:54:21 +08:00
|
|
|
#!/usr/bin/env python3
|
2015-06-28 08:10:45 +08:00
|
|
|
#
|
|
|
|
# This is free and unencumbered software released into the public domain.
|
2015-07-02 16:49:35 +08:00
|
|
|
#
|
2015-06-28 08:10:45 +08:00
|
|
|
# Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
|
|
# distribute this software, either in source code form or as a compiled
|
|
|
|
# binary, for any purpose, commercial or non-commercial, and by any
|
|
|
|
# means.
|
2015-06-06 20:01:37 +08:00
|
|
|
|
|
|
|
from sys import argv
|
|
|
|
|
2015-07-16 17:10:02 +08:00
|
|
|
binfile = argv[1]
|
|
|
|
nwords = int(argv[2])
|
|
|
|
|
|
|
|
with open(binfile, "rb") as f:
|
2015-06-06 20:01:37 +08:00
|
|
|
bindata = f.read()
|
|
|
|
|
2015-07-16 17:10:02 +08:00
|
|
|
assert len(bindata) < 4*nwords
|
2015-06-06 20:01:37 +08:00
|
|
|
assert len(bindata) % 4 == 0
|
|
|
|
|
2015-07-16 17:10:02 +08:00
|
|
|
for i in range(nwords):
|
2015-06-06 20:01:37 +08:00
|
|
|
if i < len(bindata) // 4:
|
|
|
|
w = bindata[4*i : 4*i+4]
|
|
|
|
print("%02x%02x%02x%02x" % (w[3], w[2], w[1], w[0]))
|
|
|
|
else:
|
|
|
|
print("0")
|
|
|
|
|