Advertisement
Guest User

2old.py

a guest
Mar 4th, 2019
8,288
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. '''
  2. 2old by zoogie
  3. convert new3ds exclusives to old3ds titles (maybe)
  4.  
  5. run this on an extracted and decrypted main cxi
  6. then rebuild the cia with:
  7. makerom -f cia -o game.cia -target t -i 0.cxi:0:0
  8. you might need to use an older makerom as the newer ones tend to throw a -10 error
  9. don't take this too seriously, most likely the games that work on old3ds are simplistic and sucky XD
  10. '''
  11. import hashlib, os, sys
  12. buff=""
  13. replace=""
  14. smdh=0
  15. exefs=0
  16. SMDH=-1
  17. MB=1024*1024
  18. MAX_READ=32*MB
  19.  
  20.  
  21. f=open(sys.argv[1],"rb+")
  22. #print(hashlib.sha256(test).digest())
  23.  
  24. def bytes2int(data):
  25.     u32=(ord(data[0])*1)+(ord(data[1])*0x100)+(ord(data[2])*0x10000)+(ord(data[3])*0x1000000)
  26.     return u32
  27.  
  28. def patchByte(f, offset, data):
  29.     f.seek(offset)
  30.     f.write(data)
  31.    
  32. def updateSHA256(f, hash_offset, data_offset, length):
  33.     data=""
  34.     hash=""
  35.     f.seek(data_offset)
  36.     data=f.read(length)
  37.     hash=hashlib.sha256(data).digest()
  38.     f.seek(hash_offset)
  39.     f.write(hash)
  40.    
  41. def findSMDH(f):
  42.     global exefs
  43.     global smdh
  44.    
  45.     f.seek(0x1A0)
  46.     bytes=f.read(4)
  47.     exefs=bytes2int(bytes) * 0x200
  48.    
  49.     f.seek(exefs+0x28)
  50.     bytes=f.read(4)
  51.     smdh=bytes2int(bytes) + 0x200
  52.    
  53.     f.seek(exefs + smdh)
  54.     bytes=f.read(4)
  55.     if bytes != "SMDH":
  56.         return -1
  57.        
  58.     return exefs + smdh
  59.    
  60. SMDH=findSMDH(f)
  61. print(hex(smdh))
  62.  
  63. f.seek(SMDH+0x2029)
  64. buff=f.read(1)
  65. buff=chr(ord(buff) & 0xEF)
  66. f.seek(SMDH+0x2029)
  67. f.write(buff)
  68.  
  69. updateSHA256(f, exefs+0x1A0, SMDH, 0x36c0)
  70. updateSHA256(f, 0x1C0, exefs, 0x200)
  71.  
  72. f.seek(0x40E)
  73. buff=f.read(1)
  74. buff=chr(ord(buff) | 0x30)
  75. patchByte(f,0x40E,buff)
  76.  
  77. updateSHA256(f, 0x160, 0x200, 0x400)
  78.  
  79. f.seek(0x80E)
  80. buff=f.read(1)
  81. buff=chr(ord(buff) | 0x30)
  82. patchByte(f,0x80E,buff)
  83.  
  84. patchByte(f, 0x150, "C")
  85. #patchByte(f, 0x10B, "\x00")
  86. #patchByte(f, 0x11B, "\x00")
  87.  
  88. print(hex(SMDH))
  89. f.close()
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement