-recompiled libntfs with -O2 as it was before the update

-changed the IOS patching system, should be much more safe now
This commit is contained in:
fix94.1 2013-01-27 12:12:44 +00:00
parent 0c703207ea
commit eb24ebf76f
12 changed files with 57 additions and 77 deletions

Binary file not shown.

View File

@ -78,7 +78,7 @@ void WiiFlow_ExternalBooter(u8 vidMode, bool vipatch, bool countryString, u8 pat
normalCFG.wip_list = get_wip_list(); normalCFG.wip_list = get_wip_list();
normalCFG.wip_count = get_wip_count(); normalCFG.wip_count = get_wip_count();
ShutdownBeforeExit(BootType == TYPE_CHANNEL); ShutdownBeforeExit();
/* Copy CFG into new memory region */ /* Copy CFG into new memory region */
memcpy(BooterConfig, &normalCFG, sizeof(the_CFG)); memcpy(BooterConfig, &normalCFG, sizeof(the_CFG));
DCFlushRange(BooterConfig, sizeof(the_CFG)); DCFlushRange(BooterConfig, sizeof(the_CFG));
@ -111,10 +111,10 @@ void ExternalBooter_ChannelSetup(u64 title, bool dol)
normalCFG.use_dol = dol; normalCFG.use_dol = dol;
} }
void ShutdownBeforeExit(bool KeepPatches) void ShutdownBeforeExit(void)
{ {
DeviceHandle.UnMountAll(); DeviceHandle.UnMountAll();
NandHandle.DeInit_ISFS(KeepPatches); NandHandle.DeInit_ISFS();
WDVD_Close(); WDVD_Close();
Close_Inputs(); Close_Inputs();
/* Deinit network */ /* Deinit network */

View File

@ -32,6 +32,6 @@ void WiiFlow_ExternalBooter(u8 vidMode, bool vipatch, bool countryString, u8 pat
int aspectRatio, u32 returnTo, u8 BootType, bool use_led); int aspectRatio, u32 returnTo, u8 BootType, bool use_led);
void ExternalBooter_ChannelSetup(u64 title, bool dol); void ExternalBooter_ChannelSetup(u64 title, bool dol);
void ExternalBooter_WiiGameSetup(bool wbfs, bool dvd, const char *ID); void ExternalBooter_WiiGameSetup(bool wbfs, bool dvd, const char *ID);
void ShutdownBeforeExit(bool KeepPatches = false); void ShutdownBeforeExit(void);
#endif #endif

View File

@ -4,77 +4,60 @@
#include <gccore.h> #include <gccore.h>
#include <ogc/machine/processor.h> #include <ogc/machine/processor.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "gecko/gecko.hpp" #include "gecko/gecko.hpp"
#include "memory/memory.h" #include "memory/memory.h"
#include "identify.h" #include "identify.h"
static bool apply_patch(char *name, const u8 *old, u32 old_size, const u8 *patch, u32 patch_size, u32 patch_offset) static inline bool apply_patch(char *name, const u8 *old, const u8 *patch, u32 size)
{ {
u8 *ptr = (u8*)0x93400000; u8 i;
bool found = false; u32 found = 0;
u8 *location = NULL; u8 *ptr = (u8*)IOS_Patch_Start;
while((u32)ptr < (0x94000000 - patch_size))
u32 level = IRQ_Disable();
while((u32)ptr < (u32)IOS_Patch_End)
{ {
if(memcmp(ptr, old, old_size) == 0) if(memcmp(ptr, old, size) == 0)
{ {
found = true; for(i = 0; i < size; ++i)
location = ptr + patch_offset; *(vu8*)(ptr+i) = *(vu8*)(patch+i);
u32 i; found++;
for(i = 0; i < patch_size; i++)
location[i] = patch[i];
DCFlushRange(location, patch_size);
break;
} }
ptr++; ptr++;
} }
if(found) IRQ_Restore(level);
gprintf("apply_patch '%s': found at %08x\n", name, ptr); usleep(1000);
else
gprintf("apply_patch '%s': not found\n", name); gprintf("patched %s %u times.\n", name, found);
return found; return (found > 0);
} }
const u8 isfs_permissions_old[] = { 0x42, 0x8B, 0xD0, 0x01, 0x25, 0x66 }; static const u8 isfs_perm_old[] = { 0x42, 0x8B, 0xD0, 0x01, 0x25, 0x66 };
const u8 isfs_permissions_patch[] = { 0x42, 0x8B, 0xE0, 0x01, 0x25, 0x66 }; static const u8 isfs_perm_patch[] = { 0x42, 0x8B, 0xE0, 0x01, 0x25, 0x66 };
static const u8 setuid_old[] = { 0xD1, 0x2A, 0x1C, 0x39 }; static const u8 setuid_old[] = { 0xD1, 0x2A, 0x1C, 0x39 };
static const u8 setuid_patch[] = { 0x46, 0xC0 }; static const u8 setuid_patch[] = { 0x46, 0xC0, 0x1C, 0x39 };
const u8 es_identify_old[] = { 0x28, 0x03, 0xD1, 0x23 }; static const u8 es_identify_old[] = { 0x28, 0x03, 0xD1, 0x23 };
const u8 es_identify_patch[] = { 0x00, 0x00 }; static const u8 es_identify_patch[] = { 0x28, 0x03, 0x00, 0x00 };
const u8 hash_old[] = { 0x20, 0x07, 0x23, 0xA2 }; static const u8 hash_old[] = { 0x20, 0x07, 0x23, 0xA2 };
const u8 hash_patch[] = { 0x00 }; static const u8 hash_patch[] = { 0x20, 0x00, 0x23, 0xA2 };
const u8 new_hash_old[] = { 0x20, 0x07, 0x4B, 0x0B }; static const u8 new_hash_old[] = { 0x20, 0x07, 0x4B, 0x0B };
static const u8 new_hash_patch[] = { 0x20, 0x00, 0x4B, 0x0B };
bool Patch_ISFS_Permission(bool enable) void PatchIOS(void)
{
/* Disable memory protection */
write16(MEM_PROT, 0);
/* Do Patches */
bool ret = false;
if(enable)
{
gprintf("Enabling ISFS Patches...\n");
ret = apply_patch("isfs_permissions", isfs_permissions_old, sizeof(isfs_permissions_old), isfs_permissions_patch, sizeof(isfs_permissions_patch), 0);
}
else /* Just revert it */
{
gprintf("Disabling ISFS Patches...\n");
ret = apply_patch("isfs_permissions", isfs_permissions_patch, sizeof(isfs_permissions_patch), isfs_permissions_old, sizeof(isfs_permissions_old), 0);
}
/* Enable memory protection */
write16(MEM_PROT, 1);
return ret;
}
void Patch_Channel_Boot(void)
{ {
/* Stop IOS from blocking shit */
__IOS_ShutdownSubsystems();
/* Disable memory protection */ /* Disable memory protection */
write16(MEM_PROT, 0); write16(MEM_PROT, 0);
/* Do Patching */ /* Do Patching */
apply_patch("es_setuid", setuid_old, sizeof(setuid_old), setuid_patch, sizeof(setuid_patch), 0); apply_patch("isfs_permissions", isfs_perm_old, isfs_perm_patch, sizeof(isfs_perm_patch));
apply_patch("es_identify", es_identify_old, sizeof(es_identify_old), es_identify_patch, sizeof(es_identify_patch), 2); apply_patch("es_setuid", setuid_old, setuid_patch, sizeof(setuid_patch));
apply_patch("hash_check", hash_old, sizeof(hash_old), hash_patch, sizeof(hash_patch), 1); apply_patch("es_identify", es_identify_old, es_identify_patch, sizeof(es_identify_patch));
apply_patch("new_hash_check", new_hash_old, sizeof(new_hash_old), hash_patch, sizeof(hash_patch), 1); apply_patch("hash_check", hash_old, hash_patch, sizeof(hash_patch));
apply_patch("new_hash_check", new_hash_old, new_hash_patch, sizeof(new_hash_patch));
/* Enable memory protection */ /* Enable memory protection */
write16(MEM_PROT, 1); write16(MEM_PROT, 1);
/* Restart our IOS stuff */
__IOS_InitializeSubsystems();
} }

View File

@ -6,8 +6,7 @@ extern "C"
#ifndef _PATCHER_H_ #ifndef _PATCHER_H_
#define _PATCHER_H_ #define _PATCHER_H_
bool Patch_ISFS_Permission(bool enable); void PatchIOS(void);
void Patch_Channel_Boot(void);
#endif #endif

View File

@ -72,10 +72,10 @@ void Nand::Init()
{ {
MountedDevice = 0; MountedDevice = 0;
EmuDevice = REAL_NAND; EmuDevice = REAL_NAND;
AccessPatched = false;
Partition = 0; Partition = 0;
FullMode = 0x100; FullMode = 0x100;
memset(NandPath, 0, sizeof(NandPath)); memset(NandPath, 0, sizeof(NandPath));
isfs_inited = false;
} }
bool Nand::LoadDefaultIOS(void) bool Nand::LoadDefaultIOS(void)
@ -1040,26 +1040,22 @@ s32 Nand::Do_Region_Change(string id)
void Nand::Init_ISFS() void Nand::Init_ISFS()
{ {
if(isfs_inited)
return;
if(IOS_GetVersion() < 222) if(IOS_GetVersion() < 222)
{ PatchIOS();
Patch_ISFS_Permission(true);
AccessPatched = true;
}
usleep(1000); usleep(1000);
gprintf("Init ISFS\n"); gprintf("Init ISFS\n");
ISFS_Initialize(); ISFS_Initialize();
isfs_inited = true;
} }
void Nand::DeInit_ISFS(bool KeepPatches) void Nand::DeInit_ISFS()
{ {
gprintf("Deinit ISFS\n"); gprintf("Deinit ISFS\n");
ISFS_Deinitialize(); ISFS_Deinitialize();
isfs_inited = false;
usleep(1000); usleep(1000);
if(AccessPatched && !KeepPatches)
{
Patch_ISFS_Permission(false);
AccessPatched = false;
}
} }
/* Thanks to postloader for that patch */ /* Thanks to postloader for that patch */

View File

@ -76,7 +76,7 @@ public:
void Patch_AHB(); void Patch_AHB();
void Init_ISFS(); void Init_ISFS();
void DeInit_ISFS(bool KeepPatches = false); void DeInit_ISFS();
const char *Get_NandPath(void) { return NandPath; }; const char *Get_NandPath(void) { return NandPath; };
u32 Get_Partition(void) { return Partition; }; u32 Get_Partition(void) { return Partition; };
@ -134,7 +134,7 @@ private:
u32 FoldersDone; u32 FoldersDone;
bool fake; bool fake;
bool showprogress; bool showprogress;
bool AccessPatched; bool isfs_inited;
void *data; void *data;
dump_callback_t dumper; dump_callback_t dumper;

View File

@ -75,7 +75,6 @@ bool NandSave::CheckSave()
if(certBuffer == NULL || certSize == 0) if(certBuffer == NULL || certSize == 0)
goto error; goto error;
/* Install tik and tmd */ /* Install tik and tmd */
Patch_Channel_Boot();
tik_bin = (const signed_blob*)u8_get_file(u8_bin, "tik.bin", &tik_bin_size); tik_bin = (const signed_blob*)u8_get_file(u8_bin, "tik.bin", &tik_bin_size);
if(tik_bin == NULL || tik_bin_size == 0) if(tik_bin == NULL || tik_bin_size == 0)
goto error; goto error;

View File

@ -80,9 +80,9 @@ bool loadIOS(int ios, bool MountDevices)
if(ios != CurIOS && IOS_GetType(ios) != IOS_TYPE_STUB) if(ios != CurIOS && IOS_GetType(ios) != IOS_TYPE_STUB)
{ {
WDVD_Close(); WDVD_Close();
NandHandle.Patch_AHB(); //No AHBPROT for the next IOS
gprintf("Reloading into IOS %i from %i...\n", ios, CurIOS); gprintf("Reloading into IOS %i from %i...\n", ios, CurIOS);
ShutdownBeforeExit(); ShutdownBeforeExit();
NandHandle.Patch_AHB(); //No AHBPROT for the next IOS
ret = IOS_ReloadIOS(ios) == 0; ret = IOS_ReloadIOS(ios) == 0;
gprintf("AHBPROT after IOS Reload: %u\n", AHBRPOT_Patched()); gprintf("AHBPROT after IOS Reload: %u\n", AHBRPOT_Patched());
NandHandle.Init_ISFS(); NandHandle.Init_ISFS();

View File

@ -72,8 +72,8 @@ int main(int argc, char **argv)
iosOK = loadIOS(IOS_GetVersion(), false); iosOK = loadIOS(IOS_GetVersion(), false);
else if(useMainIOS && CustomIOS(IOS_GetType(mainIOS))) /* Requested */ else if(useMainIOS && CustomIOS(IOS_GetType(mainIOS))) /* Requested */
iosOK = loadIOS(mainIOS, false) && CustomIOS(CurrentIOS.Type); iosOK = loadIOS(mainIOS, false) && CustomIOS(CurrentIOS.Type);
else /* safe reload to the default IOS */ else /* Keep our current IOS */
iosOK = NandHandle.LoadDefaultIOS(); iosOK = loadIOS(IOS_GetVersion(), false);
// Init // Init
Sys_Init(); Sys_Init();

View File

@ -28,6 +28,9 @@
#define Priiloader_CFG1 ((vu32*)0x8132FFFB) #define Priiloader_CFG1 ((vu32*)0x8132FFFB)
#define Priiloader_CFG2 ((vu32*)0x817FEFF0) #define Priiloader_CFG2 ((vu32*)0x817FEFF0)
#define IOS_Patch_Start ((vu32*)0x93400000)
#define IOS_Patch_End ((vu32*)0x94000000)
#define HW_GPIO_OUT ((vu32*)0xCD8000E0) #define HW_GPIO_OUT ((vu32*)0xCD8000E0)
#define HW_GPIOB_OUT ((vu32*)0xCD8000C0) #define HW_GPIOB_OUT ((vu32*)0xCD8000C0)
#define HW_AHBPROT ((vu32*)0xCD800064) #define HW_AHBPROT ((vu32*)0xCD800064)

View File

@ -1168,8 +1168,8 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
{ {
setLanguage(language); setLanguage(language);
ocarina_load_code(cheatFile, cheatSize); ocarina_load_code(cheatFile, cheatSize);
Patch_Channel_Boot(); /* Patch for everything */
NandHandle.Patch_AHB(); /* Identify may takes it */ NandHandle.Patch_AHB(); /* Identify may takes it */
PatchIOS(); /* Patch for everything */
Identify(gameTitle); Identify(gameTitle);
ExternalBooter_ChannelSetup(gameTitle, use_dol); ExternalBooter_ChannelSetup(gameTitle, use_dol);
WiiFlow_ExternalBooter(videoMode, vipatch, countryPatch, patchVidMode, aspectRatio, 0, TYPE_CHANNEL, use_led); WiiFlow_ExternalBooter(videoMode, vipatch, countryPatch, patchVidMode, aspectRatio, 0, TYPE_CHANNEL, use_led);