Run automattic code formatting

This commit is contained in:
TheShadowEevee 2022-04-20 20:38:39 -05:00
parent ccbdddd2f2
commit 08c9eb7710
No known key found for this signature in database
GPG Key ID: 7A8AA92B3BAFAB75
14 changed files with 1742 additions and 1387 deletions

View File

@ -1,29 +1,29 @@
/*------------------------------------------------------------- /*-------------------------------------------------------------
detect_settings.c -- detects various system settings detect_settings.c -- detects various system settings
Copyright (C) 2008 tona Copyright (C) 2008 tona
Unless other credit specified Unless other credit specified
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
damages arising from the use of this software. damages arising from the use of this software.
Permission is granted to anyone to use this software for any Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions: redistribute it freely, subject to the following restrictions:
1.The origin of this software must not be misrepresented; you 1.The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required. documentation would be appreciated but is not required.
2.Altered source versions must be plainly marked as such, and 2.Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software. must not be misrepresented as being the original software.
3.This notice may not be removed or altered from any source 3.This notice may not be removed or altered from any source
distribution. distribution.
-------------------------------------------------------------*/ -------------------------------------------------------------*/
#include <stdio.h> #include <stdio.h>
@ -34,141 +34,149 @@ distribution.
#include "wiibasics.h" #include "wiibasics.h"
#include "detect_settings.h" #include "detect_settings.h"
u16 get_installed_title_version(u64 title) { u16 get_installed_title_version(u64 title)
{
s32 ret, fd; s32 ret, fd;
static char filepath[256] ATTRIBUTE_ALIGN(32); static char filepath[256] ATTRIBUTE_ALIGN(32);
// Check to see if title exists // Check to see if title exists
if (ES_GetDataDir(title, filepath) >= 0 ) { if (ES_GetDataDir(title, filepath) >= 0)
{
u32 tmd_size; u32 tmd_size;
static u8 tmd_buf[MAX_SIGNED_TMD_SIZE] ATTRIBUTE_ALIGN(32); static u8 tmd_buf[MAX_SIGNED_TMD_SIZE] ATTRIBUTE_ALIGN(32);
ret = ES_GetStoredTMDSize(title, &tmd_size); ret = ES_GetStoredTMDSize(title, &tmd_size);
if (ret < 0){ if (ret < 0)
{
// If we fail to use the ES function, try reading manually // If we fail to use the ES function, try reading manually
// This is a workaround added since some IOS (like 21) don't like our // This is a workaround added since some IOS (like 21) don't like our
// call to ES_GetStoredTMDSize // call to ES_GetStoredTMDSize
//printf("Error! ES_GetStoredTMDSize: %d\n", ret); // printf("Error! ES_GetStoredTMDSize: %d\n", ret);
sprintf(filepath, "/title/%08lx/%08lx/content/title.tmd", TITLE_UPPER(title), TITLE_LOWER(title)); sprintf(filepath, "/title/%08lx/%08lx/content/title.tmd", TITLE_UPPER(title), TITLE_LOWER(title));
ret = ISFS_Open(filepath, ISFS_OPEN_READ); ret = ISFS_Open(filepath, ISFS_OPEN_READ);
if (ret <= 0) if (ret <= 0)
{ {
printf("Error! ISFS_Open (ret = %ld)\n", ret); printf("Error! ISFS_Open (ret = %ld)\n", ret);
return 0; return 0;
} }
fd = ret; fd = ret;
ret = ISFS_Seek(fd, 0x1dc, 0); ret = ISFS_Seek(fd, 0x1dc, 0);
if (ret < 0) if (ret < 0)
{ {
printf("Error! ISFS_Seek (ret = %ld)\n", ret); printf("Error! ISFS_Seek (ret = %ld)\n", ret);
return 0; return 0;
} }
ret = ISFS_Read(fd,tmd_buf,2); ret = ISFS_Read(fd, tmd_buf, 2);
if (ret < 0) if (ret < 0)
{ {
printf("Error! ISFS_Read (ret = %ld)\n", ret); printf("Error! ISFS_Read (ret = %ld)\n", ret);
return 0; return 0;
} }
ret = ISFS_Close(fd); ret = ISFS_Close(fd);
if (ret < 0) if (ret < 0)
{ {
printf("Error! ISFS_Close (ret = %ld)\n", ret); printf("Error! ISFS_Close (ret = %ld)\n", ret);
return 0; return 0;
} }
return be16(tmd_buf); return be16(tmd_buf);
}
} else { else
{
// Normal versions of IOS won't have a problem, so we do things the "right" way. // Normal versions of IOS won't have a problem, so we do things the "right" way.
// Some of this code adapted from bushing's title_lister.c // Some of this code adapted from bushing's title_lister.c
signed_blob *s_tmd = (signed_blob *)tmd_buf; signed_blob *s_tmd = (signed_blob *)tmd_buf;
ret = ES_GetStoredTMD(title, s_tmd, tmd_size); ret = ES_GetStoredTMD(title, s_tmd, tmd_size);
if (ret < 0){ if (ret < 0)
{
printf("Error! ES_GetStoredTMD: %ld\n", ret); printf("Error! ES_GetStoredTMD: %ld\n", ret);
return -1; return -1;
} }
tmd *t = SIGNATURE_PAYLOAD(s_tmd); tmd *t = SIGNATURE_PAYLOAD(s_tmd);
return t->title_version; return t->title_version;
} }
}
}
return 0; return 0;
} }
u64 get_title_ios(u64 title) { u64 get_title_ios(u64 title)
{
s32 ret, fd; s32 ret, fd;
static char filepath[256] ATTRIBUTE_ALIGN(32); static char filepath[256] ATTRIBUTE_ALIGN(32);
// Check to see if title exists // Check to see if title exists
if (ES_GetDataDir(title, filepath) >= 0 ) { if (ES_GetDataDir(title, filepath) >= 0)
{
u32 tmd_size; u32 tmd_size;
static u8 tmd_buf[MAX_SIGNED_TMD_SIZE] ATTRIBUTE_ALIGN(32); static u8 tmd_buf[MAX_SIGNED_TMD_SIZE] ATTRIBUTE_ALIGN(32);
ret = ES_GetStoredTMDSize(title, &tmd_size); ret = ES_GetStoredTMDSize(title, &tmd_size);
if (ret < 0){ if (ret < 0)
{
// If we fail to use the ES function, try reading manually // If we fail to use the ES function, try reading manually
// This is a workaround added since some IOS (like 21) don't like our // This is a workaround added since some IOS (like 21) don't like our
// call to ES_GetStoredTMDSize // call to ES_GetStoredTMDSize
//printf("Error! ES_GetStoredTMDSize: %d\n", ret); // printf("Error! ES_GetStoredTMDSize: %d\n", ret);
sprintf(filepath, "/title/%08lx/%08lx/content/title.tmd", TITLE_UPPER(title), TITLE_LOWER(title)); sprintf(filepath, "/title/%08lx/%08lx/content/title.tmd", TITLE_UPPER(title), TITLE_LOWER(title));
ret = ISFS_Open(filepath, ISFS_OPEN_READ); ret = ISFS_Open(filepath, ISFS_OPEN_READ);
if (ret <= 0) if (ret <= 0)
{ {
printf("Error! ISFS_Open (ret = %ld)\n", ret); printf("Error! ISFS_Open (ret = %ld)\n", ret);
return 0; return 0;
} }
fd = ret; fd = ret;
ret = ISFS_Seek(fd, 0x184, 0); ret = ISFS_Seek(fd, 0x184, 0);
if (ret < 0) if (ret < 0)
{ {
printf("Error! ISFS_Seek (ret = %ld)\n", ret); printf("Error! ISFS_Seek (ret = %ld)\n", ret);
return 0; return 0;
} }
ret = ISFS_Read(fd,tmd_buf,8); ret = ISFS_Read(fd, tmd_buf, 8);
if (ret < 0) if (ret < 0)
{ {
printf("Error! ISFS_Read (ret = %ld)\n", ret); printf("Error! ISFS_Read (ret = %ld)\n", ret);
return 0; return 0;
} }
ret = ISFS_Close(fd); ret = ISFS_Close(fd);
if (ret < 0) if (ret < 0)
{ {
printf("Error! ISFS_Close (ret = %ld)\n", ret); printf("Error! ISFS_Close (ret = %ld)\n", ret);
return 0; return 0;
} }
return be64(tmd_buf); return be64(tmd_buf);
}
} else { else
{
// Normal versions of IOS won't have a problem, so we do things the "right" way. // Normal versions of IOS won't have a problem, so we do things the "right" way.
// Some of this code adapted from bushing's title_lister.c // Some of this code adapted from bushing's title_lister.c
signed_blob *s_tmd = (signed_blob *)tmd_buf; signed_blob *s_tmd = (signed_blob *)tmd_buf;
ret = ES_GetStoredTMD(title, s_tmd, tmd_size); ret = ES_GetStoredTMD(title, s_tmd, tmd_size);
if (ret < 0){ if (ret < 0)
{
printf("Error! ES_GetStoredTMD: %ld\n", ret); printf("Error! ES_GetStoredTMD: %ld\n", ret);
return -1; return -1;
} }
tmd *t = SIGNATURE_PAYLOAD(s_tmd); tmd *t = SIGNATURE_PAYLOAD(s_tmd);
return t->sys_version; return t->sys_version;
} }
}
}
return 0; return 0;
} }
@ -176,21 +184,20 @@ u64 get_title_ios(u64 title) {
by looking into it's resource content file for region information. */ by looking into it's resource content file for region information. */
char get_sysmenu_region(void) char get_sysmenu_region(void)
{ {
s32 ret, cfd; s32 ret, cfd;
static u8 fbuffer[0x500] ATTRIBUTE_ALIGN(32); static u8 fbuffer[0x500] ATTRIBUTE_ALIGN(32);
static tikview viewdata[0x10] ATTRIBUTE_ALIGN(32); static tikview viewdata[0x10] ATTRIBUTE_ALIGN(32);
u32 views; u32 views;
static u64 tid ATTRIBUTE_ALIGN(32) = TITLE_ID(1,2); static u64 tid ATTRIBUTE_ALIGN(32) = TITLE_ID(1, 2);
u8 region, match[] = "FINAL"; u8 region, match[] = "FINAL";
/*ret = ES_SetUID(TITLE_ID(1,2)); /*ret = ES_SetUID(TITLE_ID(1,2));
if (ret){ if (ret){
printf("Error! ES_GetSetUID %d\n", ret); printf("Error! ES_GetSetUID %d\n", ret);
wait_anyKey(); wait_anyKey();
return 0; return 0;
} }
ret = ES_GetTitleID(&tid); ret = ES_GetTitleID(&tid);
if (ret){ if (ret){
printf("Error! ES_GetTitleID %d\n", ret); printf("Error! ES_GetTitleID %d\n", ret);
@ -209,24 +216,28 @@ char get_sysmenu_region(void)
wait_anyKey(); wait_anyKey();
return 0; return 0;
}*/ }*/
ret = ES_GetNumTicketViews(tid, &views); ret = ES_GetNumTicketViews(tid, &views);
if (ret < 0) { if (ret < 0)
{
printf(" Error! ES_GetNumTickets (ret = %ld)\n", ret); printf(" Error! ES_GetNumTickets (ret = %ld)\n", ret);
wait_anyKey(); wait_anyKey();
return ret; return ret;
} }
if (!views) { if (!views)
{
printf(" No tickets found!\n"); printf(" No tickets found!\n");
wait_anyKey(); wait_anyKey();
return 0; return 0;
} else if (views > 16) { }
else if (views > 16)
{
printf(" Too many ticket views! (views = %ld)\n", views); printf(" Too many ticket views! (views = %ld)\n", views);
wait_anyKey(); wait_anyKey();
return 0; return 0;
} }
ret = ES_GetTicketViews(tid, viewdata, 1); ret = ES_GetTicketViews(tid, viewdata, 1);
if (ret < 0) if (ret < 0)
{ {
@ -234,7 +245,7 @@ char get_sysmenu_region(void)
wait_anyKey(); wait_anyKey();
return 0; return 0;
} }
ret = ES_OpenTitleContent(tid, viewdata, 1); ret = ES_OpenTitleContent(tid, viewdata, 1);
if (ret < 0) if (ret < 0)
{ {
@ -242,28 +253,31 @@ char get_sysmenu_region(void)
wait_anyKey(); wait_anyKey();
return 0; return 0;
} }
cfd = ret; cfd = ret;
region = 0; region = 0;
while (!region){ while (!region)
{
int i; int i;
ret = ES_ReadContent(cfd,fbuffer,0x500); ret = ES_ReadContent(cfd, fbuffer, 0x500);
if (ret < 0) if (ret < 0)
{ {
printf("Error! ES_ReadContent (ret = %ld)\n", ret); printf("Error! ES_ReadContent (ret = %ld)\n", ret);
wait_anyKey(); wait_anyKey();
return 0; return 0;
} }
for(i=0;i<0x500;i++) { for (i = 0; i < 0x500; i++)
if (fbuffer[i] == 'F'){ {
if (!memcmp(&fbuffer[i], match, 6)){ if (fbuffer[i] == 'F')
region = fbuffer[i+6]; {
if (!memcmp(&fbuffer[i], match, 6))
{
region = fbuffer[i + 6];
break; break;
} }
} }
} }
} }
ret = ES_CloseContent(cfd); ret = ES_CloseContent(cfd);
if (ret < 0) if (ret < 0)
@ -272,16 +286,17 @@ char get_sysmenu_region(void)
wait_anyKey(); wait_anyKey();
return 0; return 0;
} }
switch (region){ switch (region)
{
case 'U': case 'U':
case 'E': case 'E':
case 'J': case 'J':
case 'K': case 'K':
return region; return region;
break; break;
default: default:
return -1; return -1;
break; break;
} }
} }

View File

@ -1,41 +1,41 @@
/*------------------------------------------------------------- /*-------------------------------------------------------------
detect_settings.h -- detects various system settings detect_settings.h -- detects various system settings
Copyright (C) 2008 tona Copyright (C) 2008 tona
Unless other credit specified Unless other credit specified
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
damages arising from the use of this software. damages arising from the use of this software.
Permission is granted to anyone to use this software for any Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions: redistribute it freely, subject to the following restrictions:
1.The origin of this software must not be misrepresented; you 1.The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required. documentation would be appreciated but is not required.
2.Altered source versions must be plainly marked as such, and 2.Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software. must not be misrepresented as being the original software.
3.This notice may not be removed or altered from any source 3.This notice may not be removed or altered from any source
distribution. distribution.
-------------------------------------------------------------*/ -------------------------------------------------------------*/
#ifndef __SYSMENU_DETECT_H_ #ifndef __SYSMENU_DETECT_H_
#define __SYSMENU_DETECT_H_ #define __SYSMENU_DETECT_H_
//Get the title version of a given title // Get the title version of a given title
u16 get_installed_title_version(u64 title); u16 get_installed_title_version(u64 title);
//Get the IOS version of a given title // Get the IOS version of a given title
u64 get_title_ios(u64 title); u64 get_title_ios(u64 title);
//Get the region that the System menu is currently using // Get the region that the System menu is currently using
char get_sysmenu_region(void); char get_sysmenu_region(void);
#endif #endif

View File

@ -10,7 +10,6 @@
//#include "fat2.h" //#include "fat2.h"
//#include "install.h" //#include "install.h"
/* init-globals */ /* init-globals */
static bool geckoinit = false; static bool geckoinit = false;
char DirPath[64] = "Fat:/debug"; char DirPath[64] = "Fat:/debug";
@ -24,126 +23,131 @@ int vasprintf(char **, const char *, va_list);
void gprintf(const char *format, ...) void gprintf(const char *format, ...)
{ {
if (!geckoinit) if (!geckoinit)
return; return;
char * tmp = NULL; char *tmp = NULL;
va_list va; va_list va;
va_start(va, format); va_start(va, format);
if((vasprintf(&tmp, format, va) >= 0) && tmp) if ((vasprintf(&tmp, format, va) >= 0) && tmp)
{ {
usb_sendbuffer(1, tmp, strlen(tmp)); usb_sendbuffer(1, tmp, strlen(tmp));
} }
va_end(va); va_end(va);
if(tmp) if (tmp)
free(tmp); free(tmp);
} }
bool InitGecko() bool InitGecko()
{ {
u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1); u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1);
if (geckoattached) if (geckoattached)
{ {
usb_flush(EXI_CHANNEL_1); usb_flush(EXI_CHANNEL_1);
geckoinit = true; geckoinit = true;
return true; return true;
} }
return false; return false;
} }
void gecko_log(const char *format, ...) { void gecko_log(const char *format, ...)
//ret = Fat_MakeDir(DirPath); {
//void *f = NULL; // ret = Fat_MakeDir(DirPath);
// void *f = NULL;
gprintf("\n\n Fat Make Dir ret[%i] \n\n", ret); gprintf("\n\n Fat Make Dir ret[%i] \n\n", ret);
if (!geckoinit) if (!geckoinit)
return; return;
char * tmp = NULL; char *tmp = NULL;
va_list va; va_list va;
va_start(va, format); va_start(va, format);
if((vasprintf(&tmp, format, va) >= 0) && tmp) if ((vasprintf(&tmp, format, va) >= 0) && tmp)
{ {
sprintf(SavePath, "%s/debug.log", DirPath); sprintf(SavePath, "%s/debug.log", DirPath);
//f = &tmp; // f = &tmp;
//Fat_SaveFilelog(SavePath, f, strlen(tmp)); // Fat_SaveFilelog(SavePath, f, strlen(tmp));
// usb_sendbuffer(1, tmp, strlen(tmp)); // usb_sendbuffer(1, tmp, strlen(tmp));
} }
va_end(va); va_end(va);
//if(tmp) // if(tmp)
// free(tmp); // free(tmp);
tmp = NULL; tmp = NULL;
//f = NULL; // f = NULL;
} }
char ascii2(char s) char ascii2(char s)
{ {
if (s < 0x20) return '.'; if (s < 0x20)
if (s > 0x7E) return '.'; return '.';
return s; if (s > 0x7E)
return '.';
return s;
} }
void hexdump2(void *d, int len) void hexdump2(void *d, int len)
{ {
u8 *data; u8 *data;
int i, off; int i, off;
data = (u8*) d; data = (u8 *)d;
gprintf("\n 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF"); gprintf("\n 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF");
gprintf("\n==== =============================================== ================\n"); gprintf("\n==== =============================================== ================\n");
for (off = 0; off < len; off += 16) for (off = 0; off < len; off += 16)
{ {
gprintf("%04x ", off); gprintf("%04x ", off);
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
if ((i + off) >= len) if ((i + off) >= len)
gprintf(" "); gprintf(" ");
else gprintf("%02x ", data[off + i]); else
gprintf("%02x ", data[off + i]);
gprintf(" "); gprintf(" ");
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
if ((i + off) >= len) if ((i + off) >= len)
gprintf(" "); gprintf(" ");
else gprintf("%c", ascii2(data[off + i])); else
gprintf("\n"); gprintf("%c", ascii2(data[off + i]));
} gprintf("\n");
}
} }
static ssize_t __out_write(struct _reent *r, int fd, const char *ptr, size_t len) static ssize_t __out_write(struct _reent *r, int fd, const char *ptr, size_t len)
{ {
if(geckoinit && ptr) if (geckoinit && ptr)
{ {
usb_sendbuffer(1, ptr, len); usb_sendbuffer(1, ptr, len);
} }
return len; return len;
} }
static const devoptab_t gecko_out = { static const devoptab_t gecko_out = {
"stdout", // device name "stdout", // device name
0, // size of file structure 0, // size of file structure
NULL, // device open NULL, // device open
NULL, // device close NULL, // device close
__out_write, // device write __out_write, // device write
NULL, // device read NULL, // device read
NULL, // device seek NULL, // device seek
NULL, // device fstat NULL, // device fstat
NULL, // device stat NULL, // device stat
NULL, // device link NULL, // device link
NULL, // device unlink NULL, // device unlink
NULL, // device chdir NULL, // device chdir
NULL, // device rename NULL, // device rename
NULL, // device mkdir NULL, // device mkdir
0, // dirStateSize 0, // dirStateSize
NULL, // device diropen_r NULL, // device diropen_r
NULL, // device dirreset_r NULL, // device dirreset_r
NULL, // device dirnext_r NULL, // device dirnext_r
NULL, // device dirclose_r NULL, // device dirclose_r
NULL, // device statvfs_r NULL, // device statvfs_r
NULL, // device ftruncate_r NULL, // device ftruncate_r
NULL, // device fsync_r NULL, // device fsync_r
NULL, // device deviceData NULL, // device deviceData
NULL, // device chmod_r NULL, // device chmod_r
NULL, // device fchmod_r NULL, // device fchmod_r
}; };
void USBGeckoOutput() void USBGeckoOutput()

View File

@ -9,22 +9,21 @@ extern "C"
char ascii2(char s); char ascii2(char s);
//#ifndef NO_DEBUG //#ifndef NO_DEBUG
//use this just like printf(); // use this just like printf();
void gprintf(const char *str, ...); void gprintf(const char *str, ...);
bool InitGecko(); bool InitGecko();
void hexdump2(void *d, int len); void hexdump2(void *d, int len);
void USBGeckoOutput(); void USBGeckoOutput();
void gecko_log(const char *str, ...); void gecko_log(const char *str, ...);
//#else //#else
//#define gprintf(...) //#define gprintf(...)
//#define InitGecko() false //#define InitGecko() false
//#define hexdump( x, y ) //#define hexdump( x, y )
//#endif /* NO_DEBUG */ //#endif /* NO_DEBUG */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

View File

@ -1,29 +1,29 @@
/*------------------------------------------------------------- /*-------------------------------------------------------------
id.c -- ES Identification code id.c -- ES Identification code
Copyright (C) 2008 tona Copyright (C) 2008 tona
Unless other credit specified Unless other credit specified
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
damages arising from the use of this software. damages arising from the use of this software.
Permission is granted to anyone to use this software for any Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions: redistribute it freely, subject to the following restrictions:
1.The origin of this software must not be misrepresented; you 1.The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required. documentation would be appreciated but is not required.
2.Altered source versions must be plainly marked as such, and 2.Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software. must not be misrepresented as being the original software.
3.This notice may not be removed or altered from any source 3.This notice may not be removed or altered from any source
distribution. distribution.
-------------------------------------------------------------*/ -------------------------------------------------------------*/
#include <stdio.h> #include <stdio.h>
@ -37,12 +37,10 @@ distribution.
#include "sha1.h" #include "sha1.h"
#include "certs_dat.h" #include "certs_dat.h"
/* Debug functions adapted from libogc's es.c */ /* Debug functions adapted from libogc's es.c */
//#define DEBUG_ES //#define DEBUG_ES
//#define DEBUG_IDENT //#define DEBUG_IDENT
#define ISALIGNED(x) ((((u32)x)&0x1F)==0) #define ISALIGNED(x) ((((u32)x) & 0x1F) == 0)
static u8 su_tmd[0x208] ATTRIBUTE_ALIGN(32); static u8 su_tmd[0x208] ATTRIBUTE_ALIGN(32);
static u8 su_tik[STD_SIGNED_TIK_SIZE] ATTRIBUTE_ALIGN(32); static u8 su_tik[STD_SIGNED_TIK_SIZE] ATTRIBUTE_ALIGN(32);
@ -53,134 +51,151 @@ s32 __sanity_check_certlist(const signed_blob *certs, u32 certsize)
{ {
int count = 0; int count = 0;
signed_blob *end; signed_blob *end;
if(!certs || !certsize) return 0; if (!certs || !certsize)
return 0;
end = (signed_blob*)(((u8*)certs) + certsize);
while(certs != end) { end = (signed_blob *)(((u8 *)certs) + certsize);
while (certs != end)
{
#ifdef DEBUG_ES #ifdef DEBUG_ES
printf("Checking certificate at %p\n",certs); printf("Checking certificate at %p\n", certs);
#endif #endif
certs = ES_NextCert(certs); certs = ES_NextCert(certs);
if(!certs) return 0; if (!certs)
return 0;
count++; count++;
} }
#ifdef DEBUG_ES #ifdef DEBUG_ES
printf("Num of certificates: %d\n",count); printf("Num of certificates: %d\n", count);
#endif #endif
return count; return count;
} }
#endif #endif
void zero_sig(signed_blob *sig) { void zero_sig(signed_blob *sig)
u8 *sig_ptr = (u8 *)sig; {
memset(sig_ptr + 4, 0, SIGNATURE_SIZE(sig)-4); u8 *sig_ptr = (u8 *)sig;
memset(sig_ptr + 4, 0, SIGNATURE_SIZE(sig) - 4);
} }
void brute_tmd(tmd *p_tmd) { void brute_tmd(tmd *p_tmd)
u16 fill; {
for(fill=0; fill<65535; fill++) { u16 fill;
p_tmd->fill2=fill; for (fill = 0; fill < 65535; fill++)
sha1 hash; {
// debug_printf("SHA1(%p, %x, %p)\n", p_tmd, TMD_SIZE(p_tmd), hash); p_tmd->fill2 = fill;
SHA1((u8 *)p_tmd, TMD_SIZE(p_tmd), hash);; sha1 hash;
// debug_printf("SHA1(%p, %x, %p)\n", p_tmd, TMD_SIZE(p_tmd), hash);
if (hash[0]==0) { SHA1((u8 *)p_tmd, TMD_SIZE(p_tmd), hash);
// debug_printf("setting fill3 to %04hx\n", fill); ;
return;
} if (hash[0] == 0)
} {
printf("Unable to fix tmd :(\n"); // debug_printf("setting fill3 to %04hx\n", fill);
exit(4); return;
}
}
printf("Unable to fix tmd :(\n");
exit(4);
} }
void brute_tik(tik *p_tik) { void brute_tik(tik *p_tik)
u16 fill; {
for(fill=0; fill<65535; fill++) { u16 fill;
p_tik->padding=fill; for (fill = 0; fill < 65535; fill++)
sha1 hash; {
// debug_printf("SHA1(%p, %x, %p)\n", p_tmd, TMD_SIZE(p_tmd), hash); p_tik->padding = fill;
SHA1((u8 *)p_tik, sizeof(tik), hash); sha1 hash;
// debug_printf("SHA1(%p, %x, %p)\n", p_tmd, TMD_SIZE(p_tmd), hash);
if (hash[0]==0) return; SHA1((u8 *)p_tik, sizeof(tik), hash);
}
printf("Unable to fix tik :(\n"); if (hash[0] == 0)
exit(5); return;
} }
printf("Unable to fix tik :(\n");
void forge_tmd(signed_blob *s_tmd) { exit(5);
// debug_printf("forging tmd sig");
zero_sig(s_tmd);
brute_tmd(SIGNATURE_PAYLOAD(s_tmd));
} }
void forge_tik(signed_blob *s_tik) { void forge_tmd(signed_blob *s_tmd)
// debug_printf("forging tik sig"); {
zero_sig(s_tik); // debug_printf("forging tmd sig");
brute_tik(SIGNATURE_PAYLOAD(s_tik)); zero_sig(s_tmd);
brute_tmd(SIGNATURE_PAYLOAD(s_tmd));
} }
void forge_tik(signed_blob *s_tik)
{
// debug_printf("forging tik sig");
zero_sig(s_tik);
brute_tik(SIGNATURE_PAYLOAD(s_tik));
}
void Make_SUID(void) { void Make_SUID(void)
{
signed_blob *s_tmd, *s_tik; signed_blob *s_tmd, *s_tik;
tmd *p_tmd; tmd *p_tmd;
tik *p_tik; tik *p_tik;
memset(su_tmd, 0, sizeof su_tmd); memset(su_tmd, 0, sizeof su_tmd);
memset(su_tik, 0, sizeof su_tik); memset(su_tik, 0, sizeof su_tik);
s_tmd = (signed_blob*)&su_tmd[0]; s_tmd = (signed_blob *)&su_tmd[0];
s_tik = (signed_blob*)&su_tik[0]; s_tik = (signed_blob *)&su_tik[0];
*s_tmd = *s_tik = 0x10001; *s_tmd = *s_tik = 0x10001;
p_tmd = (tmd*)SIGNATURE_PAYLOAD(s_tmd); p_tmd = (tmd *)SIGNATURE_PAYLOAD(s_tmd);
p_tik = (tik*)SIGNATURE_PAYLOAD(s_tik); p_tik = (tik *)SIGNATURE_PAYLOAD(s_tik);
strcpy(p_tmd->issuer, "Root-CA00000001-CP00000004"); strcpy(p_tmd->issuer, "Root-CA00000001-CP00000004");
p_tmd->title_id = TITLE_ID(1,2); p_tmd->title_id = TITLE_ID(1, 2);
p_tmd->num_contents = 1; p_tmd->num_contents = 1;
forge_tmd(s_tmd); forge_tmd(s_tmd);
strcpy(p_tik->issuer, "Root-CA00000001-XS00000003"); strcpy(p_tik->issuer, "Root-CA00000001-XS00000003");
p_tik->ticketid = 0x000038A45236EE5FLL; p_tik->ticketid = 0x000038A45236EE5FLL;
p_tik->titleid = TITLE_ID(1,2); p_tik->titleid = TITLE_ID(1, 2);
memset(p_tik->cidx_mask, 0xFF, 0x20); memset(p_tik->cidx_mask, 0xFF, 0x20);
forge_tik(s_tik); forge_tik(s_tik);
su_id_filled = 1; su_id_filled = 1;
} }
s32 Identify(const u8 *certs, u32 certs_size, const u8 *idtmd, u32 idtmd_size, const u8 *idticket, u32 idticket_size) { s32 Identify(const u8 *certs, u32 certs_size, const u8 *idtmd, u32 idtmd_size, const u8 *idticket, u32 idticket_size)
{
s32 ret; s32 ret;
u32 keyid = 0; u32 keyid = 0;
ret = ES_Identify((signed_blob*)certs, certs_size, (signed_blob*)idtmd, idtmd_size, (signed_blob*)idticket, idticket_size, &keyid); ret = ES_Identify((signed_blob *)certs, certs_size, (signed_blob *)idtmd, idtmd_size, (signed_blob *)idticket, idticket_size, &keyid);
if (ret < 0){ if (ret < 0)
switch(ret){ {
case ES_EINVAL: switch (ret)
printf("Error! ES_Identify (ret = %ld;) Data invalid!\n", ret); {
break; case ES_EINVAL:
case ES_EALIGN: printf("Error! ES_Identify (ret = %ld;) Data invalid!\n", ret);
printf("Error! ES_Identify (ret = %ld;) Data not aligned!\n", ret); break;
break; case ES_EALIGN:
case ES_ENOTINIT: printf("Error! ES_Identify (ret = %ld;) Data not aligned!\n", ret);
printf("Error! ES_Identify (ret = %ld;) ES not initialized!\n", ret); break;
break; case ES_ENOTINIT:
case ES_ENOMEM: printf("Error! ES_Identify (ret = %ld;) ES not initialized!\n", ret);
printf("Error! ES_Identify (ret = %ld;) No memory!\n", ret); break;
break; case ES_ENOMEM:
default: printf("Error! ES_Identify (ret = %ld;) No memory!\n", ret);
printf("Error! ES_Identify (ret = %ld)\n", ret); break;
break; default:
printf("Error! ES_Identify (ret = %ld)\n", ret);
break;
} }
#ifdef DEBUG_IDENT #ifdef DEBUG_IDENT
printf("\tTicket: %u Std: %u Max: %u\n", idticket_size, STD_SIGNED_TIK_SIZE, MAX_SIGNED_TMD_SIZE); printf("\tTicket: %u Std: %u Max: %u\n", idticket_size, STD_SIGNED_TIK_SIZE, MAX_SIGNED_TMD_SIZE);
printf("\tTMD invalid? %d %d %d Tik invalid? %d %d\n", !(signed_blob*)idtmd, !idtmd_size, !IS_VALID_SIGNATURE((signed_blob*)idtmd), !(signed_blob*)idticket, !IS_VALID_SIGNATURE((signed_blob*)idticket)); printf("\tTMD invalid? %d %d %d Tik invalid? %d %d\n", !(signed_blob *)idtmd, !idtmd_size, !IS_VALID_SIGNATURE((signed_blob *)idtmd), !(signed_blob *)idticket, !IS_VALID_SIGNATURE((signed_blob *)idticket));
printf("\tCerts: Sane? %d\n", __sanity_check_certlist((signed_blob*)certs, certs_size)); printf("\tCerts: Sane? %d\n", __sanity_check_certlist((signed_blob *)certs, certs_size));
if (!ISALIGNED(certs)) printf("\tCertificate data is not aligned!\n"); if (!ISALIGNED(certs))
if (!ISALIGNED(idtmd)) printf("\tTMD data is not aligned!\n"); printf("\tCertificate data is not aligned!\n");
if (!ISALIGNED(idticket)) printf("\tTicket data is not aligned!\n"); if (!ISALIGNED(idtmd))
printf("\tTMD data is not aligned!\n");
if (!ISALIGNED(idticket))
printf("\tTicket data is not aligned!\n");
#endif #endif
} }
else else
@ -188,44 +203,47 @@ s32 Identify(const u8 *certs, u32 certs_size, const u8 *idtmd, u32 idtmd_size, c
return ret; return ret;
} }
s32 Identify_SU(void)
s32 Identify_SU(void) { {
if (!su_id_filled) if (!su_id_filled)
Make_SUID(); Make_SUID();
gprintf("\nIdentifying as SU..."); gprintf("\nIdentifying as SU...");
fflush(stdout); fflush(stdout);
return Identify(certs_dat, certs_dat_size, su_tmd, sizeof su_tmd, su_tik, sizeof su_tik); return Identify(certs_dat, certs_dat_size, su_tmd, sizeof su_tmd, su_tik, sizeof su_tik);
} }
s32 Identify_SysMenu(void) { s32 Identify_SysMenu(void)
{
s32 ret; s32 ret;
u32 sysmenu_tmd_size, sysmenu_ticket_size; u32 sysmenu_tmd_size, sysmenu_ticket_size;
//static u8 certs[0xA00] ATTRIBUTE_ALIGN(32); // static u8 certs[0xA00] ATTRIBUTE_ALIGN(32);
static u8 sysmenu_tmd[MAX_SIGNED_TMD_SIZE] ATTRIBUTE_ALIGN(32); static u8 sysmenu_tmd[MAX_SIGNED_TMD_SIZE] ATTRIBUTE_ALIGN(32);
static u8 sysmenu_ticket[STD_SIGNED_TIK_SIZE] ATTRIBUTE_ALIGN(32); static u8 sysmenu_ticket[STD_SIGNED_TIK_SIZE] ATTRIBUTE_ALIGN(32);
/*printf("\nPulling Certs..."); /*printf("\nPulling Certs...");
ret = ISFS_ReadFileToArray ("/sys/certs.sys", certs, 0xA00, &certs_size); ret = ISFS_ReadFileToArray ("/sys/certs.sys", certs, 0xA00, &certs_size);
if (ret < 0) { if (ret < 0) {
printf("\tReading Certs failed!\n"); printf("\tReading Certs failed!\n");
return -1; return -1;
}*/ }*/
printf("\nPulling Sysmenu TMD..."); printf("\nPulling Sysmenu TMD...");
ret = ISFS_ReadFileToArray ("/title/00000001/00000002/content/title.tmd", sysmenu_tmd, MAX_SIGNED_TMD_SIZE, &sysmenu_tmd_size); ret = ISFS_ReadFileToArray("/title/00000001/00000002/content/title.tmd", sysmenu_tmd, MAX_SIGNED_TMD_SIZE, &sysmenu_tmd_size);
if (ret < 0) { if (ret < 0)
{
printf("\tReading TMD failed!\n"); printf("\tReading TMD failed!\n");
return -1; return -1;
} }
printf("\nPulling Sysmenu Ticket..."); printf("\nPulling Sysmenu Ticket...");
ret = ISFS_ReadFileToArray ("/ticket/00000001/00000002.tik", sysmenu_ticket, STD_SIGNED_TIK_SIZE, &sysmenu_ticket_size); ret = ISFS_ReadFileToArray("/ticket/00000001/00000002.tik", sysmenu_ticket, STD_SIGNED_TIK_SIZE, &sysmenu_ticket_size);
if (ret < 0) { if (ret < 0)
{
printf("\tReading TMD failed!\n"); printf("\tReading TMD failed!\n");
return -1; return -1;
} }
printf("\nIdentifying as SysMenu..."); printf("\nIdentifying as SysMenu...");
fflush(stdout); fflush(stdout);
return Identify(certs_dat, certs_dat_size, sysmenu_tmd, sysmenu_tmd_size, sysmenu_ticket, sysmenu_ticket_size); return Identify(certs_dat, certs_dat_size, sysmenu_tmd, sysmenu_tmd_size, sysmenu_ticket, sysmenu_ticket_size);

View File

@ -1,29 +1,29 @@
/*------------------------------------------------------------- /*-------------------------------------------------------------
id.h -- ES Identification code id.h -- ES Identification code
Copyright (C) 2008 tona Copyright (C) 2008 tona
Unless other credit specified Unless other credit specified
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
damages arising from the use of this software. damages arising from the use of this software.
Permission is granted to anyone to use this software for any Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions: redistribute it freely, subject to the following restrictions:
1.The origin of this software must not be misrepresented; you 1.The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required. documentation would be appreciated but is not required.
2.Altered source versions must be plainly marked as such, and 2.Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software. must not be misrepresented as being the original software.
3.This notice may not be removed or altered from any source 3.This notice may not be removed or altered from any source
distribution. distribution.
-------------------------------------------------------------*/ -------------------------------------------------------------*/
#ifndef _ID_H_ #ifndef _ID_H_

View File

@ -1,28 +1,28 @@
/*------------------------------------------------------------- /*-------------------------------------------------------------
regionchange.c -- Region Changing application regionchange.c -- Region Changing application
Copyright (C) 2008 tona Copyright (C) 2008 tona
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
damages arising from the use of this software. damages arising from the use of this software.
Permission is granted to anyone to use this software for any Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions: redistribute it freely, subject to the following restrictions:
1.The origin of this software must not be misrepresented; you 1.The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required. documentation would be appreciated but is not required.
2.Altered source versions must be plainly marked as such, and 2.Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software. must not be misrepresented as being the original software.
3.This notice may not be removed or altered from any source 3.This notice may not be removed or altered from any source
distribution. distribution.
-------------------------------------------------------------*/ -------------------------------------------------------------*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -42,10 +42,10 @@ distribution.
#include "detect_settings.h" #include "detect_settings.h"
#include "gecko.h" #include "gecko.h"
#define ITEMS 11 #define ITEMS 11
#define SADR_LENGTH 0x1007 + 1 #define SADR_LENGTH 0x1007 + 1
#define WARNING_SIGN "\x1b[30;1m\x1b[43;1m/!\\\x1b[37;1m\x1b[40m" #define WARNING_SIGN "\x1b[30;1m\x1b[43;1m/!\\\x1b[37;1m\x1b[40m"
#define maxdata 256 #define maxdata 256
u32 selected = 0; u32 selected = 0;
char page_contents[ITEMS][64]; char page_contents[ITEMS][64];
@ -59,10 +59,11 @@ char regions[][ITEMS] = {"Japan ", "USA ", "Europe ", "Korea "};
char vmodes[][ITEMS] = {"NTSC ", "PAL ", "MPAL "}; char vmodes[][ITEMS] = {"NTSC ", "PAL ", "MPAL "};
char eulas[][ITEMS] = {"Unread ", "Read "}; char eulas[][ITEMS] = {"Unread ", "Read "};
void draw_credits() { void draw_credits()
{
ClearScreen(); ClearScreen();
PrintBanner(); PrintBanner();
Console_SetPosition(3, 0); Console_SetPosition(3, 0);
printf("\t\t\t\tCREDITS:\n\n\n"); printf("\t\t\t\tCREDITS:\n\n\n");
printf("\tOriginal Program:\n"); printf("\tOriginal Program:\n");
printf("\t- Tona\n"); printf("\t- Tona\n");
@ -75,17 +76,18 @@ void draw_credits() {
printf("\t- TheShadowEevee - KR region support \n"); printf("\t- TheShadowEevee - KR region support \n");
printf("\t- To Many Coders To Thank For The Great Code I Used ..... \n"); printf("\t- To Many Coders To Thank For The Great Code I Used ..... \n");
printf("\n"); printf("\n");
Console_SetPosition(26,0); Console_SetPosition(26, 0);
ClearLine(); ClearLine();
Console_SetPosition(26, 20); Console_SetPosition(26, 20);
printf("Press Any Button To Return ..... "); printf("Press Any Button To Return ..... ");
} }
void Draw_Disclaimer() { void Draw_Disclaimer()
{
ClearScreen(); ClearScreen();
PrintBanner(); PrintBanner();
printf("\n\t This software comes supplied with absolutely no warranty.\n"); printf("\n\t This software comes supplied with absolutely no warranty.\n");
printf("\t\t\t\tUse this software at your own risk.\n"); printf("\t\t\t\tUse this software at your own risk.\n");
printf("\n\n\n\t\t\t\t" WARNING_SIGN " IMPORTANT BRICK INFORMATION " WARNING_SIGN "\n\n"); printf("\n\n\n\t\t\t\t" WARNING_SIGN " IMPORTANT BRICK INFORMATION " WARNING_SIGN "\n\n");
printf("\n\tSemi Bricks are caused by the Console Area setting not matching\n"); printf("\n\tSemi Bricks are caused by the Console Area setting not matching\n");
printf("\tyour System Menu region. A semi-brick in itself is not terribly\n"); printf("\tyour System Menu region. A semi-brick in itself is not terribly\n");
@ -95,72 +97,94 @@ void Draw_Disclaimer() {
printf("\tplease make sure that your Console Area and System Menu region \n"); printf("\tplease make sure that your Console Area and System Menu region \n");
printf("\tare congruent before rebooting your system. A warning will be\n"); printf("\tare congruent before rebooting your system. A warning will be\n");
printf("\tdisplayed if they are not in agreement.\n"); printf("\tdisplayed if they are not in agreement.\n");
sleep(5); sleep(5);
printf("\n\n\n\n\t\t\t\t[A] Continue [Home] Exit\n"); printf("\n\n\n\n\t\t\t\t[A] Continue [Home] Exit\n");
wait_key(WPAD_BUTTON_A); wait_key(WPAD_BUTTON_A);
} }
void handleError(const char* string, int errorval){ void handleError(const char *string, int errorval)
{
printf("Unexpected Error: %s Value: %d\n", string, errorval); printf("Unexpected Error: %s Value: %d\n", string, errorval);
printf("Press any key to quit\n"); printf("Press any key to quit\n");
wait_anyKey(); wait_anyKey();
exit(0); exit(0);
} }
void getSettings(void){ void getSettings(void)
{
int ret; int ret;
lang = SYSCONF_GetLanguage(); lang = SYSCONF_GetLanguage();
area = SYSCONF_GetArea(); area = SYSCONF_GetArea();
game = SYSCONF_GetRegion(); game = SYSCONF_GetRegion();
video = SYSCONF_GetVideo(); video = SYSCONF_GetVideo();
eula = SYSCONF_GetEULA(); eula = SYSCONF_GetEULA();
if (lang < 0 || area < 0 || game < 0 || video < 0 || (eula != SYSCONF_ENOENT && eula < 0)){ if (lang < 0 || area < 0 || game < 0 || video < 0 || (eula != SYSCONF_ENOENT && eula < 0))
{
printf("Error getting settings! %d, %d, %d, %d, %d\n", lang, area, game, video, eula); printf("Error getting settings! %d, %d, %d, %d, %d\n", lang, area, game, video, eula);
wait_anyKey(); wait_anyKey();
exit(1); exit(1);
} }
if (SYSCONF_GetLength("IPL.SADR") != SADR_LENGTH) handleError("IPL.SADR Length Incorrect", SYSCONF_GetLength("IPL.SADR")); if (SYSCONF_GetLength("IPL.SADR") != SADR_LENGTH)
handleError("IPL.SADR Length Incorrect", SYSCONF_GetLength("IPL.SADR"));
ret = SYSCONF_Get("IPL.SADR", sadr, SADR_LENGTH); ret = SYSCONF_Get("IPL.SADR", sadr, SADR_LENGTH);
if (ret < 0 ) handleError("SYSCONF_Get IPL.SADR", ret); if (ret < 0)
handleError("SYSCONF_Get IPL.SADR", ret);
country = sadr[0]; country = sadr[0];
gprintf("\n\ncountry[%i] \n\n", country); gprintf("\n\ncountry[%i] \n\n", country);
} }
void saveSettings(void){ void saveSettings(void)
{
Console_SetPosition(24, 0); Console_SetPosition(24, 0);
int ret = 0; int ret = 0;
if (lang != SYSCONF_GetLanguage()) ret = SYSCONF_SetLanguage(lang); if (lang != SYSCONF_GetLanguage())
if (ret) handleError("SYSCONF_SetLanguage", ret); ret = SYSCONF_SetLanguage(lang);
if (area != SYSCONF_GetArea()) ret = SYSCONF_SetArea(area); if (ret)
if (ret) handleError("SYSCONF_SetArea", ret); handleError("SYSCONF_SetLanguage", ret);
if(game != SYSCONF_GetRegion()) ret = SYSCONF_SetRegion(game); if (area != SYSCONF_GetArea())
if (ret) handleError("SYSCONF_SetRegion", ret); ret = SYSCONF_SetArea(area);
if (video != SYSCONF_GetVideo()) ret = SYSCONF_SetVideo(video); if (ret)
if (ret) handleError("SYSCONF_SetVideo", ret); handleError("SYSCONF_SetArea", ret);
if (eula != SYSCONF_GetEULA()) ret = SYSCONF_SetEULA(eula); if (game != SYSCONF_GetRegion())
if (ret) handleError("SYSCONF_SetEULA", ret); ret = SYSCONF_SetRegion(game);
if (ret)
if (country != sadr[0]){ handleError("SYSCONF_SetRegion", ret);
if (video != SYSCONF_GetVideo())
ret = SYSCONF_SetVideo(video);
if (ret)
handleError("SYSCONF_SetVideo", ret);
if (eula != SYSCONF_GetEULA())
ret = SYSCONF_SetEULA(eula);
if (ret)
handleError("SYSCONF_SetEULA", ret);
if (country != sadr[0])
{
memset(sadr, 0, SADR_LENGTH); memset(sadr, 0, SADR_LENGTH);
sadr[0] = country; sadr[0] = country;
ret = SYSCONF_Set("IPL.SADR", sadr, SADR_LENGTH); ret = SYSCONF_Set("IPL.SADR", sadr, SADR_LENGTH);
if (ret) handleError("SYSCONF_Set IPL.SADR", ret); if (ret)
handleError("SYSCONF_Set IPL.SADR", ret);
} }
//wait_anyKey(); // wait_anyKey();
printf("Saving..."); printf("Saving...");
ret = SYSCONF_SaveChanges(); ret = SYSCONF_SaveChanges();
if (ret < 0) handleError("SYSCONF_SaveChanges", ret); if (ret < 0)
else printf("OK!\n"); handleError("SYSCONF_SaveChanges", ret);
else
printf("OK!\n");
printf("Press any key to continue ....."); printf("Press any key to continue .....");
wait_anyKey(); wait_anyKey();
} }
void updateSelected(int delta){ void updateSelected(int delta)
if (selected + delta >= ITEMS || selected + delta < 0) return; {
if (selected + delta >= ITEMS || selected + delta < 0)
if (delta != 0){ return;
if (delta != 0)
{
// Remove the cursor from the last selected item // Remove the cursor from the last selected item
page_contents[selected][1] = ' '; page_contents[selected][1] = ' ';
page_contents[selected][45] = ' '; page_contents[selected][45] = ' ';
@ -168,21 +192,22 @@ void updateSelected(int delta){
// Set new cursor location // Set new cursor location
selected += delta; selected += delta;
} }
// Add the cursor to the now-selected item // Add the cursor to the now-selected item
page_contents[selected][1] = '>'; page_contents[selected][1] = '>';
page_contents[selected][45] = '<'; page_contents[selected][45] = '<';
page_contents[selected][57] = '>'; page_contents[selected][57] = '>';
} }
void updatePage(void){ void updatePage(void)
{
sprintf(page_contents[0], " %-40s %10s \n", "Language Setting:", languages[lang]); sprintf(page_contents[0], " %-40s %10s \n", "Language Setting:", languages[lang]);
sprintf(page_contents[1], " %-40s %10s \n", "Console Area Setting:", areas[area]); sprintf(page_contents[1], " %-40s %10s \n", "Console Area Setting:", areas[area]);
sprintf(page_contents[2], " %-40s %10s \n", "Game Region Setting:", regions[game]); sprintf(page_contents[2], " %-40s %10s \n", "Game Region Setting:", regions[game]);
sprintf(page_contents[3], " %-40s %10s \n", "Console Video Mode:", vmodes[video]); sprintf(page_contents[3], " %-40s %10s \n", "Console Video Mode:", vmodes[video]);
sprintf(page_contents[4], " %-40s %10d \n", "Shop Country Code:", country); sprintf(page_contents[4], " %-40s %10d \n", "Shop Country Code:", country);
sprintf(page_contents[5], " %-40s %10s \n", "Services EULA:", (eula == SYSCONF_ENOENT)?"Disabled":eulas[eula]); sprintf(page_contents[5], " %-40s %10s \n", "Services EULA:", (eula == SYSCONF_ENOENT) ? "Disabled" : eulas[eula]);
sprintf(page_contents[6], " %-40s %10s \n", "Revert Settings", "Revert "); sprintf(page_contents[6], " %-40s %10s \n", "Revert Settings", "Revert ");
sprintf(page_contents[7], " %-40s %10s \n", "Save Settings", "Save "); sprintf(page_contents[7], " %-40s %10s \n", "Save Settings", "Save ");
sprintf(page_contents[8], " %-40s %10s \n", "Auto Fix Settings ", "Fix "); sprintf(page_contents[8], " %-40s %10s \n", "Auto Fix Settings ", "Fix ");
@ -191,69 +216,77 @@ void updatePage(void){
updateSelected(0); updateSelected(0);
} }
char AREAtoSysMenuRegion(int area){ char AREAtoSysMenuRegion(int area)
{
// Data based on my own tests with AREA/Sysmenu // Data based on my own tests with AREA/Sysmenu
switch (area){ switch (area)
case 0: {
case 5: case 0:
case 6: case 5:
return 'J'; case 6:
case 1: return 'J';
case 4: case 1:
case 7: case 4:
case 8: case 7:
case 9: case 8:
case 10: case 9:
case 11: case 10:
return 'U'; case 11:
case 2: return 'U';
case 3: case 2:
return 'E'; case 3:
default: return 'E';
return 0; default:
return 0;
} }
} }
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
int main(int argc, char **argv) { int main(int argc, char **argv)
//--------------------------------------------------------------------------------- {
//---------------------------------------------------------------------------------
int ret = 0, i; int ret = 0, i;
u16 sysmenu_version; u16 sysmenu_version;
char sysmenu_region; char sysmenu_region;
bool needbreak = false; bool needbreak = false;
u32 buttons; u32 buttons;
int Current_Ios = 0; int Current_Ios = 0;
ret = IOS_ReloadIOS(236); ret = IOS_ReloadIOS(236);
if(ret != 0) { if (ret != 0)
{
ret = IOS_ReloadIOS(249); ret = IOS_ReloadIOS(249);
if(ret != 0) { if (ret != 0)
{
IosPatch_FULL(true, true, false, false, 58); IosPatch_FULL(true, true, false, false, 58);
} }
} }
basicInit(); basicInit();
miscInit(); miscInit();
if(InitGecko()) if (InitGecko())
USBGeckoOutput(); USBGeckoOutput();
Current_Ios = IOS_GetVersion(); Current_Ios = IOS_GetVersion();
gprintf("\n\ncurrent_ios [%i] \n\n", Current_Ios); gprintf("\n\ncurrent_ios [%i] \n\n", Current_Ios);
sysmenu_version = get_installed_title_version(TITLE_ID(1,2)); sysmenu_version = get_installed_title_version(TITLE_ID(1, 2));
sysmenu_region = get_sysmenu_region(); sysmenu_region = get_sysmenu_region();
gprintf("\n\nsysmenu_version[%u] sysmenu_region[%c] \n\n", sysmenu_version, sysmenu_region); gprintf("\n\nsysmenu_version[%u] sysmenu_region[%c] \n\n", sysmenu_version, sysmenu_region);
gprintf("Init SYSCONF..."); gprintf("Init SYSCONF...");
ret = SYSCONF_Init(); ret = SYSCONF_Init();
if (ret < 0) handleError("SYSCONF_Init", ret); if (ret < 0)
else gprintf("OK!\n"); handleError("SYSCONF_Init", ret);
else
gprintf("OK!\n");
getSettings(); getSettings();
region = game; region = game;
Draw_Disclaimer(); Draw_Disclaimer();
updatePage(); updatePage();
while(1) { while (1)
{
PrintBanner(); PrintBanner();
printf("\n------------------------------------------------------------------------"); printf("\n------------------------------------------------------------------------");
printf("Edit Region Settings"); printf("Edit Region Settings");
@ -262,9 +295,9 @@ int main(int argc, char **argv) {
printf("\n------------------------------------------------------------------------"); printf("\n------------------------------------------------------------------------");
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
printf(page_contents[i]); printf(page_contents[i]);
printf("\t Country Codes: \t1[JPN] 49[USA] 110[UK] 136[KOR]\n"); printf("\t Country Codes: \t1[JPN] 49[USA] 110[UK] 136[KOR]\n");
for (i = i; i < 8; i++) for (i = i; i < 8; i++)
printf(page_contents[i]); printf(page_contents[i]);
printf("------------------------------------------------------------------------"); printf("------------------------------------------------------------------------");
@ -284,128 +317,160 @@ int main(int argc, char **argv) {
gprintf("\n\nselected [%i] \n\n", selected); gprintf("\n\nselected [%i] \n\n", selected);
if (buttons & WPAD_BUTTON_DOWN) if (buttons & WPAD_BUTTON_DOWN)
updateSelected(1); updateSelected(1);
if (buttons & WPAD_BUTTON_UP) if (buttons & WPAD_BUTTON_UP)
updateSelected(-1); updateSelected(-1);
if (buttons & WPAD_BUTTON_LEFT){ if (buttons & WPAD_BUTTON_LEFT)
switch(selected){ {
case 0: switch (selected)
if (--lang < 0) lang = 6; {
case 0:
if (--lang < 0)
lang = 6;
break; break;
case 1: case 1:
if (--area < 0) area = 11; if (--area < 0)
area = 11;
break; break;
case 2: case 2:
if (--game < 0) game = 3; if (--game < 0)
game = 3;
break; break;
case 3: case 3:
if (--video < 0) video = 2; if (--video < 0)
video = 2;
break; break;
case 4: case 4:
if (country == 1) country = 136; if (country == 1)
else if (country == 49) country = 1; country = 136;
else if (country == 110) country = 49; else if (country == 49)
else if (country == 136) country = 110; country = 1;
if (eula >= 0) eula = 0; else if (country == 110)
country = 49;
else if (country == 136)
country = 110;
if (eula >= 0)
eula = 0;
break; break;
case 5: case 5:
if (eula >= 0) eula = !eula; if (eula >= 0)
eula = !eula;
break; break;
} }
} }
if (buttons & WPAD_BUTTON_RIGHT){ if (buttons & WPAD_BUTTON_RIGHT)
switch(selected){ {
case 0: switch (selected)
if (++lang == 7) lang = 0; {
case 0:
if (++lang == 7)
lang = 0;
break; break;
case 1: case 1:
if (++area == 12) area = 0; if (++area == 12)
area = 0;
break; break;
case 2: case 2:
if (++game == 4) game = 0; if (++game == 4)
game = 0;
break; break;
case 3: case 3:
if (++video == 3) video = 0; if (++video == 3)
video = 0;
break; break;
case 4: case 4:
if (country == 1) country = 49; if (country == 1)
else if (country == 49) country = 110; country = 49;
else if (country == 110) country = 136; else if (country == 49)
else if (country == 136) country = 1; country = 110;
if (eula >= 0) eula = 0; else if (country == 110)
country = 136;
else if (country == 136)
country = 1;
if (eula >= 0)
eula = 0;
break; break;
case 5: case 5:
if (eula >= 0) eula = !eula; if (eula >= 0)
eula = !eula;
break; break;
} }
} }
if (buttons & WPAD_BUTTON_A){ if (buttons & WPAD_BUTTON_A)
switch(selected){ {
case 6: switch (selected)
getSettings(); {
case 6:
getSettings();
break; break;
case 7: case 7:
saveSettings(); saveSettings();
break; break;
case 8: case 8:
if(sysmenu_region == 85) { // usa if (sysmenu_region == 85)
lang = 1; { // usa
area = 1; lang = 1;
game = 1; area = 1;
video = 0; game = 1;
country = 49; video = 0;
} country = 49;
else if(sysmenu_region == 74) { // jpn }
lang = 0; else if (sysmenu_region == 74)
area = 0; { // jpn
game = 0; lang = 0;
video = 0; area = 0;
country = 1; game = 0;
} video = 0;
else if(sysmenu_region == 69) { // EUR/PAL country = 1;
lang = 1; }
area = 2; else if (sysmenu_region == 69)
game = 2; { // EUR/PAL
video = 1; lang = 1;
country = 110; area = 2;
} game = 2;
else if(sysmenu_region == 255) { // KOR video = 1;
lang = 1; country = 110;
area = 7; }
game = 3; else if (sysmenu_region == 255)
video = 0; { // KOR
country = 136; lang = 1;
} area = 7;
saveSettings(); game = 3;
video = 0;
country = 136;
}
saveSettings();
break; break;
case 9: case 9:
needbreak = true; needbreak = true;
break; break;
case 10: case 10:
STM_RebootSystem(); STM_RebootSystem();
break; break;
} }
} }
if (buttons & WPAD_BUTTON_B) { if (buttons & WPAD_BUTTON_B)
{
selected = 9; selected = 9;
} }
if (buttons & WPAD_BUTTON_1) { if (buttons & WPAD_BUTTON_1)
{
draw_credits(); draw_credits();
wait_anyKey(); wait_anyKey();
} }
updatePage(); updatePage();
if(needbreak) if (needbreak)
break; break;
} }
Console_SetPosition(26,30); Console_SetPosition(26, 30);
Console_SetColors(BLACK, 0, GREEN, 0); Console_SetColors(BLACK, 0, GREEN, 0);
printf("Exiting"); printf("Exiting");
miscDeInit(); miscDeInit();
exit(0); exit(0);
} }

View File

@ -30,103 +30,101 @@
/** /**
*Returns true when HW_AHBPROT access can be applied *Returns true when HW_AHBPROT access can be applied
*/ */
#define AHBPROT_DISABLED (*(vu32*)0xcd800064 == 0xFFFFFFFF) #define AHBPROT_DISABLED (*(vu32 *)0xcd800064 == 0xFFFFFFFF)
//============================================================================== //==============================================================================
// Error code definitions: // Error code definitions:
//============================================================================== //==============================================================================
#define ERROR_AHBPROT -5 #define ERROR_AHBPROT -5
#define ERROR_PATCH -7 #define ERROR_PATCH -7
//============================================================================== //==============================================================================
// C++ header // C++ header
//============================================================================== //==============================================================================
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif #endif
/* __cplusplus */ /* __cplusplus */
//============================================================================== //==============================================================================
// Patchsets: // Patchsets:
//============================================================================== //==============================================================================
/* /*
Wii: Wii:
* DI Readlimit * DI Readlimit
* ISFS Permissions * ISFS Permissions
* ES SetUID * ES SetUID
* ES SetIdentify * ES SetIdentify
* Hash Check (aka Trucha) * Hash Check (aka Trucha)
* New Hash Check (aka New Trucha) * New Hash Check (aka New Trucha)
* SSL patches * SSL patches
Sciifii: Sciifii:
* MEM2 Prot * MEM2 Prot
* ES OpenTitleContent 1 & 2 * ES OpenTitleContent 1 & 2
* ES ReadContent Prot * ES ReadContent Prot
* ES CloseContent * ES CloseContent
* ES TitleVersionCheck * ES TitleVersionCheck
* ES TitleDeleteCheck * ES TitleDeleteCheck
vWii: vWii:
* Kill Anti-SystemTitle-Install 1, 2, 3, 4 & 5 * Kill Anti-SystemTitle-Install 1, 2, 3, 4 & 5
*/ */
//==============================================================================
// Functions:
//==============================================================================
//============================================================================== /**
// Functions: * This function can be used to keep HW_AHBPROT access when going to reload IOS
//============================================================================== * @param verbose Flag determing whether or not to print messages on-screen
* @example
* if(AHBPROT_DISABLED) {
* s32 ret;
* ret = IosPatch_AHBPROT(false);
* if (ret) {
* IOS_ReloadIOS(36);
* } else {
* printf("IosPatch_AHBPROT failed.");
* }
* }
* @return Signed 32bit integer representing code
* > 0 : Success - return equals to number of applied patches
* ERROR_AHBPROT : Error - No HW_AHBPROT access
*/
s32 IosPatch_AHBPROT(bool verbose);
/** /**
* This function can be used to keep HW_AHBPROT access when going to reload IOS * This function applies patches on current IOS
* @param verbose Flag determing whether or not to print messages on-screen * @see Patchsets
* @example * @param wii Flag determing whether or not to apply Wii patches.
* if(AHBPROT_DISABLED) { * @param sciifii Flag determing whether or not to apply extra Sciifii patches.
* s32 ret; * @param vwii Flag determing whether or not to apply extra vWii patches.
* ret = IosPatch_AHBPROT(false); * @param verbose Flag determing whether or not to print messages on-screen.
* if (ret) { * @example if(AHBPROT_DISABLED) IosPatch_FULL(true, false, false, false);
* IOS_ReloadIOS(36); * @return Signed 32bit integer representing code
* } else { * > 0 : Success - return equals to number of applied patches
* printf("IosPatch_AHBPROT failed."); * ERROR_AHBPROT : Error - No HW_AHBPROT access
* } * ERROR_PATCH : Error - Patching HW_AHBPROT access failed
* } */
* @return Signed 32bit integer representing code s32 IosPatch_RUNTIME(bool wii, bool sciifii, bool vwii, bool verbose);
* > 0 : Success - return equals to number of applied patches
* ERROR_AHBPROT : Error - No HW_AHBPROT access
*/
s32 IosPatch_AHBPROT(bool verbose);
/**
/** * This function combines IosPatch_AHBPROT + IOS_ReloadIOS + IosPatch_RUNTIME
* This function applies patches on current IOS * @see Patchsets
* @see Patchsets * @param wii Flag determing whether or not to apply Wii patches.
* @param wii Flag determing whether or not to apply Wii patches. * @param sciifii Flag determing whether or not to apply extra Sciifii patches.
* @param sciifii Flag determing whether or not to apply extra Sciifii patches. * @param vwii Flag determing whether or not to apply extra vWii patches.
* @param vwii Flag determing whether or not to apply extra vWii patches. * @param verbose Flag determing whether or not to print messages on-screen.
* @param verbose Flag determing whether or not to print messages on-screen. * @param IOS Which IOS to reload into.
* @example if(AHBPROT_DISABLED) IosPatch_FULL(true, false, false, false); * @example if(AHBPROT_DISABLED) IosPatch_FULL(true, false, false, false, 58);
* @return Signed 32bit integer representing code * @return Signed 32bit integer representing code
* > 0 : Success - return equals to number of applied patches * > 0 : Success - return equals to number of applied patches
* ERROR_AHBPROT : Error - No HW_AHBPROT access * ERROR_AHBPROT : Error - No HW_AHBPROT access
* ERROR_PATCH : Error - Patching HW_AHBPROT access failed * ERROR_PATCH : Error - Patching HW_AHBPROT access failed
*/ */
s32 IosPatch_RUNTIME(bool wii, bool sciifii, bool vwii, bool verbose); s32 IosPatch_FULL(bool wii, bool sciifii, bool vwii, bool verbose, int IOS);
/**
* This function combines IosPatch_AHBPROT + IOS_ReloadIOS + IosPatch_RUNTIME
* @see Patchsets
* @param wii Flag determing whether or not to apply Wii patches.
* @param sciifii Flag determing whether or not to apply extra Sciifii patches.
* @param vwii Flag determing whether or not to apply extra vWii patches.
* @param verbose Flag determing whether or not to print messages on-screen.
* @param IOS Which IOS to reload into.
* @example if(AHBPROT_DISABLED) IosPatch_FULL(true, false, false, false, 58);
* @return Signed 32bit integer representing code
* > 0 : Success - return equals to number of applied patches
* ERROR_AHBPROT : Error - No HW_AHBPROT access
* ERROR_PATCH : Error - Patching HW_AHBPROT access failed
*/
s32 IosPatch_FULL(bool wii, bool sciifii, bool vwii, bool verbose, int IOS);
//============================================================================== //==============================================================================
// C++ footer // C++ footer

View File

@ -24,38 +24,46 @@ A million repetitions of "a"
/* blk0() and blk() perform the initial expand. */ /* blk0() and blk() perform the initial expand. */
/* I got the idea of expanding during the round function from SSLeay */ /* I got the idea of expanding during the round function from SSLeay */
#ifdef LITTLE_ENDIAN #ifdef LITTLE_ENDIAN
#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ #define blk0(i) (block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) | (rol(block->l[i], 8) & 0x00FF00FF))
|(rol(block->l[i],8)&0x00FF00FF))
#else #else
#define blk0(i) block->l[i] #define blk0(i) block->l[i]
#endif #endif
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ #define blk(i) (block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ block->l[i & 15], 1))
^block->l[(i+2)&15]^block->l[i&15],1))
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); #define R0(v, w, x, y, z, i) \
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); z += ((w & (x ^ y)) ^ y) + blk0(i) + 0x5A827999 + rol(v, 5); \
#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); w = rol(w, 30);
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); #define R1(v, w, x, y, z, i) \
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + rol(v, 5); \
w = rol(w, 30);
#define R2(v, w, x, y, z, i) \
z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); \
w = rol(w, 30);
#define R3(v, w, x, y, z, i) \
z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); \
w = rol(w, 30);
#define R4(v, w, x, y, z, i) \
z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \
w = rol(w, 30);
/* Hash a single 512-bit block. This is the core of the algorithm. */ /* Hash a single 512-bit block. This is the core of the algorithm. */
void SHA1Transform(unsigned long state[5], unsigned char buffer[64]) void SHA1Transform(unsigned long state[5], unsigned char buffer[64])
{ {
unsigned long a, b, c, d, e; unsigned long a, b, c, d, e;
typedef union { typedef union
unsigned char c[64]; {
unsigned long l[16]; unsigned char c[64];
} CHAR64LONG16; unsigned long l[16];
CHAR64LONG16* block; } CHAR64LONG16;
CHAR64LONG16 *block;
#ifdef SHA1HANDSOFF #ifdef SHA1HANDSOFF
static unsigned char workspace[64]; static unsigned char workspace[64];
block = (CHAR64LONG16*)workspace; block = (CHAR64LONG16 *)workspace;
memcpy(block, buffer, 64); memcpy(block, buffer, 64);
#else #else
block = (CHAR64LONG16*)buffer; block = (CHAR64LONG16 *)buffer;
#endif #endif
/* Copy context->state[] to working vars */ /* Copy context->state[] to working vars */
a = state[0]; a = state[0];
@ -64,26 +72,86 @@ static unsigned char workspace[64];
d = state[3]; d = state[3];
e = state[4]; e = state[4];
/* 4 rounds of 20 operations each. Loop unrolled. */ /* 4 rounds of 20 operations each. Loop unrolled. */
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); R0(a, b, c, d, e, 0);
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); R0(e, a, b, c, d, 1);
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); R0(d, e, a, b, c, 2);
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); R0(c, d, e, a, b, 3);
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); R0(b, c, d, e, a, 4);
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); R0(a, b, c, d, e, 5);
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); R0(e, a, b, c, d, 6);
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); R0(d, e, a, b, c, 7);
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); R0(c, d, e, a, b, 8);
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); R0(b, c, d, e, a, 9);
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); R0(a, b, c, d, e, 10);
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); R0(e, a, b, c, d, 11);
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); R0(d, e, a, b, c, 12);
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); R0(c, d, e, a, b, 13);
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); R0(b, c, d, e, a, 14);
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); R0(a, b, c, d, e, 15);
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); R1(e, a, b, c, d, 16);
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); R1(d, e, a, b, c, 17);
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); R1(c, d, e, a, b, 18);
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); R1(b, c, d, e, a, 19);
R2(a, b, c, d, e, 20);
R2(e, a, b, c, d, 21);
R2(d, e, a, b, c, 22);
R2(c, d, e, a, b, 23);
R2(b, c, d, e, a, 24);
R2(a, b, c, d, e, 25);
R2(e, a, b, c, d, 26);
R2(d, e, a, b, c, 27);
R2(c, d, e, a, b, 28);
R2(b, c, d, e, a, 29);
R2(a, b, c, d, e, 30);
R2(e, a, b, c, d, 31);
R2(d, e, a, b, c, 32);
R2(c, d, e, a, b, 33);
R2(b, c, d, e, a, 34);
R2(a, b, c, d, e, 35);
R2(e, a, b, c, d, 36);
R2(d, e, a, b, c, 37);
R2(c, d, e, a, b, 38);
R2(b, c, d, e, a, 39);
R3(a, b, c, d, e, 40);
R3(e, a, b, c, d, 41);
R3(d, e, a, b, c, 42);
R3(c, d, e, a, b, 43);
R3(b, c, d, e, a, 44);
R3(a, b, c, d, e, 45);
R3(e, a, b, c, d, 46);
R3(d, e, a, b, c, 47);
R3(c, d, e, a, b, 48);
R3(b, c, d, e, a, 49);
R3(a, b, c, d, e, 50);
R3(e, a, b, c, d, 51);
R3(d, e, a, b, c, 52);
R3(c, d, e, a, b, 53);
R3(b, c, d, e, a, 54);
R3(a, b, c, d, e, 55);
R3(e, a, b, c, d, 56);
R3(d, e, a, b, c, 57);
R3(c, d, e, a, b, 58);
R3(b, c, d, e, a, 59);
R4(a, b, c, d, e, 60);
R4(e, a, b, c, d, 61);
R4(d, e, a, b, c, 62);
R4(c, d, e, a, b, 63);
R4(b, c, d, e, a, 64);
R4(a, b, c, d, e, 65);
R4(e, a, b, c, d, 66);
R4(d, e, a, b, c, 67);
R4(c, d, e, a, b, 68);
R4(b, c, d, e, a, 69);
R4(a, b, c, d, e, 70);
R4(e, a, b, c, d, 71);
R4(d, e, a, b, c, 72);
R4(c, d, e, a, b, 73);
R4(b, c, d, e, a, 74);
R4(a, b, c, d, e, 75);
R4(e, a, b, c, d, 76);
R4(d, e, a, b, c, 77);
R4(c, d, e, a, b, 78);
R4(b, c, d, e, a, 79);
/* Add the working vars back into context.state[] */ /* Add the working vars back into context.state[] */
state[0] += a; state[0] += a;
state[1] += b; state[1] += b;
@ -94,10 +162,9 @@ static unsigned char workspace[64];
a = b = c = d = e = 0; a = b = c = d = e = 0;
} }
/* SHA1Init - Initialize new context */ /* SHA1Init - Initialize new context */
void SHA1Init(SHA1_CTX* context) void SHA1Init(SHA1_CTX *context)
{ {
/* SHA1 initialization constants */ /* SHA1 initialization constants */
context->state[0] = 0x67452301; context->state[0] = 0x67452301;
@ -108,48 +175,51 @@ void SHA1Init(SHA1_CTX* context)
context->count[0] = context->count[1] = 0; context->count[0] = context->count[1] = 0;
} }
/* Run your data through this. */ /* Run your data through this. */
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len) void SHA1Update(SHA1_CTX *context, unsigned char *data, unsigned int len)
{ {
unsigned int i, j; unsigned int i, j;
j = (context->count[0] >> 3) & 63; j = (context->count[0] >> 3) & 63;
if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++; if ((context->count[0] += len << 3) < (len << 3))
context->count[1]++;
context->count[1] += (len >> 29); context->count[1] += (len >> 29);
if ((j + len) > 63) { if ((j + len) > 63)
memcpy(&context->buffer[j], data, (i = 64-j)); {
memcpy(&context->buffer[j], data, (i = 64 - j));
SHA1Transform(context->state, context->buffer); SHA1Transform(context->state, context->buffer);
for ( ; i + 63 < len; i += 64) { for (; i + 63 < len; i += 64)
{
SHA1Transform(context->state, &data[i]); SHA1Transform(context->state, &data[i]);
} }
j = 0; j = 0;
} }
else i = 0; else
i = 0;
memcpy(&context->buffer[j], &data[i], len - i); memcpy(&context->buffer[j], &data[i], len - i);
} }
/* Add padding and return the message digest. */ /* Add padding and return the message digest. */
void SHA1Final(unsigned char digest[20], SHA1_CTX* context) void SHA1Final(unsigned char digest[20], SHA1_CTX *context)
{ {
unsigned long i, j; unsigned long i, j;
unsigned char finalcount[8]; unsigned char finalcount[8];
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++)
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] {
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8)) & 255); /* Endian independent */
} }
SHA1Update(context, (unsigned char *)"\200", 1); SHA1Update(context, (unsigned char *)"\200", 1);
while ((context->count[0] & 504) != 448) { while ((context->count[0] & 504) != 448)
{
SHA1Update(context, (unsigned char *)"\0", 1); SHA1Update(context, (unsigned char *)"\0", 1);
} }
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
for (i = 0; i < 20; i++) { for (i = 0; i < 20; i++)
digest[i] = (unsigned char) {
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); digest[i] = (unsigned char)((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
} }
/* Wipe variables */ /* Wipe variables */
i = j = 0; i = j = 0;
@ -157,16 +227,16 @@ unsigned char finalcount[8];
memset(context->state, 0, 20); memset(context->state, 0, 20);
memset(context->count, 0, 8); memset(context->count, 0, 8);
memset(&finalcount, 0, 8); memset(&finalcount, 0, 8);
#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */ #ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */
SHA1Transform(context->state, context->buffer); SHA1Transform(context->state, context->buffer);
#endif #endif
} }
void SHA1(unsigned char *ptr, unsigned int size, unsigned char *outbuf) { void SHA1(unsigned char *ptr, unsigned int size, unsigned char *outbuf)
SHA1_CTX ctx; {
SHA1_CTX ctx;
SHA1Init(&ctx);
SHA1Update(&ctx, ptr, size);
SHA1Final(outbuf, &ctx);
}
SHA1Init(&ctx);
SHA1Update(&ctx, ptr, size);
SHA1Final(outbuf, &ctx);
}

View File

@ -1,12 +1,13 @@
typedef struct { typedef struct
{
unsigned long state[5]; unsigned long state[5];
unsigned long count[2]; unsigned long count[2];
unsigned char buffer[64]; unsigned char buffer[64];
} SHA1_CTX; } SHA1_CTX;
void SHA1Transform(unsigned long state[5], unsigned char buffer[64]); void SHA1Transform(unsigned long state[5], unsigned char buffer[64]);
void SHA1Init(SHA1_CTX* context); void SHA1Init(SHA1_CTX *context);
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len); void SHA1Update(SHA1_CTX *context, unsigned char *data, unsigned int len);
void SHA1Final(unsigned char digest[20], SHA1_CTX* context); void SHA1Final(unsigned char digest[20], SHA1_CTX *context);
void SHA1(unsigned char *ptr, unsigned int size, unsigned char *outbuf); void SHA1(unsigned char *ptr, unsigned int size, unsigned char *outbuf);

File diff suppressed because it is too large Load Diff

View File

@ -36,177 +36,186 @@ distribution.
#include <gctypes.h> #include <gctypes.h>
#include <gcutil.h> #include <gcutil.h>
#define SYSCONF_EBADFILE -0x6001 #define SYSCONF_EBADFILE -0x6001
#define SYSCONF_ENOENT -0x6002 #define SYSCONF_ENOENT -0x6002
#define SYSCONF_ETOOBIG -0x6003 #define SYSCONF_ETOOBIG -0x6003
#define SYSCONF_ENOTINIT -0x6004 #define SYSCONF_ENOTINIT -0x6004
#define SYSCONF_ENOTIMPL -0x6005 #define SYSCONF_ENOTIMPL -0x6005
#define SYSCONF_EBADVALUE -0x6006 #define SYSCONF_EBADVALUE -0x6006
#define SYSCONF_ENOMEM -0x6007 #define SYSCONF_ENOMEM -0x6007
#define SYSCONF_EPERMS -0x6008 #define SYSCONF_EPERMS -0x6008
#define SYSCONF_EBADWRITE -0x6009 #define SYSCONF_EBADWRITE -0x6009
#define SYSCONF_ERR_OK 0 #define SYSCONF_ERR_OK 0
//#define DEBUG_SYSCONF //#define DEBUG_SYSCONF
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif /* __cplusplus */ #endif /* __cplusplus */
enum { enum
SYSCONF_BIGARRAY = 1, {
SYSCONF_SMALLARRAY, SYSCONF_BIGARRAY = 1,
SYSCONF_BYTE, SYSCONF_SMALLARRAY,
SYSCONF_SHORT, SYSCONF_BYTE,
SYSCONF_LONG, SYSCONF_SHORT,
SYSCONF_BOOL = 7 SYSCONF_LONG,
}; SYSCONF_BOOL = 7
};
enum { enum
SYSCONF_VIDEO_NTSC = 0, {
SYSCONF_VIDEO_PAL, SYSCONF_VIDEO_NTSC = 0,
SYSCONF_VIDEO_MPAL SYSCONF_VIDEO_PAL,
}; SYSCONF_VIDEO_MPAL
};
enum { enum
SYSCONF_REGION_JP = 0, {
SYSCONF_REGION_US, SYSCONF_REGION_JP = 0,
SYSCONF_REGION_EU, SYSCONF_REGION_US,
SYSCONF_REGION_KR, SYSCONF_REGION_EU,
SYSCONF_REGION_CN SYSCONF_REGION_KR,
}; SYSCONF_REGION_CN
};
enum { enum
SYSCONF_AREA_JPN = 0, {
SYSCONF_AREA_USA, SYSCONF_AREA_JPN = 0,
SYSCONF_AREA_EUR, SYSCONF_AREA_USA,
SYSCONF_AREA_AUS, SYSCONF_AREA_EUR,
SYSCONF_AREA_BRA, SYSCONF_AREA_AUS,
SYSCONF_AREA_TWN, SYSCONF_AREA_BRA,
SYSCONF_AREA_ROC, SYSCONF_AREA_TWN,
SYSCONF_AREA_KOR, SYSCONF_AREA_ROC,
SYSCONF_AREA_HKG, SYSCONF_AREA_KOR,
SYSCONF_AREA_ASI, SYSCONF_AREA_HKG,
SYSCONF_AREA_LTN, SYSCONF_AREA_ASI,
SYSCONF_AREA_SAF SYSCONF_AREA_LTN,
}; SYSCONF_AREA_SAF
};
enum { enum
SYSCONF_SHUTDOWN_STANDBY = 0, {
SYSCONF_SHUTDOWN_IDLE SYSCONF_SHUTDOWN_STANDBY = 0,
}; SYSCONF_SHUTDOWN_IDLE
};
enum { enum
SYSCONF_LED_OFF = 0, {
SYSCONF_LED_DIM, SYSCONF_LED_OFF = 0,
SYSCONF_LED_BRIGHT SYSCONF_LED_DIM,
}; SYSCONF_LED_BRIGHT
};
enum { enum
SYSCONF_SOUND_MONO = 0, {
SYSCONF_SOUND_STEREO, SYSCONF_SOUND_MONO = 0,
SYSCONF_SOUND_SURROUND SYSCONF_SOUND_STEREO,
}; SYSCONF_SOUND_SURROUND
};
enum { enum
SYSCONF_LANG_JAPANESE = 0, {
SYSCONF_LANG_ENGLISH, SYSCONF_LANG_JAPANESE = 0,
SYSCONF_LANG_GERMAN, SYSCONF_LANG_ENGLISH,
SYSCONF_LANG_FRENCH, SYSCONF_LANG_GERMAN,
SYSCONF_LANG_SPANISH, SYSCONF_LANG_FRENCH,
SYSCONF_LANG_ITALIAN, SYSCONF_LANG_SPANISH,
SYSCONF_LANG_DUTCH SYSCONF_LANG_ITALIAN,
}; SYSCONF_LANG_DUTCH
};
enum { enum
SYSCONF_ASPECT_4_3 = 0, {
SYSCONF_ASPECT_16_9 SYSCONF_ASPECT_4_3 = 0,
}; SYSCONF_ASPECT_16_9
};
enum { enum
SYSCONF_SENSORBAR_BOTTOM = 0, {
SYSCONF_SENSORBAR_TOP SYSCONF_SENSORBAR_BOTTOM = 0,
}; SYSCONF_SENSORBAR_TOP
};
typedef struct _sysconf_pad_device sysconf_pad_device; typedef struct _sysconf_pad_device sysconf_pad_device;
struct _sysconf_pad_device { struct _sysconf_pad_device
u8 bdaddr[6]; {
char name[0x40]; u8 bdaddr[6];
} ATTRIBUTE_PACKED; char name[0x40];
} ATTRIBUTE_PACKED;
#ifdef DEBUG_SYSCONF #ifdef DEBUG_SYSCONF
void SYSCONF_DumpBuffer(void); void SYSCONF_DumpBuffer(void);
void SYSCONF_DumpTxtBuffer(void); void SYSCONF_DumpTxtBuffer(void);
void SYSCONF_DumpEncryptedTxtBuffer(void); void SYSCONF_DumpEncryptedTxtBuffer(void);
void SYSCONF_PrintAllSettings(void); void SYSCONF_PrintAllSettings(void);
#endif /* DEBUG_SYSCONF */ #endif /* DEBUG_SYSCONF */
s32 SYSCONF_Init(void); s32 SYSCONF_Init(void);
/* SYSCONF configuation */ /* SYSCONF configuation */
s32 SYSCONF_GetLength(const char *name); s32 SYSCONF_GetLength(const char *name);
s32 SYSCONF_GetType(const char *name); s32 SYSCONF_GetType(const char *name);
s32 SYSCONF_Get(const char *name, void *buffer, u32 length); s32 SYSCONF_Get(const char *name, void *buffer, u32 length);
s32 SYSCONF_GetShutdownMode(void); s32 SYSCONF_GetShutdownMode(void);
s32 SYSCONF_GetIdleLedMode(void); s32 SYSCONF_GetIdleLedMode(void);
s32 SYSCONF_GetProgressiveScan(void); s32 SYSCONF_GetProgressiveScan(void);
s32 SYSCONF_GetEuRGB60(void); s32 SYSCONF_GetEuRGB60(void);
s32 SYSCONF_GetIRSensitivity(void); s32 SYSCONF_GetIRSensitivity(void);
s32 SYSCONF_GetSensorBarPosition(void); s32 SYSCONF_GetSensorBarPosition(void);
s32 SYSCONF_GetPadSpeakerVolume(void); s32 SYSCONF_GetPadSpeakerVolume(void);
s32 SYSCONF_GetPadMotorMode(void); s32 SYSCONF_GetPadMotorMode(void);
s32 SYSCONF_GetSoundMode(void); s32 SYSCONF_GetSoundMode(void);
s32 SYSCONF_GetLanguage(void); s32 SYSCONF_GetLanguage(void);
s32 SYSCONF_GetCounterBias(u32 *bias); s32 SYSCONF_GetCounterBias(u32 *bias);
s32 SYSCONF_GetScreenSaverMode(void); s32 SYSCONF_GetScreenSaverMode(void);
s32 SYSCONF_GetDisplayOffsetH(s8 *offset); s32 SYSCONF_GetDisplayOffsetH(s8 *offset);
s32 SYSCONF_GetPadDevices(sysconf_pad_device *devs, int count); s32 SYSCONF_GetPadDevices(sysconf_pad_device *devs, int count);
s32 SYSCONF_GetNickName(u8 *nickname); s32 SYSCONF_GetNickName(u8 *nickname);
s32 SYSCONF_GetAspectRatio(void); s32 SYSCONF_GetAspectRatio(void);
s32 SYSCONF_GetEULA(void); s32 SYSCONF_GetEULA(void);
s32 SYSCONF_GetParentalPassword(s8 *password); s32 SYSCONF_GetParentalPassword(s8 *password);
s32 SYSCONF_GetParentalAnswer(s8 *answer); s32 SYSCONF_GetParentalAnswer(s8 *answer);
s32 SYSCONF_GetWiiConnect24(void); s32 SYSCONF_GetWiiConnect24(void);
/* setting.txt configuration */ /* setting.txt configuration */
s32 SYSCONF_GetRegion(void); s32 SYSCONF_GetRegion(void);
s32 SYSCONF_GetArea(void); s32 SYSCONF_GetArea(void);
s32 SYSCONF_GetVideo(void); s32 SYSCONF_GetVideo(void);
/* Set functions */
s32 SYSCONF_SaveChanges(void);
s32 SYSCONF_Set(const char *name, const void *value, u32 length);
/* Set functions */ s32 SYSCONF_SetShutdownMode(u8 value);
s32 SYSCONF_SaveChanges(void); s32 SYSCONF_SetIdleLedMode(u8 value);
s32 SYSCONF_Set(const char *name, const void *value, u32 length); s32 SYSCONF_SetProgressiveScan(u8 value);
s32 SYSCONF_SetEuRGB60(u8 value);
s32 SYSCONF_SetIRSensitivity(u32 value);
s32 SYSCONF_SetSensorBarPosition(u8 value);
s32 SYSCONF_SetPadSpeakerVolume(u8 value);
s32 SYSCONF_SetPadMotorMode(u8 value);
s32 SYSCONF_SetSoundMode(u8 value);
s32 SYSCONF_SetLanguage(u8 value);
s32 SYSCONF_SetCounterBias(u32 bias);
s32 SYSCONF_SetScreenSaverMode(u8 value);
s32 SYSCONF_SetDisplayOffsetH(s8 offset);
s32 SYSCONF_SetPadDevices(const sysconf_pad_device *devs, u8 count);
s32 SYSCONF_SetNickName(const u8 *nickname, u16 length);
s32 SYSCONF_SetAspectRatio(u8 value);
s32 SYSCONF_SetEULA(u8 value);
s32 SYSCONF_SetParentalPassword(const s8 *password, u32 length);
s32 SYSCONF_SetParentalAnswer(const s8 *answer, u32 length);
s32 SYSCONF_SetWiiConnect24(u32 value);
s32 SYSCONF_SetShutdownMode(u8 value); s32 SYSCONF_SetRegion(s32 value);
s32 SYSCONF_SetIdleLedMode(u8 value); s32 SYSCONF_SetArea(s32 value);
s32 SYSCONF_SetProgressiveScan(u8 value); s32 SYSCONF_SetVideo(s32 value);
s32 SYSCONF_SetEuRGB60(u8 value);
s32 SYSCONF_SetIRSensitivity(u32 value);
s32 SYSCONF_SetSensorBarPosition(u8 value);
s32 SYSCONF_SetPadSpeakerVolume(u8 value);
s32 SYSCONF_SetPadMotorMode(u8 value);
s32 SYSCONF_SetSoundMode(u8 value);
s32 SYSCONF_SetLanguage(u8 value);
s32 SYSCONF_SetCounterBias(u32 bias);
s32 SYSCONF_SetScreenSaverMode(u8 value);
s32 SYSCONF_SetDisplayOffsetH(s8 offset);
s32 SYSCONF_SetPadDevices(const sysconf_pad_device *devs, u8 count);
s32 SYSCONF_SetNickName(const u8 *nickname, u16 length);
s32 SYSCONF_SetAspectRatio(u8 value);
s32 SYSCONF_SetEULA(u8 value);
s32 SYSCONF_SetParentalPassword(const s8 *password, u32 length);
s32 SYSCONF_SetParentalAnswer(const s8 *answer, u32 length);
s32 SYSCONF_SetWiiConnect24(u32 value);
s32 SYSCONF_SetRegion(s32 value);
s32 SYSCONF_SetArea(s32 value);
s32 SYSCONF_SetVideo(s32 value);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif

View File

@ -1,29 +1,29 @@
/*------------------------------------------------------------- /*-------------------------------------------------------------
wiibasics.c -- basic Wii initialization and functions wiibasics.c -- basic Wii initialization and functions
Copyright (C) 2008 tona Copyright (C) 2008 tona
Unless other credit specified Unless other credit specified
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
damages arising from the use of this software. damages arising from the use of this software.
Permission is granted to anyone to use this software for any Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions: redistribute it freely, subject to the following restrictions:
1.The origin of this software must not be misrepresented; you 1.The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required. documentation would be appreciated but is not required.
2.Altered source versions must be plainly marked as such, and 2.Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software. must not be misrepresented as being the original software.
3.This notice may not be removed or altered from any source 3.This notice may not be removed or altered from any source
distribution. distribution.
-------------------------------------------------------------*/ -------------------------------------------------------------*/
#include <stdio.h> #include <stdio.h>
@ -38,7 +38,6 @@ distribution.
#define MAX_WIIMOTES 4 #define MAX_WIIMOTES 4
static void *xfb = NULL; static void *xfb = NULL;
static GXRModeObj *rmode = NULL; static GXRModeObj *rmode = NULL;
int ConsoleRows; int ConsoleRows;
@ -58,65 +57,64 @@ u64 be64(const u8 *p)
return ((u64)be32(p) << 32) | be32(p + 4); return ((u64)be32(p) << 32) | be32(p + 4);
} }
u32 getTitleIDUID(u64 titleID){ u32 getTitleIDUID(u64 titleID)
{
s32 ret, i; s32 ret, i;
static u8 uid_buffer[0x1000] ATTRIBUTE_ALIGN(32); static u8 uid_buffer[0x1000] ATTRIBUTE_ALIGN(32);
u32 size; u32 size;
ret = ISFS_ReadFileToArray("/sys/uid.sys", uid_buffer, 0x1000, &size); ret = ISFS_ReadFileToArray("/sys/uid.sys", uid_buffer, 0x1000, &size);
if (ret < 0) if (ret < 0)
return 0; return 0;
for(i = 0; i < size; i+=12) for (i = 0; i < size; i += 12)
if (be64(&uid_buffer[i]) == titleID) if (be64(&uid_buffer[i]) == titleID)
return be32(&uid_buffer[i+8]); return be32(&uid_buffer[i + 8]);
return 0; return 0;
} }
u64 getUIDTitleID(u32 uid){ u64 getUIDTitleID(u32 uid)
{
s32 ret, i; s32 ret, i;
static u8 uid_buffer[0x1000] ATTRIBUTE_ALIGN(32); static u8 uid_buffer[0x1000] ATTRIBUTE_ALIGN(32);
u32 size; u32 size;
ret = ISFS_ReadFileToArray("/sys/uid.sys", uid_buffer, 0x1000, &size); ret = ISFS_ReadFileToArray("/sys/uid.sys", uid_buffer, 0x1000, &size);
if (ret < 0) if (ret < 0)
return 0; return 0;
for(i = 8; i < size; i+=12)
if (be32(&uid_buffer[i]) == uid)
return be64(&uid_buffer[i-8]);
return 0;
}
for (i = 8; i < size; i += 12)
if (be32(&uid_buffer[i]) == uid)
return be64(&uid_buffer[i - 8]);
return 0;
}
/* Basic init taken pretty directly from the libOGC examples */ /* Basic init taken pretty directly from the libOGC examples */
void basicInit(void) void basicInit(void)
{ {
// Initialise the video system // Initialise the video system
VIDEO_Init(); VIDEO_Init();
// Obtain the preferred video mode from the system // Obtain the preferred video mode from the system
// This will correspond to the settings in the Wii menu // This will correspond to the settings in the Wii menu
rmode = VIDEO_GetPreferredMode(NULL); rmode = VIDEO_GetPreferredMode(NULL);
//rmode->viWidth = 678; // rmode->viWidth = 678;
//rmode->viXOrigin = (VI_MAX_WIDTH_PAL - 678)/2; // rmode->viXOrigin = (VI_MAX_WIDTH_PAL - 678)/2;
GX_AdjustForOverscan(rmode, rmode, 32, 24); GX_AdjustForOverscan(rmode, rmode, 32, 24);
// Allocate memory for the display in the uncached region // Allocate memory for the display in the uncached region
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
// Initialise the console, required for printf // Initialise the console, required for printf
console_init(xfb,0,0,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); console_init(xfb, 0, 0, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ);
// Set up the video registers with the chosen mode // Set up the video registers with the chosen mode
VIDEO_Configure(rmode); VIDEO_Configure(rmode);
// Tell the video hardware where our display memory is // Tell the video hardware where our display memory is
VIDEO_SetNextFramebuffer(xfb); VIDEO_SetNextFramebuffer(xfb);
// Make the display visible // Make the display visible
VIDEO_SetBlack(FALSE); VIDEO_SetBlack(FALSE);
@ -125,104 +123,118 @@ void basicInit(void)
// Wait for Video setup to complete // Wait for Video setup to complete
VIDEO_WaitVSync(); VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); if (rmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
// The console understands VT terminal escape codes // The console understands VT terminal escape codes
// This positions the cursor on row 2, column 0 // This positions the cursor on row 2, column 0
// we can use variables for this with format codes too // we can use variables for this with format codes too
// e.g. printf ("\x1b[%d;%dH", row, column ); // e.g. printf ("\x1b[%d;%dH", row, column );
//printf("\x1b[2;0H"); // printf("\x1b[2;0H");
CON_GetMetrics(&ConsoleCols, &ConsoleRows); CON_GetMetrics(&ConsoleCols, &ConsoleRows);
} }
void ClearScreen() { void ClearScreen()
/* Clear console */ {
printf("\x1b[2J"); /* Clear console */
fflush(stdout); printf("\x1b[2J");
fflush(stdout);
} }
void ClearLine() { void ClearLine()
printf("\r\x1b[2K\r"); {
fflush(stdout); printf("\r\x1b[2K\r");
fflush(stdout);
} }
void PrintCenter(char *text, int width) { void PrintCenter(char *text, int width)
int textLen = strlen(text); {
int leftPad = (width - textLen) / 2; int textLen = strlen(text);
int rightPad = (width - textLen) - leftPad; int leftPad = (width - textLen) / 2;
printf("%*s%s%*s", leftPad, " ", text, rightPad, " "); int rightPad = (width - textLen) - leftPad;
printf("%*s%s%*s", leftPad, " ", text, rightPad, " ");
} }
void Console_SetFgColor(u8 color, u8 bold) { void Console_SetFgColor(u8 color, u8 bold)
printf("\x1b[%u;%dm", color + 30, bold); {
printf("\x1b[%u;%dm", color + 30, bold);
} }
void Console_SetBgColor(u8 color, u8 bold) { void Console_SetBgColor(u8 color, u8 bold)
printf("\x1b[%u;%dm", color + 40, bold); {
printf("\x1b[%u;%dm", color + 40, bold);
} }
void Console_SetColors(u8 bgColor, u8 bgBold, u8 fgColor, u8 fgBold) { void Console_SetColors(u8 bgColor, u8 bgBold, u8 fgColor, u8 fgBold)
Console_SetBgColor(bgColor, bgBold); {
Console_SetFgColor(fgColor, fgBold); Console_SetBgColor(bgColor, bgBold);
Console_SetFgColor(fgColor, fgBold);
} }
void Console_SetPosition(u8 row, u8 column) { void Console_SetPosition(u8 row, u8 column)
// The console understands VT terminal escape codes {
// This positions the cursor on row 2, column 0 // The console understands VT terminal escape codes
// we can use variables for this with format codes too // This positions the cursor on row 2, column 0
// e.g. printf ("\x1b[%d;%dH", row, column ); // we can use variables for this with format codes too
printf("\x1b[%u;%uH", row, column); // e.g. printf ("\x1b[%d;%dH", row, column );
printf("\x1b[%u;%uH", row, column);
} }
void PrintBanner() { void PrintBanner()
ClearScreen(); {
Console_SetColors(GREEN, 0, WHITE, 2); ClearScreen();
char text[ConsoleCols]; Console_SetColors(GREEN, 0, WHITE, 2);
snprintf(text, sizeof(text), "Any Region Changer ModMii Edition %.1lf.%i IOS: %i", ARCME_VERSION, ARCME_REV, IOS_GetVersion()); char text[ConsoleCols];
PrintCenter(text, ConsoleCols); snprintf(text, sizeof(text), "Any Region Changer ModMii Edition %.1lf.%i IOS: %i", ARCME_VERSION, ARCME_REV, IOS_GetVersion());
Console_SetColors(BLACK, 0, WHITE, 2); PrintCenter(text, ConsoleCols);
Console_SetColors(BLACK, 0, WHITE, 2);
} }
void miscInit(void) void miscInit(void)
{ {
int ret; int ret;
// This function initialises the attached controllers // This function initialises the attached controllers
WPAD_Init(); WPAD_Init();
Identify_SU(); Identify_SU();
gprintf("Initializing Filesystem driver..."); gprintf("Initializing Filesystem driver...");
fflush(stdout); fflush(stdout);
ret = ISFS_Initialize(); ret = ISFS_Initialize();
if (ret < 0) { if (ret < 0)
{
gprintf("\nError! ISFS_Initialize (ret = %d)\n", ret); gprintf("\nError! ISFS_Initialize (ret = %d)\n", ret);
wait_anyKey(); wait_anyKey();
exit(0); exit(0);
} else { }
else
{
gprintf("OK!\n"); gprintf("OK!\n");
} }
//IdentSysMenu(); // IdentSysMenu();
} }
void IdentSysMenu(void){ void IdentSysMenu(void)
{
int ret; int ret;
Identify_SysMenu(); Identify_SysMenu();
ret = ES_SetUID(TITLE_ID(1, 2)); ret = ES_SetUID(TITLE_ID(1, 2));
if (ret < 0){ if (ret < 0)
{
printf("SetUID fail %d", ret); printf("SetUID fail %d", ret);
wait_anyKey(); wait_anyKey();
exit(1); exit(1);
} }
printf("Initializing Filesystem driver..."); printf("Initializing Filesystem driver...");
fflush(stdout); fflush(stdout);
ISFS_Deinitialize(); ISFS_Deinitialize();
ret = ISFS_Initialize(); ret = ISFS_Initialize();
if (ret < 0) { if (ret < 0)
{
printf("\nError! ISFS_Initialize (ret = %d)\n", ret); printf("\nError! ISFS_Initialize (ret = %d)\n", ret);
wait_anyKey(); wait_anyKey();
exit(1); exit(1);
} else { }
else
{
printf("OK!\n"); printf("OK!\n");
} }
} }
@ -239,15 +251,18 @@ u32 getButtons(void)
return WPAD_ButtonsDown(0); return WPAD_ButtonsDown(0);
} }
u32 wait_anyKey(void) { u32 wait_anyKey(void)
{
u32 pressed; u32 pressed;
while(!(pressed = getButtons())) { while (!(pressed = getButtons()))
{
VIDEO_WaitVSync(); VIDEO_WaitVSync();
} }
if (pressed & WPAD_BUTTON_HOME) { if (pressed & WPAD_BUTTON_HOME)
Console_SetPosition(26,0); {
Console_SetPosition(26, 0);
ClearLine(); ClearLine();
Console_SetPosition(26,30); Console_SetPosition(26, 30);
Console_SetColors(BLACK, 0, GREEN, 0); Console_SetColors(BLACK, 0, GREEN, 0);
printf("Exiting"); printf("Exiting");
exit(0); exit(0);
@ -255,52 +270,60 @@ u32 wait_anyKey(void) {
return pressed; return pressed;
} }
u32 wait_key(u32 button) { u32 wait_key(u32 button)
{
u32 pressed; u32 pressed;
do { do
{
VIDEO_WaitVSync(); VIDEO_WaitVSync();
pressed = getButtons(); pressed = getButtons();
if (pressed & WPAD_BUTTON_HOME) { if (pressed & WPAD_BUTTON_HOME)
Console_SetPosition(26,0); {
Console_SetPosition(26, 0);
ClearLine(); ClearLine();
Console_SetPosition(26,30); Console_SetPosition(26, 30);
Console_SetColors(BLACK, 0, GREEN, 0); Console_SetColors(BLACK, 0, GREEN, 0);
printf("Exiting"); printf("Exiting");
exit(0); exit(0);
} }
} while(!(pressed & button)); } while (!(pressed & button));
return pressed; return pressed;
} }
char charASCII(u8 c) { char charASCII(u8 c)
{
if (c < 0x20 || c > 0x7E) if (c < 0x20 || c > 0x7E)
return '.'; return '.';
else else
return (char)c; return (char)c;
} }
void hex_print_array16(const u8 *array, u32 size){ void hex_print_array16(const u8 *array, u32 size)
{
u32 offset = 0; u32 offset = 0;
u32 page_size = 0x100; u32 page_size = 0x100;
char line[17]; char line[17];
line[16] = 0; line[16] = 0;
if (size > page_size) if (size > page_size)
printf("Page 1 of %lu", (size / page_size)+1); printf("Page 1 of %lu", (size / page_size) + 1);
while (offset < size){ while (offset < size)
if (!(offset % 16)) printf("\n0x%08lX: ", offset); {
if (!(offset % 16))
printf("\n0x%08lX: ", offset);
printf("%02X", array[offset]); printf("%02X", array[offset]);
line[offset % 16] = charASCII(array[offset]); line[offset % 16] = charASCII(array[offset]);
if (!(++offset % 2)) if (!(++offset % 2))
printf(" "); printf(" ");
if (!(offset % 16)) if (!(offset % 16))
printf(line); printf(line);
if (!(offset % page_size) && offset < size){ if (!(offset % page_size) && offset < size)
{
u32 pressed; u32 pressed;
printf("\n\tPress a key for next page or B for finish\n"); printf("\n\tPress a key for next page or B for finish\n");
pressed = wait_anyKey(); pressed = wait_anyKey();
@ -312,27 +335,29 @@ void hex_print_array16(const u8 *array, u32 size){
} }
} }
bool yes_or_no(void){ bool yes_or_no(void)
{
bool yes = 0; bool yes = 0;
u32 buttons = 0; u32 buttons = 0;
do { do
{
yes = buttons & WPAD_BUTTON_LEFT; yes = buttons & WPAD_BUTTON_LEFT;
if(yes) if (yes)
printf("\r\x1b[K <\x1b[30m\x1b[47;1m Yes \x1b[37;1m\x1b[40m> No "); printf("\r\x1b[K <\x1b[30m\x1b[47;1m Yes \x1b[37;1m\x1b[40m> No ");
else else
printf("\r\x1b[K Yes <\x1b[30m\x1b[47;1m No \x1b[37;1m\x1b[40m> "); printf("\r\x1b[K Yes <\x1b[30m\x1b[47;1m No \x1b[37;1m\x1b[40m> ");
} while ((buttons = wait_key(WPAD_BUTTON_A | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT)) } while ((buttons = wait_key(WPAD_BUTTON_A | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT)) && (!(buttons & WPAD_BUTTON_A)));
&& (!(buttons & WPAD_BUTTON_A)));
printf("\n"); printf("\n");
return yes; return yes;
} }
/* Reads a file from ISFS to an array in memory */ /* Reads a file from ISFS to an array in memory */
s32 ISFS_ReadFileToArray (const char *filepath, u8 *filearray, u32 max_size, u32 *file_size) { s32 ISFS_ReadFileToArray(const char *filepath, u8 *filearray, u32 max_size, u32 *file_size)
{
s32 ret, fd; s32 ret, fd;
static fstats filestats ATTRIBUTE_ALIGN(32); static fstats filestats ATTRIBUTE_ALIGN(32);
*file_size = 0; *file_size = 0;
ret = ISFS_Open(filepath, ISFS_OPEN_READ); ret = ISFS_Open(filepath, ISFS_OPEN_READ);
if (ret <= 0) if (ret <= 0)
@ -340,37 +365,37 @@ s32 ISFS_ReadFileToArray (const char *filepath, u8 *filearray, u32 max_size, u32
printf("Error! ISFS_Open (ret = %ld)\n", ret); printf("Error! ISFS_Open (ret = %ld)\n", ret);
return -1; return -1;
} }
fd = ret; fd = ret;
ret = ISFS_GetFileStats(fd, &filestats); ret = ISFS_GetFileStats(fd, &filestats);
if (ret < 0) if (ret < 0)
{ {
printf("Error! ISFS_GetFileStats (ret = %ld)\n", ret); printf("Error! ISFS_GetFileStats (ret = %ld)\n", ret);
return -1; return -1;
} }
*file_size = filestats.file_length; *file_size = filestats.file_length;
if (*file_size > max_size) if (*file_size > max_size)
{ {
printf("File is too large! Size: %lu Max: %lu", *file_size, max_size); printf("File is too large! Size: %lu Max: %lu", *file_size, max_size);
return -1; return -1;
} }
ret = ISFS_Read(fd, filearray, *file_size); ret = ISFS_Read(fd, filearray, *file_size);
*file_size = ret; *file_size = ret;
if (ret < 0) if (ret < 0)
{ {
printf("Error! ISFS_Read (ret = %ld)\n", ret); printf("Error! ISFS_Read (ret = %ld)\n", ret);
return -1; return -1;
} }
else if (ret != filestats.file_length) else if (ret != filestats.file_length)
{ {
printf("Error! ISFS_Read Only read: %ld\n", ret); printf("Error! ISFS_Read Only read: %ld\n", ret);
return -1; return -1;
} }
ret = ISFS_Close(fd); ret = ISFS_Close(fd);
if (ret < 0) if (ret < 0)
{ {
@ -381,7 +406,8 @@ s32 ISFS_ReadFileToArray (const char *filepath, u8 *filearray, u32 max_size, u32
} }
/* Writes from an array in memory to a file with ISFS */ /* Writes from an array in memory to a file with ISFS */
s32 ISFS_WriteFileFromArray (const char *filepath, const u8 *filearray, u32 array_size, u32 ownerID, u16 groupID, u8 attr, u8 own_perm, u8 group_perm, u8 other_perm){ s32 ISFS_WriteFileFromArray(const char *filepath, const u8 *filearray, u32 array_size, u32 ownerID, u16 groupID, u8 attr, u8 own_perm, u8 group_perm, u8 other_perm)
{
s32 ret, fd = 0, out; s32 ret, fd = 0, out;
u64 currentTid; u64 currentTid;
u32 realownid; u32 realownid;
@ -390,10 +416,11 @@ s32 ISFS_WriteFileFromArray (const char *filepath, const u8 *filearray, u32 arra
static fstats filestats ATTRIBUTE_ALIGN(32); static fstats filestats ATTRIBUTE_ALIGN(32);
out = 0; out = 0;
ret = ISFS_Open(filepath, ISFS_OPEN_WRITE); ret = ISFS_Open(filepath, ISFS_OPEN_WRITE);
if (ret == -102){ if (ret == -102)
{
printf("\tMaking file writable...\n"); printf("\tMaking file writable...\n");
ret = ISFS_SetAttr(filepath, ownerID, groupID, attr, 3, 3, 3); ret = ISFS_SetAttr(filepath, ownerID, groupID, attr, 3, 3, 3);
if (ret < 0) if (ret < 0)
@ -402,36 +429,40 @@ s32 ISFS_WriteFileFromArray (const char *filepath, const u8 *filearray, u32 arra
out = -1; out = -1;
goto cleanup; goto cleanup;
} }
return ISFS_WriteFileFromArray(filepath, filearray, array_size, ownerID, groupID, attr, own_perm, group_perm, other_perm); return ISFS_WriteFileFromArray(filepath, filearray, array_size, ownerID, groupID, attr, own_perm, group_perm, other_perm);
}
} else if (ret == -106){ else if (ret == -106)
{
printf("\tCreating file...\n"); printf("\tCreating file...\n");
ret = ISFS_CreateFile(filepath, attr, 3, 3, 3); ret = ISFS_CreateFile(filepath, attr, 3, 3, 3);
if (ret < 0){ if (ret < 0)
{
printf("Error! ISFS_CreateFile (ret = %ld)\n", ret); printf("Error! ISFS_CreateFile (ret = %ld)\n", ret);
out = -1; out = -1;
goto cleanup; goto cleanup;
} }
return ISFS_WriteFileFromArray(filepath, filearray, array_size, ownerID, groupID, attr, own_perm, group_perm, other_perm); return ISFS_WriteFileFromArray(filepath, filearray, array_size, ownerID, groupID, attr, own_perm, group_perm, other_perm);
}
} else if (ret <= 0) { else if (ret <= 0)
{
printf("Error! ISFS_Open WRITE (ret = %ld)\n", ret); printf("Error! ISFS_Open WRITE (ret = %ld)\n", ret);
out = -1; out = -1;
goto cleanup; goto cleanup;
} }
fd = ret; fd = ret;
ret = ISFS_Seek(fd, 0, 0); ret = ISFS_Seek(fd, 0, 0);
if (ret < 0) { if (ret < 0)
{
printf("Error! ISFS_Seek (ret = %ld)\n", ret); printf("Error! ISFS_Seek (ret = %ld)\n", ret);
out = -1; out = -1;
goto cleanup; goto cleanup;
} }
ret = ISFS_Write(fd, filearray, array_size); ret = ISFS_Write(fd, filearray, array_size);
if (ret < 0) if (ret < 0)
{ {
@ -439,13 +470,13 @@ s32 ISFS_WriteFileFromArray (const char *filepath, const u8 *filearray, u32 arra
out = -1; out = -1;
goto cleanup; goto cleanup;
} }
if (ret != array_size) if (ret != array_size)
{ {
printf("Filesize is wrong! Wrote:%lu Expect:%lu", filestats.file_length, array_size); printf("Filesize is wrong! Wrote:%lu Expect:%lu", filestats.file_length, array_size);
out = -1; out = -1;
} }
ret = ISFS_Close(fd); ret = ISFS_Close(fd);
if (ret < 0) if (ret < 0)
{ {
@ -453,7 +484,7 @@ s32 ISFS_WriteFileFromArray (const char *filepath, const u8 *filearray, u32 arra
return -1; return -1;
} }
fd = 0; fd = 0;
/* /*
ret = ISFS_Open(filepath, ISFS_OPEN_READ); ret = ISFS_Open(filepath, ISFS_OPEN_READ);
if (ret <= 0) { if (ret <= 0) {
@ -462,7 +493,7 @@ s32 ISFS_WriteFileFromArray (const char *filepath, const u8 *filearray, u32 arra
goto cleanup; goto cleanup;
} }
fd = ret; fd = ret;
ret = ISFS_GetFileStats(fd, &filestats); ret = ISFS_GetFileStats(fd, &filestats);
if (ret < 0) if (ret < 0)
{ {
@ -470,7 +501,7 @@ s32 ISFS_WriteFileFromArray (const char *filepath, const u8 *filearray, u32 arra
out = -1; out = -1;
goto cleanup; goto cleanup;
} }
ret = ISFS_Close(fd); ret = ISFS_Close(fd);
if (ret < 0) if (ret < 0)
{ {
@ -485,23 +516,26 @@ s32 ISFS_WriteFileFromArray (const char *filepath, const u8 *filearray, u32 arra
printf("Error! ISFS_GetAttr (ret = %ld)\n", ret); printf("Error! ISFS_GetAttr (ret = %ld)\n", ret);
out = -1; out = -1;
} }
if (realownid != ownerID){ if (realownid != ownerID)
{
ret = ES_GetTitleID(&currentTid); ret = ES_GetTitleID(&currentTid);
if (ret){ if (ret)
{
printf("Fail GetTitleID %ld", ret); printf("Fail GetTitleID %ld", ret);
if(wait_key(WPAD_BUTTON_A | WPAD_BUTTON_B) & WPAD_BUTTON_B) if (wait_key(WPAD_BUTTON_A | WPAD_BUTTON_B) & WPAD_BUTTON_B)
goto cleanup; goto cleanup;
} }
ret = ES_SetUID(getUIDTitleID(ownerID)); ret = ES_SetUID(getUIDTitleID(ownerID));
if (ret){ if (ret)
{
printf("Couldn't set OwnerID, using current owner ID\n"); printf("Couldn't set OwnerID, using current owner ID\n");
if(wait_key(WPAD_BUTTON_A | WPAD_BUTTON_B) & WPAD_BUTTON_B) if (wait_key(WPAD_BUTTON_A | WPAD_BUTTON_B) & WPAD_BUTTON_B)
goto cleanup; goto cleanup;
ownerID = realownid; ownerID = realownid;
} }
} }
ret = ISFS_SetAttr(filepath, ownerID, groupID, attr, own_perm, group_perm, other_perm); ret = ISFS_SetAttr(filepath, ownerID, groupID, attr, own_perm, group_perm, other_perm);
if (ret < 0) if (ret < 0)
{ {
@ -509,18 +543,21 @@ s32 ISFS_WriteFileFromArray (const char *filepath, const u8 *filearray, u32 arra
out = -1; out = -1;
goto cleanup; goto cleanup;
} }
if (realownid != ownerID){ if (realownid != ownerID)
{
ret = ES_SetUID(currentTid); ret = ES_SetUID(currentTid);
if (ret){ if (ret)
{
printf("Fail SetUID %ld", ret); printf("Fail SetUID %ld", ret);
if(wait_key(WPAD_BUTTON_A | WPAD_BUTTON_B) & WPAD_BUTTON_B) if (wait_key(WPAD_BUTTON_A | WPAD_BUTTON_B) & WPAD_BUTTON_B)
goto cleanup; goto cleanup;
} }
} }
cleanup: cleanup:
if (fd) { if (fd)
{
ret = ISFS_Close(fd); ret = ISFS_Close(fd);
if (ret < 0) if (ret < 0)
{ {
@ -529,5 +566,4 @@ s32 ISFS_WriteFileFromArray (const char *filepath, const u8 *filearray, u32 arra
} }
} }
return out; return out;
}
}

View File

@ -1,61 +1,60 @@
/*------------------------------------------------------------- /*-------------------------------------------------------------
wiibasics.h -- basic Wii initialization and functions wiibasics.h -- basic Wii initialization and functions
Copyright (C) 2008 tona Copyright (C) 2008 tona
Unless other credit specified Unless other credit specified
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
damages arising from the use of this software. damages arising from the use of this software.
Permission is granted to anyone to use this software for any Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions: redistribute it freely, subject to the following restrictions:
1.The origin of this software must not be misrepresented; you 1.The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required. documentation would be appreciated but is not required.
2.Altered source versions must be plainly marked as such, and 2.Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software. must not be misrepresented as being the original software.
3.This notice may not be removed or altered from any source 3.This notice may not be removed or altered from any source
distribution. distribution.
-------------------------------------------------------------*/ -------------------------------------------------------------*/
#ifndef _WII_BASICS_H_ #ifndef _WII_BASICS_H_
#define _WII_BASICS_H_ #define _WII_BASICS_H_
// Turn upper and lower into a full title ID // Turn upper and lower into a full title ID
#define TITLE_ID(x,y) (((u64)(x) << 32) | (y)) #define TITLE_ID(x, y) (((u64)(x) << 32) | (y))
// Get upper or lower half of a title ID // Get upper or lower half of a title ID
#define TITLE_UPPER(x) ((u32)((x) >> 32)) #define TITLE_UPPER(x) ((u32)((x) >> 32))
// Turn upper and lower into a full title ID // Turn upper and lower into a full title ID
#define TITLE_LOWER(x) ((u32)(x)) #define TITLE_LOWER(x) ((u32)(x))
#define BLACK 0 #define BLACK 0
#define RED 1 #define RED 1
#define GREEN 2 #define GREEN 2
#define YELLOW 3 #define YELLOW 3
#define BLUE 4 #define BLUE 4
#define MAGENTA 5 #define MAGENTA 5
#define CYAN 6 #define CYAN 6
#define WHITE 7 #define WHITE 7
#define BOLD_NONE 0 #define BOLD_NONE 0
#define BOLD_NORMAL 1 #define BOLD_NORMAL 1
#define BOLD_FAINT 2 #define BOLD_FAINT 2
#define UP_ARROW "\x1E" #define UP_ARROW "\x1E"
#define DOWN_ARROW "\x1F" #define DOWN_ARROW "\x1F"
#define LEFT_ARROW "\x11" #define LEFT_ARROW "\x11"
#define RIGHT_ARROW "\x10" #define RIGHT_ARROW "\x10"
#define ARCME_VERSION 1.0 #define ARCME_VERSION 1.0
#define ARCME_REV 6 #define ARCME_REV 6
// be functions from segher's wii.git // be functions from segher's wii.git
u16 be16(const u8 *p); u16 be16(const u8 *p);
@ -84,10 +83,10 @@ u32 wait_key(u32 button);
void hex_print_array16(const u8 *array, u32 size); void hex_print_array16(const u8 *array, u32 size);
/* Reads a file from ISFS to an array in memory */ /* Reads a file from ISFS to an array in memory */
s32 ISFS_ReadFileToArray (const char *filepath, u8 *filearray, u32 max_size, u32 *file_size); s32 ISFS_ReadFileToArray(const char *filepath, u8 *filearray, u32 max_size, u32 *file_size);
/* Writes from an array in memory to a file with ISFS */ /* Writes from an array in memory to a file with ISFS */
s32 ISFS_WriteFileFromArray (const char *filepath, const u8 *filearray, u32 array_size, u32 ownerID, u16 groupID, u8 attr, u8 own_perm, u8 group_perm, u8 other_perm); s32 ISFS_WriteFileFromArray(const char *filepath, const u8 *filearray, u32 array_size, u32 ownerID, u16 groupID, u8 attr, u8 own_perm, u8 group_perm, u8 other_perm);
bool yes_or_no(); bool yes_or_no();
void ClearScreen(); void ClearScreen();