Skip to content

Commit

Permalink
fixed the priiloader detection oooops
Browse files Browse the repository at this point in the history
  • Loading branch information
Naim2000 committed Dec 2, 2023
1 parent 6dccdc5 commit 376c275
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
34 changes: 18 additions & 16 deletions source/directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions source/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion source/sysmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) = {};
Expand Down
43 changes: 22 additions & 21 deletions source/theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;


Expand All @@ -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 };
}
Expand All @@ -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");
Expand All @@ -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);
Expand Down

0 comments on commit 376c275

Please sign in to comment.