Created
September 15, 2017 01:07
-
-
Save iGlitch/981ea9a3bc8e721fadc1969f0a0b913c to your computer and use it in GitHub Desktop.
Patch New 3DS exclusives to work with Old 3DS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
n2o3ds by Glitch | |
convert new3ds exclusives to old3ds titles (perhaps) | |
run this on an extracted and decrypted main cxi | |
then rebuild the cia with: | |
makerom -f cia -o game.cia -target t -i 0.cxi:0:0 | |
you might need to use an older makerom as the newer ones tend to throw a -10 error | |
don't take this too seriously, most likely the games that work on old3ds are simplistic and sucky XD | |
''' | |
import hashlib, os, sys | |
buff="" | |
replace="" | |
smdh=0 | |
exefs=0 | |
SMDH=-1 | |
MB=1024*1024 | |
MAX_READ=32*MB | |
f=open(sys.argv[1],"rb+") | |
#print(hashlib.sha256(test).digest()) | |
def bytes2int(data): | |
u32=(ord(data[0])*1)+(ord(data[1])*0x100)+(ord(data[2])*0x10000)+(ord(data[3])*0x1000000) | |
return u32 | |
def patchByte(f, offset, data): | |
f.seek(offset) | |
f.write(data) | |
def updateSHA256(f, hash_offset, data_offset, length): | |
data="" | |
hash="" | |
f.seek(data_offset) | |
data=f.read(length) | |
hash=hashlib.sha256(data).digest() | |
f.seek(hash_offset) | |
f.write(hash) | |
def findSMDH(f): | |
global exefs | |
global smdh | |
f.seek(0x1A0) | |
bytes=f.read(4) | |
exefs=bytes2int(bytes) * 0x200 | |
f.seek(exefs+0x28) | |
bytes=f.read(4) | |
smdh=bytes2int(bytes) + 0x200 | |
f.seek(exefs + smdh) | |
bytes=f.read(4) | |
if bytes != "SMDH": | |
return -1 | |
return exefs + smdh | |
SMDH=findSMDH(f) | |
print(hex(smdh)) | |
f.seek(SMDH+0x2029) | |
buff=f.read(1) | |
buff=chr(ord(buff) & 0xEF) | |
f.seek(SMDH+0x2029) | |
f.write(buff) | |
updateSHA256(f, exefs+0x1A0, SMDH, 0x36c0) | |
updateSHA256(f, 0x1C0, exefs, 0x200) | |
f.seek(0x40E) | |
buff=f.read(1) | |
buff=chr(ord(buff) | 0x30) | |
patchByte(f,0x40E,buff) | |
updateSHA256(f, 0x160, 0x200, 0x400) | |
f.seek(0x80E) | |
buff=f.read(1) | |
buff=chr(ord(buff) | 0x30) | |
patchByte(f,0x80E,buff) | |
patchByte(f, 0x150, "C") | |
#patchByte(f, 0x10B, "\x00") | |
#patchByte(f, 0x11B, "\x00") | |
print(hex(SMDH)) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment