Advertisement
Jhynjhiruu

Very WIP

May 16th, 2018
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.40 KB | None | 0 0
  1. import subprocess
  2. import sys
  3. import pathlib
  4. import binascii
  5. settings = []
  6. def flushSettings():
  7.     with open("settings.ids", "w") as f:
  8.         f.write("\n".join(settings))
  9. try:
  10.     with open("settings.ids") as f:
  11.         [settings.append(line.rstrip("\n")) for line in f]
  12. except:
  13.     with open("settings.ids", "a") as f:
  14.         [f.write("False\n") for i in range(10)]
  15.         [settings.append("False") for i in range(10)]
  16. if settings[0] == "False":
  17.     commands = ["B", "3 005d1870.rec", "3 recrypt.sys", "q"]
  18.     exe = subprocess.Popen("ique_diag.exe", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  19.     toStdin = "\n".join(commands)
  20.     print("Dumping necessary files... (This will only be done once)")
  21.     returned = exe.communicate(input=bytes(toStdin.encode("utf-8")))
  22.     for i in returned[0].decode("utf-8").split("\n"):
  23.         if "__BBC_CheckHandle" in i:
  24.             input("Make sure your iQue Player is connected to your VM. Press enter to exit...")
  25.             sys.exit()
  26.         elif "FFFFFFF" in i:
  27.             input("Please play Dr. Mario at least once before using this program. Press enter to exit...")
  28.     print("Necessary file dump finished.")
  29.     plaintext = pathlib.Path("005d1870.z64")
  30.     plaintextPath = "005d1870.z64"
  31.     if not plaintext.is_file():
  32.         while True:
  33.             plaintextPath = str(input("Please enter the path to a Dr. Mario plaintext ROM, in .z64 format:\n"))
  34.             if plaintextPath.split(".")[-1] == ".z64":
  35.                 break
  36.             else:
  37.                 print("Invalid ROM")
  38.     print("Patching Dr. Mario .rec... (This will only be done once)")
  39.     subprocess.call(["ique_cbc_attack.exe", "-p", plaintextPath, "-r", "005d1870.rec", "-d", "081F0000000000000000000000000000", "-o", "1000"])
  40.     commands = ["B", "4 005d1870.rec", "4 005d1870.sta", "q"]
  41.     exe = subprocess.Popen("ique_diag.exe", stdin=subprocess.PIPE)
  42.     toStdin = "\n".join(commands)
  43.     print("Flashing patched Dr. Mario back to your iQue Player... (This will only be done once)")
  44.     exe.communicate(input=bytes(toStdin.encode("utf-8")))
  45.     print("Done!")
  46.     settings[0] = "True"
  47.     flushSettings()
  48. if settings[1] == "False":
  49.     input("You must now open Dr. Mario. Turn off your iQue Player, unplug the USB cable, turn your iQue Player on, open Dr. Mario. Wait approximately 10 seconds, then reset your iQue Player. When the menu appears, turn off your iQue Player, connect the USB cable, and turn it on. If you're using a VM, make sure that your iQue Player is correctly connected to your VM before continuing.")
  50.     commands = ["B", "3 005d1870.sta", "q"]
  51.     exe = subprocess.Popen("ique_diag.exe", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  52.     toStdin = "\n".join(commands)
  53.     print("Dumping file... (This will only be done once)")
  54.     returned = exe.communicate(input=bytes(toStdin.encode("utf-8")))
  55.     for i in returned[0].decode("utf-8").split("\n"):
  56.         if "__BBC_CheckHandle" in i:
  57.             input("Make sure your iQue Player is connected to your VM. Press enter to exit...")
  58.             sys.exit()
  59.     v2 = bytearray(open("005d1870.sta", 'rb').read())
  60.     v2_bytes = []
  61.     for i in v2:
  62.         v2_bytes.append(hex(i).lstrip("0x").upper().zfill(2))
  63.     with open("v2.bin", 'wb') as output:
  64.         bytes_towrite = binascii.a2b_hex(''.join(v2_bytes[1536:1792]))
  65.         output.write(bytes_towrite)
  66.     settings[1] = "True"
  67.     flushSettings()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement