Clean up
This commit is contained in:
parent
a77d0713b2
commit
c521bcd633
@ -50,7 +50,7 @@ int UmountFS(void *pClient, void *pCmd, const char *mountPath)
|
|||||||
|
|
||||||
int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size)
|
int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size)
|
||||||
{
|
{
|
||||||
//! always initialze input
|
// Always initialize input
|
||||||
*inbuffer = NULL;
|
*inbuffer = NULL;
|
||||||
if(size)
|
if(size)
|
||||||
*size = 0;
|
*size = 0;
|
||||||
|
89
src/main.c
89
src/main.c
@ -3,7 +3,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include "dynamic_libs/os_functions.h"
|
#include "dynamic_libs/os_functions.h"
|
||||||
@ -19,8 +18,7 @@
|
|||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
|
#include "main.h"
|
||||||
#define FS_BUFFER_SIZE 40000
|
|
||||||
|
|
||||||
int CCHandler;
|
int CCHandler;
|
||||||
|
|
||||||
@ -30,9 +28,10 @@ void startMiiMaker() {
|
|||||||
_SYSLaunchTitleByPathFromLauncher(buf_vol_odd, 18, 0);
|
_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 */
|
/* Entry point */
|
||||||
int Menu_Main(void) {
|
int Menu_Main(void) {
|
||||||
@ -94,45 +93,36 @@ int Menu_Main(void) {
|
|||||||
|
|
||||||
VPADInit();
|
VPADInit();
|
||||||
|
|
||||||
// Prepare screen
|
|
||||||
int screen_buf0_size = 0;
|
|
||||||
int screen_buf1_size = 0;
|
|
||||||
|
|
||||||
// Init screen and screen buffers
|
// Init screen and screen buffers
|
||||||
OSScreenInit();
|
OSScreenInit();
|
||||||
screen_buf0_size = OSScreenGetBufferSizeEx(0);
|
int screenBuffer0Size = OSScreenGetBufferSizeEx(0);
|
||||||
screen_buf1_size = OSScreenGetBufferSizeEx(1);
|
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(0, screenBuffer);
|
||||||
OSScreenSetBufferEx(1, (screenBuffer + screen_buf0_size));
|
OSScreenSetBufferEx(1, (screenBuffer + screenBuffer0Size));
|
||||||
|
|
||||||
OSScreenEnableEx(0, 1);
|
OSScreenEnableEx(0, 1);
|
||||||
OSScreenEnableEx(1, 1);
|
OSScreenEnableEx(1, 1);
|
||||||
|
|
||||||
char msg[80];
|
char messageBuffer[80];
|
||||||
int launchMethod = 0;
|
int launchMethod = 0;
|
||||||
int update_screen = 1;
|
int update_screen = 1;
|
||||||
int vpadError = -1;
|
int vpadError = -1;
|
||||||
VPADData vpad_data;
|
VPADData vpad_data;
|
||||||
|
|
||||||
while (1) {
|
while (true) {
|
||||||
// Read vpad
|
|
||||||
VPADRead(0, &vpad_data, 1, &vpadError);
|
VPADRead(0, &vpad_data, 1, &vpadError);
|
||||||
|
|
||||||
if (update_screen) {
|
if (update_screen) {
|
||||||
OSScreenClearBufferEx(0, 0);
|
OSScreenClearBufferEx(0, 0);
|
||||||
OSScreenClearBufferEx(1, 0);
|
OSScreenClearBufferEx(1, 0);
|
||||||
|
|
||||||
// Print message
|
PRINT_TEXT2(14, 1, "-- TCP Gecko Installer --")
|
||||||
PRINT_TEXT2(14, 1, "-- TCPGecko Installer --");
|
PRINT_TEXT2(0, 5, "Press A to install TCPGecko.")
|
||||||
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, 6, "Press X to install TCPGecko with CosmoCortney's codehandler...");
|
PRINT_TEXT2(0, 17, "Press Home to exit ...")
|
||||||
|
|
||||||
|
|
||||||
PRINT_TEXT2(0, 17, "Press home button to exit ...");
|
|
||||||
|
|
||||||
|
|
||||||
OSScreenFlipBuffersEx(0);
|
OSScreenFlipBuffersEx(0);
|
||||||
OSScreenFlipBuffersEx(1);
|
OSScreenFlipBuffersEx(1);
|
||||||
@ -145,46 +135,55 @@ int Menu_Main(void) {
|
|||||||
launchMethod = 0;
|
launchMethod = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Button
|
// A Button
|
||||||
if (pressedButtons & VPAD_BUTTON_A) {
|
if (pressedButtons & VPAD_BUTTON_A) {
|
||||||
launchMethod = 2;
|
launchMethod = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// X Button
|
// X Button
|
||||||
if (pressedButtons & VPAD_BUTTON_X) {
|
if (pressedButtons & VPAD_BUTTON_X) {
|
||||||
mount_sd_fat("sd");
|
mount_sd_fat("sd");
|
||||||
|
|
||||||
unsigned char *Badbuffer = 0;
|
unsigned char *temporaryCodeHandlerBuffer = 0;
|
||||||
unsigned int filesize = 0;
|
unsigned int codeHandlerSize = 0;
|
||||||
int ret = LoadFileToMem("sd:/wiiu/apps/TCPGecko/codehandler.bin", &Badbuffer, &filesize);
|
const char *filePath = "sd:/wiiu/apps/TCPGecko/codehandler.bin";
|
||||||
if (ret == -1) {
|
int codeHandlerLoaded = LoadFileToMem(filePath, &temporaryCodeHandlerBuffer, &codeHandlerSize);
|
||||||
|
if (codeHandlerLoaded == -1) {
|
||||||
OSScreenClearBufferEx(0, 0);
|
OSScreenClearBufferEx(0, 0);
|
||||||
OSScreenClearBufferEx(1, 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(0);
|
||||||
OSScreenFlipBuffersEx(1);
|
OSScreenFlipBuffersEx(1);
|
||||||
launchMethod = 0;
|
launchMethod = 0;
|
||||||
sleep(2);
|
sleep(2);
|
||||||
|
|
||||||
break;
|
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);
|
unsigned int physicalCodeHandlerAddress = (unsigned int) OSEffectiveToPhysical(
|
||||||
SC0x25_KernelCopyData((u32) phys_cafe_codehandler_loc, (int) buffer, filesize);
|
(void *) CODE_HANDLER_INSTALL_ADDRESS);
|
||||||
m_DCInvalidateRange((u32) phys_cafe_codehandler_loc, filesize);
|
DCFlushRange(&codeHandlerBuffer, codeHandlerSize);
|
||||||
|
SC0x25_KernelCopyData((u32) physicalCodeHandlerAddress, (int) codeHandlerBuffer, codeHandlerSize);
|
||||||
|
m_DCInvalidateRange((u32) physicalCodeHandlerAddress, codeHandlerSize);
|
||||||
|
|
||||||
unmount_sd_fat("sd");
|
unmount_sd_fat("sd");
|
||||||
CCHandler = 1;
|
CCHandler = 1;
|
||||||
|
@ -12,7 +12,6 @@ extern "C" {
|
|||||||
//! C wrapper for our C++ functions
|
//! C wrapper for our C++ functions
|
||||||
int Menu_Main(void);
|
int Menu_Main(void);
|
||||||
|
|
||||||
extern int pygecko;
|
|
||||||
extern int CCHandler;
|
extern int CCHandler;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -47,7 +47,7 @@ struct pygecko_bss_t {
|
|||||||
#define COMMAND_ACCOUNT_IDENTIFIER 0x57
|
#define COMMAND_ACCOUNT_IDENTIFIER 0x57
|
||||||
#define COMMAND_WRITE_SCREEN 0x58 // TODO Exception DSI
|
#define COMMAND_WRITE_SCREEN 0x58 // TODO Exception DSI
|
||||||
#define COMMAND_FOLLOW_POINTER 0x60
|
#define COMMAND_FOLLOW_POINTER 0x60
|
||||||
#define COMMAND_RPC 0x70
|
#define COMMAND_REMOTE_PROCEDURE_CALL 0x70
|
||||||
#define COMMAND_GET_SYMBOL 0x71
|
#define COMMAND_GET_SYMBOL 0x71
|
||||||
#define COMMAND_MEMORY_SEARCH 0x73
|
#define COMMAND_MEMORY_SEARCH 0x73
|
||||||
// #define COMMAND_SYSTEM_CALL 0x80
|
// #define COMMAND_SYSTEM_CALL 0x80
|
||||||
@ -60,11 +60,9 @@ struct pygecko_bss_t {
|
|||||||
#define errno (*__gh_errno_ptr())
|
#define errno (*__gh_errno_ptr())
|
||||||
#define MSG_DONTWAIT 32
|
#define MSG_DONTWAIT 32
|
||||||
#define EWOULDBLOCK 6
|
#define EWOULDBLOCK 6
|
||||||
#define FS_BUFFER_SIZE 0x1000
|
|
||||||
#define DATA_BUFFER_SIZE 0x5000
|
#define DATA_BUFFER_SIZE 0x5000
|
||||||
#define DISASSEMBLER_BUFFER_SIZE 0x1024
|
|
||||||
#define WRITE_SCREEN_MESSAGE_BUFFER_SIZE 100
|
#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 ONLY_ZEROS_READ 0xB0
|
||||||
#define NON_ZEROS_READ 0xBD
|
#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) {
|
void pygecko_memcpy(unsigned char *destinationBuffer, unsigned char *sourceBuffer, unsigned int length) {
|
||||||
memcpy(memcpy_buffer, sourceBuffer, length);
|
memcpy(memcpy_buffer, sourceBuffer, length);
|
||||||
SC0x25_KernelCopyData((unsigned int) OSEffectiveToPhysical(destinationBuffer), (unsigned int) &memcpy_buffer,
|
SC0x25_KernelCopyData((unsigned int) OSEffectiveToPhysical(destinationBuffer), (unsigned int) &memcpy_buffer, length);
|
||||||
length);
|
|
||||||
DCFlushRange(destinationBuffer, (u32) length);
|
DCFlushRange(destinationBuffer, (u32) length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,6 +327,7 @@ void considerInitializingFileSystem() {
|
|||||||
|
|
||||||
char *disassemblerBuffer;
|
char *disassemblerBuffer;
|
||||||
void *disassemblerBufferPointer;
|
void *disassemblerBufferPointer;
|
||||||
|
#define DISASSEMBLER_BUFFER_SIZE 0x1024
|
||||||
|
|
||||||
void formatDisassembled(char *format, ...) {
|
void formatDisassembled(char *format, ...) {
|
||||||
if (!disassemblerBuffer) {
|
if (!disassemblerBuffer) {
|
||||||
@ -375,10 +373,6 @@ void reportIllegalCommandByte(int commandByte) {
|
|||||||
OSFatal(errorBuffer);
|
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 MINIMUM_KERNEL_COMPARE_LENGTH 4
|
||||||
#define KERNEL_MEMORY_COMPARE_STEP_SIZE 1
|
#define KERNEL_MEMORY_COMPARE_STEP_SIZE 1
|
||||||
|
|
||||||
@ -919,7 +913,7 @@ static int rungecko(struct pygecko_bss_t *bss, int clientfd) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COMMAND_REPLACE_FILE: {
|
case COMMAND_REPLACE_FILE: {
|
||||||
// TODO Write file
|
// TODO FSOpenFile ACCESS_ERROR
|
||||||
|
|
||||||
// Receive the file path
|
// Receive the file path
|
||||||
char file_path[FS_MAX_FULLPATH_SIZE] = {0};
|
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);
|
ret = recvwait(bss, clientfd, fileBuffer, dataLength);
|
||||||
ASSERT_FUNCTION_SUCCEEDED(ret, "recvwait (File buffer)")
|
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,
|
ret = FSWriteFile(client, commandBlock, fileBuffer, 1,
|
||||||
dataLength, handle, 0, FS_RET_ALL_ERROR);
|
dataLength, handle, 0, FS_RET_ALL_ERROR);
|
||||||
ASSERT_FUNCTION_SUCCEEDED(ret, "FSWriteFile")
|
ASSERT_FUNCTION_SUCCEEDED(ret, "FSWriteFile")
|
||||||
} else {
|
} else {
|
||||||
// Done
|
// Done with receiving the new file
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1133,7 +1127,7 @@ static int rungecko(struct pygecko_bss_t *bss, int clientfd) {
|
|||||||
CHECK_ERROR(ret < 0)
|
CHECK_ERROR(ret < 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COMMAND_RPC: {
|
case COMMAND_REMOTE_PROCEDURE_CALL: {
|
||||||
long long (*fun)(int, int, int, int, int, int, int, int);
|
long long (*fun)(int, int, int, int, int, int, int, int);
|
||||||
int r3, r4, r5, r6, r7, r8, r9, r10;
|
int r3, r4, r5, r6, r7, r8, r9, r10;
|
||||||
long long result;
|
long long result;
|
||||||
@ -1234,16 +1228,16 @@ static int rungecko(struct pygecko_bss_t *bss, int clientfd) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/*case COMMAND_SYSTEM_CALL: {
|
/*case COMMAND_SYSTEM_CALL: {
|
||||||
ret = recvwait(bss, clientfd, buffer, 4);
|
ret = recvwait(bss, clientfd, buffer, 4);
|
||||||
ASSERT_FUNCTION_SUCCEEDED(ret, "recvwait (system call)")
|
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: {
|
case COMMAND_EXECUTE_ASSEMBLY: {
|
||||||
// Receive the assembly
|
// Receive the assembly
|
||||||
receiveString(bss, clientfd, (char *) buffer, DATA_BUFFER_SIZE);
|
receiveString(bss, clientfd, (char *) buffer, DATA_BUFFER_SIZE);
|
||||||
|
BIN
tcpgecko.elf
BIN
tcpgecko.elf
Binary file not shown.
Loading…
Reference in New Issue
Block a user