| 1 | # |
| 2 | # Copyright (C) 2006 Steve Ratcliffe |
| 3 | # |
| 4 | # This program is free software; you can redistribute it and/or modify |
| 5 | # it under the terms of the GNU General Public License version 2 as |
| 6 | # published by the Free Software Foundation. |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | # GNU General Public License for more details. |
| 12 | # |
| 13 | # |
| 14 | # Author: Steve Ratcliffe |
| 15 | # Create date: 10 Dec 2006 |
| 16 | # |
| 17 | |
| 18 | # |
| 19 | # Sets the check sum for the file. It is possible that the check sum |
| 20 | # is not actually checked by anything. |
| 21 | # |
| 22 | |
| 23 | import sys |
| 24 | |
| 25 | file = sys.argv[1] |
| 26 | print "file is", file |
| 27 | |
| 28 | f = open(file) |
| 29 | |
| 30 | cksum = 0 |
| 31 | while 1: |
| 32 | block = f.read(512) |
| 33 | if not block: break |
| 34 | for c in block: |
| 35 | cksum -= ord(c) |
| 36 | |
| 37 | cksum = (cksum & 0xff) |
| 38 | print "checksum is", cksum, hex(cksum) |
| 39 | |
| 40 | if cksum != 0: |
| 41 | fw = open(file, "r+b") |
| 42 | fw.seek(15) |
| 43 | print "setting checksum, please re-check afterwards" |
| 44 | ch = chr(cksum) |
| 45 | print 'chr', ord(ch) |
| 46 | fw.write(ch) |
| 47 | fw.close() |
| 48 |