From 3f2546b2ef55b661fd8dd69682b38992225e86f6 Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Mon, 29 Apr 2019 01:17:54 +0100 Subject: Initial import of qemu-2.4.1 --- scripts/signrom.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/signrom.py (limited to 'scripts/signrom.py') diff --git a/scripts/signrom.py b/scripts/signrom.py new file mode 100644 index 00000000..f9c35ccf --- /dev/null +++ b/scripts/signrom.py @@ -0,0 +1,40 @@ +# +# Option ROM signing utility +# +# Authors: +# Jan Kiszka +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. + +import sys +import struct + +if len(sys.argv) < 3: + print('usage: signrom.py input output') + sys.exit(1) + +fin = open(sys.argv[1], 'rb') +fout = open(sys.argv[2], 'wb') + +fin.seek(2) +size = ord(fin.read(1)) * 512 - 1 + +fin.seek(0) +data = fin.read(size) +fout.write(data) + +checksum = 0 +for b in data: + # catch Python 2 vs. 3 differences + if isinstance(b, int): + checksum += b + else: + checksum += ord(b) +checksum = (256 - checksum) % 256 + +# Python 3 no longer allows chr(checksum) +fout.write(struct.pack('B', checksum)) + +fin.close() +fout.close() -- cgit v1.2.3