Fix Internet Browser crashing and merge code handler into ELF

This commit is contained in:
BullyWiiPlaza 2017-05-04 23:18:05 +02:00
parent 8a0413ab85
commit aa526c88ef
7 changed files with 2949 additions and 74 deletions

Binary file not shown.

2915
src/code_handler.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -10,18 +10,21 @@
#define TITLE_ID_MII_VERSE 0x000500301001600A #define TITLE_ID_MII_VERSE 0x000500301001600A
#define TITLE_ID_MII_MAKER 0x000500101004A000 #define TITLE_ID_MII_MAKER 0x000500101004A000
#define TITLE_ID_BAYONETTA_2 0x0005000010172500 #define TITLE_ID_BAYONETTA_2 0x0005000010172500
#define TITLE_ID_INTERNET_BROWSER 0x000500301001200A
bool isRunningTitleID(unsigned long long int japaneseTitleID) { bool isRunningTitleID(unsigned long long int japaneseTitleID) {
return OSGetTitleID() == japaneseTitleID // JAP unsigned long long int currentTitleID = (unsigned long long int) OSGetTitleID();
|| OSGetTitleID() == japaneseTitleID + 0x100 // USA return currentTitleID == japaneseTitleID // JAP
|| OSGetTitleID() == japaneseTitleID + 0x200; // EUR || currentTitleID == japaneseTitleID + 0x100 // USA
|| currentTitleID == japaneseTitleID + 0x200; // EUR
} }
int __entry_menu(int argc, char **argv) { int __entry_menu(int argc, char **argv) {
if (OSGetTitleID != 0 if (OSGetTitleID != 0
&& !isRunningTitleID(TITLE_ID_MII_VERSE) && !isRunningTitleID(TITLE_ID_MII_VERSE)
&& !isRunningTitleID(TITLE_ID_MII_MAKER) && !isRunningTitleID(TITLE_ID_MII_MAKER)
&& !isRunningTitleID(TITLE_ID_BAYONETTA_2)) { && !isRunningTitleID(TITLE_ID_BAYONETTA_2)
&& !isRunningTitleID(TITLE_ID_INTERNET_BROWSER)) {
InitOSFunctionPointers(); InitOSFunctionPointers();
InitSocketFunctionPointers(); InitSocketFunctionPointers();
InitGX2FunctionPointers(); InitGX2FunctionPointers();

View File

@ -11,26 +11,21 @@
#include "dynamic_libs/vpad_functions.h" #include "dynamic_libs/vpad_functions.h"
#include "dynamic_libs/socket_functions.h" #include "dynamic_libs/socket_functions.h"
#include "patcher/function_hooks.h" #include "patcher/function_hooks.h"
#include "fs/fs_utils.h"
#include "fs/sd_fat_devoptab.h"
#include "kernel/kernel_functions.h" #include "kernel/kernel_functions.h"
#include "system/memory.h" #include "system/memory.h"
#include "utils/utils.h"
#include "common/common.h" #include "common/common.h"
#include "main.h" #include "main.h"
#include "code_handler.h"
int codeHandlerInstalled; bool isCodeHandlerInstalled;
void startMiiMaker() { // TODO Make sure accessing the browser does not freeze the console
char buf_vol_odd[20];
snprintf(buf_vol_odd, sizeof(buf_vol_odd), "%s", "/vol/storage_odd03");
_SYSLaunchTitleByPathFromLauncher(buf_vol_odd, 18, 0);
}
#define PRINT_TEXT2(x, y, ...) { snprintf(messageBuffer, 80, __VA_ARGS__); OSScreenPutFontEx(0, x, y, messageBuffer); OSScreenPutFontEx(1, x, y, messageBuffer); } #define PRINT_TEXT2(x, y, ...) { snprintf(messageBuffer, 80, __VA_ARGS__); OSScreenPutFontEx(0, x, y, messageBuffer); OSScreenPutFontEx(1, x, y, messageBuffer); }
#define MAXIMUM_CODE_HANDLER_SIZE 15000 typedef enum {
char *codeHandlerBuffer[MAXIMUM_CODE_HANDLER_SIZE]; EXIT = 0x0, TCP_GECKO = 0x1
} LaunchMethod;
/* Entry point */ /* Entry point */
int Menu_Main(void) { int Menu_Main(void) {
@ -100,7 +95,7 @@ int Menu_Main(void) {
OSScreenEnableEx(1, 1); OSScreenEnableEx(1, 1);
char messageBuffer[80]; char messageBuffer[80];
int launchMethod = 0; int launchMethod;
int update_screen = 1; int update_screen = 1;
int vpadError = -1; int vpadError = -1;
VPADData vpad_data; VPADData vpad_data;
@ -122,7 +117,6 @@ int Menu_Main(void) {
PRINT_TEXT2(14, 1, "-- TCP Gecko Installer --") PRINT_TEXT2(14, 1, "-- TCP Gecko Installer --")
PRINT_TEXT2(7, 2, ipAddressMessageBuffer) PRINT_TEXT2(7, 2, ipAddressMessageBuffer)
PRINT_TEXT2(0, 5, "Press A to install TCP Gecko...") PRINT_TEXT2(0, 5, "Press A to install TCP Gecko...")
PRINT_TEXT2(0, 6, "Press X to install TCP Gecko with CosmoCortney's codehandler...")
PRINT_TEXT2(0, 17, "Press Home to exit...") PRINT_TEXT2(0, 17, "Press Home to exit...")
OSScreenFlipBuffersEx(0); OSScreenFlipBuffersEx(0);
@ -133,70 +127,25 @@ int Menu_Main(void) {
// Home Button // Home Button
if (pressedButtons & VPAD_BUTTON_HOME) { if (pressedButtons & VPAD_BUTTON_HOME) {
launchMethod = 0; launchMethod = EXIT;
break; break;
} }
// A Button // A Button
if (pressedButtons & VPAD_BUTTON_A) { if (pressedButtons & VPAD_BUTTON_A) {
launchMethod = 2;
break;
}
// X Button
if (pressedButtons & VPAD_BUTTON_X) {
mount_sd_fat("sd");
unsigned char *temporaryCodeHandlerBuffer = 0;
unsigned int codeHandlerSize = 0;
const char *filePath = "sd:/wiiu/apps/TCPGecko/codehandler.bin";
int codeHandlerLoaded = LoadFileToMem(filePath, &temporaryCodeHandlerBuffer, &codeHandlerSize);
if (codeHandlerLoaded == -1) {
OSScreenClearBufferEx(0, 0);
OSScreenClearBufferEx(1, 0);
char codeHandlerNotFoundMessageBuffer[100];
snprintf(codeHandlerNotFoundMessageBuffer, sizeof(codeHandlerNotFoundMessageBuffer), "%s not found",
filePath);
PRINT_TEXT2(0, 0, codeHandlerNotFoundMessageBuffer)
OSScreenFlipBuffersEx(0);
OSScreenFlipBuffersEx(1);
launchMethod = 0;
sleep(4);
break;
}
if (codeHandlerSize > MAXIMUM_CODE_HANDLER_SIZE) {
OSScreenClearBufferEx(0, 0);
OSScreenClearBufferEx(1, 0);
PRINT_TEXT2(14, 5, "Codehandler too big");
OSScreenFlipBuffersEx(0);
OSScreenFlipBuffersEx(1);
launchMethod = 0;
sleep(2);
break;
}
memcpy(codeHandlerBuffer, temporaryCodeHandlerBuffer, codeHandlerSize);
free(temporaryCodeHandlerBuffer);
unsigned int physicalCodeHandlerAddress = (unsigned int) OSEffectiveToPhysical( unsigned int physicalCodeHandlerAddress = (unsigned int) OSEffectiveToPhysical(
(void *) CODE_HANDLER_INSTALL_ADDRESS); (void *) CODE_HANDLER_INSTALL_ADDRESS);
DCFlushRange(&codeHandlerBuffer, codeHandlerSize); SC0x25_KernelCopyData((u32) physicalCodeHandlerAddress, (int) codeHandler, codeHandlerLength);
SC0x25_KernelCopyData((u32) physicalCodeHandlerAddress, (int) codeHandlerBuffer, codeHandlerSize); DCFlushRange((const void *) CODE_HANDLER_INSTALL_ADDRESS, (u32) codeHandlerLength);
m_DCInvalidateRange((u32) physicalCodeHandlerAddress, codeHandlerSize);
unmount_sd_fat("sd"); isCodeHandlerInstalled = true;
codeHandlerInstalled = 1; launchMethod = TCP_GECKO;
launchMethod = 2;
break; break;
} }
// Button pressed ? // Button pressed ?
update_screen = (pressedButtons & (VPAD_BUTTON_LEFT | VPAD_BUTTON_RIGHT | VPAD_BUTTON_UP | VPAD_BUTTON_DOWN)) update_screen = (pressedButtons & (VPAD_BUTTON_LEFT | VPAD_BUTTON_RIGHT | VPAD_BUTTON_UP | VPAD_BUTTON_DOWN)) ? 1 : 0;
? 1 : 0;
usleep(20 * 1000); usleep(20 * 1000);
} }
@ -208,7 +157,7 @@ int Menu_Main(void) {
memoryRelease(); memoryRelease();
if (launchMethod == 0) { if (launchMethod == EXIT) {
RestoreInstructions(); RestoreInstructions();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} else { } else {

View File

@ -14,7 +14,7 @@ extern "C" {
//! C wrapper for our C++ functions //! C wrapper for our C++ functions
int Menu_Main(void); int Menu_Main(void);
extern int codeHandlerInstalled; extern bool isCodeHandlerInstalled;
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -15,7 +15,6 @@
#include "system/exception_handler.h" #include "system/exception_handler.h"
#include "utils/logger.h" #include "utils/logger.h"
#include "system/memory.h" #include "system/memory.h"
#include "entry.h"
void *client; void *client;
void *commandBlock; void *commandBlock;
@ -62,6 +61,7 @@ struct pygecko_bss_t {
#define COMMAND_OS_VERSION 0x9A #define COMMAND_OS_VERSION 0x9A
#define COMMAND_RUN_KERNEL_COPY_SERVICE 0xCD #define COMMAND_RUN_KERNEL_COPY_SERVICE 0xCD
#define COMMAND_IOSUHAX_READ_FILE 0xD0 #define COMMAND_IOSUHAX_READ_FILE 0xD0
#define COMMAND_GET_VERSION_HASH 0xE0
#define CHECK_ERROR(cond) if (cond) { bss->line = __LINE__; goto error; } #define CHECK_ERROR(cond) if (cond) { bss->line = __LINE__; goto error; }
#define errno (*__gh_errno_ptr()) #define errno (*__gh_errno_ptr())
@ -73,6 +73,8 @@ struct pygecko_bss_t {
#define ONLY_ZEROS_READ 0xB0 #define ONLY_ZEROS_READ 0xB0
#define NON_ZEROS_READ 0xBD #define NON_ZEROS_READ 0xBD
#define VERSION_HASH 0x3516D3B9
#define ASSERT_MINIMUM_HOLDS(actual, minimum, variableName) \ #define ASSERT_MINIMUM_HOLDS(actual, minimum, variableName) \
if(actual < minimum) { \ if(actual < minimum) { \
char buffer[100] = {0}; \ char buffer[100] = {0}; \
@ -1118,10 +1120,16 @@ static int processCommands(struct pygecko_bss_t *bss, int clientfd) {
break; break;
} }
case COMMAND_GET_VERSION_HASH: {
((int *) buffer)[0] = VERSION_HASH;
ret = sendwait(bss, clientfd, buffer, 4);
break;
}
case COMMAND_GET_CODE_HANDLER_ADDRESS: { case COMMAND_GET_CODE_HANDLER_ADDRESS: {
((int *) buffer)[0] = CODE_HANDLER_INSTALL_ADDRESS; ((int *) buffer)[0] = CODE_HANDLER_INSTALL_ADDRESS;
ret = sendwait(bss, clientfd, buffer, 4); ret = sendwait(bss, clientfd, buffer, 4);
CHECK_ERROR(ret < 0) ASSERT_FUNCTION_SUCCEEDED(ret, "sendwait (code handler address)")
break; break;
} }
@ -1530,7 +1538,7 @@ static int startTCPGeckoThread(int argc, void *argv) {
log_print("TCP Gecko thread started...\n"); log_print("TCP Gecko thread started...\n");
// Execute the code handler if it is installed // Execute the code handler if it is installed
if (codeHandlerInstalled) { if (isCodeHandlerInstalled) {
log_print("Code handler installed...\n"); log_print("Code handler installed...\n");
void (*codeHandlerFunction)() = (void (*)()) CODE_HANDLER_INSTALL_ADDRESS; void (*codeHandlerFunction)() = (void (*)()) CODE_HANDLER_INSTALL_ADDRESS;

Binary file not shown.