void ctr_twl_keyslot_setup(void) { //Only a9lh really needs to bother with this, and it really only needs to happen once, before ITCM gets messed up. static bool setup = false; if (!setup && ctr_detect_a9lh_entry()) { uint32_t* TwlCustId = (uint32_t*) (0x01FFB808); uint32_t TwlKeyX[4]; alignas(32) uint8_t TwlKeyY[16]; // thanks b1l1s & Normmatt // see source from https://gbatemp.net/threads/release-twltool-dsi-downgrading-save-injection-etc-multitool.393488/ const char* nintendo = "NINTENDO"; TwlKeyX[0] = (TwlCustId[0] ^ 0xB358A6AF) | 0x80000000; TwlKeyX[3] = TwlCustId[1] ^ 0x08C267B7; memcpy(TwlKeyX + 1, nintendo, 8); // see: https://www.3dbrew.org/wiki/Memory_layout#ARM9_ITCM uint32_t TwlKeyYW3 = 0xE1A00005; memcpy(TwlKeyY, (uint8_t*) 0x01FFD3C8, 12); memcpy(TwlKeyY + 12, &TwlKeyYW3, 4); setup_aeskeyX(0x03, (uint8_t*)TwlKeyX); setup_aeskeyY(0x03, TwlKeyY); use_aeskey(0x03); } setup = true; }
static inline void check_and_do_twl_init() { static bool setup = false; if (!setup && ctr_detect_a9lh_entry()) { ctr_twl_keyslot_setup(); } }
static inline void check_and_do_n3ds_init() { static bool setup = false; if (!setup && ctr_detect_a9lh_entry() && ctr_get_system_type() == SYSTEM_N3DS) { ctr_n3ds_ctrnand_keyslot_setup(); } }