#!/usr/local/bin/python3
import sys
from os import path
# Initialize NAND filename, path and the default exit code
nand_file = 'nand.bin'
nand_path = ''
exit_code = 0
# Try to get the NAND file from the command line
if len(sys.argv) > 1:
nand_path, nand_file = path.split(sys.argv[1])
# Read the NAND file
try:
with open(path.join(nand_path, nand_file), 'rb') as f:
# Go to the No$GBA footer offset
f.seek(0xF000000)
# Read the footer's header :-)
bstr = f.read(0x10)
if bstr == b'DSi eMMC CID/CPU':
# Read the CID
bstr = f.read(0x10)
cid = bytearray(bstr).hex().upper()
print('eMMC CID : ' + cid)
# Save it to a text file at the same NAND location
with open(path.join(nand_path, 'CID.txt'), 'w') as ftxt:
ftxt.write(cid)
# Read the console ID
bstr = f.read(8)
console_id = bytearray(reversed(bstr)).hex().upper()
print('Console ID: ' + console_id)
# Save it to a text file at the same NAND location
with open(path.join(nand_path, 'ConsoleID.txt'), 'w') as ftxt:
ftxt.write(console_id)
else:
print('ERROR: No$GBA footer not found')
exit_code = 1
except FileNotFoundError:
print('ERROR: Could not open the file ' + nand_file)
exit_code = 1
sys.exit(exit_code)