Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #arg1 : CTRFAT image filename
- #arg2 : CTRFAT XORpad filename
- #change physical drive
- #use at your own risk (wrong PD could mean losing data)
- import os
- import sys
- SECTOR_SIZE = 0x200
- MULTIPLE = 0x50
- print("opening device...")
- drive = open("\\\\.\\PhysicalDrive1","rb+")
- drive.seek(SECTOR_SIZE*0x3CA800)
- #check
- print("checking device...")
- sector=bytearray(drive.read(SECTOR_SIZE))
- check=open("checkSector.bin", "rb").read()
- if(sector!=check):
- print("sector0 doesn't match !")
- exit(1)
- print("device confirmed.")
- #write our shit
- drive.seek(SECTOR_SIZE*(0x3CA800+0x5CAE5))
- src1fn=sys.argv[1] # nand image (CTRFAT)
- src2fn=sys.argv[2] # xorpad
- print("writing...")
- k=0
- with open(src1fn, "rb") as f1:
- with open(src2fn, "rb") as f2:
- sector = bytearray(f1.read(SECTOR_SIZE*MULTIPLE))
- sectorXOR = bytearray(f2.read(SECTOR_SIZE*MULTIPLE))
- while sector != b"" and sectorXOR != b"":
- # XORing here is uber slow
- for i in range(len(sector)):
- sector[i]=sector[i]^sectorXOR[i]
- drive.write(sector)
- sys.stdout.write("Write progress: %f%% (sector %s) \r" % (float(100*k)/0x179F1B, hex(k)) ); sys.stdout.flush();
- sector = bytearray(f1.read(SECTOR_SIZE*MULTIPLE))
- sectorXOR = bytearray(f2.read(SECTOR_SIZE*MULTIPLE))
- k+=MULTIPLE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement