void FirmLoader(){ char firm_path[256]; if (!FileExplorerMain(firm_path, sizeof(firm_path))) { UINT fsz; if (loadFirm(firm_path, &fsz)) { ConsoleInit(); ConsoleSetTitle(strings[STR_LOAD], strings[STR_FIRMWARE_FILE]); print(strings[STR_WRONG], "", strings[STR_FIRMWARE_FILE]); print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]); ConsoleShow(); WaitForButton(BUTTON_A); return; } if (loadExecReboot()) { ConsoleInit(); ConsoleSetTitle(strings[STR_LOAD], strings[STR_FIRMWARE_FILE]); print(strings[STR_ERROR_LAUNCHING], strings[STR_FIRMWARE_FILE]); print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]); ConsoleShow(); WaitForButton(BUTTON_A); return; } } }
void rxModeSys(){ ConsoleInit(); ConsoleSetTitle("rxMode - Booting in SysNand"); print("Loading...\n"); ConsoleShow(); rxMode(0); print("Cannot boot in rxMode.\n\nPress A to exit\n"); ConsoleShow(); WaitForButton(BUTTON_A); }
void DumpNandPartitions(){ ConsoleSetTitle(strings[STR_DUMP], strings[STR_NAND_PARTITIONS]); int isEmuNand = SYS_NAND; if(checkEmuNAND() && (isEmuNand = NandSwitch()) == UNK_NAND) return; isEmuNand--; ConsoleInit(); ConsoleSetTitle(strings[STR_DUMP], strings[STR_NAND_PARTITIONS]); print(strings[STR_PROCESSING], isEmuNand ? strings[STR_EMUNAND] : strings[STR_SYSNAND]); wchar_t* p_name[] = { L"twln.bin", L"twlp.bin", L"agb_save.bin", L"firm0.bin", L"firm1.bin", L"ctrnand.bin" }; wchar_t* p_descr[] = { strings[STR_TWLN], strings[STR_TWLP], strings[STR_AGB_SAVE], strings[STR_FIRM0], strings[STR_FIRM1], strings[STR_CTRNAND] }; unsigned int p_size[] = { 0x08FB5200, 0x020B6600, 0x00030000, 0x00400000, 0x00400000, getMpInfo() == MPINFO_KTR ? 0x41D2D200 : 0x2F3E3600 }; unsigned int p_addr[] = { TWLN, TWLP, AGB_SAVE, FIRM0, FIRM1, CTRNAND }; int sect_row = 0x80; wchar_t tmp[_MAX_LFN]; for(int i = 3; i < 6; i++){ //Cutting out twln, twlp and agb_save. Todo: Properly decrypt them File out; swprintf(tmp, _MAX_LFN, L"rxTools/nand/%ls%ls", isEmuNand ? L"emu_" : L"", p_name[i]); FileOpen(&out, tmp, 1); print(strings[STR_DUMPING], p_descr[i], tmp); ConsoleShow(); for(int j = 0; j*0x200 < p_size[i]; j += sect_row){ swprintf(tmp, _MAX_LFN, L"%08X / %08X", j*0x200, p_size[i]); int x, y; ConsoleGetXY(&x, &y); y += FONT_HEIGHT * 3; x += FONT_HWIDTH*2; ConsoleShow(); DrawString(BOT_SCREEN, tmp, x, y, ConsoleGetTextColor(), ConsoleGetBackgroundColor()); if(isEmuNand) emunand_readsectors(j, sect_row, BUF1, p_addr[i]); else nand_readsectors(j, sect_row, BUF1, p_addr[i]); FileWrite(&out, BUF1, sect_row*0x200, j*0x200); } FileClose(&out); } print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]); ConsoleShow(); WaitForButton(BUTTON_A); }
void MenuInit(Menu* menu){ MyMenu = menu; ConsoleInit(); MyMenu->Current = 0; MyMenu->Showed = 0; ConsoleSetTitle(MyMenu->Name); for(int i = 0; i < MyMenu->nEntryes; i++){ print(MyMenu->Option[i].Str); print("\n"); } }
void rxModeEmu(){ if(!checkEmuNAND()) rxModeSys(); else{ ConsoleInit(); ConsoleSetTitle("rxMode - Booting in EmuNand"); print("Loading...\n"); ConsoleShow(); rxMode(1); print("Cannot boot in rxMode.\n\nPress A to exit\n"); ConsoleShow(); WaitForButton(BUTTON_A); } }
void PadGen(){ ConsoleInit(); ConsoleSetTitle(strings[STR_GENERATE], strings[STR_XORPAD]); NcchPadgen(); ConsoleShow(); SdPadgen(); ConsoleShow(); print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]); ConsoleShow(); WaitForButton(BUTTON_A); }
void NandDumper(){ File myFile; int isEmuNand = SYS_NAND; if(checkEmuNAND() && (isEmuNand = NandSwitch()) == UNK_NAND) return; isEmuNand--; ConsoleInit(); ConsoleSetTitle(L"%sNAND Dumper", isEmuNand ? "emu" : "sys"); unsigned char* buf = (void*)0x21000000; unsigned int nsectors = 0x200; //sectors in a row wchar_t ProgressBar[] = L"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ "; unsigned int progress = 0; /* int BACKCOLOR = */ConsoleGetBackgroundColor(); //can be removed, left only to keep binaries the same if(FileOpen(&myFile, isEmuNand ? "rxTools/nand/EMUNAND.bin" : "rxTools/nand/NAND.bin", 1)){ print(L"Dumping...\n\n"); ConsoleShow(); int x, y; ConsoleGetXY(&x, &y); y += FONT_HEIGHT * 6; x += FONT_HWIDTH * 2; DrawString(BOT_SCREEN, ProgressBar, x, y, ConsoleGetTextColor(), ConsoleGetBackgroundColor()); DrawString(BOT_SCREEN, L"Press Ⓑ anytime to abort", x, y + FONT_HEIGHT*2, ConsoleGetTextColor(), ConsoleGetBackgroundColor()); for(int count = 0; count < NAND_SIZE/NAND_SECTOR_SIZE/nsectors; count++){ if(isEmuNand) sdmmc_sdcard_readsectors(count*nsectors, nsectors, buf); else sdmmc_nand_readsectors(count*nsectors, nsectors, buf); FileWrite(&myFile, buf, nsectors*NAND_SECTOR_SIZE, count*NAND_SECTOR_SIZE*nsectors); TryScreenShot(); if((count % (int)(NAND_SIZE/NAND_SECTOR_SIZE/nsectors/16)) == 0 && count != 0){ DrawString(BOT_SCREEN, PROGRESS_OK, x+(FONT_WIDTH*(progress++)), y, ConsoleGetTextColor(), ConsoleGetBackgroundColor()); } unsigned int pad = GetInput(); if(pad & BUTTON_B) break; } if(isEmuNand){ sdmmc_sdcard_readsectors(checkEmuNAND()/0x200, 1, buf); FileWrite(&myFile, buf, 0x200, 0); } FileClose(&myFile); print(L"\nFinished dumping!\n"); ConsoleShow(); }else{ print(L"Failed to create the dump.\n"); ConsoleShow(); } print(L"\nPress Ⓐ to exit\n"); ConsoleShow(); WaitForButton(BUTTON_A); }
void FirmLoader(TCHAR firm_path[]){ UINT fsz; if (loadFirm(firm_path, &fsz)) { ConsoleInit(); ConsoleSetTitle(strings[STR_LOAD], strings[STR_FIRMWARE_FILE]); print(strings[STR_WRONG], L"", strings[STR_FIRMWARE_FILE]); print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]); ConsoleShow(); WaitForButton(BUTTON_A); return; } if (loadExecReboot()) { ConsoleInit(); ConsoleSetTitle(strings[STR_LOAD], strings[STR_FIRMWARE_FILE]); print(strings[STR_ERROR_LAUNCHING], strings[STR_FIRMWARE_FILE]); print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]); ConsoleShow(); WaitForButton(BUTTON_A); return; } }
void AdvFileManagerFileAction(TCHAR filePath[], TCHAR fileName[]) { int actions_idx = 0; while (true) { //DRAW GUI ConsoleInit(); ConsoleSetTitle(fileName); wchar_t* beg; for (i = 0; i < FILE_ACTIONS; i++) { if (i == actions_idx) beg = strings[STR_CURSOR]; else beg = strings[STR_NO_CURSOR]; if (i == 0)print(L"%ls Launch as firm\n", beg); if (i == 1)print(L"%ls Something...\n", beg); } ConsoleShow(); //APP CONTROLS uint32_t pad_state = InputWait(); if (pad_state & BUTTON_DOWN) { if (actions_idx != FILE_ACTIONS - 1) actions_idx++; //MOVE DOWN else actions_idx = 0; //MOVE DOWN While at bottom -> go to top } else if (pad_state & BUTTON_UP) { if (actions_idx != 0) actions_idx--; //MOVE UP else actions_idx = FILE_ACTIONS - 1; //MOVE UP While at top -> go to bottom } else if (pad_state & BUTTON_A) { switch(actions_idx) { case 0: FirmLoader(filePath); break; case 1: //Something.... break; } break; } else if (pad_state & BUTTON_B) break; } }
static void warn(const wchar_t *format, ...) { va_list va; if (!warned) { ConsoleInit(); ConsoleSetTitle(strings[STR_WARNING]); warned = 1; } va_start(va, format); vprint(format, va); va_end(va); ConsoleShow(); }
int NandSwitch(){ if(!checkEmuNAND()) return 0; //If No EmuNAND, we force to work on SysNAND ConsoleInit(); /* freezes ConsoleSetTitle(STR_CHOOSE_NAND[language]); print(STR_PRESS_X_SYSNAND[language]); print(STR_PRESS_Y_EMUNAND[language]); print(STR_PRESS_B_BACK[language]); */ ConsoleSetTitle(L"Choose the NAND you want to use"); print(L"Ⓧ sysNAND\nⓎ emuNAND\nⒷ Cancel\n"); ConsoleShow(); while (true) { u32 pad_state = InputWait(); if(pad_state & BUTTON_X) return SYS_NAND; if(pad_state & BUTTON_Y) return EMU_NAND; if(pad_state & BUTTON_B) return UNK_NAND; } }
int main(){ if (Initialize()) while (1); //7.X Keys stuff File KeyFile; const char *keyfile = "/slot0x25KeyX.bin"; if(FileOpen(&KeyFile, keyfile, 0)){ uint8_t keyX[16]; FileRead(&KeyFile, keyX, 16, 0); FileClose(&KeyFile); setup_aeskeyX(0x25, keyX); }else{ if (sysver < 7) { ConsoleInit(); ConsoleSetTitle(strings[STR_WARNING]); print(strings[STR_ERROR_OPENING], keyfile); print(strings[STR_WARNING_KEYFILE]); print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]); ConsoleShow(); WaitForButton(BUTTON_A); } } //That's the Main Menu initialization, easy and cool OpenAnimation(); MenuInit(&MainMenu); MenuShow(); while (true) { uint32_t pad_state = InputWait(); if (pad_state & (BUTTON_DOWN | BUTTON_RIGHT | BUTTON_R1)) MenuNextSelection(); //I try to support every theme style if (pad_state & (BUTTON_UP | BUTTON_LEFT | BUTTON_L1)) MenuPrevSelection(); if (pad_state & BUTTON_A) { OpenAnimation(); MenuSelect(); } if (pad_state & BUTTON_SELECT) { fadeOut(); ShutDown(); } if (pad_state & BUTTON_START) { fadeOut(); returnHomeMenu(); } TryScreenShot(); MenuShow(); } FSDeInit(); return 0; }
void DumpNandPartitions(){ int isEmuNand = SYS_NAND; if(checkEmuNAND() && (isEmuNand = NandSwitch()) == UNK_NAND) return; isEmuNand--; char* p_name[] = { "twln.bin", "twlp.bin", "agb_save.bin", "firm0.bin", "firm1.bin", "ctrnand.bin" }; unsigned int p_size[] = { 0x08FB5200, 0x020B6600, 0x00030000, 0x00400000, 0x00400000, 0x2F3E3600}; unsigned int p_addr[] = { TWLN, TWLP, AGB_SAVE, FIRM0, FIRM1, CTRNAND }; int sect_row = 0x80; ConsoleInit(); ConsoleSetTitle(L"%sNAND Partitions Decryptor", isEmuNand ? "emu" : "sys"); char tmp[256]; wchar_t wtmp[256]; for(int i = 3; i < 6; i++){ //Cutting out twln, twlp and agb_save. Todo: Properly decrypt them File out; sprintf(tmp, "rxTools/nand/%s%s", isEmuNand ? "emu_" : "", p_name[i]); FileOpen(&out, tmp, 1); print(L"Dumping %s ...\n", p_name[i]); ConsoleShow(); for(int j = 0; j*0x200 < p_size[i]; j += sect_row){ swprintf(wtmp, sizeof(wtmp)/sizeof(wtmp[0]), L"%08X / %08X", j*0x200, p_size[i]); int x, y; ConsoleGetXY(&x, &y); y += FONT_HEIGHT * 3; x += FONT_HWIDTH*2; DrawString(BOT_SCREEN, wtmp, x, y, ConsoleGetTextColor(), ConsoleGetBackgroundColor()); if(isEmuNand) emunand_readsectors(j, sect_row, BUF1, p_addr[i]); else nand_readsectors(j, sect_row, BUF1, p_addr[i]); FileWrite(&out, BUF1, sect_row*0x200, j*0x200); } FileClose(&out); } print(L"\nPress Ⓐ to exit\n"); ConsoleShow(); WaitForButton(BUTTON_A); }
void restoreCoolFiles(){ int nandtype = NandSwitch(); if(nandtype == -1){ return; } selectedFile = -1; MenuInit(&CoolFilesMenu); MenuShow(); while (true) { u32 pad_state = InputWait(); if(pad_state & BUTTON_DOWN) MenuNextSelection(); if(pad_state & BUTTON_UP) MenuPrevSelection(); if(pad_state & BUTTON_A) { MenuSelect(); break; } if(pad_state & BUTTON_B) break; TryScreenShot(); MenuShow(); } if(selectedFile == -1) return; ConsoleInit(); ConsoleSetTitle("File Inject : %s", CoolFiles[selectedFile].name); char dest[256]; sprintf(tmpstr, "rxTools/%s", CoolFiles[selectedFile].name); sprintf(dest, "%d:%s", nandtype + 1, CoolFiles[selectedFile].path); print("Injecting...\n"); ConsoleShow(); int res = FileCopy(dest, tmpstr); char* showres; switch(res){ case 1 : showres = "Success!"; break; case -1 : showres = "Cannot write to file!"; break; case -2 : showres = "Cannot read from file!"; break; default : showres = "Failure!"; break; } print(showres); print("\n"); print("\nPress A to exit\n"); ConsoleShow(); WaitForButton(BUTTON_A); }
int main(){ Initialize(); //7.X Keys stuff File KeyFile; if(FileOpen(&KeyFile, "/slot0x25KeyX.bin", 0)){ u8 keyX[16]; FileRead(&KeyFile, keyX, 16, 0); FileClose(&KeyFile); setup_aeskeyX(0x25, keyX); }else{ if(GetSystemVersion() < 3){ ConsoleInit(); ConsoleSetTitle(" WARNING"); print("WARNING:\n\nCannot find slot0x25KeyX.bin. If\nyour firmware version is less than\n7.X, some titles decryption will\nfail, and some EmuNANDs will not\nboot.\n\nPress A to continue...\n"); ConsoleShow(); WaitForButton(BUTTON_A); } } //That's the Main Menu initialization, easy and cool MenuInit(&MainMenu); MenuShow(); while (true) { u32 pad_state = InputWait(); if (pad_state & (BUTTON_DOWN | BUTTON_RIGHT | BUTTON_R1)) MenuNextSelection(); //I try to support every theme style if (pad_state & (BUTTON_UP | BUTTON_LEFT | BUTTON_L1)) MenuPrevSelection(); if(pad_state & BUTTON_A) MenuSelect(); if(pad_state & BUTTON_SELECT) ShutDown(); if(pad_state & BUTTON_START) returnHomeMenu(); TryScreenShot(); MenuShow(); } FSDeInit(); return 0; }
void Initialize(){ char str[100]; char strl[100]; char strr[100]; DrawString(BOT_SCREEN, " INITIALIZE... ", 0, SCREEN_HEIGHT-FONT_SIZE, WHITE, BLACK); if(FSInit()){ DrawString(BOT_SCREEN, " LOADING... ", 0, SCREEN_HEIGHT-FONT_SIZE, WHITE, BLACK); }else{ DrawString(BOT_SCREEN, " ERROR! ", 0, SCREEN_HEIGHT-FONT_SIZE, RED, BLACK); } LoadPack(); //Console Stuff ConsoleSetXY(15, 20); ConsoleSetWH(SCREEN_WIDTH-30, SCREEN_HEIGHT-80); ConsoleSetBorderColor(BLUE); ConsoleSetTextColor(RGB(0, 141, 197)); ConsoleSetBackgroundColor(TRANSPARENT); ConsoleSetSpecialColor(BLUE); ConsoleSetSpacing(2); ConsoleSetBorderWidth(3); //Check that the data is installed f_mkdir("rxTools"); f_mkdir("rxTools/nand"); InstallConfigData(); LoadSettings(); sprintf(str, "/rxTools/Theme/%c/TOP.bin", Theme); sprintf(strl, "/rxTools/Theme/%c/TOPL.bin", Theme); sprintf(strr, "/rxTools/Theme/%c/TOPR.bin", Theme); if(theme_3d) DrawTopSplash(str, strl, strr); else DrawTopSplash(str, str, str); if (!bootGUI) { if(silent_boot) { sprintf(str, "/rxTools/Theme/%c/boot.bin", Theme); DrawBottomSplash(str); for (int i = 0; i < 0x333333 * 2; i++){ u32 pad = GetInput(); if (pad & BUTTON_R1 && i > 0x333333) goto rxTools_boot; } } else { ConsoleInit(); ConsoleSetTitle(STR_AUTOBOOT[language]); print(STR_HOLD_R[language]); ConsoleShow(); for (int i = 0; i < 0x333333 * 6; i++){ u32 pad = GetInput(); if (pad & BUTTON_R1 && i > 0x333333) goto rxTools_boot; } } rxModeQuickBoot(); } rxTools_boot: sprintf(str, "/rxTools/Theme/%c/TOP.bin", Theme); sprintf(strl, "/rxTools/Theme/%c/TOPL.bin", Theme); sprintf(strr, "/rxTools/Theme/%c/TOPR.bin", Theme); if(theme_3d) DrawTopSplash(str, strl, strr); else DrawTopSplash(str, str, str); }
int rxMode(int emu) { if (!checkEmuNAND() && emu) { ConsoleInit(); ConsoleSetTitle(L"EMUNAND NOT FOUND!"); print(L"The emunand was not found on\n"); print(L"your SDCard. \n"); print(L"\n"); print(L"Press A to boot SYSNAND\n"); ConsoleShow(); WaitForButton(BUTTON_A); emu = 0; char s[32]; sprintf(s, "/rxTools/Theme/%u/boot.bin", cfgs[CFG_THEME].val.i); DrawBottomSplash(s); } static const char patchNandPrefix[] = ".patch.p9.nand"; unsigned int cur, offset, shstrSize; char path[64], shstrtab[512], *sh_name; const char *platformDir; const wchar_t *msg; int r, sector; void *p; Elf32_Ehdr ehdr; Elf32_Shdr shdr; FIL fd, keyxFd; UINT br, fsz; setAgbBios(); getFirmPath(path, getMpInfo() == MPINFO_KTR ? TID_KTR_NATIVE_FIRM : TID_CTR_NATIVE_FIRM); strcpy(path + strlen(path) - 4, "orig.bin"); r = loadFirm(path, &fsz); if (r) { msg = L"Failed to load NATIVE_FIRM: %d\n" L"Reboot rxTools and try again.\n"; goto fail; } r = getMpInfo(); switch (r) { case MPINFO_KTR: platformDir = "ktr"; break; case MPINFO_CTR: platformDir = "ctr"; break; default: msg = L"Unknown Platform: %d"; goto fail; } sprintf(path, SYS_PATH "/patches/%s/native_firm.elf", platformDir); r = f_open(&fd, path, FA_READ); if (r != FR_OK) goto patchFail; r = f_read(&fd, &ehdr, sizeof(ehdr), &br); if (r != FR_OK) goto patchFail; r = f_lseek(&fd, ehdr.e_shoff + ehdr.e_shstrndx * sizeof(Elf32_Shdr)); if (r != FR_OK) goto patchFail; r = f_read(&fd, &shdr, sizeof(shdr), &br); if (r != FR_OK) goto patchFail; r = f_lseek(&fd, shdr.sh_offset); if (r != FR_OK) goto patchFail; r = f_read(&fd, shstrtab, shdr.sh_size > sizeof(shstrtab) ? sizeof(shstrtab) : shdr.sh_size, &shstrSize); if (r != FR_OK) goto patchFail; if (emu) { sector = checkEmuNAND(); if (sector == 0) { msg = L"Failed to find EmuNAND.\n" L"Check your EmuNAND.\n"; goto fail; } } else sector = 0; cur = ehdr.e_shoff; for (; ehdr.e_shnum; ehdr.e_shnum--, cur += sizeof(shdr)) { if (f_lseek(&fd, cur) != FR_OK) continue; if (f_read(&fd, &shdr, sizeof(shdr), &br) != FR_OK) continue; if (!(shdr.sh_flags & SHF_ALLOC) || shdr.sh_name >= shstrSize) continue; offset = locateSecInFirm(&shdr, (FirmHdr *)FIRM_ADDR); if (offset == 0) continue; p = (void *)(FIRM_ADDR + offset); sh_name = shstrtab + shdr.sh_name; if (!strcmp(sh_name, ".rodata.keyx")) { if (sysver >= 7) continue; if (f_open(&keyxFd, "slot0x25KeyX.bin", FA_READ) != FR_OK) continue; f_read(&keyxFd, p, shdr.sh_size, &br); f_close(&keyxFd); } else if (!strcmp(sh_name, ".rodata.nand.sector")) { if (sector) *(uint32_t *)p = (sector / 0x200) - 1; } else if (!strcmp(sh_name, ".rodata.label")) { *(uint32_t *)p = sector ? 'E-XR' : 'S-XR'; } else if (shdr.sh_type == SHT_PROGBITS && (sector || memcmp(sh_name, patchNandPrefix, sizeof(patchNandPrefix) - 1)) && (sysver < 7 || strcmp(sh_name, ".patch.p9.keyx"))) { if (f_lseek(&fd, shdr.sh_offset) != FR_OK) continue; f_read(&fd, p, shdr.sh_size, &br); } } getFirmPath(path, getMpInfo() == MPINFO_KTR ? TID_KTR_NATIVE_FIRM : TID_CTR_NATIVE_FIRM); f_open(&fd, path, FA_WRITE | FA_CREATE_ALWAYS); f_write(&fd, (void *)FIRM_ADDR, fsz, &br); f_close(&fd); r = loadExecReboot(); // This won't return if it succeeds. msg = L"Failed to load reboot.bin: %d\n" L"Check your installation.\n"; fail: ConsoleInit(); ConsoleSetTitle(L"rxMode"); print(msg, r); print(L"\n"); print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]); ConsoleShow(); WaitForButton(BUTTON_A); return r; patchFail: msg = L"Failed to load native_firm.elf: %d\n" L"Check your installation.\n"; goto fail; }
void dumpCoolFiles() { int nandtype = NandSwitch(); if (nandtype == UNK_NAND) return; selectedFile = -1; MenuInit(&CoolFilesMenu); MenuShow(); while (true) { uint32_t pad_state = InputWait(); if (pad_state & BUTTON_DOWN) MenuNextSelection(); if (pad_state & BUTTON_UP) MenuPrevSelection(); if (pad_state & BUTTON_A) { MenuSelect(); break; } if (pad_state & BUTTON_B) break; TryScreenShot(); MenuShow(); } if (selectedFile == -1) return; ConsoleInit(); ConsoleSetTitle(strings[STR_DUMP], strings[STR_FILES]); char dest[256], tmpstr[sizeof(dest)]; wchar_t wsrc[sizeof(tmpstr)]; sprintf(dest, "rxTools/%s", CoolFiles[selectedFile].name); sprintf(tmpstr, "%d:%s/%s", nandtype, CoolFiles[selectedFile].path, CoolFiles[selectedFile].name); mbstowcs(wsrc, tmpstr, sizeof(tmpstr)); print(strings[STR_DUMPING], wsrc, dest); ConsoleShow(); unsigned int res = FSFileCopy(dest, tmpstr); if (res != 0 && (selectedFile == 1 || selectedFile == 2)){ if (selectedFile == 1) { /* Fix for SecureInfo_B */ sprintf(dest, "rxTools/%.11s%c", CoolFiles[selectedFile].name, 'B'); sprintf(tmpstr, "%d:%s/%.11s%c", nandtype, CoolFiles[selectedFile].path, CoolFiles[selectedFile].name, 'B'); } else if (selectedFile == 2) { /* Fix for LocalFriendCodeSeed_A */ sprintf(dest, "rxTools/%.20s%c", CoolFiles[selectedFile].name, 'A'); sprintf(tmpstr, "%d:%s/%.20s%c", nandtype, CoolFiles[selectedFile].path, CoolFiles[selectedFile].name, 'A'); } mbstowcs(wsrc, tmpstr, sizeof(tmpstr)); print(strings[STR_FAILED]); print(strings[STR_DUMPING], wsrc, dest); ConsoleShow(); res = FSFileCopy(dest, tmpstr); } switch ((res >> 8) & 0xFF) { case 0: print(strings[STR_COMPLETED]); break; case 1: print(strings[STR_ERROR_OPENING], tmpstr); break; case 2: print(strings[STR_ERROR_CREATING], dest); break; case 3: case 4: print(strings[STR_ERROR_READING], tmpstr); break; case 5: case 6: print(strings[STR_ERROR_WRITING], dest); break; default: print(strings[STR_FAILED]); break; } print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]); ConsoleShow(); WaitForButton(BUTTON_A); }
void NandDumper(){ ConsoleSetTitle(strings[STR_DUMP], strings[STR_NAND]); File myFile; int isEmuNand = SYS_NAND; if(checkEmuNAND() && (isEmuNand = NandSwitch()) == UNK_NAND) return; isEmuNand--; ConsoleInit(); ConsoleSetTitle(strings[STR_DUMP], strings[STR_NAND]); unsigned char* buf = (void*)0x21000000; unsigned int nsectors = 0x200; //sectors in a row wchar_t tmpstr[STR_MAX_LEN]; wchar_t ProgressBar[41] = {0,}; for(int i=0; i<PROGRESS_WIDTH; i++) wcscat(ProgressBar, strings[STR_PROGRESS]); unsigned int progress = 0; wchar_t filename[_MAX_LFN]; swprintf(filename, _MAX_LFN, L"rxTools/nand/%sNAND.bin", isEmuNand ? L"EMU" : L""); if(FileOpen(&myFile, filename, 1)){ print(strings[STR_DUMPING], isEmuNand ? strings[STR_EMUNAND] : strings[STR_SYSNAND], filename); ConsoleShow(); int x, y; ConsoleGetXY(&x, &y); y += FONT_HEIGHT * 6; x += FONT_HWIDTH * 2; DrawString(BOT_SCREEN, ProgressBar, x, y, ConsoleGetTextColor(), ConsoleGetBackgroundColor()); swprintf(tmpstr, STR_MAX_LEN, strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_B], strings[STR_CANCEL]); DrawString(BOT_SCREEN, tmpstr, x, y + FONT_HEIGHT*2, ConsoleGetTextColor(), ConsoleGetBackgroundColor()); for(int count = 0; count < getNandSize()/NAND_SECTOR_SIZE/nsectors; count++){ if(isEmuNand) sdmmc_sdcard_readsectors(count*nsectors, nsectors, buf); else sdmmc_nand_readsectors(count*nsectors, nsectors, buf); FileWrite(&myFile, buf, nsectors*NAND_SECTOR_SIZE, count*NAND_SECTOR_SIZE*nsectors); TryScreenShot(); if((count % (int)(getNandSize()/NAND_SECTOR_SIZE/nsectors/PROGRESS_WIDTH)) == 0 && count != 0){ DrawString(BOT_SCREEN, strings[STR_PROGRESS_OK], x+(FONT_WIDTH*(progress++)), y, ConsoleGetTextColor(), ConsoleGetBackgroundColor()); } unsigned int pad = GetInput(); if (pad & BUTTON_B) { FileClose(&myFile); goto end; } } if(isEmuNand){ sdmmc_sdcard_readsectors(checkEmuNAND()/0x200, 1, buf); FileWrite(&myFile, buf, 0x200, 0); } FileClose(&myFile); print(strings[STR_COMPLETED]); ConsoleShow(); }else{ print(strings[STR_FAILED]); ConsoleShow(); } end: print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]); ConsoleShow(); WaitForButton(BUTTON_A); }
int rxMode(int emu) { wchar_t path[64]; const char *shstrtab; const wchar_t *msg; uint8_t keyx[16]; uint32_t tid; int r, sector; Elf32_Ehdr *ehdr; Elf32_Shdr *shdr, *btm; void *keyxArg; FIL fd; UINT br, fsz; if (emu) { sector = checkEmuNAND(); if (sector == 0) { ConsoleInit(); ConsoleSetTitle(L"EMUNAND NOT FOUND!"); print(L"The emunand was not found on\n"); print(L"your SDCard. \n"); print(L"\n"); print(L"Press A to boot SYSNAND\n"); ConsoleShow(); WaitForButton(BUTTON_A); swprintf(path, _MAX_LFN, L"/rxTools/Theme/%u/boot.bin", cfgs[CFG_THEME].val.i); DrawBottomSplash(path); } } else sector = 0; r = getMpInfo(); switch (r) { case MPINFO_KTR: tid = TID_KTR_NATIVE_FIRM; break; case MPINFO_CTR: tid = TID_CTR_NATIVE_FIRM; break; default: msg = L"Unknown Platform: %d"; goto fail; } setAgbBios(); if (sysver < 7 && f_open(&fd, _T("slot0x25KeyX.bin"), FA_READ) == FR_OK) { f_read(&fd, keyx, sizeof(keyx), &br); f_close(&fd); keyxArg = keyx; } else keyxArg = NULL; getFirmPath(path, tid); r = loadFirm(path, &fsz); if (r) { msg = L"Failed to load NATIVE_FIRM: %d\n" L"Reboot rxTools and try again.\n"; goto fail; } ((FirmHdr *)FIRM_ADDR)->arm9Entry = 0x0801B01C; getFirmPatchPath(path, tid); r = f_open(&fd, path, FA_READ); if (r != FR_OK) goto patchFail; r = f_read(&fd, (void *)PATCH_ADDR, PATCH_SIZE, &br); if (r != FR_OK) goto patchFail; f_close(&fd); ehdr = (void *)PATCH_ADDR; shdr = (void *)(PATCH_ADDR + ehdr->e_shoff); shstrtab = (char *)PATCH_ADDR + shdr[ehdr->e_shstrndx].sh_offset; for (btm = shdr + ehdr->e_shnum; shdr != btm; shdr++) { if (!strcmp(shstrtab + shdr->sh_name, ".patch.p9.reboot.body")) { execReboot(sector, keyxArg, ehdr->e_entry, shdr); __builtin_unreachable(); } } msg = L".patch.p9.reboot.body not found\n" L"Please check your installation.\n"; fail: ConsoleInit(); ConsoleSetTitle(L"rxMode"); print(msg, r); print(L"\n"); print(strings[STR_PRESS_BUTTON_ACTION], strings[STR_BUTTON_A], strings[STR_CONTINUE]); ConsoleShow(); WaitForButton(BUTTON_A); return r; patchFail: msg = L"Failed to load the patch: %d\n" L"Check your installation.\n"; goto fail; }
int Initialize() { char str[100]; char strl[100]; char strr[100]; char tmp[256]; wchar_t wtmp[256]; int r; preloadStringsA(); DrawString(BOT_SCREEN, strings[STR_INITIALIZING], FONT_WIDTH, SCREEN_HEIGHT-FONT_HEIGHT, WHITE, BLACK); if(FSInit()){ DrawString(BOT_SCREEN, strings[STR_LOADING], BOT_SCREEN_WIDTH/2, SCREEN_HEIGHT-FONT_HEIGHT, WHITE, BLACK); }else{ DrawString(BOT_SCREEN, strings[STR_FAILED], BOT_SCREEN_WIDTH/2, SCREEN_HEIGHT-FONT_HEIGHT, RED, BLACK); return 1; } LoadFont(); if (fontLoaded){ swprintf(wtmp, sizeof(wtmp)/sizeof(wtmp[0]), strings[STR_ERROR_OPENING], fontpath); DrawString(BOT_SCREEN, wtmp, FONT_WIDTH, SCREEN_HEIGHT-FONT_HEIGHT*2, RED, BLACK); }else{ preloadStringsU(); } //Console Stuff ConsoleSetXY(15, 20); ConsoleSetWH(BOT_SCREEN_WIDTH-30, SCREEN_HEIGHT-80); ConsoleSetBorderColor(BLUE); ConsoleSetTextColor(RGB(0, 141, 197)); ConsoleSetBackgroundColor(TRANSPARENT); ConsoleSetSpecialColor(BLUE); ConsoleSetSpacing(2); ConsoleSetBorderWidth(3); //Check that the data is installed f_mkdir("rxTools"); f_mkdir("rxTools/nand"); InstallConfigData(); readCfg(); if (fontLoaded) cfgs[CFG_LANG].val.s = cfgLang; r = loadStrings(); if (r) { sprintf(tmp, "%s/%s", langPath, cfgs[CFG_LANG].val.s); swprintf(wtmp, sizeof(wtmp)/sizeof(wtmp[0]), strings[STR_ERROR_OPENING], tmp); DrawString(BOT_SCREEN, wtmp, FONT_WIDTH, SCREEN_HEIGHT-FONT_HEIGHT*3, RED, BLACK); } sprintf(str, "/rxTools/Theme/%u/TOP.bin", cfgs[CFG_THEME].val.i); sprintf(strl, "/rxTools/Theme/%u/TOPL.bin", cfgs[CFG_THEME].val.i); sprintf(strr, "/rxTools/Theme/%u/TOPR.bin", cfgs[CFG_THEME].val.i); if (cfgs[CFG_3D].val.i) DrawTopSplash(str, strl, strr); else DrawTopSplash(str, str, str); if (!cfgs[CFG_GUI].val.i) { if(cfgs[CFG_SILENT].val.i) { sprintf(str, "/rxTools/Theme/%u/boot.bin", cfgs[CFG_THEME].val.i); DrawBottomSplash(str); for (int i = 0; i < 0x333333 * 2; i++){ uint32_t pad = GetInput(); if (pad & BUTTON_R1 && i > 0x333333) goto rxTools_boot; } } else { ConsoleInit(); ConsoleSetTitle(strings[STR_AUTOBOOT]); print(strings[STR_HOLD_BUTTON_ACTION], strings[STR_BUTTON_R], strings[STR_OPEN_MENU]); ConsoleShow(); for (int i = 0; i < 0x333333 * 6; i++){ uint32_t pad = GetInput(); if (pad & BUTTON_R1 && i > 0x333333) goto rxTools_boot; } } rxMode(1); } rxTools_boot: sprintf(str, "/rxTools/Theme/%u/TOP.bin", cfgs[CFG_THEME].val.i); sprintf(strl, "/rxTools/Theme/%u/TOPL.bin", cfgs[CFG_THEME].val.i); sprintf(strr, "/rxTools/Theme/%u/TOPR.bin", cfgs[CFG_THEME].val.i); if (cfgs[CFG_3D].val.i) DrawTopSplash(str, strl, strr); else DrawTopSplash(str, str, str); return 0; }
int rxMode(int emu) { const Elf32_Addr line = 32; wchar_t path[64]; const char *shstrtab; const wchar_t *msg; uint8_t keyx[16]; uint32_t tid; int r, sector; Elf32_Ehdr *ehdr; Elf32_Shdr *shdr, *btmShdr; Elf32_Addr cur, btm; void *keyxArg; FIL fd; UINT br, fsz; if (emu) { sector = checkEmuNAND(); if (sector == 0) { ConsoleInit(); ConsoleSetTitle(L"EMUNAND NOT FOUND!"); print(L"The emunand was not found on\n"); print(L"your SDCard. \n"); print(L"\n"); print(L"Press A to boot SYSNAND\n"); ConsoleShow(); WaitForButton(BUTTON_A); swprintf(path, _MAX_LFN, L"/rxTools/Theme/%u/boot.bin", cfgs[CFG_THEME].val.i); DrawBottomSplash(path); } } else sector = 0; r = getMpInfo(); switch (r) { case MPINFO_KTR: tid = TID_KTR_NATIVE_FIRM; break; case MPINFO_CTR: tid = TID_CTR_NATIVE_FIRM; break; default: msg = L"Unknown Platform: %d"; goto fail; } setAgbBios(); if (sysver < 7 && f_open(&fd, _T("slot0x25KeyX.bin"), FA_READ) == FR_OK) { f_read(&fd, keyx, sizeof(keyx), &br); f_close(&fd); keyxArg = keyx; } else keyxArg = NULL; getFirmPath(path, tid); r = loadFirm(path, &fsz); if (r) { msg = L"Failed to load NATIVE_FIRM: %d\n" L"Reboot rxTools and try again.\n"; goto fail; } ((FirmHdr *)FIRM_ADDR)->arm9Entry = 0x0801B01C; getFirmPatchPath(path, tid); r = f_open(&fd, path, FA_READ); if (r != FR_OK) goto patchFail; r = f_read(&fd, (void *)PATCH_ADDR, PATCH_SIZE, &br); if (r != FR_OK) goto patchFail; f_close(&fd); ehdr = (void *)PATCH_ADDR; shdr = (void *)(PATCH_ADDR + ehdr->e_shoff); shstrtab = (char *)PATCH_ADDR + shdr[ehdr->e_shstrndx].sh_offset; for (btmShdr = shdr + ehdr->e_shnum; shdr != btmShdr; shdr++) { if (!strcmp(shstrtab + shdr->sh_name, ".patch.p9.reboot.body")) { memcpy((void *)ehdr->e_entry, (void *)(PATCH_ADDR + shdr->sh_offset), shdr->sh_size); // Drain write buffer __asm__ volatile ("mcr p15, 0, %0, c7, c10, 4" :: "r"(0)); cur = ehdr->e_entry & ~(line - 1); btm = ehdr->e_entry + shdr->sh_size; while (cur < btm) { __asm__ volatile ( // Clean Dcache "mcr p15, 0, %0, c7, c10, 1\n\t" // Flush Icache "mcr p15, 0, %0, c7, c5, 1" :: "r"(cur)); cur += line; } ((void (*)(uint32_t, void *, uintptr_t))ehdr->e_entry)( sector, keyxArg, 0x1FFFFFF8); __builtin_unreachable(); } }