|
Merge code to patch Wii Channels' Menu button with bootOpera... June 25, 2011 01:38AM | Registered: 16 years ago Posts: 18 |
|
Re: Merge code to patch Wii Channels' Menu button with bootOpera... June 25, 2011 03:51AM | Registered: 16 years ago Posts: 223 |
|
Re: Merge code to patch Wii Channels' Menu button with bootOpera... June 25, 2011 10:27AM | Registered: 16 years ago Posts: 18 |
|
Re: Merge code to patch Wii Channels' Menu button with bootOpera... June 25, 2011 11:11PM | Registered: 15 years ago Posts: 220 |
|
Re: Merge code to patch Wii Channels' Menu button with bootOpera... June 25, 2011 11:30PM | Moderator Registered: 16 years ago Posts: 5,075 |
//giantpune's magic super patch to return to channels - Added by Dr. Clipper
bool PatchReturnTo(void *Address, int Size, u32 id) {
if( !id )return 0;
//new __OSLoadMenu() (SM2.0 and higher)
u8 SearchPattern[ 12 ] = { 0x38, 0x80, 0x00, 0x02, 0x38, 0x60, 0x00, 0x01, 0x38, 0xa0, 0x00, 0x00 };
//old _OSLoadMenu() (used in launch games)
u8 SearchPatternB[ 12 ] = { 0x38, 0xC0, 0x00, 0x02, 0x38, 0xA0, 0x00, 0x01, 0x38, 0xE0, 0x00, 0x00 };
//identifier for the safe place
u8 SearchPattern2[ 12 ] = { 0x4D, 0x65, 0x74, 0x72, 0x6F, 0x77, 0x65, 0x72, 0x6B, 0x73, 0x20, 0x54 };
int found = 0;
int patched = 0;
u8 oldSDK = 0;
u32 ad[ 4 ] = { 0, 0, 0, 0 };
void *Addr = Address;
void *Addr_end = Address+Size;
while (Addr <= Addr_end - 12 ) {
//find a safe place or the patch to hang out
if ( ! ad[ 3 ] && memcmp( Addr, SearchPattern2, 12 )==0 ) {
ad[ 3 ] = (u32)Addr + 0x30;
debug_printf("found a safe place @ %08x\n", ad[ 3 ]);
//hexdump( Addr, 0x50 );
}
//find __OSLaunchMenu() and remember some addresses in it
else if ( memcmp( Addr, SearchPattern, 12 )==0 ) {
ad[ found++ ] = (u32)Addr;
}
else if ( ad[ 0 ] && memcmp( Addr, SearchPattern, 8 )==0 ) //after the first match is found, only search the first 8 bytes for the other 2
{
if( !ad[ 1 ] ) ad[ found++ ] = (u32)Addr;
else if( !ad[ 2 ] ) ad[ found++ ] = (u32)Addr;
if( found >= 3 )break;
}
Addr += 4;
}
//check for the older-ass version of the SDK
if( found < 3 && ad[ 3 ] )
{
Addr = Address;
ad[ 0 ] = 0;
ad[ 1 ] = 0;
ad[ 2 ] = 0;
found = 0;
oldSDK = 1;
while (Addr <= Addr_end - 12 ) {
//find __OSLaunchMenu() and remember some addresses in it
if ( memcmp( Addr, SearchPatternB, 12 )==0 ) {
ad[ found++ ] = (u32)Addr;
}
else if ( ad[ 0 ] && memcmp( Addr, SearchPatternB, 8 ) == 0 ) //after the first match is found, only search the first 8 bytes for the other 2
{
if( !ad[ 1 ] ) ad[ found++ ] = (u32)Addr;
else if( !ad[ 2 ] ) ad[ found++ ] = (u32)Addr;
if( found >= 3 )break;
}
Addr += 4;
}
}
//if the function is found and if it is not too far into the main.dol
if( found == 3 && ( ad[ 2 ] - ad[ 3 ] < 0x1000001 ) && ad[ 3 ] )
{
debug_printf("patch __OSLaunchMenu( 0x00010001, 0x%08x )\n", id);
u32 nop = 0x60000000;
//the magic that writes the TID to the registers
u8 jump[ 20 ] = { 0x3C, 0x60, 0x00, 0x01, 0x60, 0x63, 0x00, 0x01,
0x3C, 0x80, 0x4A, 0x4F, 0x60, 0x84, 0x44, 0x49,
0x4E, 0x80, 0x00, 0x20 };
if( oldSDK )
{
jump[ 1 ] = 0xA0; //3CA00001 60A50001
jump[ 5 ] = 0xA5; //3CC04A4F 60C64449
jump[ 9 ] = 0xC0;
jump[ 13 ] = 0xC6;
}
//patch the thing to use the new TID
jump[ 10 ] = (u8)( id >> 24 );
jump[ 11 ] = (u8)( id >> 16 );
jump[ 14 ] = (u8)( id >> 8 );
jump[ 15 ] = (u8)id;
void* addr = (u32*)ad[ 3 ];
//write new stuff to memory main.dol in a unused part of the main.dol
memcpy( addr, jump, sizeof( jump ) );
//ES_GetTicketViews()
u32 newval = ( ad[ 3 ] - ad[ 0 ] );
newval &= 0x03FFFFFC;
newval |= 0x48000001;
addr = (u32*)ad[ 0 ];
memcpy( addr, &newval, sizeof( u32 ) );
memcpy( addr + 4, &nop, sizeof( u32 ) );
debug_printf("\t%p -> %08x\n", addr, newval );
//ES_GetTicketViews() again
newval = ( ad[ 3 ] - ad[ 1 ] );
newval &= 0x03FFFFFC;
newval |= 0x48000001;
addr = (u32*)ad[ 1 ];
memcpy( addr, &newval, sizeof( u32 ) );
memcpy( addr + 4, &nop, sizeof( u32 ) );
debug_printf("\t%p -> %08x\n", addr, newval );
//ES_LaunchTitle()
newval = ( ad[ 3 ] - ad[ 2 ] );
newval &= 0x03FFFFFC;
newval |= 0x48000001;
addr = (u32*)ad[ 2 ];
memcpy( addr, &newval, sizeof( u32 ) );
memcpy( addr + 4, &nop, sizeof( u32 ) );
debug_printf("\t%p -> %08x\n", addr, newval );
patched = 1;
}
else
{
debug_printf("not patched\n");
debug_printf("found %d addresses\n", found);
int i;
for( i = 0; i< 4; i++)
debug_printf("ad[ %d ]: %08x\n", i, ad[ i ] );
debug_printf("offset : %08x\n", ad[ 2 ] - ad[ 3 ] );
}
return patched;
}|
Re: Merge code to patch Wii Channels' Menu button with bootOpera... June 26, 2011 03:53AM | Registered: 16 years ago Posts: 18 |
#include "gccore.h"
#include "wiiuse/wpad.h"
#include "ogc/ios.h"
#include "fat.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "unistd.h"
static void *xfb = NULL;
static GXRModeObj *vmode = NULL;
char * url = "";
void setupVideo() {
VIDEO_Init();
vmode = VIDEO_GetPreferredMode(NULL);
VIDEO_Configure(vmode);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode));
console_init (xfb, 20, 20, vmode->fbWidth, vmode->xfbHeight, vmode->fbWidth*VI_DISPLAY_PIX_SZ);
VIDEO_Configure(vmode);
VIDEO_ClearFrameBuffer(vmode, xfb, COLOR_BLACK);
VIDEO_SetNextFramebuffer(xfb);
VIDEO_SetBlack(0);
VIDEO_Flush();
VIDEO_WaitVSync();
if (vmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
}
s32 launchTitle(u64 TitleID, char * url) {
WII_Initialize();
if (url[0] != 0) {
//Load title with specified URL as an argument
return WII_LaunchTitleWithArgs(TitleID, 0, url, NULL);
} else {
return WII_LaunchTitle(TitleID);
}
}
s32 readCfg(char * path) {
int c = 0;
int i = 0;
FILE *f = fopen(path, "r");
if (f == NULL)
return 0;
fseek(f , 0 , SEEK_END);
u32 size = ftell(f);
rewind(f);
url = (char*) malloc(sizeof(char)*size);
while (c != EOF) {
c = fgetc(f);
if (31 < c && c < 127)
url[i++] = c;
}
url = '\0';
fclose(f);
return 1;
}
int main(int argc, char **argv) {
setupVideo();
s32 ret;
if (argc > 0) {
char path[MAXPATHLEN];
int len = strlen(argv[0]);
int i = 0;
for(i = len; argv[0] != '/'; i--);
if(i < 1)
readCfg("sd:/url.cfg");
else {
argv[0] = 0;
sprintf(path, "%s/url.cfg", argv[0]);
readCfg(path);
}
}
ret = launchTitle(0x0001000148414445LL, url);
if (ret < 0) {
ret = launchTitle(0x000100014841444ALL, url);
}
if (ret < 0) {
ret = launchTitle(0x0001000148414450LL, url);
}
return ret;
}
This is the bootOpera code which compiles into a working dol./* * Copyright (C) 2008 Nuke (wiinuke@gmail.com) * * this file is part of GeckoOS for USB Gecko * [www.usbgecko.com] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __PATCHCODE_H__ #define __PATCHCODE_H__ // Globals u32 hooktype; int patched; u8 configbytes[2]; u32 regionfree; // Function prototypes void dogamehooks(void *addr, u32 len); void langpatcher(void *addr, u32 len); void vidolpatcher(void *addr, u32 len); void patchdebug(void *addr, u32 len); #endif // __PATCHCODE_H__
#ifndef _APPLOADER_H_ #define _APPLOADER_H_ /* Entry point */ typedef void (*entry_point)(void); /* Prototypes */ s32 Apploader_Run(entry_point *); bool disable_return_to_patch; #endif
#ifndef _GECKO_H_
#define _GECKO_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifndef NO_DEBUG
//use this just like printf();
void gprintf(const char *str, ...);
void gsenddata(const u8 *data, int length, const char *filename);
void ghexdump(void *d, int len);
bool InitGecko();
#else
#define gprintf(...)
#define gsenddata(...)
#define InitGecko() false
#endif /* NO_DEBUG */
#ifdef __cplusplus
}
#endif
#endif
I believe these are the extra parameters to include when making the patch compile.|
Re: Merge code to patch Wii Channels' Menu button with bootOpera... June 26, 2011 07:13AM | Registered: 16 years ago Posts: 234 |
|
Re: Merge code to patch Wii Channels' Menu button with bootOpera... June 28, 2011 12:57AM | Registered: 16 years ago Posts: 18 |
|
Re: Merge code to patch Wii Channels' Menu button with bootOpera... June 28, 2011 11:09AM | Moderator Registered: 16 years ago Posts: 5,075 |
|
Re: Merge code to patch Wii Channels' Menu button with bootOpera... June 28, 2011 11:33PM | Registered: 16 years ago Posts: 18 |
|
Re: Merge code to patch Wii Channels' Menu button with bootOpera... June 28, 2011 11:52PM | Moderator Registered: 16 years ago Posts: 5,075 |