This commit is contained in:
BullyWiiPlaza 2017-03-30 21:37:55 +02:00
parent a77d0713b2
commit c521bcd633
5 changed files with 60 additions and 68 deletions

View File

@ -50,7 +50,7 @@ int UmountFS(void *pClient, void *pCmd, const char *mountPath)
int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size)
{
//! always initialze input
// Always initialize input
*inbuffer = NULL;
if(size)
*size = 0;

View File

@ -3,7 +3,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <unistd.h>
#include <fcntl.h>
#include "dynamic_libs/os_functions.h"
@ -19,8 +18,7 @@
#include "utils/logger.h"
#include "utils/utils.h"
#include "common/common.h"
#define FS_BUFFER_SIZE 40000
#include "main.h"
int CCHandler;
@ -30,9 +28,10 @@ void startMiiMaker() {
_SYSLaunchTitleByPathFromLauncher(buf_vol_odd, 18, 0);
}
char *buffer[FS_BUFFER_SIZE];
#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(msg, 80, __VA_ARGS__); OSScreenPutFontEx(0, x, y, msg); OSScreenPutFontEx(1, x, y, msg); }
#define MAXIMUM_CODE_HANDLER_SIZE 15000
char *codeHandlerBuffer[MAXIMUM_CODE_HANDLER_SIZE];
/* Entry point */
int Menu_Main(void) {
@ -94,45 +93,36 @@ int Menu_Main(void) {
VPADInit();
// Prepare screen
int screen_buf0_size = 0;
int screen_buf1_size = 0;
// Init screen and screen buffers
OSScreenInit();
screen_buf0_size = OSScreenGetBufferSizeEx(0);
screen_buf1_size = OSScreenGetBufferSizeEx(1);
int screenBuffer0Size = OSScreenGetBufferSizeEx(0);
int screenBuffer1Size = OSScreenGetBufferSizeEx(1);
unsigned char *screenBuffer = MEM1_alloc(screen_buf0_size + screen_buf1_size, 0x40);
unsigned char *screenBuffer = MEM1_alloc(screenBuffer0Size + screenBuffer1Size, 0x40);
OSScreenSetBufferEx(0, screenBuffer);
OSScreenSetBufferEx(1, (screenBuffer + screen_buf0_size));
OSScreenSetBufferEx(1, (screenBuffer + screenBuffer0Size));
OSScreenEnableEx(0, 1);
OSScreenEnableEx(1, 1);
char msg[80];
char messageBuffer[80];
int launchMethod = 0;
int update_screen = 1;
int vpadError = -1;
VPADData vpad_data;
while (1) {
// Read vpad
while (true) {
VPADRead(0, &vpad_data, 1, &vpadError);
if (update_screen) {
OSScreenClearBufferEx(0, 0);
OSScreenClearBufferEx(1, 0);
// Print message
PRINT_TEXT2(14, 1, "-- TCPGecko Installer --");
PRINT_TEXT2(0, 5, "Press A to install TCPGecko.");
PRINT_TEXT2(0, 6, "Press X to install TCPGecko with CosmoCortney's codehandler...");
PRINT_TEXT2(0, 17, "Press home button to exit ...");
PRINT_TEXT2(14, 1, "-- TCP Gecko Installer --")
PRINT_TEXT2(0, 5, "Press A to install TCPGecko.")
PRINT_TEXT2(0, 6, "Press X to install TCPGecko with CosmoCortney's codehandler...")
PRINT_TEXT2(0, 17, "Press Home to exit ...")
OSScreenFlipBuffersEx(0);
OSScreenFlipBuffersEx(1);
@ -145,46 +135,55 @@ int Menu_Main(void) {
launchMethod = 0;
break;
}
// A Button
if (pressedButtons & VPAD_BUTTON_A) {
launchMethod = 2;
break;
}
// X Button
if (pressedButtons & VPAD_BUTTON_X) {
mount_sd_fat("sd");
unsigned char *Badbuffer = 0;
unsigned int filesize = 0;
int ret = LoadFileToMem("sd:/wiiu/apps/TCPGecko/codehandler.bin", &Badbuffer, &filesize);
if (ret == -1) {
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);
PRINT_TEXT2(14, 5, "Codehandler.bin not found");
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;
}
if (filesize > FS_BUFFER_SIZE) {
OSScreenClearBufferEx(0, 0);
OSScreenClearBufferEx(1, 0);
PRINT_TEXT2(14, 5, "Codehandler.bin is too big");
OSScreenFlipBuffersEx(0);
OSScreenFlipBuffersEx(1);
launchMethod = 0;
sleep(2);
break;
}
memcpy(buffer, Badbuffer, filesize);
free(Badbuffer);
unsigned int phys_cafe_codehandler_loc = (unsigned int) OSEffectiveToPhysical((void *) CODE_HANDLER_INSTALL_ADDRESS);
memcpy(codeHandlerBuffer, temporaryCodeHandlerBuffer, codeHandlerSize);
free(temporaryCodeHandlerBuffer);
DCFlushRange(&buffer, filesize);
SC0x25_KernelCopyData((u32) phys_cafe_codehandler_loc, (int) buffer, filesize);
m_DCInvalidateRange((u32) phys_cafe_codehandler_loc, filesize);
unsigned int physicalCodeHandlerAddress = (unsigned int) OSEffectiveToPhysical(
(void *) CODE_HANDLER_INSTALL_ADDRESS);
DCFlushRange(&codeHandlerBuffer, codeHandlerSize);
SC0x25_KernelCopyData((u32) physicalCodeHandlerAddress, (int) codeHandlerBuffer, codeHandlerSize);
m_DCInvalidateRange((u32) physicalCodeHandlerAddress, codeHandlerSize);
unmount_sd_fat("sd");
CCHandler = 1;

View File

@ -12,7 +12,6 @@ extern "C" {
//! C wrapper for our C++ functions
int Menu_Main(void);
extern int pygecko;
extern int CCHandler;
#ifdef __cplusplus

View File

@ -47,7 +47,7 @@ struct pygecko_bss_t {
#define COMMAND_ACCOUNT_IDENTIFIER 0x57
#define COMMAND_WRITE_SCREEN 0x58 // TODO Exception DSI
#define COMMAND_FOLLOW_POINTER 0x60
#define COMMAND_RPC 0x70
#define COMMAND_REMOTE_PROCEDURE_CALL 0x70
#define COMMAND_GET_SYMBOL 0x71
#define COMMAND_MEMORY_SEARCH 0x73
// #define COMMAND_SYSTEM_CALL 0x80
@ -60,11 +60,9 @@ struct pygecko_bss_t {
#define errno (*__gh_errno_ptr())
#define MSG_DONTWAIT 32
#define EWOULDBLOCK 6
#define FS_BUFFER_SIZE 0x1000
#define DATA_BUFFER_SIZE 0x5000
#define DISASSEMBLER_BUFFER_SIZE 0x1024
#define WRITE_SCREEN_MESSAGE_BUFFER_SIZE 100
#define SERVER_VERSION "02/25/2017"
#define SERVER_VERSION "03/30/2017"
#define ONLY_ZEROS_READ 0xB0
#define NON_ZEROS_READ 0xBD
@ -153,8 +151,7 @@ unsigned char *memcpy_buffer[DATA_BUFFER_SIZE];
void pygecko_memcpy(unsigned char *destinationBuffer, unsigned char *sourceBuffer, unsigned int length) {
memcpy(memcpy_buffer, sourceBuffer, length);
SC0x25_KernelCopyData((unsigned int) OSEffectiveToPhysical(destinationBuffer), (unsigned int) &memcpy_buffer,
length);
SC0x25_KernelCopyData((unsigned int) OSEffectiveToPhysical(destinationBuffer), (unsigned int) &memcpy_buffer, length);
DCFlushRange(destinationBuffer, (u32) length);
}
@ -330,6 +327,7 @@ void considerInitializingFileSystem() {
char *disassemblerBuffer;
void *disassemblerBufferPointer;
#define DISASSEMBLER_BUFFER_SIZE 0x1024
void formatDisassembled(char *format, ...) {
if (!disassemblerBuffer) {
@ -375,10 +373,6 @@ void reportIllegalCommandByte(int commandByte) {
OSFatal(errorBuffer);
}
void writeInt(unsigned int address, unsigned int value) {
pygecko_memcpy((unsigned char *) address, (unsigned char *) &value, 4);
}
#define MINIMUM_KERNEL_COMPARE_LENGTH 4
#define KERNEL_MEMORY_COMPARE_STEP_SIZE 1
@ -919,7 +913,7 @@ static int rungecko(struct pygecko_bss_t *bss, int clientfd) {
break;
}
case COMMAND_REPLACE_FILE: {
// TODO Write file
// TODO FSOpenFile ACCESS_ERROR
// Receive the file path
char file_path[FS_MAX_FULLPATH_SIZE] = {0};
@ -962,12 +956,12 @@ static int rungecko(struct pygecko_bss_t *bss, int clientfd) {
ret = recvwait(bss, clientfd, fileBuffer, dataLength);
ASSERT_FUNCTION_SUCCEEDED(ret, "recvwait (File buffer)")
// Write the data and advance file handle position
// Write the data (and advance file handle position implicitly)
ret = FSWriteFile(client, commandBlock, fileBuffer, 1,
dataLength, handle, 0, FS_RET_ALL_ERROR);
ASSERT_FUNCTION_SUCCEEDED(ret, "FSWriteFile")
} else {
// Done
// Done with receiving the new file
break;
}
}
@ -1133,7 +1127,7 @@ static int rungecko(struct pygecko_bss_t *bss, int clientfd) {
CHECK_ERROR(ret < 0)
break;
}
case COMMAND_RPC: {
case COMMAND_REMOTE_PROCEDURE_CALL: {
long long (*fun)(int, int, int, int, int, int, int, int);
int r3, r4, r5, r6, r7, r8, r9, r10;
long long result;
@ -1234,16 +1228,16 @@ static int rungecko(struct pygecko_bss_t *bss, int clientfd) {
break;
}
/*case COMMAND_SYSTEM_CALL: {
ret = recvwait(bss, clientfd, buffer, 4);
ASSERT_FUNCTION_SUCCEEDED(ret, "recvwait (system call)")
/*case COMMAND_SYSTEM_CALL: {
ret = recvwait(bss, clientfd, buffer, 4);
ASSERT_FUNCTION_SUCCEEDED(ret, "recvwait (system call)")
int value = ((int *) buffer)[0];
int value = ((int *) buffer)[0];
performSystemCall(value);
performSystemCall(value);
break;
}*/
break;
}*/
case COMMAND_EXECUTE_ASSEMBLY: {
// Receive the assembly
receiveString(bss, clientfd, (char *) buffer, DATA_BUFFER_SIZE);

Binary file not shown.