void DumpNandPartitions(){ int isEmuNand = checkEmuNAND() ? NandSwitch() : 0; if(isEmuNand == -1) return; 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(); ConsoleAddText(isEmuNand ? "EmuNAND Partitions Decryptor\n \n" : "NAND Partitions Decryptor\n \n"); for(int i = 3; i < 6; i++){ //Cutting out twln, twlp and agb_save. Todo: Properly decrypt them File out; sprintf(myString, isEmuNand ? "nand/emu_%s" : "nand/%s", p_name[i]); FileOpen(&out, myString, 1); sprintf(myString, "Dumping %s ...", p_name[i]); ConsoleAddText(myString); ConsoleShow(); for(int j = 0; j*0x200 < p_size[i]; j += sect_row){ sprintf(myString, "%08X / %08X", j*0x200, p_size[i]); int x, y; ConsoleGetXY(&x, &y); y += CHAR_WIDTH * 4; x += CHAR_WIDTH*2; DrawString(TOP_SCREEN, myString, 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); } ConsoleAddText("\nPress A to exit"); ConsoleShow(); WaitForButton(BUTTON_A); }
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 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 CTRDecryptor(){ ConsoleInit(); ConsoleAddText(TITLE); ConsoleShow(); int nfiles = ExploreFolders(""); char str[256]; ConsoleInit(); ConsoleAddText(TITLE); sprintf(str, "Decrypted %d files\n", nfiles); ConsoleAddText(str); ConsoleAddText("Press A to exit"); ConsoleShow(); WaitForButton(BUTTON_A); }
One<Builder> MakeBuild::CreateBuilder(Host *host) { SetupDefaultMethod(); VectorMap<String, String> bm = GetMethodVars(method); String builder = bm.Get("BUILDER", "GCC"); int q = BuilderMap().Find(builder); if(q < 0) { PutConsole("Invalid builder " + builder); ConsoleShow(); return NULL; } One<Builder> b = (*BuilderMap().Get(builder))(); b->host = host; b->compiler = bm.Get("COMPILER", ""); b->include = SplitDirs(GetVar("UPP") + ';' + bm.Get("INCLUDE", "") + ';' + add_includes); const Workspace& wspc = GetIdeWorkspace(); for(int i = 0; i < wspc.GetCount(); i++) { const Package& pkg = wspc.GetPackage(i); for(int j = 0; j < pkg.include.GetCount(); j++) b->include.Add(SourcePath(wspc[i], pkg.include[j].text)); } b->libpath = SplitDirs(bm.Get("LIB", "")); b->debug_options = bm.Get("DEBUG_OPTIONS", ""); b->release_options = bm.Get("RELEASE_OPTIONS", ""); b->release_size_options = bm.Get("RELEASE_SIZE_OPTIONS", ""); b->debug_link = bm.Get("DEBUG_LINK", ""); b->release_link = bm.Get("RELEASE_LINK", ""); b->script = bm.Get("SCRIPT", ""); b->main_conf = !!main_conf.GetCount(); return b; }
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 NandDumper(){ File myFile; int isEmuNand = checkEmuNAND() ? NandSwitch() : 0; if(isEmuNand == -1) return; ConsoleInit(); ConsoleAddText(isEmuNand ? "EmuNAND Dumper\n" : "NAND Dumper\n"); unsigned char* buf = 0x21000000; unsigned int nsectors = 0x200; //sectors in a row char ProgressBar[] = "[ ]"; unsigned int progress = 1; int BACKCOLOR = ConsoleGetBackgroundColor(); if(FileOpen(&myFile, isEmuNand ? "/nand/EMUNAND.bin" : "/nand/NAND.bin", 1)){ ConsoleAddText("Dumping...\n"); ConsoleShow(); int x, y; ConsoleGetXY(&x, &y); y += CHAR_WIDTH * 6; x += CHAR_WIDTH*2; DrawString(TOP_SCREEN, ProgressBar, x, y, ConsoleGetTextColor(), ConsoleGetBackgroundColor()); DrawString(TOP_SCREEN, "Press B anytime to abort", x, y + CHAR_WIDTH*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/25)) == 0 && count != 0){ DrawString(TOP_SCREEN, "-", x+(CHAR_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); ConsoleAddText("\nFinished dumping!"); ConsoleShow(); }else{ ConsoleAddText("Failed to create the dump"); ConsoleShow(); } ConsoleAddText("\nPress A to exit"); ConsoleShow(); WaitForButton(BUTTON_A); }
void MenuShow(){ int x = 0, y = 0; ConsoleGetXY(&x, &y); if(!MyMenu->Showed){ ConsoleShow(); MyMenu->Showed = 1; } for(int i = 0; i < MyMenu->nEntryes; i++){ DrawString(BOT_SCREEN, i == MyMenu->Current ? ">" : " ", x+CHAR_WIDTH*(ConsoleGetSpacing()-1), (i) * CHAR_WIDTH + y + CHAR_WIDTH*(ConsoleGetSpacing()+1), ConsoleGetSpecialColor(), ConsoleGetBackgroundColor()); } }
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); }
int NandSwitch(){ ConsoleInit(); ConsoleAddText("Choose the NAND you want to use\n"); ConsoleAddText("Press X : SysNAND"); ConsoleAddText("Press Y : EmuNAND"); ConsoleAddText("Press B : Back"); ConsoleShow(); while (true) { u32 pad_state = InputWait(); if(pad_state & BUTTON_X) return 0; if(pad_state & BUTTON_Y) return 1; if(pad_state & BUTTON_B) return -1; } }
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); }
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(); print(strings[STR_CHOOSE], strings[STR_NAND]); print(strings[STR_BLANK_BUTTON_ACTION], strings[STR_BUTTON_X], strings[STR_SYSNAND]); print(strings[STR_BLANK_BUTTON_ACTION], strings[STR_BUTTON_Y], strings[STR_EMUNAND]); print(strings[STR_BLANK_BUTTON_ACTION], strings[STR_BUTTON_B], strings[STR_CANCEL]); ConsoleShow(); while (true) { uint32_t 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; } }
bool MakeBuild::Build() { VectorMap<String, String> bm = GetMethodVars(method); if(bm.GetCount() == 0) { PutConsole("Invalid build method"); ConsoleShow(); return false; } One<Host> host = CreateHost(false); One<Builder> builder = CreateBuilder(~host); if(!builder) return false; Index<String> p = PackageConfig(GetIdeWorkspace(), 0, bm, mainconfigparam, *host, *builder); Workspace wspc; wspc.Scan(GetMain(), p.GetKeys()); return Build(wspc, mainconfigparam, Null); }
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; }
int main(){ Initialize(); DrawString(TOP_SCREEN, "SUPPORT THE ORIGINAL, NOT THE IMITATION!", 75, 240-10, GREY, BLACK); //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); DrawString(TOP_SCREEN, " NewKeyX ", 0, 240-8, GREEN, BLACK); }else{ if(GetSystemVersion() < 3){ ConsoleInit(); print("WARNING:\n\nCannot find slot0x25KeyX.bin.\nSome titles decryption will fail,\nand some some EmuNANDs will not boot.\n\nPress A to continue...\n"); ConsoleShow(); WaitForButton(BUTTON_A); } DrawString(TOP_SCREEN, " NewKeyX ", 0, 240-8, RED, BLACK); } DrawString(TOP_SCREEN, " EmuNAND ", 0, 240-16, checkEmuNAND() ? GREEN : RED, BLACK); //That's the Main Menu initialization, easy and cool MenuInit(&MainMenu); MenuShow(); while (true) { DrawString(TOP_SCREEN, "[SELECT] Reboot", 349-18*8, 181-24-8, RED, BLACK); DrawString(TOP_SCREEN, "[START] Shutdown", 349-18*8, 181-24, RED, BLACK); u32 pad_state = InputWait(); if(pad_state & BUTTON_DOWN) MenuNextSelection(); if(pad_state & BUTTON_UP) MenuPrevSelection(); if(pad_state & BUTTON_A) MenuSelect(); if(pad_state & BUTTON_SELECT) returnHomeMenu(); if(pad_state & BUTTON_START) ShutDown(); TryScreenShot(); MenuShow(); } FSDeInit(); return 0; }
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); }
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 ProcessCTR(char* path){ PartitionInfo myInfo; File myFile; char myString[256]; //In case it is needed... if(FileOpen(&myFile, path, 0)){ ConsoleInit(); ConsoleAddText(TITLE); unsigned int ncch_base = 0x100; unsigned char magic[] = { 0, 0, 0, 0, 0}; FileRead(&myFile, magic, 4, ncch_base); if(magic[0] == 'N' && magic[1] == 'C' && magic[2] == 'S' && magic[3] == 'D'){ ncch_base = 0x4000; FileRead(&myFile, magic, 4, ncch_base+0x100); if(!(magic[0] == 'N' && magic[1] == 'C' && magic[2] == 'C' && magic[3] == 'H')){ FileClose(&myFile); return 2; } }else if(magic[0] == 'N' && magic[1] == 'C' && magic[2] == 'C' && magic[3] == 'H'){ ncch_base = 0x0; }else{ FileClose(&myFile); return 2; } ctr_ncchheader NCCH; unsigned int mediaunitsize = 0x200; FileRead(&myFile, &NCCH, 0x200, ncch_base); //ConsoleAddText(path); ConsoleAddText(NCCH.productcode); unsigned int NEWCRYPTO = 0, CRYPTO = 1; if(NCCH.flags[3] != 0) NEWCRYPTO = 1; if(NCCH.flags[7] & 4) CRYPTO = 0; if(NEWCRYPTO){ ConsoleAddText("\nCryptoType : 7.X Key security"); }else if(CRYPTO){ ConsoleAddText("\nCryptoType : Secure"); }else{ ConsoleAddText("\nCryptoType : None"); ConsoleAddText("Decryption completed!"); FileClose(&myFile); ConsoleShow(); return 3; } ConsoleShow(); u8 CTR[16]; if(getle32(NCCH.extendedheadersize) > 0){ ConsoleAddText("Decrypting ExHeader..."); ConsoleShow(); ncch_get_counter(NCCH, CTR, 1); FileRead(&myFile, BUFFER_ADDR, 0x800, ncch_base + 0x200); myInfo.buffer = BUFFER_ADDR; myInfo.size = 0x800; myInfo.keyslot = 0x2C; myInfo.ctr = CTR; myInfo.keyY = NCCH.signature; DecryptPartition(&myInfo); FileWrite(&myFile, BUFFER_ADDR, 0x800, ncch_base + 0x200); } if(getle32(NCCH.exefssize) > 0){ ConsoleAddText("Decrypting ExeFS..."); ConsoleShow(); ncch_get_counter(NCCH, CTR, 2); myInfo.buffer = BUFFER_ADDR; myInfo.keyslot = NEWCRYPTO ? 0x25 : 0x2C; myInfo.ctr = CTR; myInfo.keyY = NCCH.signature; size_t bytesRead = FileRead(&myFile, BUFFER_ADDR, getle32(NCCH.exefssize) * mediaunitsize, ncch_base + getle32(NCCH.exefsoffset) * mediaunitsize); myInfo.size = bytesRead; ProcessExeFS(&myInfo); //Explanation at function definition FileWrite(&myFile, BUFFER_ADDR, getle32(NCCH.exefssize) * mediaunitsize, ncch_base + getle32(NCCH.exefsoffset) * mediaunitsize); } if(getle32(NCCH.romfssize) > 0){ ConsoleAddText("Decrypting RomFS..."); ConsoleShow(); ncch_get_counter(NCCH, CTR, 3); myInfo.buffer = BUFFER_ADDR; myInfo.keyslot = NEWCRYPTO ? 0x25 : 0x2C; myInfo.ctr = CTR; myInfo.keyY = NCCH.signature; for(int i = 0; i < getle32(NCCH.romfssize) * mediaunitsize / BLOCK_SIZE; i++){ sprintf(myString, "%i%%", (int)((i*BLOCK_SIZE)/(getle32(NCCH.romfssize) * mediaunitsize/ 100))); int x, y; ConsoleGetXY(&x, &y); y += CHAR_WIDTH * 4; x += CHAR_WIDTH*22; DrawString(TOP_SCREEN, myString, x, y, ConsoleGetTextColor(), ConsoleGetBackgroundColor()); size_t bytesRead = FileRead(&myFile, BUFFER_ADDR, BLOCK_SIZE, ncch_base + getle32(NCCH.romfsoffset) * mediaunitsize + i*BLOCK_SIZE); myInfo.size = bytesRead; DecryptPartition(&myInfo); add_ctr(myInfo.ctr, bytesRead/16); FileWrite(&myFile, BUFFER_ADDR, BLOCK_SIZE, ncch_base + getle32(NCCH.romfsoffset) * mediaunitsize + i*BLOCK_SIZE); } } NCCH.flags[7] |= 4; //Disable encryption NCCH.flags[3] = 0; //Disable 7.XKey usage FileWrite(&myFile, &NCCH, 0x200, ncch_base); if(ncch_base == 0x4000) FileWrite(&myFile, ((u8*)&NCCH) + 0x100, 0x100, 0x1100); //Only for NCSD FileClose(&myFile); ConsoleAddText("Decryption completed!"); ConsoleShow(); return 0; }else return 1; }
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; }
bool MakeBuild::BuildPackage(const Workspace& wspc, int pkindex, int pknumber, int pkcount, String mainparam, String outfile, Vector<String>& linkfile, String& linkopt, bool link) { String package = wspc[pkindex]; String mainpackage = wspc[0]; const Package& pkg = wspc.package[pkindex]; VectorMap<String, String> bm = GetMethodVars(method); if(bm.GetCount() == 0) { PutConsole("Invalid build method"); ConsoleShow(); return false; } One<Host> host = CreateHost(false); if(!IsNull(onefile)) { OneFileHost *h = new OneFileHost; h->host = host; h->onefile = onefile; host = h; } One<Builder> b = CreateBuilder(~host); if(!b) return false; b->config = PackageConfig(wspc, pkindex, bm, mainparam, *host, *b); const TargetMode& m = targetmode == 0 ? debug : release; b->version = m.version; b->method = method; b->outdir = OutDir(b->config, package, bm); host->RealizeDir(b->outdir); String mainfn = Null; Index<String> mcfg = PackageConfig(wspc, 0, bm, mainparam, *host, *b, &mainfn); HdependClearDependencies(); for(int i = 0; i < pkg.GetCount(); i++) { const Array<OptItem>& f = pkg[i].depends; for(int j = 0; j < f.GetCount(); j++) if(MatchWhen(f[j].when, mcfg.GetKeys())) HdependAddDependency(SourcePath(package, pkg[i]), SourcePath(package, f[j].text)); } String tout = OutDir(mcfg, mainpackage, bm, use_target); host->RealizeDir(tout); if(IsNull(mainfn)) mainfn = GetFileTitle(mainpackage) + b->GetTargetExt(); if(!IsNull(outfile)) target = NormalizePath(outfile, tout); else { if(m.target_override && !IsNull(m.target) && IsFolder(m.target)) target = host->NormalizePath(AppendFileName(m.target, mainfn)); else if(m.target_override && (IsFullPath(m.target) || *m.target == '/' || *m.target == '\\')) target = m.target; else if(m.target_override && !IsNull(m.target)) target = host->NormalizePath(AppendFileName(tout, m.target)); else if(IsFullPath(mainfn)) target = mainfn; else target = host->NormalizePath(AppendFileName(tout, mainfn)); } b->target = target; b->mainpackage = mainpackage; if(IsNull(onefile)) { String out; out << "----- " << package << " ( " << Join(b->config.GetKeys(), " ") << " )"; if(pkcount > 1) out << " (" << (pknumber + 1) << " / " << pkcount << ')'; PutConsole(out); } else b->config.FindAdd("NOLIB"); bool ok = b->BuildPackage(package, linkfile, linkopt, GetAllUses(wspc, pkindex), GetAllLibraries(wspc, pkindex, bm, mainparam, *host, *b), targetmode - 1); Vector<String> errors = PickErrors(); host->DeleteFile(errors); if(!ok || !errors.IsEmpty()) return false; if(link) { ok = b->Link(linkfile, linkopt, GetTargetMode().createmap); errors = PickErrors(); host->DeleteFile(errors); if(!ok || !errors.IsEmpty()) return false; } return true; }