SHARE
TWEET

BS-X SRAM Checksum Fixer

LuigiBlood Aug 15th, 2015 188 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from struct import *
  2. import sys
  3. print "BS-X SRAM Checksum Fixer v0.2"
  4. print "By LuigiBlood/Seru-kun"
  5. #Usage: CHKFIX.py [-f] <SRAM File>
  6. #  -f = Fix Checksum
  7.  
  8. #12287
  9. if sys.argv[1] == "-f" and sys.argv[2] <> "" :
  10.    FILE = sys.argv[2]
  11. elif sys.argv[1] <> "-f" and sys.argv[1] <> "" :
  12.    FILE = sys.argv[1]
  13.  
  14. if FILE <> "" and sys.argv[1] == FILE :
  15.    SRAM = open(FILE,"r+b")
  16.    CHK = 0
  17.    CHK2 = 0
  18.    OFFSET = int("2fff", 16)
  19.    SRAM.seek(4)
  20.    OLD=ord(SRAM.read(1))+ord(SRAM.read(1))*256
  21.    print "Checksum : " + hex(OLD)
  22.    SRAM.seek(2)
  23.    OLDR=ord(SRAM.read(1))+ord(SRAM.read(1))*256
  24.    print "Reversed Checksum : " + hex(OLDR)
  25. elif FILE <> "" and sys.argv[1] == "-f" and sys.argv[2] == FILE :
  26.    SRAM = open(FILE,"r+b")
  27.    CHK = 0
  28.    CHK2 = 0
  29.    A = 0
  30.    OFFSET = int("fff", 16)
  31.    SRAM.seek(4)
  32.    OLD=ord(SRAM.read(1))+ord(SRAM.read(1))*256
  33.    print "Checksum : " + hex(OLD)
  34.    SRAM.seek(2)
  35.    OLDR=ord(SRAM.read(1))+ord(SRAM.read(1))*256
  36.    print "Reversed Checksum : " + hex(OLDR)
  37.    SRAM.seek(2)
  38.    SRAM.write(chr(255))
  39.    SRAM.write(chr(255))
  40.    SRAM.write(chr(0))
  41.    SRAM.write(chr(0))
  42.    print "Checksum Removed, calculating..."
  43.    while OFFSET >= 0:
  44.        SRAM.seek(OFFSET)
  45.        A = ord(SRAM.read(1))
  46.        A += CHK
  47.        CHK = A
  48.        SRAM.seek(OFFSET + int("1000", 16))
  49.        A = ord(SRAM.read(1))
  50.        A += CHK
  51.        CHK = A
  52.        SRAM.seek(OFFSET + int("2000", 16))
  53.        A = ord(SRAM.read(1))
  54.        A += CHK
  55.        CHK = A
  56.        OFFSET -= 1
  57.  
  58.    SRAM.seek(2)
  59.    CHK2 = CHK & int("ffff", 16)
  60.    print "NEW Checksum : " + hex(CHK2)
  61.    RCHK = CHK2 ^ int("ffff", 16)
  62.    print "NEW Reversed Checksum : " + hex(RCHK)
  63.    print "Replacing Checksums..."
  64.    SRAM.write(pack("H", RCHK))
  65.    SRAM.write(pack("H", CHK2))
  66.    print "Done !"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top