/* main.c -- YoYo Loader Qoi Decoder based on .so loader * * Copyright (C) 2021 Andy Nguyen * Copyright (C) 2022 Rinnegatamante * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file for details. */ // FIXME: This file can greatly be stripped out of stuffs #define _POSIX_TIMERS #include #include #include #include #include #define AL_ALEXT_PROTOTYPES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "main.h" #include "config.h" #include "dialog.h" #include "so_util.h" #include "sha1.h" #include "unzip.h" static int __stack_chk_guard_fake = 0x42424242; unsigned int _pthread_stack_default_user = 1 * 1024 * 1024; so_module yoyoloader_mod; void *__wrap_memcpy(void *dest, const void *src, size_t n) { return sceClibMemcpy(dest, src, n); } void *__wrap_memmove(void *dest, const void *src, size_t n) { return sceClibMemmove(dest, src, n); } void *__wrap_memset(void *s, int c, size_t n) { return sceClibMemset(s, c, n); } int debugPrintf(char *text, ...) { return 0; } struct android_dirent { char pad[18]; unsigned char d_type; char d_name[256]; }; // From https://github.com/kraj/uClibc/blob/master/libc/misc/dirent/scandir.c int scandir_hook(const char *dir, struct android_dirent ***namelist, int (*selector) (const struct dirent *), int (*compar) (const struct dirent **, const struct dirent **)) { DIR *dp = opendir (dir); struct dirent *current; struct android_dirent d; struct android_dirent *android_current = &d; struct android_dirent **names = NULL; size_t names_size = 0, pos; //int save; if (dp == NULL) return -1; //save = errno; //__set_errno (0); pos = 0; while ((current = readdir (dp)) != NULL) { int use_it = selector == NULL; sceClibMemcpy(android_current->d_name, current->d_name, 256); android_current->d_type = SCE_S_ISDIR(current->d_stat.st_mode) ? 4 : 8; if (! use_it) { use_it = (*selector) (android_current); /* The selector function might have changed errno. * It was zero before and it need to be again to make * the latter tests work. */ //if (! use_it) //__set_errno (0); } if (use_it) { struct android_dirent *vnew; size_t dsize; /* Ignore errors from selector or readdir */ //__set_errno (0); if (pos == names_size) { struct android_dirent **new; if (names_size == 0) names_size = 10; else names_size *= 2; new = (struct android_dirent **) vglRealloc (names, names_size * sizeof (struct android_dirent *)); if (new == NULL) break; names = new; } dsize = &android_current->d_name[256+1] - (char*)android_current; vnew = (struct android_dirent *) vglMalloc (dsize); if (vnew == NULL) break; names[pos++] = (struct android_dirent *) sceClibMemcpy (vnew, android_current, dsize); } } if (errno != 0) { //save = errno; closedir (dp); while (pos > 0) vglFree (names[--pos]); vglFree (names); //__set_errno (save); return -1; } closedir (dp); //__set_errno (save); /* Sort the list if we have a comparison function to sort with. */ if (compar != NULL) qsort (names, pos, sizeof (struct android_dirent *), (__compar_fn_t) compar); *namelist = names; return pos; } int __android_log_print(int prio, const char *tag, const char *fmt, ...) { return 0; } int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list list) { return 0; } int ret0(void) { return 0; } int ret1(void) { return 1; } int pthread_mutex_init_fake(pthread_mutex_t **uid, const pthread_mutexattr_t *mutexattr) { pthread_mutex_t *m = calloc(1, sizeof(pthread_mutex_t)); if (!m) return -1; const int recursive = (mutexattr && *(const int *)mutexattr == 1); *m = recursive ? PTHREAD_RECURSIVE_MUTEX_INITIALIZER : PTHREAD_MUTEX_INITIALIZER; int ret = pthread_mutex_init(m, mutexattr); if (ret < 0) { free(m); return -1; } *uid = m; return 0; } int pthread_mutex_destroy_fake(pthread_mutex_t **uid) { if (uid && *uid && (uintptr_t)*uid > 0x8000) { pthread_mutex_destroy(*uid); free(*uid); *uid = NULL; } return 0; } int pthread_mutex_lock_fake(pthread_mutex_t **uid) { int ret = 0; if (!*uid) { ret = pthread_mutex_init_fake(uid, NULL); } else if ((uintptr_t)*uid == 0x4000) { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); ret = pthread_mutex_init_fake(uid, &attr); pthread_mutexattr_destroy(&attr); } else if ((uintptr_t)*uid == 0x8000) { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); ret = pthread_mutex_init_fake(uid, &attr); pthread_mutexattr_destroy(&attr); } if (ret < 0) return ret; return pthread_mutex_lock(*uid); } int pthread_mutex_unlock_fake(pthread_mutex_t **uid) { int ret = 0; if (!*uid) { ret = pthread_mutex_init_fake(uid, NULL); } else if ((uintptr_t)*uid == 0x4000) { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); ret = pthread_mutex_init_fake(uid, &attr); pthread_mutexattr_destroy(&attr); } else if ((uintptr_t)*uid == 0x8000) { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); ret = pthread_mutex_init_fake(uid, &attr); pthread_mutexattr_destroy(&attr); } if (ret < 0) return ret; return pthread_mutex_unlock(*uid); } int pthread_cond_init_fake(pthread_cond_t **cnd, const int *condattr) { pthread_cond_t *c = calloc(1, sizeof(pthread_cond_t)); if (!c) return -1; *c = PTHREAD_COND_INITIALIZER; int ret = pthread_cond_init(c, NULL); if (ret < 0) { free(c); return -1; } *cnd = c; return 0; } int pthread_cond_broadcast_fake(pthread_cond_t **cnd) { if (!*cnd) { if (pthread_cond_init_fake(cnd, NULL) < 0) return -1; } return pthread_cond_broadcast(*cnd); } int pthread_cond_signal_fake(pthread_cond_t **cnd) { if (!*cnd) { if (pthread_cond_init_fake(cnd, NULL) < 0) return -1; } return pthread_cond_signal(*cnd); } int pthread_cond_destroy_fake(pthread_cond_t **cnd) { if (cnd && *cnd) { pthread_cond_destroy(*cnd); free(*cnd); *cnd = NULL; } return 0; } int pthread_cond_wait_fake(pthread_cond_t **cnd, pthread_mutex_t **mtx) { if (!*cnd) { if (pthread_cond_init_fake(cnd, NULL) < 0) return -1; } return pthread_cond_wait(*cnd, *mtx); } int pthread_cond_timedwait_fake(pthread_cond_t **cnd, pthread_mutex_t **mtx, const struct timespec *t) { if (!*cnd) { if (pthread_cond_init_fake(cnd, NULL) < 0) return -1; } return pthread_cond_timedwait(*cnd, *mtx, t); } int pthread_create_fake(pthread_t *thread, const void *unused, void *entry, void *arg) { return pthread_create(thread, NULL, entry, arg); } int pthread_once_fake(volatile int *once_control, void (*init_routine)(void)) { if (!once_control || !init_routine) return -1; if (__sync_lock_test_and_set(once_control, 1) == 0) (*init_routine)(); return 0; } extern void *__aeabi_ldiv0; int DebugPrintf(int *target, const char *fmt, ...) { return 0; } void __stack_chk_fail_fake() {} extern void *_Znaj; extern void *_Znwj; extern void *_ZdlPv; extern void *_ZdaPv; extern void *_ZTVN10__cxxabiv117__class_type_infoE; extern void *_ZTVN10__cxxabiv120__si_class_type_infoE; extern void *_ZNSt12length_errorD1Ev; extern void *_ZNSt13runtime_errorD1Ev; extern void *_ZTVSt12length_error; extern void *__aeabi_memclr; extern void *__aeabi_memclr4; extern void *__aeabi_memclr8; extern void *__aeabi_memcpy4; extern void *__aeabi_memcpy8; extern void *__aeabi_memmove4; extern void *__aeabi_memmove8; extern void *__aeabi_memcpy; extern void *__aeabi_memmove; extern void *__aeabi_memset; extern void *__aeabi_memset4; extern void *__aeabi_memset8; extern void *__aeabi_atexit; extern void *__aeabi_idiv; extern void *__aeabi_idivmod; extern void *__aeabi_ldivmod; extern void *__aeabi_uidiv; extern void *__aeabi_uidivmod; extern void *__aeabi_uldivmod; extern void *__aeabi_f2d; extern void *__aeabi_l2d; extern void *__aeabi_l2f; extern void *__aeabi_d2uiz; extern void *__aeabi_d2lz; extern void *__aeabi_d2ulz; extern void *__aeabi_ui2d; extern void *__aeabi_ul2d; extern void *__aeabi_ddiv; extern void *__aeabi_dadd; extern void *__aeabi_dcmplt; extern void *__aeabi_dmul; extern void *__aeabi_dsub; extern void *__aeabi_dcmpge; extern void *__aeabi_dcmpgt; extern void *__aeabi_i2d; extern void *__cxa_atexit; extern void *__cxa_finalize; extern void *__cxa_guard_acquire; extern void *__cxa_guard_release; extern void *__cxa_pure_virtual; extern void *__cxa_allocate_exception; extern void __cxa_throw(void *thrown_exception, void *tinfo, void (*dest)(void *)); extern void *__gnu_unwind_frame; extern void *__stack_chk_fail; char __progname[32] = {0}; int __page_size = 0; int open(const char *pathname, int flags); static FILE __sF_fake[0x100][3]; int stat_hook(const char *pathname, void *statbuf) { struct stat st; int res = stat(pathname, &st); if (res == 0) *(uint64_t *)(statbuf + 0x30) = st.st_size; return res; } void *AAssetManager_open(void *mgr, const char *filename, int mode) { return NULL; } void *AAsset_close() { return NULL; } void *AAssetManager_fromJava() { return NULL; } void *AAsset_read() { return NULL; } void *AAsset_seek() { return NULL; } void *AAsset_getLength() { return NULL; } int fstat_hook(int fd, void *statbuf) { struct stat st; int res = fstat(fd, &st); if (res == 0) *(uint64_t *)(statbuf + 0x30) = st.st_size; return res; } void *dlopen_hook(const char *filename, int flags) { return NULL; } void *dlsym_hook( void *handle, const char *symbol) { return NULL; } void *sceClibMemclr(void *dst, SceSize len) { return sceClibMemset(dst, 0, len); } void *sceClibMemset2(void *dst, SceSize len, int ch) { return sceClibMemset(dst, ch, len); } #define IS_LEAP(n) ((!(((n) + 1900) % 400) || (!(((n) + 1900) % 4) && (((n) + 1900) % 100))) != 0) #define days_in_gregorian_cycle ((365 * 400) + 100 - 4 + 1) static const int length_of_year[2] = { 365, 366 }; static const int julian_days_by_month[2][12] = { {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}, }; struct tm *localtime64(const int64_t *time) { time_t _t = *time; return localtime(&_t); } struct tm *gmtime64(const int64_t *time) { time_t _t = *time; return gmtime(&_t); } int64_t mktime64(struct tm *time) { return mktime(time); } int64_t timegm64(const struct tm *date) { int64_t days = 0; int64_t seconds = 0; int64_t year; int64_t orig_year = (int64_t)date->tm_year; int cycles = 0; if( orig_year > 100 ) { cycles = (orig_year - 100) / 400; orig_year -= cycles * 400; days += (int64_t)cycles * days_in_gregorian_cycle; } else if( orig_year < -300 ) { cycles = (orig_year - 100) / 400; orig_year -= cycles * 400; days += (int64_t)cycles * days_in_gregorian_cycle; } if( orig_year > 70 ) { year = 70; while( year < orig_year ) { days += length_of_year[IS_LEAP(year)]; year++; } } else if ( orig_year < 70 ) { year = 69; do { days -= length_of_year[IS_LEAP(year)]; year--; } while( year >= orig_year ); } days += julian_days_by_month[IS_LEAP(orig_year)][date->tm_mon]; days += date->tm_mday - 1; seconds = days * 60 * 60 * 24; seconds += date->tm_hour * 60 * 60; seconds += date->tm_min * 60; seconds += date->tm_sec; return seconds; } int is_prime(int n) { if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0; for (int i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (i + 2) == 0) return 0; } return 1; } int _ZNSt6__ndk112__next_primeEj(void *this, int n) { if (n <= 1) return 2; while (!is_prime(n)) { n++; } return n; } void __cxa_throw_hook(void *thrown_exception, void *tinfo, void (*dest)(void *)) { if (tinfo == so_symbol(&yoyoloader_mod, "_ZTI14YYGMLException")) { void (* YYCatchGMLException)(void *exception) = so_symbol(&yoyoloader_mod, "_Z19YYCatchGMLExceptionRK14YYGMLException"); YYCatchGMLException(thrown_exception); if (dest) dest(thrown_exception); } else __cxa_throw(thrown_exception, tinfo, dest); } void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) { return vglMalloc(length); } int munmap(void *addr, size_t length) { vglFree(addr); return 0; } int nanosleep_hook(const struct timespec *req, struct timespec *rem) { const uint32_t usec = req->tv_sec * 1000 * 1000 + req->tv_nsec / 1000; return sceKernelDelayThreadCB(usec); } static so_default_dynlib default_dynlib[] = { { "AAssetManager_open", (uintptr_t)&AAssetManager_open}, { "AAsset_close", (uintptr_t)&AAsset_close}, { "AAssetManager_fromJava", (uintptr_t)&AAssetManager_fromJava}, { "AAsset_read", (uintptr_t)&AAsset_read}, { "AAsset_seek", (uintptr_t)&AAsset_seek}, { "AAsset_getLength", (uintptr_t)&AAsset_getLength}, { "_tolower_tab_", (uintptr_t)&tolower}, { "_toupper_tab_", (uintptr_t)&toupper}, { "_Znaj", (uintptr_t)&_Znaj }, { "_Znwj", (uintptr_t)&_Znwj }, { "_ZdaPv", (uintptr_t)&_ZdaPv }, { "_ZdlPv", (uintptr_t)&_ZdlPv }, { "_ZTVN10__cxxabiv117__class_type_infoE", (uintptr_t)&_ZTVN10__cxxabiv117__class_type_infoE}, { "_ZTVN10__cxxabiv120__si_class_type_infoE", (uintptr_t)&_ZTVN10__cxxabiv120__si_class_type_infoE}, { "_ZNSt12length_errorD1Ev", (uintptr_t)&_ZNSt12length_errorD1Ev}, { "_ZNSt13runtime_errorD1Ev", (uintptr_t)&_ZNSt13runtime_errorD1Ev}, { "_ZTVSt12length_error", (uintptr_t)&_ZTVSt12length_error}, { "_ZNSt6__ndk112__next_primeEj", &_ZNSt6__ndk112__next_primeEj}, { "__aeabi_f2d", (uintptr_t)&__aeabi_f2d }, { "__aeabi_l2d", (uintptr_t)&__aeabi_l2d }, { "__aeabi_l2f", (uintptr_t)&__aeabi_l2f }, { "__aeabi_d2uiz", (uintptr_t)&__aeabi_d2uiz }, { "__aeabi_d2ulz", (uintptr_t)&__aeabi_d2ulz }, { "__aeabi_d2lz", (uintptr_t)&__aeabi_d2lz }, { "__aeabi_ui2d", (uintptr_t)&__aeabi_ui2d }, { "__aeabi_ul2d", (uintptr_t)&__aeabi_ul2d }, { "__aeabi_i2d", (uintptr_t)&__aeabi_i2d }, { "__aeabi_idivmod", (uintptr_t)&__aeabi_idivmod }, { "__aeabi_ldivmod", (uintptr_t)&__aeabi_ldivmod }, { "__aeabi_uidivmod", (uintptr_t)&__aeabi_uidivmod }, { "__aeabi_uldivmod", (uintptr_t)&__aeabi_uldivmod }, { "__aeabi_ddiv", (uintptr_t)&__aeabi_ddiv }, { "__aeabi_idiv", (uintptr_t)&__aeabi_idiv }, { "__aeabi_uidiv", (uintptr_t)&__aeabi_uidiv }, { "__aeabi_dadd", (uintptr_t)&__aeabi_dadd }, { "__aeabi_dcmplt", (uintptr_t)&__aeabi_dcmplt }, { "__aeabi_dcmpge", (uintptr_t)&__aeabi_dcmpge }, { "__aeabi_dcmpgt", (uintptr_t)&__aeabi_dcmpgt }, { "__aeabi_dmul", (uintptr_t)&__aeabi_dmul }, { "__aeabi_dsub", (uintptr_t)&__aeabi_dsub }, { "__aeabi_memclr", (uintptr_t)&sceClibMemclr }, { "__aeabi_memclr4", (uintptr_t)&sceClibMemclr }, { "__aeabi_memclr8", (uintptr_t)&sceClibMemclr }, { "__aeabi_memcpy4", (uintptr_t)&sceClibMemcpy }, { "__aeabi_memcpy8", (uintptr_t)&sceClibMemcpy }, { "__aeabi_memmove4", (uintptr_t)&sceClibMemmove }, { "__aeabi_memmove8", (uintptr_t)&sceClibMemmove }, { "__aeabi_memcpy", (uintptr_t)&sceClibMemcpy }, { "__aeabi_memmove", (uintptr_t)&sceClibMemmove }, { "__aeabi_memset", (uintptr_t)&sceClibMemset2 }, { "__aeabi_memset4", (uintptr_t)&sceClibMemset2 }, { "__aeabi_memset8", (uintptr_t)&sceClibMemset2 }, { "__aeabi_atexit", (uintptr_t)&__aeabi_atexit }, { "__android_log_print", (uintptr_t)&__android_log_print }, { "__android_log_vprint", (uintptr_t)&__android_log_vprint }, { "__cxa_allocate_exception", (uintptr_t)&__cxa_allocate_exception }, { "__cxa_atexit", (uintptr_t)&__cxa_atexit }, { "__cxa_finalize", (uintptr_t)&__cxa_finalize }, { "__cxa_guard_acquire", (uintptr_t)&__cxa_guard_acquire }, { "__cxa_guard_release", (uintptr_t)&__cxa_guard_release }, { "__cxa_pure_virtual", (uintptr_t)&__cxa_pure_virtual }, { "__cxa_throw", (uintptr_t)&__cxa_throw_hook }, { "__errno", (uintptr_t)&__errno }, { "__gnu_unwind_frame", (uintptr_t)&__gnu_unwind_frame }, { "__gnu_Unwind_Find_exidx", (uintptr_t)&ret0 }, { "__progname", (uintptr_t)&__progname }, { "__page_size", (uintptr_t)&__page_size }, { "__sF", (uintptr_t)&__sF_fake }, { "__stack_chk_fail", (uintptr_t)&__stack_chk_fail_fake }, { "__stack_chk_guard", (uintptr_t)&__stack_chk_guard_fake }, { "_ctype_", (uintptr_t)&_ctype_}, { "abort", (uintptr_t)&abort }, //{ "accept", (uintptr_t)&accept }, { "acos", (uintptr_t)&acos }, { "acosf", (uintptr_t)&acosf }, { "asin", (uintptr_t)&asin }, { "asinf", (uintptr_t)&asinf }, { "atan", (uintptr_t)&atan }, { "atan2", (uintptr_t)&atan2 }, { "atan2f", (uintptr_t)&atan2f }, { "atanf", (uintptr_t)&atanf }, { "atoi", (uintptr_t)&atoi }, { "atol", (uintptr_t)&atol }, { "atoll", (uintptr_t)&atoll }, { "bind", (uintptr_t)&bind }, { "bsearch", (uintptr_t)&bsearch }, { "btowc", (uintptr_t)&btowc }, { "calloc", (uintptr_t)&calloc }, { "ceil", (uintptr_t)&ceil }, { "ceilf", (uintptr_t)&ceilf }, { "clearerr", (uintptr_t)&clearerr }, { "clock_gettime", (uintptr_t)&clock_gettime }, { "close", (uintptr_t)&close }, { "compress", (uintptr_t)&compress }, //{ "connect", (uintptr_t)&connect }, { "cos", (uintptr_t)&cos }, { "cosf", (uintptr_t)&cosf }, { "cosh", (uintptr_t)&cosh }, { "crc32", (uintptr_t)&crc32 }, { "deflate", (uintptr_t)&deflate }, { "deflateEnd", (uintptr_t)&deflateEnd }, { "deflateInit_", (uintptr_t)&deflateInit_ }, { "deflateInit2_", (uintptr_t)&deflateInit2_ }, { "deflateReset", (uintptr_t)&deflateReset }, { "dlclose", (uintptr_t)&ret0 }, { "dlopen", (uintptr_t)&dlopen_hook }, { "dlsym", (uintptr_t)&dlsym_hook }, { "exit", (uintptr_t)&exit }, { "exp", (uintptr_t)&exp }, { "expf", (uintptr_t)&expf }, { "fclose", (uintptr_t)&fclose }, { "fcntl", (uintptr_t)&ret0 }, { "fdopen", (uintptr_t)&fdopen }, { "feof", (uintptr_t)&feof }, { "ferror", (uintptr_t)&ferror }, { "fflush", (uintptr_t)&fflush }, { "fgetpos", (uintptr_t)&fgetpos }, { "fgetc", (uintptr_t)&fgetc }, { "fgets", (uintptr_t)&fgets }, { "floor", (uintptr_t)&floor }, { "floorf", (uintptr_t)&floorf }, { "fmod", (uintptr_t)&fmod }, { "fmodf", (uintptr_t)&fmodf }, { "fopen", (uintptr_t)&fopen }, { "fprintf", (uintptr_t)&fprintf }, { "fputc", (uintptr_t)&fputc }, { "fputs", (uintptr_t)&fputs }, { "fread", (uintptr_t)&fread }, { "free", (uintptr_t)&vglFree }, //{ "freeaddrinfo", (uintptr_t)&freeaddrinfo }, { "frexp", (uintptr_t)&frexp }, { "frexpf", (uintptr_t)&frexpf }, { "fscanf", (uintptr_t)&fscanf }, { "fseek", (uintptr_t)&fseek }, { "fseeko", (uintptr_t)&fseeko }, { "fstat", (uintptr_t)&fstat_hook }, { "ftell", (uintptr_t)&ftell }, { "ftello", (uintptr_t)&ftello }, { "fwrite", (uintptr_t)&fwrite }, { "getaddrinfo", (uintptr_t)&getaddrinfo }, { "getc", (uintptr_t)&getc }, { "getenv", (uintptr_t)&ret0 }, //{ "getsockopt", (uintptr_t)&getsockopt }, { "getwc", (uintptr_t)&getwc }, { "gettimeofday", (uintptr_t)&gettimeofday }, { "gmtime64", (uintptr_t)&gmtime64 }, { "inet_addr", (uintptr_t)&inet_addr }, { "inet_ntoa", (uintptr_t)&inet_ntoa }, //{ "inet_ntop", (uintptr_t)&inet_ntop }, //{ "inet_pton", (uintptr_t)&inet_pton }, { "inflate", (uintptr_t)&inflate }, { "inflateEnd", (uintptr_t)&inflateEnd }, { "inflateInit_", (uintptr_t)&inflateInit_ }, { "inflateInit2_", (uintptr_t)&inflateInit2_ }, { "inflateReset", (uintptr_t)&inflateReset }, { "ioctl", (uintptr_t)&ret0 }, { "isalnum", (uintptr_t)&isalnum }, { "isalpha", (uintptr_t)&isalpha }, { "iscntrl", (uintptr_t)&iscntrl }, { "islower", (uintptr_t)&islower }, { "isnan", (uintptr_t)&isnan }, { "ispunct", (uintptr_t)&ispunct }, { "isprint", (uintptr_t)&isprint }, { "isspace", (uintptr_t)&isspace }, { "isupper", (uintptr_t)&isupper }, { "iswalpha", (uintptr_t)&iswalpha }, { "iswcntrl", (uintptr_t)&iswcntrl }, { "iswctype", (uintptr_t)&iswctype }, { "iswdigit", (uintptr_t)&iswdigit }, { "iswdigit", (uintptr_t)&iswdigit }, { "iswlower", (uintptr_t)&iswlower }, { "iswprint", (uintptr_t)&iswprint }, { "iswpunct", (uintptr_t)&iswpunct }, { "iswspace", (uintptr_t)&iswspace }, { "iswupper", (uintptr_t)&iswupper }, { "iswxdigit", (uintptr_t)&iswxdigit }, { "isxdigit", (uintptr_t)&isxdigit }, { "ldexp", (uintptr_t)&ldexp }, { "ldiv", (uintptr_t)&ldiv }, //{ "listen", (uintptr_t)&listen }, { "llrint", (uintptr_t)&llrint }, { "localtime_r", (uintptr_t)&localtime_r }, { "localtime64", (uintptr_t)&localtime64 }, { "log", (uintptr_t)&log }, { "log10", (uintptr_t)&log10 }, { "longjmp", (uintptr_t)&longjmp }, { "lrand48", (uintptr_t)&lrand48 }, { "lrint", (uintptr_t)&lrint }, { "lrintf", (uintptr_t)&lrintf }, { "lseek", (uintptr_t)&lseek }, { "malloc", (uintptr_t)&vglMalloc }, { "mbrtowc", (uintptr_t)&mbrtowc }, { "memalign", (uintptr_t)&vglMemalign }, { "memchr", (uintptr_t)&sceClibMemchr }, { "memcmp", (uintptr_t)&memcmp }, { "memcpy", (uintptr_t)&sceClibMemcpy }, { "memmove", (uintptr_t)&sceClibMemmove }, { "memset", (uintptr_t)&sceClibMemset }, { "mkdir", (uintptr_t)&mkdir }, { "mktime", (uintptr_t)&mktime }, { "mktime64", (uintptr_t)&mktime64 }, { "mmap", (uintptr_t)&mmap }, { "modf", (uintptr_t)&modf }, { "modff", (uintptr_t)&modff }, { "munmap", (uintptr_t)&munmap }, { "nanosleep", (uintptr_t)&nanosleep_hook }, { "open", (uintptr_t)&open }, { "pow", (uintptr_t)&pow }, { "powf", (uintptr_t)&powf }, { "printf", (uintptr_t)&debugPrintf }, { "pthread_attr_destroy", (uintptr_t)&ret0 }, { "pthread_attr_init", (uintptr_t)&ret0 }, { "pthread_attr_setdetachstate", (uintptr_t)&ret0 }, { "pthread_cond_broadcast", (uintptr_t)&pthread_cond_broadcast_fake}, { "pthread_cond_destroy", (uintptr_t)&pthread_cond_destroy_fake}, { "pthread_cond_init", (uintptr_t)&pthread_cond_init_fake}, { "pthread_cond_wait", (uintptr_t)&pthread_cond_wait_fake}, { "pthread_create", (uintptr_t)&pthread_create_fake}, { "pthread_join", (uintptr_t)&pthread_join}, { "pthread_key_create", (uintptr_t)&pthread_key_create}, { "pthread_key_delete", (uintptr_t)&pthread_key_delete}, { "pthread_mutex_destroy", (uintptr_t)&pthread_mutex_destroy_fake}, { "pthread_mutex_init", (uintptr_t)&pthread_mutex_init_fake}, { "pthread_mutex_lock", (uintptr_t)&pthread_mutex_lock_fake}, { "pthread_mutex_unlock", (uintptr_t)&pthread_mutex_unlock_fake}, { "pthread_mutexattr_destroy", (uintptr_t)&pthread_mutexattr_destroy}, { "pthread_mutexattr_init", (uintptr_t)&pthread_mutexattr_init}, { "pthread_mutexattr_settype", (uintptr_t)&pthread_mutexattr_settype}, { "pthread_setspecific", (uintptr_t)&pthread_setspecific}, { "pthread_getspecific", (uintptr_t)&pthread_getspecific}, { "putc", (uintptr_t)&putc }, { "putwc", (uintptr_t)&putwc }, { "qsort", (uintptr_t)&qsort }, { "read", (uintptr_t)&read }, { "realloc", (uintptr_t)&vglRealloc }, //{ "recv", (uintptr_t)&recv }, //{ "recvfrom", (uintptr_t)&recvfrom }, { "remove", (uintptr_t)&sceIoRemove }, { "rename", (uintptr_t)&sceIoRename }, { "rint", (uintptr_t)&rint }, { "scandir", (uintptr_t)&scandir_hook }, //{ "send", (uintptr_t)&send }, //{ "sendto", (uintptr_t)&sendto }, { "setenv", (uintptr_t)&ret0 }, { "setjmp", (uintptr_t)&setjmp }, { "setlocale", (uintptr_t)&ret0 }, //{ "setsockopt", (uintptr_t)&setsockopt }, { "setvbuf", (uintptr_t)&setvbuf }, { "sin", (uintptr_t)&sin }, { "sincosf", (uintptr_t)&sincosf }, { "sinf", (uintptr_t)&sinf }, { "sinh", (uintptr_t)&sinh }, { "snprintf", (uintptr_t)&snprintf }, { "socket", (uintptr_t)&socket }, { "sprintf", (uintptr_t)&sprintf }, { "sqrt", (uintptr_t)&sqrt }, { "sqrtf", (uintptr_t)&sqrtf }, { "srand48", (uintptr_t)&srand48 }, { "sscanf", (uintptr_t)&sscanf }, { "stat", (uintptr_t)&stat_hook }, { "strcasecmp", (uintptr_t)&strcasecmp }, { "strcat", (uintptr_t)&strcat }, { "strchr", (uintptr_t)&strchr }, { "strcmp", (uintptr_t)&strcmp }, { "strcoll", (uintptr_t)&strcoll }, { "strcpy", (uintptr_t)&strcpy }, { "strcspn", (uintptr_t)&strcspn }, { "strdup", (uintptr_t)&strdup }, { "strndup", (uintptr_t)&strndup }, { "strerror", (uintptr_t)&strerror }, { "strftime", (uintptr_t)&strftime }, { "strlen", (uintptr_t)&strlen }, { "strncasecmp", (uintptr_t)&sceClibStrncasecmp }, { "strncat", (uintptr_t)&sceClibStrncat }, { "strncmp", (uintptr_t)&sceClibStrncmp }, { "strncpy", (uintptr_t)&sceClibStrncpy }, { "strpbrk", (uintptr_t)&strpbrk }, { "strrchr", (uintptr_t)&sceClibStrrchr }, { "strstr", (uintptr_t)&sceClibStrstr }, { "strtod", (uintptr_t)&strtod }, { "strtok", (uintptr_t)&strtok }, { "strtol", (uintptr_t)&strtol }, { "strtoll", (uintptr_t)&strtoll }, { "strtoul", (uintptr_t)&strtoul }, { "strxfrm", (uintptr_t)&strxfrm }, { "sysconf", (uintptr_t)&ret0 }, { "tan", (uintptr_t)&tan }, { "tanf", (uintptr_t)&tanf }, { "tanh", (uintptr_t)&tanh }, { "time", (uintptr_t)&time }, { "timegm64", (uintptr_t)&timegm64 }, { "tolower", (uintptr_t)&tolower }, { "toupper", (uintptr_t)&toupper }, { "towlower", (uintptr_t)&towlower }, { "towupper", (uintptr_t)&towupper }, { "ungetc", (uintptr_t)&ungetc }, { "ungetwc", (uintptr_t)&ungetwc }, { "usleep", (uintptr_t)&usleep }, { "vasprintf", (uintptr_t)&vasprintf }, { "vfprintf", (uintptr_t)&vfprintf }, { "vprintf", (uintptr_t)&vprintf }, { "vsnprintf", (uintptr_t)&vsnprintf }, { "vsprintf", (uintptr_t)&vsprintf }, { "vswprintf", (uintptr_t)&vswprintf }, { "wcrtomb", (uintptr_t)&wcrtomb }, { "wcscoll", (uintptr_t)&wcscoll }, { "wcscmp", (uintptr_t)&wcscmp }, { "wcsncpy", (uintptr_t)&wcsncpy }, { "wcsftime", (uintptr_t)&wcsftime }, { "wcslen", (uintptr_t)&wcslen }, { "wcsxfrm", (uintptr_t)&wcsxfrm }, { "wctob", (uintptr_t)&wctob }, { "wctype", (uintptr_t)&wctype }, { "wmemchr", (uintptr_t)&wmemchr }, { "wmemcmp", (uintptr_t)&wmemcmp }, { "wmemcpy", (uintptr_t)&wmemcpy }, { "wmemmove", (uintptr_t)&wmemmove }, { "wmemset", (uintptr_t)&wmemset }, { "write", (uintptr_t)&write }, }; void *(*ReadQOIFFile)(void *buffer, int size, int *w, int *h, int unk); void *MemoryManagerAlloc(int size, char *text, int unk1, int unk2, int unk3) { return malloc(size); } void YYFree(void *addr) { free(addr); } void patch_runner(void) { ReadQOIFFile = so_symbol(&yoyoloader_mod, "_Z12ReadQOIFFilePviPiS0_b"); hook_addr(so_symbol(&yoyoloader_mod, "_ZN13MemoryManager5AllocEjPKcib"), (uintptr_t)&MemoryManagerAlloc); hook_addr(so_symbol(&yoyoloader_mod, "_Z6YYFreePKv_0"), (uintptr_t)&YYFree); } int runner_loaded = 0; void load_runner() { if (runner_loaded) return; printf("Loading runner on memory...\n"); int res = so_file_load(&yoyoloader_mod, "ux0:data/gms/libyoyo.tmp", 0xA8000000); if (res < 0) { printf("Error could not load lib/armeabi-v7a/libyoyo.so from inside game.apk. (Errorcode: 0x%08X)\n", res); } printf("Relocating the executable...\n"); so_relocate(&yoyoloader_mod); printf("Resolving symbols...\n"); so_resolve(&yoyoloader_mod, default_dynlib, sizeof(default_dynlib), 0); printf("Patching runner...\n"); patch_runner(); printf("Flushing cache...\n"); so_flush_caches(&yoyoloader_mod); printf("Initializing executable...\n"); so_initialize(&yoyoloader_mod); runner_loaded = 1; } void *decode_qoi(void *buffer, int size, int *w, int *h) { load_runner(); printf("Calling QOIF decoder from the runner...\n"); return ReadQOIFFile(buffer, size, w, h, 0); }