summaryrefslogtreecommitdiffstats
path: root/scripts/specBytesToCode.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:24:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:24:41 +0000
commita9bcc81f821d7c66f623779fa5147e728eb3c388 (patch)
tree98676963bcdd537ae5908a067a8eb110b93486a6 /scripts/specBytesToCode.py
parentInitial commit. (diff)
downloadfreerdp3-a9bcc81f821d7c66f623779fa5147e728eb3c388.tar.xz
freerdp3-a9bcc81f821d7c66f623779fa5147e728eb3c388.zip
Adding upstream version 3.3.0+dfsg1.upstream/3.3.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts/specBytesToCode.py')
-rw-r--r--scripts/specBytesToCode.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/scripts/specBytesToCode.py b/scripts/specBytesToCode.py
new file mode 100644
index 0000000..cee7437
--- /dev/null
+++ b/scripts/specBytesToCode.py
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+#
+# A script to convert blob from the MS spec to array of byte to use in unitary tests
+#
+# 00000000 c7 01 00 01 20 54 e2
+# 00000008 c7 01 00 01 20 54 e2
+# taken from the spec, will give:
+# 0xc7, 0x01, 0x00, 0x01, 0x20, 0x54, 0xe2,
+# 0xc7, 0x01, 0x00, 0x01, 0x20, 0x54, 0xe2,
+#
+# Notes:
+# * the script reads the two first lines to detect the number of items per lines, so you need a blob with at least 2 lines
+# * the script detects if items are hex values by searching for + or -
+#
+# sample usage:
+# $ python scripts/specBytesToCode.py < image.txt > image.c
+# then go edit image.c and paste that in your code
+import sys
+
+
+def getOffset(l):
+ token = l.split(' ')[0]
+ return int(token, 16)
+
+def isHex(l):
+ return l.find('+') == -1 and l.find('-') == -1
+
+if __name__ == '__main__':
+
+ lines = []
+ itemPerLine = 16
+ doHex = True
+
+ # parse the offset to know how many items per line we have
+ l1 = sys.stdin.readline().strip()
+ l2 = sys.stdin.readline().strip()
+ itemsPerLine = getOffset(l2) - getOffset(l1)
+
+ #
+ doHex = isHex(l1)
+
+ for l in [l1, l2] + sys.stdin.readlines():
+ # 00000000 c7 01 00 01 20 54 e2 cc 00 jh.kjkjhkhk
+ l = l.strip() # in case we have spaces before the offset
+ pos = l.find(' ')
+ l = l[pos+1:]
+ items = []
+
+ tokens = l.strip().split(' ')
+ ntokens = 0
+ for t in tokens:
+ if not t: # empty token
+ continue
+
+ if ntokens == itemPerLine:
+ break
+
+ item = ''
+ if doHex:
+ item += '0x'
+ item += t
+
+ items.append(item)
+
+ ntokens += 1
+
+ lines.append(', '.join(items))
+
+ print(",\n".join(lines))