Skip to content

Instantly share code, notes, and snippets.

@xprism1
Last active February 19, 2023 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xprism1/a8aeb6d0728fe4ca45f3a64b409945fb to your computer and use it in GitHub Desktop.
Save xprism1/a8aeb6d0728fe4ca45f3a64b409945fb to your computer and use it in GitHub Desktop.
Cleans and prepares a Nintendo DS firmware dump for No-Intro
import sys, binascii
from datetime import datetime
with open(sys.argv[1], 'rb') as f:
data = f.read()
data_hex = data.hex()
date = data_hex[0x18*2:0x18*2+10] # BCD encoded
try:
date_dt = datetime.strptime(date, '%M%H%d%m%y')
date_str = date_dt.strftime("%Y-%m-%d %H:%M")
except ValueError:
date_str = date
console_type = {
'ff': 'Nintendo DS',
'20': 'Nintendo DS Lite',
'43': 'iQue DS',
'63': 'iQue DS Lite',
'35': 'Nintendo DS Lite (Korea)',
'00': 'Prototype?',
'01': 'Nintendo Zone Box'
}
console = data_hex[0x1D*2:0x1D*2+2]
try:
console_t = console_type[console]
except KeyError:
console_t = 'Unknown'
print(f'Build timestamp: {date_str}')
print(f'Console: {console_t}')
with open('cleaned.bin', 'wb') as f:
f.write(data[:0x2A])
f.write(binascii.unhexlify('FF'*0x1D6))
f.write(data[0x200:-0x600])
f.write(binascii.unhexlify('00'*0x400))
user_settings = '05' + '00'*0x6F
for i in range(2):
if console == '35': # lite korean
usr_set = user_settings + f'0{i}00454F' + '0101AF00' + 'FF'*0x86 + 'BC25'
elif console == '63': # lite ique
usr_set = user_settings + f'0{i}00454F' + '01017E00' + '00'*0x86 + '5494'
elif console == '43': # phat ique
usr_set = user_settings + f'0{i}00454F' + '01017E00' + 'FF'*0x86 + 'E510'
else:
usr_set = user_settings + f'0{i}00454F' + 'FF'*0x8C
f.write(binascii.unhexlify(usr_set))
print("Cleaned Wi-Fi calibration, Wi-Fi access points, user settings in cleaned.bin")
with open('WifiCalibration.bin', 'wb') as f:
f.write(data[0x2A:0x200])
with open('WifiAccessPoints.bin', 'wb') as f:
f.write(data[-0x600:-0x200])
with open('UserSettings.bin', 'wb') as f:
f.write(data[-0x200:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment