int main() { suInit(); gfxInitDefault(); consoleInit(GFX_TOP, &topConsole); consoleSelect(&topConsole); cfguInit(); fsInit(); amInit(); fbTopLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); fbTopRight = gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL); fbBottom = gfxGetFramebuffer(GFX_BOTTOM, 0, NULL, NULL); u8 next = mainMenu(); while (aptMainLoop()) { switch (next) { case 0: break; case 1: next = mainMenu(); break; //case 2: next = legitInstallMenu(); break; case 3: next = downgradeMenu(); break; //case 4: next = downgradeMSETMenu(); break; //case 5: next = downgradeBrowserMenu(); break; default: next = mainMenu(); } if (next == 0) break; } gfxExit(); return 0; }
int main(int argc, const char* argv[]) { gfxInitDefault(); Result setCpuTimeRes = APT_SetAppCpuTimeLimit(30); if(R_FAILED(setCpuTimeRes)) { util_panic("Failed to set syscore CPU time limit: %08lX", setCpuTimeRes); return 1; } romfsInit(); cfguInit(); acInit(); ptmuInit(); httpcInit(0); amInit(); AM_InitializeExternalTitleDatabase(false); soc_buffer = memalign(0x1000, 0x100000); if(soc_buffer != NULL) { socInit(soc_buffer, 0x100000); } screen_init(); ui_init(); mainmenu_open(); while(aptMainLoop() && ui_update()); cleanup(); return 0; }
int main(int argc, const char* argv[]) { gfxInitDefault(); gfxSet3D(false); if(argc > 0) { svchax_init(true); if(!__ctr_svchax || !__ctr_svchax_srv) { util_panic("Failed to acquire kernel access."); return 1; } } aptOpenSession(); Result setCpuTimeRes = APT_SetAppCpuTimeLimit(30); aptCloseSession(); if(R_FAILED(setCpuTimeRes)) { util_panic("Failed to set syscore CPU time limit: %08lX", setCpuTimeRes); return 1; } romfsInit(); cfguInit(); acInit(); ptmuInit(); httpcInit(0); amInit(); AM_InitializeExternalTitleDatabase(false); soc_buffer = memalign(0x1000, 0x100000); if(soc_buffer != NULL) { socInit(soc_buffer, 0x100000); } screen_init(); ui_init(); task_init(); mainmenu_open(); while(aptMainLoop() && ui_update()); cleanup(); return 0; }
void titlesInit() { amInit(); }
int main() { gfxInitDefault(); gfxSet3D(false); PrintConsole topConsole, botConsole; consoleInit(GFX_TOP, &topConsole); consoleInit(GFX_BOTTOM, &botConsole); consoleSelect(&topConsole); consoleClear(); state_t current_state = STATE_NONE; state_t next_state = STATE_INITIALIZE; FS_ProductInfo product_info; char exploitname[64] = {0}; char titlename[64] = {0}; char versiondir[64] = {0}; char displayversion[64] = {0}; u32 flags_bitmask = 0; static char top_text[2048]; char top_text_tmp[256]; top_text[0] = '\0'; int firmware_version[6] = {0}; int firmware_selected_value = 0; int selected_slot = 0; int selected_version = 0; u32 selected_remaster = 0; AM_TitleEntry update_title; bool update_exists = false; int version_maxnum = 0; void* payload_buffer = NULL; size_t payload_size = 0; u64 program_id = 0; while(aptMainLoop()) { hidScanInput(); if(hidKeysDown() & KEY_START) break; // transition function if(next_state != current_state) { memset(top_text_tmp, 0, sizeof(top_text_tmp)); switch(next_state) { case STATE_INITIALIZE: strncat(top_text, "Initializing... You may press START at any time\nto return to menu.\n\n", sizeof(top_text) - 1); break; case STATE_INITIAL: strncat(top_text, "Welcome to sploit_installer: SALT edition!\nPlease proceed with caution, as you might lose\ndata if you don't.\n\nPress A to continue.\n\n", sizeof(top_text) - 1); break; case STATE_SELECT_VERSION: snprintf(top_text_tmp, sizeof(top_text_tmp) - 1, "Auto-detected %s version: %s\nD-Pad to select, A to continue.\n\n", titlename, displayversion); break; case STATE_SELECT_SLOT: snprintf(top_text_tmp, sizeof(top_text_tmp) - 1, "Please select the savegame slot %s will be\ninstalled to. D-Pad to select, A to continue.\n", exploitname); break; case STATE_SELECT_FIRMWARE: strncat(top_text, "Please select your console's firmware version.\nOnly select NEW 3DS if you own a New 3DS (XL).\nD-Pad to select, A to continue.\n", sizeof(top_text) - 1); break; case STATE_DOWNLOAD_PAYLOAD: snprintf(top_text, sizeof(top_text) - 1, "%s\n\n\nDownloading payload...\n", top_text); break; case STATE_COMPRESS_PAYLOAD: strncat(top_text, "Processing payload...\n", sizeof(top_text) - 1); break; case STATE_INSTALL_PAYLOAD: strncat(top_text, "Installing payload...\n\n", sizeof(top_text) - 1); break; case STATE_INSTALLED_PAYLOAD: snprintf(top_text_tmp, sizeof(top_text_tmp) - 1, "Done!\n%s was successfully installed.", exploitname); break; case STATE_ERROR: strncat(top_text, "Looks like something went wrong. :(\n", sizeof(top_text) - 1); break; default: break; } if(top_text_tmp[0]) strncat(top_text, top_text_tmp, sizeof(top_text) - 1); current_state = next_state; } consoleSelect(&topConsole); printf("\x1b[0;%dHsploit_installer: SALT edition\n\n\n", (50 - 31) / 2); printf(top_text); // state function switch(current_state) { case STATE_INITIALIZE: { fsInit(); // get an fs:USER session as the game Result ret = srvGetServiceHandleDirect(&save_session, "fs:USER"); if(R_SUCCEEDED(ret)) ret = FSUSER_Initialize(save_session); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to get game fs:USER session.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = httpcInit(0); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to initialize httpc.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } OS_VersionBin nver_versionbin, cver_versionbin; ret = osGetSystemVersionData(&nver_versionbin, &cver_versionbin); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to get the system version.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = cfguInit(); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to initialize cfgu.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } u8 region = 0; ret = CFGU_SecureInfoGetRegion(®ion); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to get the system region.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } cfguExit(); bool is_new3ds = false; APT_CheckNew3DS(&is_new3ds); firmware_version[0] = is_new3ds; firmware_version[5] = region; firmware_version[1] = cver_versionbin.mainver; firmware_version[2] = cver_versionbin.minor; firmware_version[3] = cver_versionbin.build; firmware_version[4] = nver_versionbin.mainver; u32 pid = 0; ret = svcGetProcessId(&pid, CUR_PROCESS_HANDLE); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to get the process ID for the current process.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = FSUSER_GetProductInfo(&product_info, pid); selected_remaster = product_info.remasterVersion; if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to get the product info for the current process.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = APT_GetProgramID(&program_id); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to get the program ID for the current process.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } u64 update_program_id = 0; if(((program_id >> 32) & 0xFFFF) == 0) update_program_id = program_id | 0x0000000E00000000ULL; if(update_program_id) { ret = amInit(); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to initialize AM.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = AM_GetTitleInfo(1, 1, &update_program_id, &update_title); amExit(); if(R_SUCCEEDED(ret)) update_exists = true; } ret = romfsInit(); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to initialize romfs for this application (romfsInit()).\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = load_exploitlist_config("romfs:/exploitlist_config", &program_id, exploitname, titlename, &flags_bitmask); if(ret) { snprintf(status, sizeof(status) - 1, "Failed to select the exploit.\n Error code: %08lX", ret); if(ret == 1) strncat(status, " Failed to\nopen the config file in romfs.", sizeof(status) - 1); if(ret == 2) strncat(status, " This title is not supported.", sizeof(status) - 1); next_state = STATE_ERROR; break; } int version_index = 0; u32 this_remaster = 0; char this_displayversion[64] = {0}; while(true) { ret = load_exploitversion(exploitname, &program_id, version_index, &this_remaster, this_displayversion); if(ret) break; if(this_remaster == selected_remaster) { strncpy(displayversion, this_displayversion, 63); selected_version = version_index; } version_index++; } if(version_index == 0) { snprintf(status, sizeof(status) - 1, "Failed to read remaster versions from config."); next_state = STATE_ERROR; break; } version_maxnum = version_index - 1; next_state = STATE_INITIAL; } break; case STATE_INITIAL: { if(hidKeysDown() & KEY_A) { if(version_maxnum != 0) next_state = STATE_SELECT_VERSION; else if(flags_bitmask & 0x10) next_state = STATE_SELECT_FIRMWARE; else next_state = STATE_SELECT_SLOT; } } break; case STATE_SELECT_VERSION: { if(hidKeysDown() & KEY_UP) selected_version++; if(hidKeysDown() & KEY_DOWN) selected_version--; if(hidKeysDown() & KEY_A) { if(flags_bitmask & 0x10) next_state = STATE_SELECT_FIRMWARE; else next_state = STATE_SELECT_SLOT; } if(selected_version < 0) selected_version = 0; if(selected_version > version_maxnum) selected_version = version_maxnum; Result ret = load_exploitversion(exploitname, &program_id, selected_version, &selected_remaster, displayversion); if(ret) { snprintf(status, sizeof(status) - 1, "Failed to read remaster version from config."); next_state = STATE_ERROR; break; } printf((selected_version >= version_maxnum) ? " \n" : " ^\n"); printf(" Selected version: %s \n", displayversion); printf((!selected_version) ? " \n" : " v\n"); } break; case STATE_SELECT_SLOT: { if(hidKeysDown() & KEY_UP) selected_slot++; if(hidKeysDown() & KEY_DOWN) selected_slot--; if(hidKeysDown() & KEY_A) next_state = STATE_SELECT_FIRMWARE; if(selected_slot < 0) selected_slot = 0; if(selected_slot > 2) selected_slot = 2; printf((selected_slot >= 2) ? " \n" : " ^\n"); printf(" Selected slot: %d \n", selected_slot + 1); printf((!selected_slot) ? " \n" : " v\n"); } break; case STATE_SELECT_FIRMWARE: { if(hidKeysDown() & KEY_LEFT) firmware_selected_value--; if(hidKeysDown() & KEY_RIGHT) firmware_selected_value++; if(firmware_selected_value < 0) firmware_selected_value = 0; if(firmware_selected_value > 5) firmware_selected_value = 5; if(hidKeysDown() & KEY_UP) firmware_version[firmware_selected_value]++; if(hidKeysDown() & KEY_DOWN) firmware_version[firmware_selected_value]--; int firmware_maxnum = 256; if(firmware_selected_value == 0) firmware_maxnum = 2; if(firmware_selected_value == 5) firmware_maxnum = 7; if(firmware_version[firmware_selected_value] < 0) firmware_version[firmware_selected_value] = 0; if(firmware_version[firmware_selected_value] >= firmware_maxnum) firmware_version[firmware_selected_value] = firmware_maxnum - 1; if(hidKeysDown() & KEY_A) next_state = STATE_DOWNLOAD_PAYLOAD; int offset = 26; if(firmware_selected_value) { offset += 7; for(int i = 1; i < firmware_selected_value; i++) { offset += 2; if(firmware_version[i] >= 10) offset++; } } printf((firmware_version[firmware_selected_value] < firmware_maxnum - 1) ? "%*s^%*s" : "%*s-%*s", offset, " ", 50 - offset - 1, " "); printf(" Selected firmware: %s %d-%d-%d-%d %s \n", firmware_version[0] ? "New3DS" : "Old3DS", firmware_version[1], firmware_version[2], firmware_version[3], firmware_version[4], regions[firmware_version[5]]); printf((firmware_version[firmware_selected_value] > 0) ? "%*sv%*s" : "%*s-%*s", offset, " ", 50 - offset - 1, " "); } break; case STATE_DOWNLOAD_PAYLOAD: { httpcContext context; static char in_url[512]; static char out_url[512]; snprintf(in_url, sizeof(in_url) - 1, "http://smea.mtheall.com/get_payload.php?version=%s-%d-%d-%d-%d-%s", firmware_version[0] ? "NEW" : "OLD", firmware_version[1], firmware_version[2], firmware_version[3], firmware_version[4], regions[firmware_version[5]]); char user_agent[64]; snprintf(user_agent, sizeof(user_agent) - 1, "salt_sploit_installer-%s", exploitname); Result ret = get_redirect(in_url, out_url, 512, user_agent); if(R_FAILED(ret)) { sprintf(status, "Failed to grab payload url\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = httpcOpenContext(&context, HTTPC_METHOD_GET, out_url, 0); if(R_FAILED(ret)) { sprintf(status, "Failed to open http context\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = download_file(&context, &payload_buffer, &payload_size, user_agent); if(R_FAILED(ret)) { sprintf(status, "Failed to download payload\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } if(flags_bitmask & 0x1) next_state = STATE_COMPRESS_PAYLOAD; else next_state = STATE_INSTALL_PAYLOAD; } break; case STATE_COMPRESS_PAYLOAD: payload_buffer = BLZ_Code(payload_buffer, payload_size, &payload_size, BLZ_NORMAL); next_state = STATE_INSTALL_PAYLOAD; break; case STATE_INSTALL_PAYLOAD: { u32 selected_remaster_version = 0; Result ret = load_exploitconfig(exploitname, &program_id, selected_remaster, update_exists ? &update_title.version : NULL, &selected_remaster_version, versiondir, displayversion); if(ret) { snprintf(status, sizeof(status) - 1, "Failed to find your version of\n%s in the config / config loading failed.\n Error code: %08lX", titlename, ret); if(ret == 1) strncat(status, " Failed to\nopen the config file in romfs.", sizeof(status) - 1); if(ret == 2 || ret == 4) strncat(status, " The romfs config file is invalid.", sizeof(status) - 1); if(ret == 3) { snprintf(status, sizeof(status) - 1, "this update-title version (v%u) of %s is not compatible with %s, sorry\n", update_title.version, titlename, exploitname); next_state = STATE_ERROR; break; } if(ret == 5) { snprintf(status, sizeof(status) - 1, "this remaster version (%04lX) of %s is not compatible with %s, sorry\n", selected_remaster_version, titlename, exploitname); next_state = STATE_ERROR; break; } next_state = STATE_ERROR; break; } if(flags_bitmask & 0x8) { fsUseSession(save_session); Result ret = FSUSER_FormatSaveData(ARCHIVE_SAVEDATA, (FS_Path){PATH_EMPTY, 1, (u8*)""}, 0x200, 10, 10, 11, 11, true); fsEndUseSession(); if(ret) { sprintf(status, "Failed to format savedata.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } } if(flags_bitmask & 0x2) { Result ret = parsecopy_saveconfig(versiondir, firmware_version[0], selected_slot); if(ret) { sprintf(status, "Failed to install the savefiles with romfs %s savedir.\n Error code: %08lX", firmware_version[0] == 0?"Old3DS" : "New3DS", ret); next_state = STATE_ERROR; break; } } if(flags_bitmask & 0x4) { Result ret = parsecopy_saveconfig(versiondir, 2, selected_slot); if(ret) { sprintf(status, "Failed to install the savefiles with romfs %s savedir.\n Error code: %08lX", "common", ret); next_state = STATE_ERROR; break; } } } { Result ret; if(payload_embed.enabled) { void* buffer = NULL; size_t size = 0; ret = read_savedata(payload_embed.path, &buffer, &size); if(ret) { sprintf(status, "Failed to embed payload\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } if((payload_embed.offset + payload_size + sizeof(u32)) >= size) { sprintf(status, "Failed to embed payload (too large)\n 0x%X >= 0x%X", (payload_embed.offset + payload_size + sizeof(u32)), size); next_state = STATE_ERROR; break; } *(u32*)(buffer + payload_embed.offset) = payload_size; memcpy(buffer + payload_embed.offset + sizeof(u32), payload_buffer, payload_size); ret = write_savedata(payload_embed.path, buffer, size); free(buffer); } else ret = write_savedata("/payload.bin", payload_buffer, payload_size); if(ret) { sprintf(status, "Failed to install payload\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } next_state = STATE_INSTALLED_PAYLOAD; } break; case STATE_INSTALLED_PAYLOAD: next_state = STATE_NONE; break; default: break; } consoleSelect(&botConsole); printf("\x1b[0;0H Current status:\n %s\n", status); gspWaitForVBlank(); } if(payload_buffer) free(payload_buffer); romfsExit(); httpcExit(); svcCloseHandle(save_session); fsExit(); gfxExit(); return 0; }
int main(int argc, const char* argv[]) { /* Sadly svchax crashes too much, so only allow install mode when running as a CIA // Trigger svchax so we can install CIAs if(argc > 0) { svchax_init(true); if(!__ctr_svchax || !__ctr_svchax_srv) { bSvcHaxAvailable = false; //printf("Failed to acquire kernel access. Install mode disabled.\n"); } } */ // argc is 0 when running as a CIA, and 1 when running as a 3dsx if (argc > 0) { bSvcHaxAvailable = false; } u32 *soc_sharedmem, soc_sharedmem_size = 0x100000; gfxInitDefault(); consoleInit(GFX_TOP, NULL); httpcInit(0); soc_sharedmem = (u32 *)memalign(0x1000, soc_sharedmem_size); socInit(soc_sharedmem, soc_sharedmem_size); sslcInit(0); hidInit(); acInit(); cfguInit(); if (bSvcHaxAvailable) { amInit(); AM_InitializeExternalTitleDatabase(false); } init_menu(GFX_TOP); // Make sure all CIAngel directories exists on the SD card mkpath("/CIAngel", 0777); mkpath("/CIAngel/tmp/", 0777); loadConfig(); // Set up the reading of json check_JSON(); load_JSON_data(); menu_main(); if (bSvcHaxAvailable) { amExit(); } cfguExit(); acExit(); gfxExit(); hidExit(); httpcExit(); socExit(); sslcExit(); }
int exec_cia(const char* path, const char** args){ struct stat sBuff; bool fileExists; bool inited; if(path == NULL || path[0] == '\0'){ errno = EINVAL; return -1; } fileExists = stat(path, &sBuff) == 0; if(!fileExists){ errno = ENOENT; return -1; } else if(S_ISDIR(sBuff.st_mode)){ errno = EINVAL;; return -1; } inited = R_SUCCEEDED(amInit()) && R_SUCCEEDED(fsInit()); if(inited){ Result res; AM_TitleEntry ciaInfo; FS_Archive ciaArchive; Handle ciaFile; int ciaInstalled; ciaParam param; int argsLength; //open cia file res = FSUSER_OpenArchive(&ciaArchive, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, "")); if(R_FAILED(res)) errorAndQuit("Cant open SD FS archive."); res = FSUSER_OpenFile(&ciaFile, ciaArchive, fsMakePath(PATH_ASCII, path + 5/*skip "sdmc:"*/), FS_OPEN_READ, 0); if(R_FAILED(res)) errorAndQuit("Cant open CIA file."); res = AM_GetCiaFileInfo(MEDIATYPE_SD, &ciaInfo, ciaFile); if(R_FAILED(res)) errorAndQuit("Cant get CIA file info."); ciaInstalled = isCiaInstalled(ciaInfo.titleID, ciaInfo.version); if(ciaInstalled == -1){ //error errorAndQuit("Could not read title id list."); } else if(ciaInstalled == 0){ //not installed int error = installCia(ciaFile); if(error == -1) errorAndQuit("Cant install CIA."); } FSFILE_Close(ciaFile); FSUSER_CloseArchive(ciaArchive); param.argc = 0; argsLength = 0; char* argLocation = param.args; while(args[param.argc] != NULL){ strcpy(argLocation, args[param.argc]); argLocation += strlen(args[param.argc]) + 1; argsLength += strlen(args[param.argc]) + 1; param.argc++; } res = APT_PrepareToDoApplicationJump(0, ciaInfo.titleID, 0x1); if(R_FAILED(res)) errorAndQuit("CIA cant run, cant prepare."); res = APT_DoApplicationJump(¶m, sizeof(param.argc) + argsLength, argvHmac); if(R_FAILED(res)) errorAndQuit("CIA cant run, cant jump."); //wait for application jump, for some reason its not instant while(1); } //should never be reached amExit(); fsExit(); errno = ENOTSUP; return -1; }
Result httpwn_setup(char *serverconfig_localpath) { Result ret = 0; u64 http_sysmodule_titleid = 0x0004013000002902ULL; AM_TitleEntry title_entry; u8 *cert = (u8*)builtin_rootca_der; u32 certsize = builtin_rootca_der_size; u8 *filebuffer; u32 filebuffer_size = 0x100000; u32 statuscode = 0; configctx config; targeturlctx *first_targeturlctx = NULL; FILE *f; memset(&config, 0, sizeof(configctx)); config.first_targeturlctx = &first_targeturlctx; ret = amInit(); if(ret!=0) { printf("Failed to initialize AM: 0x%08x.\n", (unsigned int)ret); if(ret==0xd8e06406) { printf("The AM service is inaccessible. With the *hax payloads this should never happen. This is normal with plain ninjhax v1.x: this app isn't usable from ninjhax v1.x without any further hax.\n"); } return ret; } ret = AM_ListTitles(0, 1, &http_sysmodule_titleid, &title_entry); amExit(); if(ret!=0) { printf("Failed to get the HTTP sysmodule title-version: 0x%08x.\n", (unsigned int)ret); return ret; } http_codebin_buf = NULL; http_codebin_buf32 = NULL; http_codebin_size = 0; ret = loadcodebin(http_sysmodule_titleid, MEDIATYPE_NAND, &http_codebin_buf, &http_codebin_size); if(R_FAILED(ret)) { printf("Failed to load the HTTP sysmodule codebin: 0x%08x.\n", (unsigned int)ret); return ret; } http_codebin_buf32 = (u32*)http_codebin_buf; ret = httpcInit(0x1000); if(ret!=0) { printf("Failed to initialize HTTPC: 0x%08x.\n", (unsigned int)ret); if(ret==0xd8e06406) { printf("The HTTPC service is inaccessible. With the *hax payload this may happen if the process this app is running under doesn't have access to that service. Please try rebooting the system, boot *hax payload, then directly launch the app.\n"); } free(http_codebin_buf); return ret; } filebuffer = malloc(filebuffer_size); if(filebuffer==NULL) { printf("Failed to allocate the config filebuffer.\n"); ret = -2; httpcExit(); free(http_codebin_buf); return ret; } memset(filebuffer, 0, filebuffer_size); printf("Downloading config...\n"); ret = download_config("https://yls8.mtheall.com/ctr-httpwn/config.php", cert, certsize, filebuffer, filebuffer_size-1, &statuscode); if(ret!=0) { printf("Config downloading failed: 0x%08x.\n", (unsigned int)ret); if(statuscode==500) { printf("HTTP status-code 500 was returned, server reply:\n%s\n", (char*)filebuffer); } f = fopen(serverconfig_localpath, "rb"); if(f) { printf("Use the cached server_config from SD instead?\nPress the A button to continue, B to abort.\n"); while(1) { gspWaitForVBlank(); hidScanInput(); if(hidKeysDown() & KEY_A)break; if(hidKeysDown() & KEY_B) { fclose(f); httpcExit(); free(http_codebin_buf); return ret; } } memset(filebuffer, 0, filebuffer_size); fread(filebuffer, 1, filebuffer_size-1, f); fclose(f); } else { httpcExit(); free(http_codebin_buf); return ret; } } else { unlink(serverconfig_localpath); f = fopen(serverconfig_localpath, "wb"); if(f) { fwrite(filebuffer, 1, strlen((char*)filebuffer), f); fclose(f); } } ret = config_parse(&config, (char*)filebuffer); if(ret==0) { if(title_entry.version != 13318) { printf("The installed HTTP sysmodule version(v%u) is not supported.", title_entry.version); if(config.incompatsysver_message[0])printf(" %s", config.incompatsysver_message); printf("\n"); httpcExit(); free(http_codebin_buf); free(filebuffer); return -1; } if(display_config_message(&config, "Message from the server:")) { httpcExit(); free(http_codebin_buf); free(filebuffer); return 0; } } if(ret==0) { f = fopen("user_config.xml", "rb"); if(f) { printf("Loading+parsing user_config.xml since it exists on SD...\n"); memset(filebuffer, 0, filebuffer_size); fread(filebuffer, 1, filebuffer_size-1, f); fclose(f); ret = config_parse(&config, (char*)filebuffer); if(ret==0) { if(display_config_message(&config, "Message from the user_config:")) { httpcExit(); free(http_codebin_buf); free(filebuffer); return 0; } } } } if(ret!=0) { printf("Config parsing failed: 0x%08x.\n", (unsigned int)ret); httpcExit(); free(http_codebin_buf); free(filebuffer); return ret; } f = fopen("user_nim_rootcertchain_rootca.der", "rb"); if(f) { printf("Loading user_nim_rootcertchain_rootca.der since it exists on SD, which will be used instead of the built-in ctr-httpwn cert...\n"); memset(filebuffer, 0, filebuffer_size); certsize = fread(filebuffer, 1, filebuffer_size, f); fclose(f); cert = filebuffer; } printf("Preparing the haxx...\n"); ret = http_haxx("http://localhost/", cert, certsize, first_targeturlctx);//URL doesn't matter much since this won't actually be requested over the network. config_freemem(&config); httpcExit(); free(http_codebin_buf); free(filebuffer); if(ret!=0) { printf("Haxx setup failed: 0x%08x.\n", (unsigned int)ret); return ret; } return ret; }
Result backupAllExtdata(u8 *filebuffer, size_t bufsize) { Result ret=0; u8 region=0; memset(filebuffer, 0, bufsize); ret = initCfgu(); if(ret!=0) { printf("initCfgu() failed: 0x%08x\n", (unsigned int)ret); gfxFlushBuffers(); gfxSwapBuffers(); return ret; } ret = CFGU_SecureInfoGetRegion(®ion); if(ret!=0) { printf("CFGU_SecureInfoGetRegion() failed: 0x%08x\n", (unsigned int)ret); gfxFlushBuffers(); gfxSwapBuffers(); return ret; } exitCfgu(); amInit(); u32 titleCount = 0; ret = AM_GetTitleCount(mediatype_SDMC, &titleCount); if(ret!=0) { printf("AM_GetTitleCount() failed: 0x%08x\n", (unsigned int)ret); gfxFlushBuffers(); gfxSwapBuffers(); return ret; } u64* titleList = (u64*)malloc(sizeof(u64) * titleCount); ret = AM_GetTitleIdList(mediatype_SDMC, titleCount, titleList); if(ret!=0) { printf("AM_GetTitleIdList() failed: 0x%08x\n", (unsigned int)ret); gfxFlushBuffers(); gfxSwapBuffers(); return ret; } int i; for (i=0; i<titleCount; ++i) { unsigned int title = (titleList[i]>>8) & 0xFFFFFF; dumpArchive(mediatype_SDMC, title, ARCH_EXTDATA, user_extdata_dumpfolder, filebuffer, bufsize); if (title == 0x725) { svcSleepThread(5000000000LL); } } free(titleList); amExit(); for (i=0xE0000000; i<0xE0000100; ++i) { dumpArchive(mediatype_NAND, i, ARCH_SHARED_EXTDATA, shared_extdata_dumpfolder, filebuffer, bufsize); } for (i=0xF0000000; i<0xF0000100; ++i) { dumpArchive(mediatype_NAND, i, ARCH_SHARED_EXTDATA, shared_extdata_dumpfolder, filebuffer, bufsize); } printf("Success!\n"); gfxFlushBuffers(); gfxSwapBuffers(); //svcSleepThread(5000000000LL); return 0; }