From 376c275f58ad74f3b26d51ce5038265151a197ff Mon Sep 17 00:00:00 2001 From: Naim2000 Date: Sat, 2 Dec 2023 11:33:18 -0500 Subject: [PATCH] fixed the priiloader detection oooops --- source/directory.c | 34 ++++++++++++++++++---------------- source/fs.c | 9 +++------ source/main.c | 2 +- source/sysmenu.c | 2 +- source/theme.c | 43 ++++++++++++++++++++++--------------------- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/source/directory.c b/source/directory.c index 0186f11..c253a7d 100644 --- a/source/directory.c +++ b/source/directory.c @@ -23,12 +23,21 @@ struct entry { static char cwd[PATH_MAX]; -bool isDirectory(const char* path) { +static bool isDirectory(const char* path) { struct stat statbuf; stat(path, &statbuf); return S_ISDIR(statbuf.st_mode) > 0; } +static bool goBack(char* path) { + if(strchr(path, '/') == strrchr(path, '/')) + return false; + + *strrchr(path, '/') = '\x00'; + *(strrchr(path, '/') + 1) = '\x00'; + return true; +} + static void PrintEntries(struct entry entries[], int count, int max, int selected) { if (!count) { printf("\t\x1b[30;1m[Nothing.]\x1b[39m"); @@ -148,8 +157,7 @@ char* SelectFileMenu(const char* header, const char* defaultFolder, FileFilter f if (defaultFolder) { sprintf(strrchr(cwd, '/'), "/%s/", defaultFolder); if (!GetDirectoryEntries(cwd, &entries, &cnt, filter)) { - *strrchr(cwd, '/') = '\x00'; - *(strrchr(cwd, '/') + 1) = '\x00'; + goBack(cwd); GetDirectoryEntries(cwd, &entries, &cnt, filter); } } @@ -198,13 +206,12 @@ char* SelectFileMenu(const char* header, const char* defaultFolder, FileFilter f } else if (buttons & (WPAD_BUTTON_A | WPAD_BUTTON_RIGHT)) { if (entry->flags & 0x80) { - *strrchr(cwd, '/') = '\x00'; - *(strrchr(cwd, '/') + 1) = '\x00'; + goBack(cwd); GetDirectoryEntries(cwd, &entries, &cnt, filter); index = 0; break; } - if (entry->flags & 0x01) { + else if (entry->flags & 0x01) { // chdir(entry->name); sprintf(strrchr(cwd, '/'), "/%s", entry->name); GetDirectoryEntries(cwd, &entries, &cnt, filter); @@ -221,20 +228,15 @@ char* SelectFileMenu(const char* header, const char* defaultFolder, FileFilter f break; } else if (buttons & (WPAD_BUTTON_B | WPAD_BUTTON_LEFT)) { - if (strchr(cwd, '/') == strrchr(cwd, '/')) { // sd:/ <-- first and last / + if (!goBack(cwd)) { errno = ECANCELED; free(entries); return NULL; } - else { - // "sd:/apps/cdbackup/". one strrchr('/') will land me right at the end. but so will another. so i will subtract one. - // i'm not sure why i typed that. - *strrchr(cwd, '/') = '\x00'; - *(strrchr(cwd, '/') + 1) = '\x00'; - GetDirectoryEntries(cwd, &entries, &cnt, filter); - index = 0; - break; - } + + GetDirectoryEntries(cwd, &entries, &cnt, filter); + index = 0; + break; } else if (buttons & WPAD_BUTTON_HOME) { errno = ECANCELED; diff --git a/source/fs.c b/source/fs.c index 867665e..5e352fb 100644 --- a/source/fs.c +++ b/source/fs.c @@ -10,12 +10,9 @@ int progressbar(size_t read, size_t total) { printf("\r["); - for (size_t i = 0; i < total; i += FS_CHUNK) { - if (i < read) - putchar('='); - else - putchar(' '); - } + for (size_t i = 0; i < total; i += FS_CHUNK) + putchar((i < read) ? '=' : ' '); + printf("] %u / %u bytes (%.2f%%) ", read, total, (read / (double)total) * 100); if (read == total) putchar('\n'); diff --git a/source/main.c b/source/main.c index a39f6af..89b84ee 100644 --- a/source/main.c +++ b/source/main.c @@ -61,7 +61,7 @@ int main(int argc, char* argv[]) { if (patchIOS(false) < 0) { puts("failed to apply IOS patches! Exiting in 5s..."); sleep(5); - return 0xD8000064; + return 0xCD800064; } initpads(); diff --git a/source/sysmenu.c b/source/sysmenu.c index 5570453..71f9cbc 100644 --- a/source/sysmenu.c +++ b/source/sysmenu.c @@ -166,7 +166,7 @@ int sysmenu_process() { *(strrchr(sysmenu_filepath, '/') + 1) = '1'; // Also how Priiloader installer does it. sort of ret = NAND_GetFileSize(sysmenu_filepath, NULL); - __hasPriiloader = (ret <= 0); + __hasPriiloader = (ret >= 0); } else { char header[4] ATTRIBUTE_ALIGN(0x20) = {}; diff --git a/source/theme.c b/source/theme.c index ec44ad9..00b2d33 100644 --- a/source/theme.c +++ b/source/theme.c @@ -23,11 +23,11 @@ static const char binary_path_search_2[] = "D:\\Compat_irdrepo\\ipl\\Compat", binary_path_fmt[] = "%c_%c\\ipl\\bin\\RVL\\Final_%c"; -static int FindString(void* buf, size_t size, const char* str) { +static int FindString(void* buf, size_t size, const char* str, bool end) { int len = strlen(str); for (int i = 0; i < (size - len); i++) if (memcmp(buf + i, str, len) == 0) - return i; + return i + (end? strlen(str) : 0); return -1; } @@ -38,7 +38,7 @@ SignatureLevel SignedTheme(unsigned char* buffer, size_t length) { if (memcmp(hash, getArchiveHash(), sizeof(sha1)) == 0) return default_theme; - else if (FindString(buffer, length, wiithemer_sig) >= 0) + else if (FindString(buffer, length, wiithemer_sig, false) >= 0) return wiithemer_signed; @@ -48,17 +48,15 @@ SignatureLevel SignedTheme(unsigned char* buffer, size_t length) { version_t GetThemeVersion(unsigned char* buffer, size_t length) { char rgn = 0, major = 0, minor = 0; - int len = strlen(binary_path_search); - int off = FindString(buffer, length, binary_path_search); + int off = FindString(buffer, length, binary_path_search, true); + + if (off < 0) + off = FindString(buffer, length, binary_path_search_2, true); - if (off < 0) { - len = strlen(binary_path_search_2); - off = FindString(buffer, length, binary_path_search_2); - } if (off < 0) return (version_t){ '?', '?', '?' }; - buffer += off + len; + buffer += off; sscanf((char*)buffer, binary_path_fmt, &major, &minor, &rgn); return (version_t) { major, minor, rgn }; } @@ -75,6 +73,16 @@ int InstallTheme(unsigned char* buffer, size_t size) { return -EINVAL; } + version_t themeversion = GetThemeVersion(buffer, size); + if (themeversion.region != getSmRegion()) { + printf("\x1b[41;30mIncompatible theme!\x1b[40;39m\nTheme region : %c\nSystem region: %c\n", themeversion.region, getSmRegion()); + return -EINVAL; + } + else if (themeversion.major != getSmVersionMajor()) { + printf("\x1b[41;30mIncompatible theme!\x1b[40;39m\nTheme version : %c.X\nSystem menu version: %c.X\n", themeversion.major, getSmVersionMajor()); + return -EINVAL; + } + switch (SignedTheme(buffer, size)) { case default_theme: puts("\x1b[32;1mThis is the default theme for your Wii menu.\x1b[39m"); @@ -85,20 +93,13 @@ int InstallTheme(unsigned char* buffer, size_t size) { default: puts("\x1b[30;1mThis theme isn't signed...\x1b[39m"); + // if (!hasPriiloader()) { + // puts("Priiloader is not installed, not installing this theme."); + // return -EPERM; + // } break; } - putchar('\n'); - - version_t themeversion = GetThemeVersion(buffer, size); - if (themeversion.region != getSmRegion()) { - printf("\x1b[41;30mIncompatible theme!\x1b[40;39m\nTheme region : %c\nSystem region: %c\n", themeversion.region, getSmRegion()); - return -EINVAL; - } - else if (themeversion.major != getSmVersionMajor()) { - printf("\x1b[41;30mIncompatible theme!\x1b[40;39m\nTheme major version : %c\nSystem major version: %c\n", themeversion.major, getSmVersionMajor()); - return -EINVAL; - } printf("%s\n", getArchivePath()); int ret = NAND_Write(getArchivePath(), buffer, size, progressbar);