Advertisement
Guest User

Untitled

a guest
Jun 16th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. import sys
  2. import binascii
  3. import os
  4. import ctypes
  5. import struct
  6.  
  7. if(len(sys.argv) is not 3):
  8.     sys.exit('usage: mainRenamer.py "pathToFile\\fileName.bin" newTitleId')
  9.  
  10. fileIn = sys.argv[1]
  11. newTitleId = struct.pack("<Q",int(sys.argv[2],16))
  12.  
  13. base = os.path.splitext(fileIn)[0]
  14. fileOut =  base+".tmp"
  15.  
  16.  
  17. readBytes = int(0)
  18. aci0Off = -0xFFFFF
  19.  
  20. metaString = ""
  21. aciString = ""
  22. with open(fileIn, "rb") as f:
  23.     with open(fileOut, "wb") as n:
  24.         chunk = 1
  25.         while True:        
  26.             if chunk:
  27.                 if readBytes == 0:
  28.                     chunk = f.read(4)
  29.                     n.write(chunk)
  30.                     readBytes += 4
  31.                     metaString = chunk.decode("utf-8")
  32.                 elif readBytes == 0x70:
  33.                     chunk = f.read(4)
  34.                     n.write(chunk)
  35.                     readBytes += 4
  36.                     aci0Off = struct.unpack("<l", chunk)[0]
  37.                 elif readBytes == aci0Off:
  38.                     chunk = f.read(4)
  39.                     n.write(chunk)
  40.                     readBytes += 4
  41.                     aciString = chunk.decode("utf-8")
  42.                 elif readBytes == (aci0Off + 0x10):
  43.                     chunk = f.read(8)
  44.                     print("old Title Id: "+ hex(struct.unpack("<Q", chunk)[0]).rstrip("L").lstrip("0x").upper())
  45.                     print("new Title Id: "+ hex(struct.unpack("<Q", newTitleId)[0]).rstrip("L").lstrip("0x").upper())
  46.                     readBytes += 8
  47.                     n.write(newTitleId)    
  48.                 else:
  49.                     chunk = f.read(1)
  50.                     readBytes += 1
  51.                     if chunk:
  52.                         n.write(chunk)
  53.                 #print(readBytes)  
  54.             else:
  55.                 break
  56.         n.close()
  57.     f.close()
  58.  
  59. if not (metaString == "META" and aciString == "ACI0"):
  60.     print("Error Wrong File Format")
  61. else:
  62.     os.rename(fileIn, base+".npdm.bak")
  63.     os.rename(fileOut, base+".npdm")
  64.     print("New TitleId written")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement