From 6f0a8765fa5eaa1a90fcbd2136ac1af263ffec8c Mon Sep 17 00:00:00 2001 From: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com> Date: Fri, 1 Sep 2023 17:24:41 +0200 Subject: [PATCH] Refactor menu options into their own files --- ios_mcp/Makefile | 2 +- ios_mcp/source/menu.c | 467 +----------------- .../source/{ => options}/DebugSystemRegion.c | 0 .../source/{ => options}/DebugSystemRegion.h | 0 .../source/{ => options}/DumpOtpAndSeeprom.c | 0 .../source/{ => options}/DumpOtpAndSeeprom.h | 0 ios_mcp/source/options/DumpSyslogs.c | 69 +++ ios_mcp/source/options/DumpSyslogs.h | 3 + ios_mcp/source/options/EditParental.c | 72 +++ ios_mcp/source/options/EditParental.h | 3 + ios_mcp/source/options/InstallWUP.c | 79 +++ ios_mcp/source/options/InstallWUP.h | 3 + ios_mcp/source/options/LoadNetConf.c | 186 +++++++ ios_mcp/source/options/LoadNetConf.h | 3 + ios_mcp/source/{ => options}/PairDRC.c | 0 ios_mcp/source/{ => options}/PairDRC.h | 0 ios_mcp/source/options/SetColdbootTitle.c | 75 +++ ios_mcp/source/options/SetColdbootTitle.h | 3 + ios_mcp/source/{ => options}/StartWupserver.c | 0 ios_mcp/source/{ => options}/StartWupserver.h | 0 .../source/{ => options}/SubmitSystemData.c | 0 .../source/{ => options}/SubmitSystemData.h | 0 .../source/{ => options}/SystemInformation.c | 0 .../source/{ => options}/SystemInformation.h | 0 ios_mcp/source/options/options.h | 13 + 25 files changed, 513 insertions(+), 465 deletions(-) rename ios_mcp/source/{ => options}/DebugSystemRegion.c (100%) rename ios_mcp/source/{ => options}/DebugSystemRegion.h (100%) rename ios_mcp/source/{ => options}/DumpOtpAndSeeprom.c (100%) rename ios_mcp/source/{ => options}/DumpOtpAndSeeprom.h (100%) create mode 100644 ios_mcp/source/options/DumpSyslogs.c create mode 100644 ios_mcp/source/options/DumpSyslogs.h create mode 100644 ios_mcp/source/options/EditParental.c create mode 100644 ios_mcp/source/options/EditParental.h create mode 100644 ios_mcp/source/options/InstallWUP.c create mode 100644 ios_mcp/source/options/InstallWUP.h create mode 100644 ios_mcp/source/options/LoadNetConf.c create mode 100644 ios_mcp/source/options/LoadNetConf.h rename ios_mcp/source/{ => options}/PairDRC.c (100%) rename ios_mcp/source/{ => options}/PairDRC.h (100%) create mode 100644 ios_mcp/source/options/SetColdbootTitle.c create mode 100644 ios_mcp/source/options/SetColdbootTitle.h rename ios_mcp/source/{ => options}/StartWupserver.c (100%) rename ios_mcp/source/{ => options}/StartWupserver.h (100%) rename ios_mcp/source/{ => options}/SubmitSystemData.c (100%) rename ios_mcp/source/{ => options}/SubmitSystemData.h (100%) rename ios_mcp/source/{ => options}/SystemInformation.c (100%) rename ios_mcp/source/{ => options}/SystemInformation.h (100%) create mode 100644 ios_mcp/source/options/options.h diff --git a/ios_mcp/Makefile b/ios_mcp/Makefile index d418774..0041708 100644 --- a/ios_mcp/Makefile +++ b/ios_mcp/Makefile @@ -33,7 +33,7 @@ MACHDEP = -DSTARBUCK -mbig-endian -mcpu=arm926ej-s -msoft-float -mfloat-abi=soft #--------------------------------------------------------------------------------- TARGET := $(notdir $(CURDIR)) BUILD := build -SOURCES := source source/minilzo +SOURCES := source source/minilzo source/options DATA := data INCLUDES := source diff --git a/ios_mcp/source/menu.c b/ios_mcp/source/menu.c index be848af..76d3cdc 100644 --- a/ios_mcp/source/menu.c +++ b/ios_mcp/source/menu.c @@ -23,30 +23,16 @@ #include "fsa.h" #include "socket.h" #include "netconf.h" -#include "mcp_install.h" -#include "sci.h" #include "mcp_misc.h" #include #include -#include "DumpOtpAndSeeprom.h" -#include "StartWupserver.h" -#include "PairDRC.h" -#include "DebugSystemRegion.h" -#include "SystemInformation.h" -#include "SubmitSystemData.h" - -static void option_SetColdbootTitle(void); -static void option_DumpSyslogs(void); -static void option_LoadNetConf(void); -static void option_InstallWUP(void); -static void option_EditParental(void); +#include "options/options.h" + static void option_Shutdown(void); extern int ppcHeartBeatThreadId; -extern uint64_t currentColdbootOS; -extern uint64_t currentColdbootTitle; int fsaHandle = -1; @@ -223,136 +209,6 @@ void waitButtonInput(void) } } -static void option_SetColdbootTitle(void) -{ - static const Menu coldbootTitleOptions[] = { - {"Back", {0} }, - {"Wii U Menu (JPN)", {.tid = 0x0005001010040000}}, - {"Wii U Menu (USA)", {.tid = 0x0005001010040100}}, - {"Wii U Menu (EUR)", {.tid = 0x0005001010040200}}, - - // non-retail systems only - {"System Config Tool", {.tid = 0x000500101F700500}}, - {"DEVMENU (pre-2.09)", {.tid = 0x000500101F7001FF}}, - {"Kiosk Menu ", {.tid = 0x000500101FA81000}}, - }; - - // Only print the non-retail options if the system is in debug mode. - const int option_count = ((IOS_CheckDebugMode() == 0) ? 7 : 4); - - int rval; - uint64_t newtid = 0; - int selected = 0; - - gfx_clear(COLOR_BACKGROUND); - while (1) { - uint32_t index = 16 + 8 + 2 + 8; - gfx_set_font_color(COLOR_PRIMARY); - - // draw current titles - gfx_printf(16, index, GfxPrintFlag_ClearBG, "Current coldboot title: %08lx-%08lx", - (uint32_t)(currentColdbootTitle >> 32), (uint32_t)(currentColdbootTitle & 0xFFFFFFFFU)); - index += CHAR_SIZE_DRC_Y + 4; - - gfx_printf(16, index, GfxPrintFlag_ClearBG, "Current coldboot os: %08lx-%08lx", - (uint32_t)(currentColdbootOS >> 32), (uint32_t)(currentColdbootOS & 0xFFFFFFFFU)); - index += (CHAR_SIZE_DRC_Y + 4) * 2; - - selected = drawMenu("Set Coldboot Title", - coldbootTitleOptions, option_count, selected, - MenuFlag_ShowTID | MenuFlag_NoClearScreen, 16, index); - index += (CHAR_SIZE_DRC_Y + 4) * option_count; - - newtid = coldbootTitleOptions[selected].tid; - if (newtid == 0) - return; - - // set the new default title ID - rval = setDefaultTitleId(newtid); - - if (newtid) { - index += (CHAR_SIZE_DRC_Y + 4) * 2; - - gfx_set_font_color(COLOR_PRIMARY); - gfx_printf(16, index, GfxPrintFlag_ClearBG, - "Setting coldboot title id to %08lx-%08lx, rval %d ", - (uint32_t)(newtid >> 32), (uint32_t)(newtid & 0xFFFFFFFFU), rval); - index += CHAR_SIZE_DRC_Y + 4; - - if (rval < 0) { - gfx_set_font_color(COLOR_ERROR); - gfx_print(16, index, GfxPrintFlag_ClearBG, "Error! Make sure title is installed correctly."); - } else { - gfx_set_font_color(COLOR_SUCCESS); - gfx_print(16, index, GfxPrintFlag_ClearBG, "Success! "); - } - } - } -} - -static void option_DumpSyslogs(void) -{ - gfx_clear(COLOR_BACKGROUND); - - drawTopBar("Dumping Syslogs..."); - - uint32_t index = 16 + 8 + 2 + 8; - gfx_print(16, index, 0, "Creating 'logs' directory..."); - index += CHAR_SIZE_DRC_Y + 4; - - int res = FSA_MakeDir(fsaHandle, "/vol/storage_recovsd/logs", 0x600); - if ((res < 0) && !(res == -0x30016)) { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, 0, "Failed to create directory: %x", res); - waitButtonInput(); - return; - } - - gfx_print(16, index, 0, "Opening system 'logs' directory..."); - index += CHAR_SIZE_DRC_Y + 4; - - int dir_handle; - res = FSA_OpenDir(fsaHandle, "/vol/system/logs", &dir_handle); - if (res < 0) { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, 0, "Failed to open system logs: %x", res); - waitButtonInput(); - return; - } - - char src_path[500]; - char dst_path[500]; - FSDirectoryEntry dir_entry; - while (FSA_ReadDir(fsaHandle, dir_handle, &dir_entry) >= 0) { - if (dir_entry.stat.flags & DIR_ENTRY_IS_DIRECTORY) { - continue; - } - - gfx_printf(16, index, GfxPrintFlag_ClearBG, "Copying %s...", dir_entry.name); - - snprintf(src_path, sizeof(src_path), "/vol/system/logs/" "%s", dir_entry.name); - snprintf(dst_path, sizeof(dst_path), "/vol/storage_recovsd/logs/" "%s", dir_entry.name); - - res = copy_file(fsaHandle, src_path, dst_path); - if (res < 0) { - index += CHAR_SIZE_DRC_Y + 4; - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, GfxPrintFlag_ClearBG, "Failed to copy %s: %x", dir_entry.name, res); - waitButtonInput(); - - FSA_CloseDir(fsaHandle, dir_handle); - return; - } - } - - index += CHAR_SIZE_DRC_Y + 4; - gfx_set_font_color(COLOR_SUCCESS); - gfx_print(16, index, 0, "Done!"); - waitButtonInput(); - - FSA_CloseDir(fsaHandle, dir_handle); -} - /** * Initialize the network configuration. * @param index [in/out] Starting (and ending) Y position. @@ -425,323 +281,6 @@ int initNetconf(uint32_t* index) return 0; } -static void network_parse_config_value(uint32_t* console_idx, NetConfCfg* cfg, const char* key, const char* value, uint32_t value_len) -{ - if (strncmp(key, "type", sizeof("type")) == 0) { - gfx_printf(16, *console_idx, 0, "Type: %s", value); - (*console_idx) += CHAR_SIZE_DRC_Y + 4; - - if (value) { - if (strncmp(value, "wifi", sizeof("wifi")) == 0) { - cfg->wl0.if_index = NET_CFG_INTERFACE_TYPE_WIFI; - cfg->wl0.if_sate = 1; - cfg->wl0.ipv4Info.mode = NET_CONFIG_IPV4_MODE_AUTO_OBTAIN_IP; - cfg->wifi.config_method = 0; - } else if (strncmp(value, "eth", sizeof("eth")) == 0) { - cfg->eth0.if_index = NET_CFG_INTERFACE_TYPE_ETHERNET; - cfg->eth0.if_sate = 1; - cfg->eth0.ipv4Info.mode = NET_CONFIG_IPV4_MODE_AUTO_OBTAIN_IP; - cfg->ethCfg.negotiation = NET_CFG_ETH_CFG_NEGOTIATION_AUTO; - } - } - } else if (strncmp(key, "ssid", sizeof("ssid")) == 0) { - gfx_printf(16, *console_idx, 0, "SSID: %s (%lu)", value, value_len); - (*console_idx) += CHAR_SIZE_DRC_Y + 4; - - if (value) { - memcpy(cfg->wifi.config.ssid, value, value_len); - cfg->wifi.config.ssidlength = value_len; - } - } else if (strncmp(key, "key", sizeof("key")) == 0) { - gfx_printf(16, *console_idx, 0, "Key: ******* (%lu)", value_len); - (*console_idx) += CHAR_SIZE_DRC_Y + 4; - - if (value) { - memcpy(cfg->wifi.config.privacy.aes_key, value, value_len); - cfg->wifi.config.privacy.aes_key_len = value_len; - } - } else if (strncmp(key, "key_type", sizeof("key_type")) == 0) { - gfx_printf(16, *console_idx, 0, "Key type: %s", value); - (*console_idx) += CHAR_SIZE_DRC_Y + 4; - - if (value) { - if (strncmp(value, "NONE", sizeof("NONE")) == 0) { - cfg->wifi.config.privacy.mode = NET_CFG_WIFI_PRIVACY_MODE_NONE; - } else if (strncmp(value, "WEP", sizeof("WEP")) == 0) { - cfg->wifi.config.privacy.mode = NET_CFG_WIFI_PRIVACY_MODE_WEP; - } else if (strncmp(value, "WPA2_PSK_TKIP", sizeof("WPA2_PSK_TKIP")) == 0) { - cfg->wifi.config.privacy.mode = NET_CFG_WIFI_PRIVACY_MODE_WPA2_PSK_TKIP; - } else if (strncmp(value, "WPA_PSK_TKIP", sizeof("WPA_PSK_TKIP")) == 0) { - cfg->wifi.config.privacy.mode = NET_CFG_WIFI_PRIVACY_MODE_WPA_PSK_TKIP; - } else if (strncmp(value, "WPA2_PSK_AES", sizeof("WPA2_PSK_AES")) == 0) { - cfg->wifi.config.privacy.mode = NET_CFG_WIFI_PRIVACY_MODE_WPA2_PSK_AES; - } else if (strncmp(value, "WPA_PSK_AES", sizeof("WPA_PSK_AES")) == 0) { - cfg->wifi.config.privacy.mode = NET_CFG_WIFI_PRIVACY_MODE_WPA_PSK_AES; - } else { - gfx_print(16, *console_idx, 0, "Unknown key type!"); - (*console_idx) += CHAR_SIZE_DRC_Y + 4; - } - } - } -} - -static void option_LoadNetConf(void) -{ - gfx_clear(COLOR_BACKGROUND); - drawTopBar("Loading network configuration..."); - - uint32_t index = 16 + 8 + 2 + 8; - gfx_print(16, index, 0, "Initializing netconf..."); - index += CHAR_SIZE_DRC_Y + 4; - - int res = netconf_init(); - if (res <= 0) { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, 0, "Failed to initialize netconf: %x", res); - waitButtonInput(); - return; - } - - gfx_print(16, index, 0, "Reading network.cfg..."); - index += CHAR_SIZE_DRC_Y + 4; - - int cfgHandle; - res = FSA_OpenFile(fsaHandle, "/vol/storage_recovsd/network.cfg", "r", &cfgHandle); - if (res < 0) { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, 0, "Failed to open network.cfg: %x", res); - waitButtonInput(); - return; - } - - FSStat stat; - res = FSA_StatFile(fsaHandle, cfgHandle, &stat); - if (res < 0) { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, 0, "Failed to stat file: %x", res); - waitButtonInput(); - - FSA_CloseFile(fsaHandle, cfgHandle); - return; - } - - char* cfgBuffer = (char*) IOS_HeapAllocAligned(CROSS_PROCESS_HEAP_ID, stat.size + 1, 0x40); - if (!cfgBuffer) { - gfx_set_font_color(COLOR_ERROR); - gfx_print(16, index, 0, "Out of memory!"); - waitButtonInput(); - - FSA_CloseFile(fsaHandle, cfgHandle); - return; - } - - cfgBuffer[stat.size] = '\0'; - - res = FSA_ReadFile(fsaHandle, cfgBuffer, 1, stat.size, cfgHandle, 0); - if (res != stat.size) { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, 0, "Failed to read file: %x", res); - waitButtonInput(); - - IOS_HeapFree(CROSS_PROCESS_HEAP_ID, cfgBuffer); - FSA_CloseFile(fsaHandle, cfgHandle); - return; - } - - NetConfCfg cfg; - memset(&cfg, 0, sizeof(cfg)); - - // parse network cfg file - const char* keyPtr = cfgBuffer; - const char* valuePtr = NULL; - for (size_t i = 0; i < stat.size; i++) { - if (cfgBuffer[i] == '=') { - cfgBuffer[i] = '\0'; - - valuePtr = cfgBuffer + i + 1; - } else if (cfgBuffer[i] == '\n') { - size_t end = i; - cfgBuffer[end] = '\0'; - if (cfgBuffer[end - 1] == '\r') { - end = i - 1; - cfgBuffer[end] = '\0'; - } - - network_parse_config_value(&index, &cfg, keyPtr, valuePtr, (cfgBuffer + end) - valuePtr); - - keyPtr = cfgBuffer + i + 1; - valuePtr = NULL; - } - } - - // if valuePtr isn't NULL there is another option without a newline at the end - if (valuePtr) { - network_parse_config_value(&index, &cfg, keyPtr, valuePtr, (cfgBuffer + stat.size) - valuePtr); - } - - gfx_print(16, index, 0, "Applying configuration..."); - index += CHAR_SIZE_DRC_Y + 4; - - res = netconf_set_running(&cfg); - if (res < 0) { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, 0, "Failed to apply configuration: %x", res); - waitButtonInput(); - - IOS_HeapFree(CROSS_PROCESS_HEAP_ID, cfgBuffer); - FSA_CloseFile(fsaHandle, cfgHandle); - return; - } - - gfx_set_font_color(COLOR_SUCCESS); - gfx_print(16, index, 0, "Done!"); - index += CHAR_SIZE_DRC_Y + 4; - - waitButtonInput(); - - IOS_HeapFree(CROSS_PROCESS_HEAP_ID, cfgBuffer); - FSA_CloseFile(fsaHandle, cfgHandle); -} - -static void option_InstallWUP(void) -{ - gfx_clear(COLOR_BACKGROUND); - drawTopBar("Installing WUP"); - - uint32_t index = 16 + 8 + 2 + 8; - gfx_print(16, index, 0, "Make sure to place a valid signed WUP directly in 'sd:/install'"); - index += CHAR_SIZE_DRC_Y + 4; - - int mcpHandle = IOS_Open("/dev/mcp", 0); - if (mcpHandle < 0) { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, 0, "Failed to open /dev/mcp: %x", mcpHandle); - waitButtonInput(); - return; - } - - gfx_print(16, index, 0, "Querying install info..."); - index += CHAR_SIZE_DRC_Y + 4; - - MCPInstallInfo info; - int res = MCP_InstallGetInfo(mcpHandle, "/vol/storage_recovsd/install", &info); - if (res < 0) { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, 0, "Failed to get install info: %x", res); - waitButtonInput(); - - IOS_Close(mcpHandle); - return; - } - - gfx_printf(16, index, 0, "Installing title: %08lx-%08lx...", - (uint32_t)(info.titleId >> 32), (uint32_t)(info.titleId & 0xFFFFFFFFU)); - index += CHAR_SIZE_DRC_Y + 4; - - // only install to NAND - res = MCP_InstallSetTargetDevice(mcpHandle, 0); - if (res < 0) { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, 0, "MCP_InstallSetTargetDevice: %x", res); - waitButtonInput(); - - IOS_Close(mcpHandle); - return; - } - res = MCP_InstallSetTargetUsb(mcpHandle, 0); - if (res < 0) { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, 0, "MCP_InstallSetTargetUsb: %x", res); - waitButtonInput(); - - IOS_Close(mcpHandle); - return; - } - - // TODO: async installations - res = MCP_InstallTitle(mcpHandle, "/vol/storage_recovsd/install"); - if (res < 0) { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, 0, "Failed to install: %x", res); - waitButtonInput(); - - IOS_Close(mcpHandle); - return; - } - - gfx_set_font_color(COLOR_SUCCESS); - gfx_print(16, index, 0, "Done!"); - waitButtonInput(); - - IOS_Close(mcpHandle); -} - -static void option_EditParental(void) -{ - static const Menu parentalControlOptions[] = { - {"Back", {0} }, - {"Disable", {0} }, - }; - - int rval; - int selected = 0; - - gfx_clear(COLOR_BACKGROUND); - while (1) { - uint32_t index = 16 + 8 + 2 + 8; - gfx_set_font_color(COLOR_PRIMARY); - - // draw current parental control info - uint8_t enabled = 0; - int res = SCIGetParentalEnable(&enabled); - if (res == 1) { - gfx_set_font_color(COLOR_PRIMARY); - gfx_printf(16, index, GfxPrintFlag_ClearBG, "Parental Controls: %s", - enabled ? "Enabled" : "Disabled"); - } else { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, GfxPrintFlag_ClearBG, "SCIGetParentalEnable failed: %d", res); - } - index += CHAR_SIZE_DRC_Y + 4; - - char pin[5] = ""; - res = SCIGetParentalPinCode(pin, sizeof(pin)); - if (res == 1) { - gfx_set_font_color(COLOR_PRIMARY); - gfx_printf(16, index, GfxPrintFlag_ClearBG, "Parental Pin Code: %s", pin); - } else { - gfx_set_font_color(COLOR_ERROR); - gfx_printf(16, index, GfxPrintFlag_ClearBG, "SCIGetParentalPinCode failed: %d", res); - } - index += (CHAR_SIZE_DRC_Y + 4) * 2; - - gfx_set_font_color(COLOR_PRIMARY); - - selected = drawMenu("Edit Parental Controls", - parentalControlOptions, ARRAY_SIZE(parentalControlOptions), selected, - MenuFlag_NoClearScreen, 16, index); - index += (CHAR_SIZE_DRC_Y + 4) * (ARRAY_SIZE(parentalControlOptions) + 1); - - if (selected == 0) - return; - - // Option 1: Disable the parental controls. - rval = SCISetParentalEnable(0); - - gfx_printf(16, index, GfxPrintFlag_ClearBG, "SCISetParentalEnable(false): %d ", rval); - index += CHAR_SIZE_DRC_Y + 4; - - if (rval != 1) { - gfx_set_font_color(COLOR_ERROR); - gfx_print(16, index, GfxPrintFlag_ClearBG, "Error! "); - } else { - gfx_set_font_color(COLOR_SUCCESS); - gfx_print(16, index, GfxPrintFlag_ClearBG, "Success!"); - } - index += CHAR_SIZE_DRC_Y + 4; - } -} - /** * Get region code information. * @param productArea_id Product area ID: 0-6 @@ -787,7 +326,7 @@ static void option_Shutdown(void) IOS_Close(fsaHandle); } - IOS_Shutdown(0); + IOS_Shutdown(0); } int menuThread(void* arg) diff --git a/ios_mcp/source/DebugSystemRegion.c b/ios_mcp/source/options/DebugSystemRegion.c similarity index 100% rename from ios_mcp/source/DebugSystemRegion.c rename to ios_mcp/source/options/DebugSystemRegion.c diff --git a/ios_mcp/source/DebugSystemRegion.h b/ios_mcp/source/options/DebugSystemRegion.h similarity index 100% rename from ios_mcp/source/DebugSystemRegion.h rename to ios_mcp/source/options/DebugSystemRegion.h diff --git a/ios_mcp/source/DumpOtpAndSeeprom.c b/ios_mcp/source/options/DumpOtpAndSeeprom.c similarity index 100% rename from ios_mcp/source/DumpOtpAndSeeprom.c rename to ios_mcp/source/options/DumpOtpAndSeeprom.c diff --git a/ios_mcp/source/DumpOtpAndSeeprom.h b/ios_mcp/source/options/DumpOtpAndSeeprom.h similarity index 100% rename from ios_mcp/source/DumpOtpAndSeeprom.h rename to ios_mcp/source/options/DumpOtpAndSeeprom.h diff --git a/ios_mcp/source/options/DumpSyslogs.c b/ios_mcp/source/options/DumpSyslogs.c new file mode 100644 index 0000000..d4f617e --- /dev/null +++ b/ios_mcp/source/options/DumpSyslogs.c @@ -0,0 +1,69 @@ +#include "DumpSyslogs.h" + +#include "menu.h" +#include "gfx.h" +#include "fsa.h" +#include "utils.h" + +void option_DumpSyslogs(void) +{ + gfx_clear(COLOR_BACKGROUND); + + drawTopBar("Dumping Syslogs..."); + + uint32_t index = 16 + 8 + 2 + 8; + gfx_print(16, index, 0, "Creating 'logs' directory..."); + index += CHAR_SIZE_DRC_Y + 4; + + int res = FSA_MakeDir(fsaHandle, "/vol/storage_recovsd/logs", 0x600); + if ((res < 0) && !(res == -0x30016)) { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, 0, "Failed to create directory: %x", res); + waitButtonInput(); + return; + } + + gfx_print(16, index, 0, "Opening system 'logs' directory..."); + index += CHAR_SIZE_DRC_Y + 4; + + int dir_handle; + res = FSA_OpenDir(fsaHandle, "/vol/system/logs", &dir_handle); + if (res < 0) { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, 0, "Failed to open system logs: %x", res); + waitButtonInput(); + return; + } + + char src_path[500]; + char dst_path[500]; + FSDirectoryEntry dir_entry; + while (FSA_ReadDir(fsaHandle, dir_handle, &dir_entry) >= 0) { + if (dir_entry.stat.flags & DIR_ENTRY_IS_DIRECTORY) { + continue; + } + + gfx_printf(16, index, GfxPrintFlag_ClearBG, "Copying %s...", dir_entry.name); + + snprintf(src_path, sizeof(src_path), "/vol/system/logs/" "%s", dir_entry.name); + snprintf(dst_path, sizeof(dst_path), "/vol/storage_recovsd/logs/" "%s", dir_entry.name); + + res = copy_file(fsaHandle, src_path, dst_path); + if (res < 0) { + index += CHAR_SIZE_DRC_Y + 4; + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, GfxPrintFlag_ClearBG, "Failed to copy %s: %x", dir_entry.name, res); + waitButtonInput(); + + FSA_CloseDir(fsaHandle, dir_handle); + return; + } + } + + index += CHAR_SIZE_DRC_Y + 4; + gfx_set_font_color(COLOR_SUCCESS); + gfx_print(16, index, 0, "Done!"); + waitButtonInput(); + + FSA_CloseDir(fsaHandle, dir_handle); +} diff --git a/ios_mcp/source/options/DumpSyslogs.h b/ios_mcp/source/options/DumpSyslogs.h new file mode 100644 index 0000000..b3e718c --- /dev/null +++ b/ios_mcp/source/options/DumpSyslogs.h @@ -0,0 +1,3 @@ +#pragma once + +void option_DumpSyslogs(void); diff --git a/ios_mcp/source/options/EditParental.c b/ios_mcp/source/options/EditParental.c new file mode 100644 index 0000000..8118211 --- /dev/null +++ b/ios_mcp/source/options/EditParental.c @@ -0,0 +1,72 @@ +#include "EditParental.h" + +#include "menu.h" +#include "gfx.h" +#include "sci.h" +#include "utils.h" + +void option_EditParental(void) +{ + static const Menu parentalControlOptions[] = { + {"Back", {0} }, + {"Disable", {0} }, + }; + + int rval; + int selected = 0; + + gfx_clear(COLOR_BACKGROUND); + while (1) { + uint32_t index = 16 + 8 + 2 + 8; + gfx_set_font_color(COLOR_PRIMARY); + + // draw current parental control info + uint8_t enabled = 0; + int res = SCIGetParentalEnable(&enabled); + if (res == 1) { + gfx_set_font_color(COLOR_PRIMARY); + gfx_printf(16, index, GfxPrintFlag_ClearBG, "Parental Controls: %s", + enabled ? "Enabled" : "Disabled"); + } else { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, GfxPrintFlag_ClearBG, "SCIGetParentalEnable failed: %d", res); + } + index += CHAR_SIZE_DRC_Y + 4; + + char pin[5] = ""; + res = SCIGetParentalPinCode(pin, sizeof(pin)); + if (res == 1) { + gfx_set_font_color(COLOR_PRIMARY); + gfx_printf(16, index, GfxPrintFlag_ClearBG, "Parental Pin Code: %s", pin); + } else { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, GfxPrintFlag_ClearBG, "SCIGetParentalPinCode failed: %d", res); + } + index += (CHAR_SIZE_DRC_Y + 4) * 2; + + gfx_set_font_color(COLOR_PRIMARY); + + selected = drawMenu("Edit Parental Controls", + parentalControlOptions, ARRAY_SIZE(parentalControlOptions), selected, + MenuFlag_NoClearScreen, 16, index); + index += (CHAR_SIZE_DRC_Y + 4) * (ARRAY_SIZE(parentalControlOptions) + 1); + + if (selected == 0) + return; + + // Option 1: Disable the parental controls. + rval = SCISetParentalEnable(0); + + gfx_printf(16, index, GfxPrintFlag_ClearBG, "SCISetParentalEnable(false): %d ", rval); + index += CHAR_SIZE_DRC_Y + 4; + + if (rval != 1) { + gfx_set_font_color(COLOR_ERROR); + gfx_print(16, index, GfxPrintFlag_ClearBG, "Error! "); + } else { + gfx_set_font_color(COLOR_SUCCESS); + gfx_print(16, index, GfxPrintFlag_ClearBG, "Success!"); + } + index += CHAR_SIZE_DRC_Y + 4; + } +} diff --git a/ios_mcp/source/options/EditParental.h b/ios_mcp/source/options/EditParental.h new file mode 100644 index 0000000..9ab7477 --- /dev/null +++ b/ios_mcp/source/options/EditParental.h @@ -0,0 +1,3 @@ +#pragma once + +void option_EditParental(void); diff --git a/ios_mcp/source/options/InstallWUP.c b/ios_mcp/source/options/InstallWUP.c new file mode 100644 index 0000000..4961243 --- /dev/null +++ b/ios_mcp/source/options/InstallWUP.c @@ -0,0 +1,79 @@ +#include "InstallWUP.h" + +#include "menu.h" +#include "gfx.h" +#include "mcp_install.h" +#include "imports.h" + +void option_InstallWUP(void) +{ + gfx_clear(COLOR_BACKGROUND); + drawTopBar("Installing WUP"); + + uint32_t index = 16 + 8 + 2 + 8; + gfx_print(16, index, 0, "Make sure to place a valid signed WUP directly in 'sd:/install'"); + index += CHAR_SIZE_DRC_Y + 4; + + int mcpHandle = IOS_Open("/dev/mcp", 0); + if (mcpHandle < 0) { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, 0, "Failed to open /dev/mcp: %x", mcpHandle); + waitButtonInput(); + return; + } + + gfx_print(16, index, 0, "Querying install info..."); + index += CHAR_SIZE_DRC_Y + 4; + + MCPInstallInfo info; + int res = MCP_InstallGetInfo(mcpHandle, "/vol/storage_recovsd/install", &info); + if (res < 0) { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, 0, "Failed to get install info: %x", res); + waitButtonInput(); + + IOS_Close(mcpHandle); + return; + } + + gfx_printf(16, index, 0, "Installing title: %08lx-%08lx...", + (uint32_t)(info.titleId >> 32), (uint32_t)(info.titleId & 0xFFFFFFFFU)); + index += CHAR_SIZE_DRC_Y + 4; + + // only install to NAND + res = MCP_InstallSetTargetDevice(mcpHandle, 0); + if (res < 0) { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, 0, "MCP_InstallSetTargetDevice: %x", res); + waitButtonInput(); + + IOS_Close(mcpHandle); + return; + } + res = MCP_InstallSetTargetUsb(mcpHandle, 0); + if (res < 0) { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, 0, "MCP_InstallSetTargetUsb: %x", res); + waitButtonInput(); + + IOS_Close(mcpHandle); + return; + } + + // TODO: async installations + res = MCP_InstallTitle(mcpHandle, "/vol/storage_recovsd/install"); + if (res < 0) { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, 0, "Failed to install: %x", res); + waitButtonInput(); + + IOS_Close(mcpHandle); + return; + } + + gfx_set_font_color(COLOR_SUCCESS); + gfx_print(16, index, 0, "Done!"); + waitButtonInput(); + + IOS_Close(mcpHandle); +} diff --git a/ios_mcp/source/options/InstallWUP.h b/ios_mcp/source/options/InstallWUP.h new file mode 100644 index 0000000..ca36b4c --- /dev/null +++ b/ios_mcp/source/options/InstallWUP.h @@ -0,0 +1,3 @@ +#pragma once + +void option_InstallWUP(void); diff --git a/ios_mcp/source/options/LoadNetConf.c b/ios_mcp/source/options/LoadNetConf.c new file mode 100644 index 0000000..7791f90 --- /dev/null +++ b/ios_mcp/source/options/LoadNetConf.c @@ -0,0 +1,186 @@ +#include "LoadNetConf.h" + +#include "menu.h" +#include "gfx.h" +#include "netconf.h" +#include "fsa.h" + +#include + +static void network_parse_config_value(uint32_t* console_idx, NetConfCfg* cfg, const char* key, const char* value, uint32_t value_len) +{ + if (strncmp(key, "type", sizeof("type")) == 0) { + gfx_printf(16, *console_idx, 0, "Type: %s", value); + (*console_idx) += CHAR_SIZE_DRC_Y + 4; + + if (value) { + if (strncmp(value, "wifi", sizeof("wifi")) == 0) { + cfg->wl0.if_index = NET_CFG_INTERFACE_TYPE_WIFI; + cfg->wl0.if_sate = 1; + cfg->wl0.ipv4Info.mode = NET_CONFIG_IPV4_MODE_AUTO_OBTAIN_IP; + cfg->wifi.config_method = 0; + } else if (strncmp(value, "eth", sizeof("eth")) == 0) { + cfg->eth0.if_index = NET_CFG_INTERFACE_TYPE_ETHERNET; + cfg->eth0.if_sate = 1; + cfg->eth0.ipv4Info.mode = NET_CONFIG_IPV4_MODE_AUTO_OBTAIN_IP; + cfg->ethCfg.negotiation = NET_CFG_ETH_CFG_NEGOTIATION_AUTO; + } + } + } else if (strncmp(key, "ssid", sizeof("ssid")) == 0) { + gfx_printf(16, *console_idx, 0, "SSID: %s (%lu)", value, value_len); + (*console_idx) += CHAR_SIZE_DRC_Y + 4; + + if (value) { + memcpy(cfg->wifi.config.ssid, value, value_len); + cfg->wifi.config.ssidlength = value_len; + } + } else if (strncmp(key, "key", sizeof("key")) == 0) { + gfx_printf(16, *console_idx, 0, "Key: ******* (%lu)", value_len); + (*console_idx) += CHAR_SIZE_DRC_Y + 4; + + if (value) { + memcpy(cfg->wifi.config.privacy.aes_key, value, value_len); + cfg->wifi.config.privacy.aes_key_len = value_len; + } + } else if (strncmp(key, "key_type", sizeof("key_type")) == 0) { + gfx_printf(16, *console_idx, 0, "Key type: %s", value); + (*console_idx) += CHAR_SIZE_DRC_Y + 4; + + if (value) { + if (strncmp(value, "NONE", sizeof("NONE")) == 0) { + cfg->wifi.config.privacy.mode = NET_CFG_WIFI_PRIVACY_MODE_NONE; + } else if (strncmp(value, "WEP", sizeof("WEP")) == 0) { + cfg->wifi.config.privacy.mode = NET_CFG_WIFI_PRIVACY_MODE_WEP; + } else if (strncmp(value, "WPA2_PSK_TKIP", sizeof("WPA2_PSK_TKIP")) == 0) { + cfg->wifi.config.privacy.mode = NET_CFG_WIFI_PRIVACY_MODE_WPA2_PSK_TKIP; + } else if (strncmp(value, "WPA_PSK_TKIP", sizeof("WPA_PSK_TKIP")) == 0) { + cfg->wifi.config.privacy.mode = NET_CFG_WIFI_PRIVACY_MODE_WPA_PSK_TKIP; + } else if (strncmp(value, "WPA2_PSK_AES", sizeof("WPA2_PSK_AES")) == 0) { + cfg->wifi.config.privacy.mode = NET_CFG_WIFI_PRIVACY_MODE_WPA2_PSK_AES; + } else if (strncmp(value, "WPA_PSK_AES", sizeof("WPA_PSK_AES")) == 0) { + cfg->wifi.config.privacy.mode = NET_CFG_WIFI_PRIVACY_MODE_WPA_PSK_AES; + } else { + gfx_print(16, *console_idx, 0, "Unknown key type!"); + (*console_idx) += CHAR_SIZE_DRC_Y + 4; + } + } + } +} + +void option_LoadNetConf(void) +{ + gfx_clear(COLOR_BACKGROUND); + drawTopBar("Loading network configuration..."); + + uint32_t index = 16 + 8 + 2 + 8; + gfx_print(16, index, 0, "Initializing netconf..."); + index += CHAR_SIZE_DRC_Y + 4; + + int res = netconf_init(); + if (res <= 0) { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, 0, "Failed to initialize netconf: %x", res); + waitButtonInput(); + return; + } + + gfx_print(16, index, 0, "Reading network.cfg..."); + index += CHAR_SIZE_DRC_Y + 4; + + int cfgHandle; + res = FSA_OpenFile(fsaHandle, "/vol/storage_recovsd/network.cfg", "r", &cfgHandle); + if (res < 0) { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, 0, "Failed to open network.cfg: %x", res); + waitButtonInput(); + return; + } + + FSStat stat; + res = FSA_StatFile(fsaHandle, cfgHandle, &stat); + if (res < 0) { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, 0, "Failed to stat file: %x", res); + waitButtonInput(); + + FSA_CloseFile(fsaHandle, cfgHandle); + return; + } + + char* cfgBuffer = (char*) IOS_HeapAllocAligned(CROSS_PROCESS_HEAP_ID, stat.size + 1, 0x40); + if (!cfgBuffer) { + gfx_set_font_color(COLOR_ERROR); + gfx_print(16, index, 0, "Out of memory!"); + waitButtonInput(); + + FSA_CloseFile(fsaHandle, cfgHandle); + return; + } + + cfgBuffer[stat.size] = '\0'; + + res = FSA_ReadFile(fsaHandle, cfgBuffer, 1, stat.size, cfgHandle, 0); + if (res != stat.size) { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, 0, "Failed to read file: %x", res); + waitButtonInput(); + + IOS_HeapFree(CROSS_PROCESS_HEAP_ID, cfgBuffer); + FSA_CloseFile(fsaHandle, cfgHandle); + return; + } + + NetConfCfg cfg; + memset(&cfg, 0, sizeof(cfg)); + + // parse network cfg file + const char* keyPtr = cfgBuffer; + const char* valuePtr = NULL; + for (size_t i = 0; i < stat.size; i++) { + if (cfgBuffer[i] == '=') { + cfgBuffer[i] = '\0'; + + valuePtr = cfgBuffer + i + 1; + } else if (cfgBuffer[i] == '\n') { + size_t end = i; + cfgBuffer[end] = '\0'; + if (cfgBuffer[end - 1] == '\r') { + end = i - 1; + cfgBuffer[end] = '\0'; + } + + network_parse_config_value(&index, &cfg, keyPtr, valuePtr, (cfgBuffer + end) - valuePtr); + + keyPtr = cfgBuffer + i + 1; + valuePtr = NULL; + } + } + + // if valuePtr isn't NULL there is another option without a newline at the end + if (valuePtr) { + network_parse_config_value(&index, &cfg, keyPtr, valuePtr, (cfgBuffer + stat.size) - valuePtr); + } + + gfx_print(16, index, 0, "Applying configuration..."); + index += CHAR_SIZE_DRC_Y + 4; + + res = netconf_set_running(&cfg); + if (res < 0) { + gfx_set_font_color(COLOR_ERROR); + gfx_printf(16, index, 0, "Failed to apply configuration: %x", res); + waitButtonInput(); + + IOS_HeapFree(CROSS_PROCESS_HEAP_ID, cfgBuffer); + FSA_CloseFile(fsaHandle, cfgHandle); + return; + } + + gfx_set_font_color(COLOR_SUCCESS); + gfx_print(16, index, 0, "Done!"); + index += CHAR_SIZE_DRC_Y + 4; + + waitButtonInput(); + + IOS_HeapFree(CROSS_PROCESS_HEAP_ID, cfgBuffer); + FSA_CloseFile(fsaHandle, cfgHandle); +} diff --git a/ios_mcp/source/options/LoadNetConf.h b/ios_mcp/source/options/LoadNetConf.h new file mode 100644 index 0000000..190f1ad --- /dev/null +++ b/ios_mcp/source/options/LoadNetConf.h @@ -0,0 +1,3 @@ +#pragma once + +void option_LoadNetConf(void); diff --git a/ios_mcp/source/PairDRC.c b/ios_mcp/source/options/PairDRC.c similarity index 100% rename from ios_mcp/source/PairDRC.c rename to ios_mcp/source/options/PairDRC.c diff --git a/ios_mcp/source/PairDRC.h b/ios_mcp/source/options/PairDRC.h similarity index 100% rename from ios_mcp/source/PairDRC.h rename to ios_mcp/source/options/PairDRC.h diff --git a/ios_mcp/source/options/SetColdbootTitle.c b/ios_mcp/source/options/SetColdbootTitle.c new file mode 100644 index 0000000..88fbec8 --- /dev/null +++ b/ios_mcp/source/options/SetColdbootTitle.c @@ -0,0 +1,75 @@ +#include "SetColdbootTitle.h" + +#include "menu.h" +#include "gfx.h" +#include "imports.h" + +extern uint64_t currentColdbootOS; +extern uint64_t currentColdbootTitle; + +void option_SetColdbootTitle(void) +{ + static const Menu coldbootTitleOptions[] = { + {"Back", {0} }, + {"Wii U Menu (JPN)", {.tid = 0x0005001010040000}}, + {"Wii U Menu (USA)", {.tid = 0x0005001010040100}}, + {"Wii U Menu (EUR)", {.tid = 0x0005001010040200}}, + + // non-retail systems only + {"System Config Tool", {.tid = 0x000500101F700500}}, + {"DEVMENU (pre-2.09)", {.tid = 0x000500101F7001FF}}, + {"Kiosk Menu ", {.tid = 0x000500101FA81000}}, + }; + + // Only print the non-retail options if the system is in debug mode. + const int option_count = ((IOS_CheckDebugMode() == 0) ? 7 : 4); + + int rval; + uint64_t newtid = 0; + int selected = 0; + + gfx_clear(COLOR_BACKGROUND); + while (1) { + uint32_t index = 16 + 8 + 2 + 8; + gfx_set_font_color(COLOR_PRIMARY); + + // draw current titles + gfx_printf(16, index, GfxPrintFlag_ClearBG, "Current coldboot title: %08lx-%08lx", + (uint32_t)(currentColdbootTitle >> 32), (uint32_t)(currentColdbootTitle & 0xFFFFFFFFU)); + index += CHAR_SIZE_DRC_Y + 4; + + gfx_printf(16, index, GfxPrintFlag_ClearBG, "Current coldboot os: %08lx-%08lx", + (uint32_t)(currentColdbootOS >> 32), (uint32_t)(currentColdbootOS & 0xFFFFFFFFU)); + index += (CHAR_SIZE_DRC_Y + 4) * 2; + + selected = drawMenu("Set Coldboot Title", + coldbootTitleOptions, option_count, selected, + MenuFlag_ShowTID | MenuFlag_NoClearScreen, 16, index); + index += (CHAR_SIZE_DRC_Y + 4) * option_count; + + newtid = coldbootTitleOptions[selected].tid; + if (newtid == 0) + return; + + // set the new default title ID + rval = setDefaultTitleId(newtid); + + if (newtid) { + index += (CHAR_SIZE_DRC_Y + 4) * 2; + + gfx_set_font_color(COLOR_PRIMARY); + gfx_printf(16, index, GfxPrintFlag_ClearBG, + "Setting coldboot title id to %08lx-%08lx, rval %d ", + (uint32_t)(newtid >> 32), (uint32_t)(newtid & 0xFFFFFFFFU), rval); + index += CHAR_SIZE_DRC_Y + 4; + + if (rval < 0) { + gfx_set_font_color(COLOR_ERROR); + gfx_print(16, index, GfxPrintFlag_ClearBG, "Error! Make sure title is installed correctly."); + } else { + gfx_set_font_color(COLOR_SUCCESS); + gfx_print(16, index, GfxPrintFlag_ClearBG, "Success! "); + } + } + } +} diff --git a/ios_mcp/source/options/SetColdbootTitle.h b/ios_mcp/source/options/SetColdbootTitle.h new file mode 100644 index 0000000..b37cbfe --- /dev/null +++ b/ios_mcp/source/options/SetColdbootTitle.h @@ -0,0 +1,3 @@ +#pragma once + +void option_SetColdbootTitle(void); diff --git a/ios_mcp/source/StartWupserver.c b/ios_mcp/source/options/StartWupserver.c similarity index 100% rename from ios_mcp/source/StartWupserver.c rename to ios_mcp/source/options/StartWupserver.c diff --git a/ios_mcp/source/StartWupserver.h b/ios_mcp/source/options/StartWupserver.h similarity index 100% rename from ios_mcp/source/StartWupserver.h rename to ios_mcp/source/options/StartWupserver.h diff --git a/ios_mcp/source/SubmitSystemData.c b/ios_mcp/source/options/SubmitSystemData.c similarity index 100% rename from ios_mcp/source/SubmitSystemData.c rename to ios_mcp/source/options/SubmitSystemData.c diff --git a/ios_mcp/source/SubmitSystemData.h b/ios_mcp/source/options/SubmitSystemData.h similarity index 100% rename from ios_mcp/source/SubmitSystemData.h rename to ios_mcp/source/options/SubmitSystemData.h diff --git a/ios_mcp/source/SystemInformation.c b/ios_mcp/source/options/SystemInformation.c similarity index 100% rename from ios_mcp/source/SystemInformation.c rename to ios_mcp/source/options/SystemInformation.c diff --git a/ios_mcp/source/SystemInformation.h b/ios_mcp/source/options/SystemInformation.h similarity index 100% rename from ios_mcp/source/SystemInformation.h rename to ios_mcp/source/options/SystemInformation.h diff --git a/ios_mcp/source/options/options.h b/ios_mcp/source/options/options.h new file mode 100644 index 0000000..688ccc3 --- /dev/null +++ b/ios_mcp/source/options/options.h @@ -0,0 +1,13 @@ +#pragma once + +#include "DebugSystemRegion.h" +#include "DumpOtpAndSeeprom.h" +#include "DumpSyslogs.h" +#include "EditParental.h" +#include "InstallWUP.h" +#include "LoadNetConf.h" +#include "PairDRC.h" +#include "SetColdbootTitle.h" +#include "StartWupserver.h" +#include "SubmitSystemData.h" +#include "SystemInformation.h"