aboutsummaryrefslogtreecommitdiff
path: root/tools/bin2h.py
diff options
context:
space:
mode:
authorTravis Geiselbrecht <geist@foobox.com>2015-09-02 14:24:00 -0700
committerTravis Geiselbrecht <geist@foobox.com>2015-09-02 17:11:51 -0700
commit78e0135169d2c53b0b99c7811109eb1da040f14d (patch)
tree2e396a91000b63c7830e0679fbfd6f323e1e5a3c /tools/bin2h.py
parent26104fb6d6b3baa738315af0c4951078cff5bf24 (diff)
downloadcommon-78e0135169d2c53b0b99c7811109eb1da040f14d.tar.gz
[tools] add bin2h.py
Quick little python tool to generate a .h file out of a raw binary.
Diffstat (limited to 'tools/bin2h.py')
-rwxr-xr-xtools/bin2h.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/bin2h.py b/tools/bin2h.py
new file mode 100755
index 00000000..52d4baee
--- /dev/null
+++ b/tools/bin2h.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# vim: set expandtab ts=4 sw=4 tw=100:
+
+import sys
+from optparse import OptionParser
+
+parser = OptionParser()
+parser.add_option("-b", "--before", dest="before", action="append",
+ help="text to put before, may be specified more than once")
+parser.add_option("-a", "--after", dest="after", action="append",
+ help="text to put after, may be specified more than once")
+(options, args) = parser.parse_args()
+
+if options.before and len(options.before) > 0:
+ for b in options.before:
+ print b
+
+offset = 0
+f = bytearray(sys.stdin.read())
+for c in f:
+ if offset != 0 and offset % 16 == 0:
+ print ""
+ print "%#04x," % c,
+ offset = offset + 1
+print ""
+
+if options.after and len(options.after) > 0:
+ for a in options.after:
+ print a
+