-Added libruntimeiospatch

-Made some changes to thread.c that will hopefully fix rendering problems
-Reorganized some code
-Rewrote logfile code so it logs directly to the file (no overflows)
-Other small optimizations

This hasn't been tested, and I'm not sure if pausing and resuming DrawCogThread won't cause problems
This commit is contained in:
Joostinonline 2013-11-07 17:58:22 +00:00
parent 6f26f9a612
commit 50ac33664e
5 changed files with 31 additions and 115 deletions

View File

@ -40,6 +40,7 @@ LIBS += -lwiilight -lwiiuse
#LIBS += -lmodplay -lasnd #LIBS += -lmodplay -lasnd
LIBS += -lbte -logc -lm LIBS += -lbte -logc -lm
LIBS += -lCheckRegion LIBS += -lCheckRegion
LIBS += -lruntimeiospatch
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing # list of directories containing libraries, this must be the top level containing

View File

@ -1,6 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <wiiuse/wpad.h> #include <wiiuse/wpad.h>
#include <ogc/lwp_watchdog.h> #include <ogc/lwp_watchdog.h>
#include <ogc/mutex.h>
#include "tahoma_ttf.h" #include "tahoma_ttf.h"
@ -46,6 +47,8 @@ GRRLIB_texImg *tex_window_png;
GRRLIB_texImg *tex_Cogs_png[5]; GRRLIB_texImg *tex_Cogs_png[5];
GRRLIB_texImg *tex_ScreenBuf; GRRLIB_texImg *tex_ScreenBuf;
//mutex_t lock_thread;
typedef struct map_entry typedef struct map_entry
{ {
char name[8]; char name[8];
@ -162,6 +165,7 @@ int initGUI(void) {
tex_Cogs_png[4] = GRRLIB_LoadTexturePNG(Cog5); tex_Cogs_png[4] = GRRLIB_LoadTexturePNG(Cog5);
tex_ScreenBuf = GRRLIB_CreateEmptyTexture(rmode->fbWidth, rmode->efbHeight); tex_ScreenBuf = GRRLIB_CreateEmptyTexture(rmode->fbWidth, rmode->efbHeight);
InitThread(); InitThread();
//LWP_MutexInit(&lock_thread, false);
return 0; return 0;
} }
@ -226,10 +230,12 @@ int printLoading(const char* msg) {
//int i; //int i;
//ResumeThread(); //ResumeThread();
u64 current_ticks = gettick(); u64 current_ticks = gettick();
PauseThread();
//GRRLIB_DrawImg(256, 112, tex_Refreshicon_png, 0, 1, 1, HEX_WHITE); //GRRLIB_DrawImg(256, 112, tex_Refreshicon_png, 0, 1, 1, HEX_WHITE);
GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE);
GRRLIB_PrintfTTF((640-strlen(msg)*9)/2, 256, myFont, msg, 20, HEX_WHITE); GRRLIB_PrintfTTF((640-strlen(msg)*9)/2, 256, myFont, msg, 20, HEX_WHITE);
CopyBuf(); CopyBuf();
ResumeThread();
//for (i = 0; i < 3; i++) { //Workaround for GRRLIB_Render() bug //for (i = 0; i < 3; i++) { //Workaround for GRRLIB_Render() bug
while(!CheckTime(current_ticks, 250)) { while(!CheckTime(current_ticks, 250)) {
//DrawBuf(); //DrawBuf();
@ -243,7 +249,7 @@ int printSelectIOS(const char* msg, const char* ios) {
int i; int i;
PauseThread(); PauseThread();
GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE);
GRRLIB_DrawImg(256, 112, tex_Refreshicon_png, 0, 1, 1, HEX_WHITE); //GRRLIB_DrawImg(256, 112, tex_Refreshicon_png, 0, 1, 1, HEX_WHITE);
GRRLIB_PrintfTTF((640-strlen(msg)*9)/2, 256, myFont, msg, 20, HEX_WHITE); GRRLIB_PrintfTTF((640-strlen(msg)*9)/2, 256, myFont, msg, 20, HEX_WHITE);
GRRLIB_PrintfTTF((640-strlen(ios)*9)/2, 300, myFont, ios, 20, HEX_WHITE); GRRLIB_PrintfTTF((640-strlen(ios)*9)/2, 300, myFont, ios, 20, HEX_WHITE);
@ -253,6 +259,7 @@ int printSelectIOS(const char* msg, const char* ios) {
GRRLIB_DrawImg(310, 388, tex_WiiButtonPlus_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(310, 388, tex_WiiButtonPlus_png, 0, 1, 1, HEX_WHITE);
GRRLIB_PrintfTTF(335-(strlen(BUT_Update)*7.8)/2, 425, myFont, BUT_Update, 14, HEX_WHITE); GRRLIB_PrintfTTF(335-(strlen(BUT_Update)*7.8)/2, 425, myFont, BUT_Update, 14, HEX_WHITE);
CopyBuf(); CopyBuf();
ResumeThread();
for (i = 0; i < 3; i++) { //Workaround for GRRLIB_Render() bug for (i = 0; i < 3; i++) { //Workaround for GRRLIB_Render() bug
DrawBuf(); DrawBuf();
GRRLIB_Render(); GRRLIB_Render();
@ -270,12 +277,14 @@ int printLoadingBar(const char* msg, const f32 percent) {
notloaded = 536 - loaded; notloaded = 536 - loaded;
//int i; //int i;
PauseThread();
GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE);
//GRRLIB_DrawImg(256, 112, tex_Refreshicon_png, 0, 1, 1, HEX_WHITE); //GRRLIB_DrawImg(256, 112, tex_Refreshicon_png, 0, 1, 1, HEX_WHITE);
GRRLIB_PrintfTTF((640-strlen(msg)*9)/2, 256, myFont, msg, 20, HEX_WHITE); GRRLIB_PrintfTTF((640-strlen(msg)*9)/2, 256, myFont, msg, 20, HEX_WHITE);
GRRLIB_DrawPart(52, 340, 0, 0, loaded, 36, tex_loadingbarblue_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawPart(52, 340, 0, 0, loaded, 36, tex_loadingbarblue_png, 0, 1, 1, HEX_WHITE);
GRRLIB_DrawPart(52+loaded, 340, loaded, 0, notloaded, 36, tex_loadingbargrey_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawPart(52+loaded, 340, loaded, 0, notloaded, 36, tex_loadingbargrey_png, 0, 1, 1, HEX_WHITE);
CopyBuf(); CopyBuf();
ResumeThread();
//for (i = 0; i < 3; i++) { //Workaround for GRRLIB_Render() bug //for (i = 0; i < 3; i++) { //Workaround for GRRLIB_Render() bug
while(!CheckTime(current_ticks, 250)) { while(!CheckTime(current_ticks, 250)) {
//DrawBuf(); //DrawBuf();
@ -287,7 +296,7 @@ int printLoadingBar(const char* msg, const f32 percent) {
int printEndSuccess(const char* msg) { int printEndSuccess(const char* msg) {
int i; int i;
//PauseThread(); PauseThread();
GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE);
GRRLIB_DrawImg(256, 112, tex_Checkicon_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(256, 112, tex_Checkicon_png, 0, 1, 1, HEX_WHITE);

View File

@ -13,6 +13,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <di/di.h> #include <di/di.h>
#include <CheckRegion.h> #include <CheckRegion.h>
#include <runtimeiospatch/runtimeiospatch.h>
#include "tmd_dat.h" #include "tmd_dat.h"
#include "sys.h" #include "sys.h"
@ -125,11 +126,11 @@ bool getInfoFromContent(IOS *ios) {
iosinfo = (iosinfo_t *)(buffer); iosinfo = (iosinfo_t *)(buffer);
if (ret >= 0 && ios->titleID == 252 && ios->num_contents == 1) { if (ret >= 0 && ios->titleID == 252 && ios->num_contents == 1) {
const char *checkStr = "bootcb2"; //const char *checkStr = "bootcb2";
int i; int i;
for (i = 0; i < filesize - strlen(checkStr); i++) for (i = 0; i < filesize - sizeof("bootcb2")-1; i++)
{ {
if (!strncmp((char*)buffer + i, checkStr, strlen(checkStr))) if (!strncmp((char*)buffer + i, "bootcb2", sizeof("bootcb2")-1))
{ {
sprintf(ios->info, " cBoot252"); sprintf(ios->info, " cBoot252");
gprintf("is cBoot252\n"); gprintf("is cBoot252\n");
@ -231,7 +232,8 @@ int main(int argc, char **argv)
if (HAVE_AHBPROT && !forceNoAHBPROT) if (HAVE_AHBPROT && !forceNoAHBPROT)
IOSPATCH_Apply(); //IOSPATCH_Apply();
IosPatch_RUNTIME(true, false, false, false);
bool nandAccess = CheckNANDAccess(); bool nandAccess = CheckNANDAccess();
// Get and display the current date and time // Get and display the current date and time

View File

@ -2,6 +2,7 @@
#include <unistd.h> #include <unistd.h>
#include <ogc/lwp_watchdog.h> #include <ogc/lwp_watchdog.h>
#include <ogc/lwp.h> #include <ogc/lwp.h>
#include <ogc/mutex.h>
#include "thread.h" #include "thread.h"
#include "gui.h" #include "gui.h"
@ -32,7 +33,7 @@ void * DrawCogThread(void *arg) {
inline void InitThread(void) { inline void InitThread(void) {
memset (&stack, 0, STACKSIZE); memset (&stack, 0, STACKSIZE);
LWP_CreateThread (&Cog_Thread, DrawCogThread, NULL, stack, STACKSIZE, PRIORITY); LWP_CreateThread (&Cog_Thread, DrawCogThread, NULL, stack, STACKSIZE, PRIORITY);
usleep(200); //usleep(200);
} }
inline s32 PauseThread(void) { inline s32 PauseThread(void) {

View File

@ -38,17 +38,14 @@ void logfile(const char *format, ...)
{ {
if (!debug) return; if (!debug) return;
MountSD(); MountSD();
char buffer[4096]; FILE *f;
//char temp[256]; f= fopen("SD:/sysCheckDebug.log", "a");
if(f == NULL) return;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vsprintf (buffer,format, args); vfprintf(f,format, args);
FILE *f;
//sprintf(temp, "SD:/sysCheckDebug.log");
f = fopen("SD:/sysCheckDebug.log", "a");
fputs(buffer, f);
fclose(f);
va_end (args); va_end (args);
fclose(f);
UnmountSD(); UnmountSD();
} }
@ -68,100 +65,6 @@ void *allocate_memory(u32 size)
return memalign(32, (size+31)&(~31) ); return memalign(32, (size+31)&(~31) );
} }
static void disable_memory_protection() {
write32(MEM_PROT, read32(MEM_PROT) & 0x0000FFFF);
}
static u32 apply_patch(char *name, const u8 *old, u32 old_size, const u8 *patch, u32 patch_size, u32 patch_offset) {
u8 *ptr_start = (u8*)*((u32*)0x80003134), *ptr_end = (u8*)0x94000000;
u32 found = 0;
u8 *location = NULL;
while (ptr_start < (ptr_end - patch_size)) {
if (!memcmp(ptr_start, old, old_size)) {
found++;
location = ptr_start + patch_offset;
u8 *start = location;
u32 i;
for (i = 0; i < patch_size; i++) {
*location++ = patch[i];
}
DCFlushRange((u8 *)(((u32)start) >> 5 << 5), (patch_size >> 5 << 5) + 64);
ICInvalidateRange((u8 *)(((u32)start) >> 5 << 5), (patch_size >> 5 << 5) + 64);
}
ptr_start++;
}
return found;
}
static const u8 di_readlimit_old[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0A, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
0x7E, 0xD4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08
};
static const u8 di_readlimit_patch[] = { 0x7e, 0xd4 };
const u8 isfs_permissions_old[] = { 0x42, 0x8B, 0xD0, 0x01, 0x25, 0x66 };
const u8 isfs_permissions_patch[] = { 0x42, 0x8B, 0xE0, 0x01, 0x25, 0x66 };
static const u8 setuid_old[] = { 0xD1, 0x2A, 0x1C, 0x39 };
static const u8 setuid_patch[] = { 0x46, 0xC0 };
const u8 es_identify_old[] = { 0x28, 0x03, 0xD1, 0x23 };
const u8 es_identify_patch[] = { 0x00, 0x00 };
const u8 hash_old[] = { 0x20, 0x07, 0x23, 0xA2 };
const u8 hash_patch[] = { 0x00 };
const u8 new_hash_old[] = { 0x20, 0x07, 0x4B, 0x0B };
const u8 addticket_vers_check[] = { 0xD2, 0x01, 0x4E, 0x56 };
const u8 addticket_patch[] = { 0xE0 };
const u8 es_set_ahbprot_pattern[] = { 0x68, 0x5B, 0x22, 0xEC, 0x00, 0x52, 0x18, 0x9B, 0x68, 0x1B, 0x46, 0x98, 0x07, 0xDB };
const u8 es_set_ahbprot_patch[] = { 0x01 };
u32 IOSPATCH_Apply(void) {
u32 count = 0;
s32 ret = 0;
if (HAVE_AHBPROT) {
disable_memory_protection();
ret = apply_patch("es_set_ahbprot", es_set_ahbprot_pattern, sizeof(es_set_ahbprot_pattern), es_set_ahbprot_patch, sizeof(es_set_ahbprot_patch), 25);
}
if (ret) {
IOS_ReloadIOS(IOS_GetVersion());
} else {
return 0;
}
if (HAVE_AHBPROT) {
disable_memory_protection();
//count += apply_patch("di_readlimit", di_readlimit_old, sizeof(di_readlimit_old), di_readlimit_patch, sizeof(di_readlimit_patch), 12);
count += apply_patch("isfs_permissions", isfs_permissions_old, sizeof(isfs_permissions_old), isfs_permissions_patch, sizeof(isfs_permissions_patch), 0);
//count += apply_patch("es_setuid", setuid_old, sizeof(setuid_old), setuid_patch, sizeof(setuid_patch), 0);
//count += apply_patch("es_identify", es_identify_old, sizeof(es_identify_old), es_identify_patch, sizeof(es_identify_patch), 2);
//count += apply_patch("hash_check", hash_old, sizeof(hash_old), hash_patch, sizeof(hash_patch), 1);
//count += apply_patch("new_hash_check", new_hash_old, sizeof(new_hash_old), hash_patch, sizeof(hash_patch), 1);
//count += apply_patch("add ticket patch", addticket_vers_check, sizeof(addticket_vers_check), addticket_patch, sizeof(addticket_patch), 0);
count += apply_patch("es_set_ahbprot", es_set_ahbprot_pattern, sizeof(es_set_ahbprot_pattern), es_set_ahbprot_patch, sizeof(es_set_ahbprot_patch), 25);
}
return count;
}
u32 es_set_ahbprot(void) {
disable_memory_protection();
return apply_patch("es_set_ahbprot", es_set_ahbprot_pattern, sizeof(es_set_ahbprot_pattern), es_set_ahbprot_patch, sizeof(es_set_ahbprot_patch), 25);
}
bool checkISFSinRAM(void) {
disable_memory_protection();
bool ret = true;
u8 *ptr_start = (u8*)*((u32*)0x80003134), *ptr_end = (u8*)0x94000000;
while (ptr_start < (ptr_end - sizeof(isfs_permissions_old))) {
if (!memcmp(ptr_start, isfs_permissions_old, sizeof(isfs_permissions_old))) {
ret = false;
}
ptr_start++;
}
return ret;
}
int NandStartup(void) int NandStartup(void)
{ {
if (NandInitialized) if (NandInitialized)