mirror of
https://github.com/ahezard/twl_firm_patcher.git
synced 2025-06-18 13:25:33 -04:00
Extraction of devLauncher ok
This commit is contained in:
parent
71be611c4c
commit
0a44fa2ca7
7
go.cmd
Normal file
7
go.cmd
Normal file
@ -0,0 +1,7 @@
|
||||
cp input\firmware_twl.bin temp\
|
||||
|
||||
cd scripts
|
||||
|
||||
extract_dev_launcher.cmd
|
||||
|
||||
pause
|
3
scripts/Modcrypt.cmd
Normal file
3
scripts/Modcrypt.cmd
Normal file
@ -0,0 +1,3 @@
|
||||
@Echo off
|
||||
TWLTool modcrypt --in %1
|
||||
pause
|
120
scripts/build_firm_bin_from_twlbg_cxi.py
Normal file
120
scripts/build_firm_bin_from_twlbg_cxi.py
Normal file
@ -0,0 +1,120 @@
|
||||
# -*- coding: utf8 -*-
|
||||
# Patch an .nds (works with homebrew and ds demo only) to make it ready for make_cia
|
||||
#
|
||||
# 2016-02-28, Ahezard
|
||||
#
|
||||
# inspired by
|
||||
# Apache Thunder .nds edited files and comments
|
||||
# https://github.com/Relys/Project_CTR/blob/master/makerom/srl.h
|
||||
# https://dsibrew.org/wiki/DSi_Cartridge_Header
|
||||
# if the header size of the input nds file is 0x200 (homebrew)
|
||||
# the header size of the output nds file will be patched to 0x4000 (normal ds/dsi header), 0x3E00 offset
|
||||
|
||||
from struct import *
|
||||
from collections import namedtuple
|
||||
from collections import OrderedDict
|
||||
from pprint import pprint
|
||||
import os, sys
|
||||
import binascii
|
||||
import argparse
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='create the twl_firm bin from twl_bg.cxi section')
|
||||
parser.add_argument('--firm', help='firm file to patch')
|
||||
parser.add_argument('--cxi', help='cxi to insert')
|
||||
parser.add_argument('--out', help='output firm file')
|
||||
args = parser.parse_args()
|
||||
|
||||
#
|
||||
# CRC16 MODULE
|
||||
#
|
||||
# includes CRC16 and CRC16 MODBUS
|
||||
#
|
||||
|
||||
from ctypes import c_ushort
|
||||
|
||||
# from https://github.com/cristianav/PyCRC/blob/master/demo.py
|
||||
class CRC16(object):
|
||||
crc16_tab = []
|
||||
|
||||
# The CRC's are computed using polynomials. Here is the most used
|
||||
# coefficient for CRC16
|
||||
crc16_constant = 0xA001 # 40961
|
||||
|
||||
def __init__(self, modbus_flag=False):
|
||||
# initialize the precalculated tables
|
||||
if not len(self.crc16_tab):
|
||||
self.init_crc16()
|
||||
self.mdflag = bool(modbus_flag)
|
||||
|
||||
def calculate(self, input_data=None):
|
||||
try:
|
||||
is_string = isinstance(input_data, str)
|
||||
is_bytes = isinstance(input_data, (bytes, bytearray))
|
||||
|
||||
if not is_string and not is_bytes:
|
||||
raise Exception("Please provide a string or a byte sequence "
|
||||
"as argument for calculation.")
|
||||
|
||||
crc_value = 0x0000 if not self.mdflag else 0xffff
|
||||
|
||||
for c in input_data:
|
||||
d = ord(c) if is_string else c
|
||||
tmp = crc_value ^ d
|
||||
rotated = crc_value >> 8
|
||||
crc_value = rotated ^ self.crc16_tab[(tmp & 0x00ff)]
|
||||
|
||||
return crc_value
|
||||
except Exception as e:
|
||||
print("EXCEPTION(calculate): {}".format(e))
|
||||
|
||||
def init_crc16(self):
|
||||
"""The algorithm uses tables with precalculated values"""
|
||||
for i in range(0, 256):
|
||||
crc = c_ushort(i).value
|
||||
for j in range(0, 8):
|
||||
if crc & 0x0001:
|
||||
crc = c_ushort(crc >> 1).value ^ self.crc16_constant
|
||||
else:
|
||||
crc = c_ushort(crc >> 1).value
|
||||
self.crc16_tab.append(crc)
|
||||
|
||||
def getSize(fileobject):
|
||||
current = fileobject.tell()
|
||||
fileobject.seek(0,2) # move the cursor to the end of the file
|
||||
size = fileobject.tell()
|
||||
fileobject.seek(current,0)
|
||||
return size
|
||||
|
||||
def skipUntilAddress(f_in,f_out, caddr, taddr):
|
||||
chunk = f_in.read(taddr-caddr)
|
||||
f_out.write(chunk)
|
||||
|
||||
def writeBlankuntilAddress(f_out, caddr, taddr):
|
||||
f_out.write("\x00"*(taddr-caddr))
|
||||
|
||||
firm_fname=args.firm
|
||||
|
||||
cxi_fname=args.cxi
|
||||
|
||||
# write the file
|
||||
filer = open(firm_fname, 'rb')
|
||||
filew = open(args.out, "wb")
|
||||
|
||||
filesize=getSize(filer)
|
||||
|
||||
skipUntilAddress(filer,filew,0,0x200)
|
||||
|
||||
cxi = open(cxi_fname, 'rb')
|
||||
cxisize=getSize(cxi)
|
||||
data = cxi.read(cxisize)
|
||||
cxi.close()
|
||||
|
||||
filew.write(data);
|
||||
filer.read(cxisize);
|
||||
|
||||
skipUntilAddress(filer,filew,cxisize+0x200,filesize)
|
||||
|
||||
filew.close()
|
||||
filer.close()
|
||||
|
119
scripts/build_twlbg_code_from_dev_launcher_srl.py
Normal file
119
scripts/build_twlbg_code_from_dev_launcher_srl.py
Normal file
@ -0,0 +1,119 @@
|
||||
# -*- coding: utf8 -*-
|
||||
# Patch an .nds (works with homebrew and ds demo only) to make it ready for make_cia
|
||||
#
|
||||
# 2016-02-28, Ahezard
|
||||
#
|
||||
# inspired by
|
||||
# Apache Thunder .nds edited files and comments
|
||||
# https://github.com/Relys/Project_CTR/blob/master/makerom/srl.h
|
||||
# https://dsibrew.org/wiki/DSi_Cartridge_Header
|
||||
# if the header size of the input nds file is 0x200 (homebrew)
|
||||
# the header size of the output nds file will be patched to 0x4000 (normal ds/dsi header), 0x3E00 offset
|
||||
|
||||
from struct import *
|
||||
from collections import namedtuple
|
||||
from collections import OrderedDict
|
||||
from pprint import pprint
|
||||
import os, sys
|
||||
import binascii
|
||||
import argparse
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='extract devLauncherSrl from the twl_bg.cxi')
|
||||
parser.add_argument('--srl', help='srl file')
|
||||
parser.add_argument('--code', help='code file')
|
||||
parser.add_argument('--out', help='output code file')
|
||||
args = parser.parse_args()
|
||||
|
||||
#
|
||||
# CRC16 MODULE
|
||||
#
|
||||
# includes CRC16 and CRC16 MODBUS
|
||||
#
|
||||
|
||||
from ctypes import c_ushort
|
||||
|
||||
# from https://github.com/cristianav/PyCRC/blob/master/demo.py
|
||||
class CRC16(object):
|
||||
crc16_tab = []
|
||||
|
||||
# The CRC's are computed using polynomials. Here is the most used
|
||||
# coefficient for CRC16
|
||||
crc16_constant = 0xA001 # 40961
|
||||
|
||||
def __init__(self, modbus_flag=False):
|
||||
# initialize the precalculated tables
|
||||
if not len(self.crc16_tab):
|
||||
self.init_crc16()
|
||||
self.mdflag = bool(modbus_flag)
|
||||
|
||||
def calculate(self, input_data=None):
|
||||
try:
|
||||
is_string = isinstance(input_data, str)
|
||||
is_bytes = isinstance(input_data, (bytes, bytearray))
|
||||
|
||||
if not is_string and not is_bytes:
|
||||
raise Exception("Please provide a string or a byte sequence "
|
||||
"as argument for calculation.")
|
||||
|
||||
crc_value = 0x0000 if not self.mdflag else 0xffff
|
||||
|
||||
for c in input_data:
|
||||
d = ord(c) if is_string else c
|
||||
tmp = crc_value ^ d
|
||||
rotated = crc_value >> 8
|
||||
crc_value = rotated ^ self.crc16_tab[(tmp & 0x00ff)]
|
||||
|
||||
return crc_value
|
||||
except Exception as e:
|
||||
print("EXCEPTION(calculate): {}".format(e))
|
||||
|
||||
def init_crc16(self):
|
||||
"""The algorithm uses tables with precalculated values"""
|
||||
for i in range(0, 256):
|
||||
crc = c_ushort(i).value
|
||||
for j in range(0, 8):
|
||||
if crc & 0x0001:
|
||||
crc = c_ushort(crc >> 1).value ^ self.crc16_constant
|
||||
else:
|
||||
crc = c_ushort(crc >> 1).value
|
||||
self.crc16_tab.append(crc)
|
||||
|
||||
def getSize(fileobject):
|
||||
current = fileobject.tell()
|
||||
fileobject.seek(0,2) # move the cursor to the end of the file
|
||||
size = fileobject.tell()
|
||||
fileobject.seek(current,0)
|
||||
return size
|
||||
|
||||
def skipUntilAddress(f_in,f_out, caddr, taddr):
|
||||
chunk = f_in.read(taddr-caddr)
|
||||
f_out.write(chunk)
|
||||
|
||||
def writeBlankuntilAddress(f_out, caddr, taddr):
|
||||
f_out.write("\x00"*(taddr-caddr))
|
||||
|
||||
srl_fname=args.srl
|
||||
|
||||
code_fname=args.code
|
||||
|
||||
srlsizeoffset=0xCD5F8
|
||||
srlsize=0xB9400
|
||||
|
||||
# write the file
|
||||
filer = open(code_fname, 'rb')
|
||||
files = open(srl_fname, 'rb')
|
||||
filew = open(args.out, "wb")
|
||||
|
||||
filesize=getSize(filer)
|
||||
|
||||
srldata=files.read(srlsize);
|
||||
|
||||
skipUntilAddress(filer,filew,0,srlsizeoffset)
|
||||
filew.write(srldata)
|
||||
filer.read(srlsize)
|
||||
skipUntilAddress(filer,filew,srlsizeoffset+srlsize,filesize)
|
||||
|
||||
filew.close()
|
||||
filer.close()
|
||||
|
2
scripts/encryptDevLauncher.cmd
Normal file
2
scripts/encryptDevLauncher.cmd
Normal file
@ -0,0 +1,2 @@
|
||||
copy devSRLlauncher_patched_dec.nds devSRLlauncher_patched_enc.nds
|
||||
Modcrypt.bat devSRLlauncher_patched_enc.nds
|
21
scripts/extract_dev_launcher.cmd
Normal file
21
scripts/extract_dev_launcher.cmd
Normal file
@ -0,0 +1,21 @@
|
||||
@@Echo off
|
||||
cd ../temp
|
||||
..\tools\ctrtool.exe -xt firm --firmdir firm firmware_twl.bin
|
||||
cp firm/firm_0_18000000.bin twlBg_original.cxi
|
||||
|
||||
pause
|
||||
|
||||
..\tools\3dstool.exe -xvtf cxi twlBg_original.cxi --header twlBg.ncch.header --exh twlBg.exheader.bin --exefs twlBg.exefs
|
||||
|
||||
..\tools\3dstool.exe -xuvtf exefs twlBg.exefs --header twlBg.exefs.header --exefs-dir twlBg_original_exefs
|
||||
|
||||
python ..\scripts\extract_dev_launcher_srl_from_twlbg_cxi.py --cxi twlBg_original_exefs/code.bin --out devSRLlauncher_original_enc.nds
|
||||
|
||||
..\tools\twltool.exe modcrypt --in devSRLlauncher_original_enc.nds --out devSRLlauncher_original_dec.nds
|
||||
|
||||
..\tools\ndstool.exe -i devSRLlauncher_original_dec.nds > devSRLlauncher_original_header.txt
|
||||
|
||||
..\tools\ndstool.exe -x -9 devSRLlauncher_original_dec.arm9 -7 devSRLlauncher_original_dec.arm7 devSRLlauncher_original_dec.nds
|
||||
|
||||
cd ..\scripts
|
||||
pause
|
112
scripts/extract_dev_launcher_srl_from_twlbg_cxi.py
Normal file
112
scripts/extract_dev_launcher_srl_from_twlbg_cxi.py
Normal file
@ -0,0 +1,112 @@
|
||||
# -*- coding: utf8 -*-
|
||||
# Patch an .nds (works with homebrew and ds demo only) to make it ready for make_cia
|
||||
#
|
||||
# 2016-02-28, Ahezard
|
||||
#
|
||||
# inspired by
|
||||
# Apache Thunder .nds edited files and comments
|
||||
# https://github.com/Relys/Project_CTR/blob/master/makerom/srl.h
|
||||
# https://dsibrew.org/wiki/DSi_Cartridge_Header
|
||||
# if the header size of the input nds file is 0x200 (homebrew)
|
||||
# the header size of the output nds file will be patched to 0x4000 (normal ds/dsi header), 0x3E00 offset
|
||||
|
||||
from struct import *
|
||||
from collections import namedtuple
|
||||
from collections import OrderedDict
|
||||
from pprint import pprint
|
||||
import os, sys
|
||||
import binascii
|
||||
import argparse
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='extract devLauncherSrl from the twl_bg.cxi')
|
||||
parser.add_argument('--cxi', help='cxi file')
|
||||
parser.add_argument('--out', help='output cxi file')
|
||||
args = parser.parse_args()
|
||||
|
||||
#
|
||||
# CRC16 MODULE
|
||||
#
|
||||
# includes CRC16 and CRC16 MODBUS
|
||||
#
|
||||
|
||||
from ctypes import c_ushort
|
||||
|
||||
# from https://github.com/cristianav/PyCRC/blob/master/demo.py
|
||||
class CRC16(object):
|
||||
crc16_tab = []
|
||||
|
||||
# The CRC's are computed using polynomials. Here is the most used
|
||||
# coefficient for CRC16
|
||||
crc16_constant = 0xA001 # 40961
|
||||
|
||||
def __init__(self, modbus_flag=False):
|
||||
# initialize the precalculated tables
|
||||
if not len(self.crc16_tab):
|
||||
self.init_crc16()
|
||||
self.mdflag = bool(modbus_flag)
|
||||
|
||||
def calculate(self, input_data=None):
|
||||
try:
|
||||
is_string = isinstance(input_data, str)
|
||||
is_bytes = isinstance(input_data, (bytes, bytearray))
|
||||
|
||||
if not is_string and not is_bytes:
|
||||
raise Exception("Please provide a string or a byte sequence "
|
||||
"as argument for calculation.")
|
||||
|
||||
crc_value = 0x0000 if not self.mdflag else 0xffff
|
||||
|
||||
for c in input_data:
|
||||
d = ord(c) if is_string else c
|
||||
tmp = crc_value ^ d
|
||||
rotated = crc_value >> 8
|
||||
crc_value = rotated ^ self.crc16_tab[(tmp & 0x00ff)]
|
||||
|
||||
return crc_value
|
||||
except Exception as e:
|
||||
print("EXCEPTION(calculate): {}".format(e))
|
||||
|
||||
def init_crc16(self):
|
||||
"""The algorithm uses tables with precalculated values"""
|
||||
for i in range(0, 256):
|
||||
crc = c_ushort(i).value
|
||||
for j in range(0, 8):
|
||||
if crc & 0x0001:
|
||||
crc = c_ushort(crc >> 1).value ^ self.crc16_constant
|
||||
else:
|
||||
crc = c_ushort(crc >> 1).value
|
||||
self.crc16_tab.append(crc)
|
||||
|
||||
def getSize(fileobject):
|
||||
current = fileobject.tell()
|
||||
fileobject.seek(0,2) # move the cursor to the end of the file
|
||||
size = fileobject.tell()
|
||||
fileobject.seek(current,0)
|
||||
return size
|
||||
|
||||
def skipUntilAddress(f_in,f_out, caddr, taddr):
|
||||
chunk = f_in.read(taddr-caddr)
|
||||
f_out.write(chunk)
|
||||
|
||||
def writeBlankuntilAddress(f_out, caddr, taddr):
|
||||
f_out.write("\x00"*(taddr-caddr))
|
||||
|
||||
cxi_fname=args.cxi
|
||||
|
||||
srlsizeoffset=0xCD5F8
|
||||
srlsize=0xB9400
|
||||
|
||||
# write the file
|
||||
filer = open(cxi_fname, 'rb')
|
||||
filew = open(args.out, "wb")
|
||||
|
||||
filesize=getSize(filer)
|
||||
|
||||
filer.read(srlsizeoffset);
|
||||
|
||||
skipUntilAddress(filer,filew,srlsizeoffset,srlsize+srlsizeoffset)
|
||||
|
||||
filew.close()
|
||||
filer.close()
|
||||
|
9
scripts/packTWLbgCXI.cmd
Normal file
9
scripts/packTWLbgCXI.cmd
Normal file
@ -0,0 +1,9 @@
|
||||
mkdir loader\twlBg_patched_exefs
|
||||
|
||||
python build_twlbg_code_from_dev_launcher_srl.py --srl=loader/devSRLlauncher_patched_enc.nds --code=loader/twlBg_original_exefs/code.bin --out=loader/twlBg_patched_exefs/code.bin
|
||||
|
||||
3dstool -czvtf exefs loader/twlBg_patched.exefs --header loader/twlBg.exefs.header --exefs-dir loader/twlBg_patched_exefs
|
||||
|
||||
3dstool -cvtf cxi loader/twlBg_patched.cxi --header loader/twlBg.ncch.header --exh loader/twlBg.exheader.bin --exefs loader/twlBg_patched.exefs
|
||||
|
||||
pause
|
5
scripts/patch_firm_bin.cmd
Normal file
5
scripts/patch_firm_bin.cmd
Normal file
@ -0,0 +1,5 @@
|
||||
@@Echo off
|
||||
python build_firm_bin_from_twlbg_cxi.py --cxi loader/twlBg_patched.cxi --firm ExeFS/code.bin --out patched_firmware_twl.bin
|
||||
|
||||
ctrtool.exe -it firm patched_firmware_twl.bin
|
||||
pause
|
BIN
tools/3dstool.exe
Normal file
BIN
tools/3dstool.exe
Normal file
Binary file not shown.
BIN
tools/ctrtool.exe
Normal file
BIN
tools/ctrtool.exe
Normal file
Binary file not shown.
BIN
tools/libgcc_s_sjlj-1.dll
Normal file
BIN
tools/libgcc_s_sjlj-1.dll
Normal file
Binary file not shown.
BIN
tools/libstdc++-6.dll
Normal file
BIN
tools/libstdc++-6.dll
Normal file
Binary file not shown.
BIN
tools/libusb-1.0.dll
Normal file
BIN
tools/libusb-1.0.dll
Normal file
Binary file not shown.
BIN
tools/makerom.exe
Normal file
BIN
tools/makerom.exe
Normal file
Binary file not shown.
BIN
tools/ndstool.exe
Normal file
BIN
tools/ndstool.exe
Normal file
Binary file not shown.
BIN
tools/twltool.exe
Normal file
BIN
tools/twltool.exe
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user