Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import binascii
- import os
- import ctypes
- import struct
- if(len(sys.argv) is not 3):
- sys.exit('usage: mainRenamer.py "pathToFile\\fileName.bin" newTitleId')
- fileIn = sys.argv[1]
- newTitleId = struct.pack("<Q",int(sys.argv[2],16))
- base = os.path.splitext(fileIn)[0]
- fileOut = base+".tmp"
- readBytes = int(0)
- aci0Off = -0xFFFFF
- metaString = ""
- aciString = ""
- with open(fileIn, "rb") as f:
- with open(fileOut, "wb") as n:
- chunk = 1
- while True:
- if chunk:
- if readBytes == 0:
- chunk = f.read(4)
- n.write(chunk)
- readBytes += 4
- metaString = chunk.decode("utf-8")
- elif readBytes == 0x70:
- chunk = f.read(4)
- n.write(chunk)
- readBytes += 4
- aci0Off = struct.unpack("<l", chunk)[0]
- elif readBytes == aci0Off:
- chunk = f.read(4)
- n.write(chunk)
- readBytes += 4
- aciString = chunk.decode("utf-8")
- elif readBytes == (aci0Off + 0x10):
- chunk = f.read(8)
- print("old Title Id: "+ hex(struct.unpack("<Q", chunk)[0]).rstrip("L").lstrip("0x").upper())
- print("new Title Id: "+ hex(struct.unpack("<Q", newTitleId)[0]).rstrip("L").lstrip("0x").upper())
- readBytes += 8
- n.write(newTitleId)
- else:
- chunk = f.read(1)
- readBytes += 1
- if chunk:
- n.write(chunk)
- #print(readBytes)
- else:
- break
- n.close()
- f.close()
- if not (metaString == "META" and aciString == "ACI0"):
- print("Error Wrong File Format")
- else:
- os.rename(fileIn, base+".npdm.bak")
- os.rename(fileOut, base+".npdm")
- print("New TitleId written")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement