Skip to content

Commit

Permalink
bin to dump
Browse files Browse the repository at this point in the history
  • Loading branch information
jumploop committed Oct 14, 2023
1 parent b929bf7 commit 05a56b6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tools/bin2dump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import with_statement, print_function
import sys
import binascii

READ_BLOCKSIZE = 16

is_py3 = sys.version_info[0] == 3


def main(argv):
if len(argv) < 3:
print('Usage: {0} input_file output_file'.format(argv[0]))
sys.exit(1)
with open(argv[1], 'rb') as file_inp, open(argv[2], 'w') as file_out:
while True:
byte_s = file_inp.read(READ_BLOCKSIZE)
if not byte_s: break
hex_char_repr = binascii.hexlify(byte_s)
hex_char_repr = str(hex_char_repr, encoding='utf-8') if is_py3 else hex_char_repr
file_out.write(hex_char_repr)
file_out.write("\n")


if __name__ == '__main__':
main(sys.argv)

0 comments on commit 05a56b6

Please sign in to comment.