summaryrefslogtreecommitdiffstats
path: root/Src/osmolib/src/target_dsp/calypso/bin2cfile.py
diff options
context:
space:
mode:
authorTom2012-01-11 17:00:30 +0100
committerTom2012-01-11 17:00:30 +0100
commit9fcc469afa01fc9ea42e4cbb96c5b195c5bcd371 (patch)
tree89d4015f6a34119069665d74a67d871fcd124509 /Src/osmolib/src/target_dsp/calypso/bin2cfile.py
parentrefresh (diff)
downloadimsi-catcher-detection-9fcc469afa01fc9ea42e4cbb96c5b195c5bcd371.tar.gz
imsi-catcher-detection-9fcc469afa01fc9ea42e4cbb96c5b195c5bcd371.tar.xz
imsi-catcher-detection-9fcc469afa01fc9ea42e4cbb96c5b195c5bcd371.zip
all reupped
Diffstat (limited to 'Src/osmolib/src/target_dsp/calypso/bin2cfile.py')
-rw-r--r--Src/osmolib/src/target_dsp/calypso/bin2cfile.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/Src/osmolib/src/target_dsp/calypso/bin2cfile.py b/Src/osmolib/src/target_dsp/calypso/bin2cfile.py
new file mode 100644
index 0000000..9456a6a
--- /dev/null
+++ b/Src/osmolib/src/target_dsp/calypso/bin2cfile.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+import struct
+import sys
+
+def group_by_n(s, n, do_join=True):
+ return ( ''.join(x) for x in zip(*[s[i::n] for i in range(n)]) )
+
+
+def main(pn, filename):
+ # Get all bytes
+ f = open(filename, 'r')
+ d = f.read()
+ f.close()
+
+ # Get the data
+ ops = ''.join([
+ '0x%04x,%s' % (
+ struct.unpack('=H', x)[0],
+ '\n\t\t\t' if (i&3==3) else ' '
+ )
+ for i, x
+ in enumerate(group_by_n(d, 2))
+ ])[:-1]
+
+ ops = '\t\t\t' + ops
+ if ops[-1] == '\t':
+ ops = ops[:-4]
+
+ # Name
+ name = filename.split('.',1)[0]
+
+ # Header / footer
+ print """
+#define _SA_DECL (const uint16_t *)&(const uint16_t [])
+
+static const struct dsp_section %s[] = {
+ {
+ .addr = 0x,
+ .size = 0x%04x,
+ .data = _SA_DECL {
+%s
+ },
+ },
+ { /* Guard */
+ .addr = 0,
+ .size = 0,
+ .data = NULL,
+ },
+};
+
+#undef _SA_DECL
+""" % (name, len(d)/2, ops)
+
+
+if __name__ == "__main__":
+ main(*sys.argv)