From a45d0d092daf4bbff6ba9a9212087fcfef64b696 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 17 Apr 2021 11:53:51 +0200 Subject: [PATCH] Use the latest wut version --- Dockerfile | 2 +- relocator/src/entry.cpp | 5 ++- relocator/src/utils/logger.c | 69 ++++++++++++++++++++++++++++++++---- relocator/src/utils/logger.h | 15 +++----- 4 files changed, 73 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2a89983..5e00827 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM wiiuenv/devkitppc:20210101 +FROM wiiuenv/devkitppc:20210414 COPY --from=wiiuenv/wiiumodulesystem:20210219 /artifacts $DEVKITPRO diff --git a/relocator/src/entry.cpp b/relocator/src/entry.cpp index fbb9376..b7d5cb8 100644 --- a/relocator/src/entry.cpp +++ b/relocator/src/entry.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -21,6 +20,8 @@ MEMHeapHandle gHeapHandle __attribute__((section(".data"))) = nullptr; uint8_t gFunctionsPatched __attribute__((section(".data"))) = 0; uint8_t gInitCalled __attribute__((section(".data"))) = 0; +extern "C" void socket_lib_init(); + std::vector OrderModulesByDependencies(const std::vector &loadedModules); extern "C" void doStart(int argc, char **argv); @@ -41,6 +42,8 @@ extern "C" int _start(int argc, char **argv) { doStart(argc, argv); DEBUG_FUNCTION_LINE_VERBOSE("Call real one\n"); + log_deinit(); + return ((int (*)(int, char **)) (*(unsigned int *) 0x1005E040))(argc, argv); } diff --git a/relocator/src/utils/logger.c b/relocator/src/utils/logger.c index f682284..0c37854 100644 --- a/relocator/src/utils/logger.c +++ b/relocator/src/utils/logger.c @@ -4,9 +4,7 @@ #include #include #include "logger.h" -#include #include - #include #include @@ -14,7 +12,57 @@ static int log_socket __attribute__((section(".data"))) = -1; static struct sockaddr_in connect_addr __attribute__((section(".data"))); static volatile int log_lock __attribute__((section(".data"))) = 0; -void log_init_() { +#define SOL_SOCKET -1 + + +#define SOCK_DGRAM 2 + + +#define INADDR_ANY 0 +#define INADDR_BROADCAST 0xFFFFFFFF + +#define PF_UNSPEC 0 +#define PF_INET 2 +#define PF_INET6 23 + +#define AF_UNSPEC PF_UNSPEC +#define AF_INET PF_INET +#define AF_INET6 PF_INET6 + +#define IPPROTO_UDP 17 + +#define SO_BROADCAST 0x0020 // broadcast + +typedef uint16_t sa_family_t; + +struct in_addr +{ + unsigned int s_addr; +}; + +struct sockaddr +{ + sa_family_t sa_family; + char sa_data[]; +}; + +struct sockaddr_in +{ + unsigned short sin_family; + unsigned short sin_port; + struct in_addr sin_addr; + char sin_zero[8]; +}; + +typedef uint32_t socklen_t; + +extern int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen); +extern int socket(int domain, int type, int protocol); +extern int socketclose(int sockfd); +extern int sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); +extern uint32_t htonl(uint32_t val); + +void log_init() { int broadcastEnable = 1; log_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (log_socket < 0) @@ -28,7 +76,16 @@ void log_init_() { connect_addr.sin_addr.s_addr = htonl(INADDR_BROADCAST); } -void log_print_(const char *str) { +void log_deinit() { + if (log_socket < 0){ + return; + } + if(socketclose(log_socket) != 0) { + return; + } +} + +void log_print(const char *str) { // socket is always 0 initially as it is in the BSS if (log_socket < 0) { return; @@ -65,7 +122,7 @@ void OSFatal_printf(const char *format, ...) { va_end(va); } -void log_printf_(const char *format, ...) { +void log_printf(const char *format, ...) { if (log_socket < 0) { return; } @@ -76,7 +133,7 @@ void log_printf_(const char *format, ...) { va_list va; va_start(va, format); if ((vsprintf(tmp, format, va) >= 0)) { - log_print_(tmp); + log_print(tmp); } va_end(va); } diff --git a/relocator/src/utils/logger.h b/relocator/src/utils/logger.h index 456a2f6..6d44221 100644 --- a/relocator/src/utils/logger.h +++ b/relocator/src/utils/logger.h @@ -7,12 +7,13 @@ extern "C" { #include -void log_init_(); +void log_init(); -//void log_deinit_(void); -void log_print_(const char *str); +void log_deinit(void); -void log_printf_(const char *format, ...); +void log_print(const char *str); + +void log_printf(const char *format, ...); void OSFatal_printf(const char *format, ...); @@ -23,12 +24,6 @@ void OSFatal_printf(const char *format, ...); OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ } while (0) - -#define log_init() log_init_() -//#define log_deinit() log_deinit_() -#define log_print(str) log_print_(str) -#define log_printf(FMT, ARGS...) log_printf_(FMT, ## ARGS); - #define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ log_printf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ } while (0)