int run_uninstall_autoloader() { #ifdef ENABLE_LOG if (verbose) WriteToLog("[UNINSTALLER]"); #endif //Check if installed if(file_exists("/dev_flash/sys/internal/sys_init_osd_orig.self") != SUCCESS) { #ifdef ENABLE_LOG if (verbose) WriteToLog("Error: sys_init_osd_orig.self not found\r\n"); #endif return FAILED; } //Enable dev_blind if(dir_exists("/dev_blind") != SUCCESS) { {lv2syscall8(SC_FS_MOUNT, (u64)(char*)"CELL_FS_IOS:BUILTIN_FLSH1", (u64)(char*)"CELL_FS_FAT", (u64)(char*)"/dev_blind", 0, 0, 0, 0, 0); } } //Restore original sys_init_osd.self if(file_exists(PATH_SYS_INI_OSD_ORIG) == SUCCESS) { if(file_exists(PATH_SYS_INI_OSD) == SUCCESS) { unlink_secure(PATH_SYS_INI_OSD); sysLv2FsRename(PATH_SYS_INI_OSD_ORIG, PATH_SYS_INI_OSD); //Remove payload char filename[128]; int fw_list[32] = { 0x355C,0x421C,0x430C,0x431C,0x440C,0x441C,0x446C,0x450C,0x453C,0x455C,0x460C,0x465C,0x466C,0x470C,0x475C,0x476C, 0x355D,0x421D,0x430D, 0x441D,0x446D,0x450D,0x453D,0x455D,0x460D,0x465D,0x466D,0x470D,0x475D,0x476D}; int i; for (i = 0; i < 32; i++) { if (fw_list[i] == 0) break; sprintf (filename, "/dev_blind/sys/internal/mpl_payload_%X.bin", fw_list[i]); if (file_exists(filename) == SUCCESS) unlink_secure(filename); sprintf (filename, "/dev_blind/sys/internal/mamba_%X.bin", fw_list[i]); if (file_exists(filename) == SUCCESS) unlink_secure(filename); } #ifdef ENABLE_LOG if (verbose) WriteToLog("Success: MAMBA/PRX Autoloader uninstalled\r\n"); #endif return SUCCESS; } else { #ifdef ENABLE_LOG if (verbose) WriteToLog("Error: sys_init_osd.self not found\r\n"); #endif return FAILED; } } else { #ifdef ENABLE_LOG if (verbose) WriteToLog("Error: /dev_blind not mounted\r\n"); #endif return FAILED; } }
int sys_reboot() { unlink_secure("/dev_hdd0/tmp/turnoff"); lv2syscall4(379,0x1200,0,0,0); return_to_user_prog(int); }
int sys_shutdown() { unlink_secure("/dev_hdd0/tmp/turnoff"); lv2syscall4(379,0x1100,0,0,0); return_to_user_prog(int); }
int copy_async_gbl(char *path1, char *path2, u64 size, char *progress_string1, char *progress_string2) { int ret = 0; FILE *fp = NULL; FILE *fp2 = NULL; float parts = 0; float cpart; char buffer[16384]; use_async_fd = 128; my_f_async.flags = 0; single_bar(progress_string1); parts = (size == 0) ? 0.0f : 100.0f / ((double) size / (double) sizeof(buffer)); cpart = 0; fp = fopen(path1, "rb"); if(!fp) {ret = -1; goto err;} fp2 = fopen(path2, "wb"); if(!fp2) {ret = -2; goto err;} int acum = 0; while (size != 0ULL) { int recv = (size > 16384) ? 16384 : size; recv = fread(buffer, 1, recv, fp); if (recv <= 0) break; if (recv > 0) { loop_write: if(use_async_fd == 128) { use_async_fd = 1; my_f_async.flags = 0; my_f_async.size = recv; my_f_async.fp = fp2; my_f_async.mem = malloc(recv); if(my_f_async.mem) memcpy(my_f_async.mem, (void *) buffer, recv); my_f_async.ret = -1; my_f_async.flags = ASYNC_ENABLE; event_thread_send(0x555ULL, (u64) my_func_async, (u64) &my_f_async); } else { if(!(my_f_async.flags & ASYNC_ENABLE)) { if(my_f_async.flags & ASYNC_ERROR) { fclose(fp2); fp2 = NULL; ret = -6; goto err; } my_f_async.flags = 0; my_f_async.size = recv; my_f_async.fp = fp2; my_f_async.mem = malloc(recv); if(my_f_async.mem) memcpy(my_f_async.mem, (void *) buffer, recv); my_f_async.ret = -1; my_f_async.flags = ASYNC_ENABLE; event_thread_send(0x555ULL, (u64) my_func_async, (u64) &my_f_async); } else { goto loop_write; } } /////////////////// size -= recv; acum+= recv; } if(progress_action == 2) {ret = -0x555; goto err;} pad_last_time = 0; if(1) { if(acum >= sizeof(buffer)) { acum-= sizeof(buffer); cpart += parts; if(cpart >= 1.0f) { update_bar((u32) cpart); cpart-= (float) ((u32) cpart); } } } } ret = 0; err: if(my_f_async.flags & ASYNC_ENABLE){ wait_event_thread(); if(my_f_async.flags & ASYNC_ERROR) { if(fp2) fclose(fp2); fp2 = NULL; ret = -6; } my_f_async.flags = 0; } event_thread_send(0x555ULL, (u64) 0, 0); msgDialogAbort(); if(fp) { fclose(fp); } if(fp2) { fclose(fp2); if(ret < 0) unlink_secure(path2); } return ret; }
static int download_file(char *url, char *file, int mode, u64 *size) { int flags = 0; int ret = 0; void *http_p = NULL; void *uri_p = NULL; httpUri uri; s32 transID = 0; s32 clientID; int pool_size = 0; int recv = -1; u64 length = 0; int code = 0; FILE *fp = NULL; float parts = 0; float cpart; char buffer[16384]; use_async_fd = 128; my_f_async.flags = 0; if(mode == 2) { if(size) sprintf(temp_buffer + 4096, "File Size: %u MB\n%s", (u32) (*size/0x100000ULL), strrchr(file, '/') + 1); else sprintf(temp_buffer + 4096, "File: %s", strrchr(file, '/') + 1); single_bar(temp_buffer + 4096); } http_p = malloc(0x10000); if(!http_p) {ret= -1; goto err;} ret = httpInit(http_p, 0x10000); if(ret < 0) goto err; flags|= 1; ret = httpCreateClient(&clientID); if(ret < 0) goto err; flags|= 2; httpClientSetConnTimeout(clientID, 10000000); ret = httpUtilParseUri(NULL, url, NULL, 0, &pool_size); if (ret < 0) goto err; uri_p = malloc(pool_size); if (!uri_p) goto err; ret = httpUtilParseUri(&uri, url, uri_p, pool_size, NULL); if (ret < 0) goto err; ret = httpCreateTransaction(&transID, clientID, HTTP_METHOD_GET, &uri); if (ret < 0) goto err; free(uri_p); uri_p = NULL; ret = httpSendRequest(transID, NULL, 0, NULL); if (ret < 0) goto err; ret = httpResponseGetStatusCode(transID, &code); if (ret < 0) goto err; if (code == 404 || code == 403) {ret=-4; goto err;} ret = httpResponseGetContentLength(transID, &length); if (ret < 0) { if (ret == HTTP_STATUS_CODE_No_Content) { length = 0ULL; ret = 0; } else goto err; } if(size) *size = length; if(mode == 1) goto err; // get only the size if(mode == 2) { parts = (length == 0) ? 0.0f : 100.0f / ((double) length / (double) sizeof(buffer)); cpart = 0; } fp = fopen(file, "wb"); if(!fp) goto err; int acum = 0; while (recv != 0 && length != 0ULL) { memset(buffer, 0x0, sizeof(buffer)); if (httpRecvResponse(transID, buffer, sizeof(buffer) - 1, &recv) < 0) {fclose(fp); ret = -5; goto err;} if (recv == 0) break; if (recv > 0) { //if(fwrite(buffer, 1, recv, fp) != recv) {fclose(fp); fp = NULL; ret = -6; goto err;} /////////////////// loop_write: if(use_async_fd == 128) { use_async_fd = 1; my_f_async.flags = 0; my_f_async.size = recv; my_f_async.fp = fp; my_f_async.mem = malloc(recv); if(my_f_async.mem) memcpy(my_f_async.mem, (void *) buffer, recv); my_f_async.ret = -1; my_f_async.flags = ASYNC_ENABLE; event_thread_send(0x555ULL, (u64) my_func_async, (u64) &my_f_async); } else { if(!(my_f_async.flags & ASYNC_ENABLE)) { if(my_f_async.flags & ASYNC_ERROR) { fclose(fp); fp = NULL; ret = -6; goto err; } my_f_async.flags = 0; my_f_async.size = recv; my_f_async.fp = fp; my_f_async.mem = malloc(recv); if(my_f_async.mem) memcpy(my_f_async.mem, (void *) buffer, recv); my_f_async.ret = -1; my_f_async.flags = ASYNC_ENABLE; event_thread_send(0x555ULL, (u64) my_func_async, (u64) &my_f_async); } else { goto loop_write; } } /////////////////// length -= recv; acum+= recv; } if(mode == 2 && progress_action == 2) {ret = -0x555; goto err;} pad_last_time = 0; if(mode == 2) { if(acum >= sizeof(buffer)) { acum-= sizeof(buffer); cpart += parts; if(cpart >= 1.0f) { update_bar((u32) cpart); cpart-= (float) ((u32) cpart); } } } } ret = 0; err: if(my_f_async.flags & ASYNC_ENABLE){ wait_event_thread(); if(my_f_async.flags & ASYNC_ERROR) { if(fp) fclose(fp); fp = NULL; ret = -6; } my_f_async.flags = 0; } event_thread_send(0x555ULL, (u64) 0, 0); if(mode == 2) { msgDialogAbort(); } if(fp) { fclose(fp); if(ret < 0) unlink_secure(file); } if(transID) httpDestroyTransaction(transID); if(flags & 2) httpDestroyClient(clientID); if(flags & 1) httpEnd(); if(http_p) free(http_p); if(uri_p) free(uri_p); return ret; }
int run_install_autoloader() { //Init FW int firmware = get_firmware(); #ifdef ENABLE_LOG if (verbose) {WriteToLog(PATH_SYS_INI_OSD_NEW); WriteToLog("\r\n");} #endif if(file_exists(PATH_SYS_INI_OSD_NEW) != SUCCESS) { #ifdef ENABLE_LOG if (verbose) WriteToLog("Error: Unable to find file\r\n"); #endif return FAILED; } char filename_mpl_payload[256]; sprintf (filename_mpl_payload, "%smpl_payload_%X.bin",PATH_DIR_PAYLOAD , firmware); #ifdef ENABLE_LOG if (verbose) {WriteToLog(filename_mpl_payload); WriteToLog("\r\n");} #endif if(file_exists(filename_mpl_payload) != SUCCESS) { #ifdef ENABLE_LOG if (verbose) WriteToLog("Error: Unable to find file\r\n"); #endif return FAILED; } char filename_mamba_payload[256]; sprintf (filename_mamba_payload, "%smamba_%X.bin",PATH_DIR_PAYLOAD , firmware); #ifdef ENABLE_LOG if (verbose) {WriteToLog(filename_mamba_payload); WriteToLog("\r\n");} #endif if(file_exists(filename_mamba_payload) != SUCCESS) { #ifdef ENABLE_LOG if (verbose) WriteToLog("Error: Unable to find file\r\n"); #endif return FAILED; } //Uninstall New_Core run_uninstall_autoloader(); #ifdef ENABLE_LOG if (verbose) WriteToLog("[INSTALLER]"); #endif //Enable dev_blind if(file_exists(PATH_SYS_INI_OSD) != SUCCESS) {{lv2syscall8(SC_FS_MOUNT, (u64)(char*)"CELL_FS_IOS:BUILTIN_FLSH1", (u64)(char*)"CELL_FS_FAT", (u64)(char*)"/dev_blind", 0, 0, 0, 0, 0); }} //Install New_Core if(file_exists(PATH_SYS_INI_OSD_ORIG) != SUCCESS) { if((file_exists(PATH_SYS_INI_OSD) == SUCCESS)) { sysLv2FsChmod(PATH_SYS_INI_OSD, 0777); sysLv2FsRename(PATH_SYS_INI_OSD, PATH_SYS_INI_OSD_ORIG); CopyFile(PATH_SYS_INI_OSD_NEW, PATH_SYS_INI_OSD); char filename[128]; sprintf (filename, "/dev_blind/sys/internal/mpl_payload_%X.bin", firmware); if (file_exists(filename) == SUCCESS) unlink_secure(filename); CopyFile(filename_mpl_payload, filename); sprintf (filename, "/dev_blind/sys/internal/mamba_%X.bin", firmware); if (file_exists(filename) == SUCCESS) unlink_secure(filename); CopyFile(filename_mamba_payload, filename); if ((file_exists("/dev_hdd0/game/MAMBAINST/USRDIR/mamba_plugins.txt") == SUCCESS) && (file_exists(VSH_PLUGINS_PATH_MAMBA) != SUCCESS)) { CopyFile("/dev_hdd0/game/MAMBAINST/USRDIR/mamba_plugins.txt", VSH_PLUGINS_PATH_MAMBA); } if ((file_exists("/dev_hdd0/game/MAMBAINST/USRDIR/prx_plugins.txt") == SUCCESS) && (file_exists(VSH_PLUGINS_PATH_PRX) != SUCCESS)) { CopyFile("/dev_hdd0/game/MAMBAINST/USRDIR/prx_plugins.txt", VSH_PLUGINS_PATH_PRX); } } else { #ifdef ENABLE_LOG if (verbose) WriteToLog("Error: sys_init_osd.self not found (/dev_blind not mounted?)\r\n"); #endif return FAILED; } return SUCCESS; } else { #ifdef ENABLE_LOG if (verbose) WriteToLog("Error: sys_init_osd_orig.self already exist\r\n"); #endif return FAILED; } }