diff --git a/Makefile.main b/Makefile.main index fe9b1831..a231267d 100644 --- a/Makefile.main +++ b/Makefile.main @@ -115,8 +115,7 @@ export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ $(sFILES:.s=.o) $(SFILES:.S=.o) \ $(PNGFILES:.png=.png.o) $(JPGFILES:.jpg=.jpg.o) \ $(OGGFILES:.ogg=.ogg.o) $(TXTFILES:.txt=.txt.o) \ - $(WAVFILES:.wav=.wav.o) $(addsuffix .o,$(BINFILES)) \ - $(CURDIR)/data/binary/magic_patcher.o + $(WAVFILES:.wav=.wav.o) $(addsuffix .o,$(BINFILES)) #--------------------------------------------------------------------------------- # build a list of include paths diff --git a/data/binary/magic_patcher.o b/data/binary/magic_patcher.o deleted file mode 100644 index a7de9a03..00000000 Binary files a/data/binary/magic_patcher.o and /dev/null differ diff --git a/source/channel/identify.c b/source/channel/identify.c new file mode 100644 index 00000000..d9a668f0 --- /dev/null +++ b/source/channel/identify.c @@ -0,0 +1,47 @@ + +/* Code from postloader - thanks to stfour */ + +#include +#include +#include + +#include "identify.h" + +const u8 isfs_permissions_old[] = { 0x42, 0x8B, 0xD0, 0x01, 0x25, 0x66 }; +const u8 isfs_permissions_patch[] = { 0x42, 0x8B, 0xE0, 0x01, 0x25, 0x66 }; + +static bool apply_patch(const u8 *old, u32 old_size, const u8 *patch, u32 patch_size) +{ + u8 *ptr = (u8*)0x93A00000; + bool found = false; + u8 *location = NULL; + while((u32)ptr < 0x93B00000) + { + if(!memcmp(ptr, old, old_size)) + { + found = true; + location = ptr; + u8 *start = location; + u32 i; + for(i = 0; i < patch_size; i++) + { + *location = patch[i]; + location++; + } + DCFlushRange((u8 *)(((u32)start) >> 5 << 5), (patch_size >> 5 << 5) + 64); + break; + } + ptr++; + } + return found; +} + +bool Patch_ISFS_Permission(bool enable) +{ + if(enable) + return apply_patch(isfs_permissions_old, sizeof(isfs_permissions_old), + isfs_permissions_patch, sizeof(isfs_permissions_patch)); + else /* Just revert it */ + return apply_patch(isfs_permissions_patch, sizeof(isfs_permissions_patch), + isfs_permissions_old, sizeof(isfs_permissions_old)); +} diff --git a/source/channel/identify.h b/source/channel/identify.h new file mode 100644 index 00000000..8ddc4e14 --- /dev/null +++ b/source/channel/identify.h @@ -0,0 +1,15 @@ +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifndef _PATCHER_H_ +#define _PATCHER_H_ + +bool Patch_ISFS_Permission(bool enable); + +#endif + +#ifdef __cplusplus +} +#endif diff --git a/source/channel/nand.cpp b/source/channel/nand.cpp index 03c27df1..41bcf2d3 100644 --- a/source/channel/nand.cpp +++ b/source/channel/nand.cpp @@ -36,6 +36,7 @@ #include #include "nand.hpp" +#include "identify.h" #include "fileOps/fileOps.h" #include "gecko/gecko.h" #include "loader/alt_ios.h" @@ -1049,18 +1050,30 @@ s32 Nand::Do_Region_Change(string id) return 1; } -extern "C" { extern s32 MagicPatches(s32); } - void Nand::Enable_ISFS_Patches(void) { if(AHBRPOT_Patched()) - gprintf("Enabling ISFS Patches: %i\n", MagicPatches(1)); + { + // Disable memory protection + write16(MEM_PROT, 0); + // Do patches + gprintf("Enabling ISFS Patches: %d\n", Patch_ISFS_Permission(true)); + // Enable memory protection + write16(MEM_PROT, 1); + } } void Nand::Disable_ISFS_Patches(void) { if(AHBRPOT_Patched()) - gprintf("Disabling ISFS Patches: %i\n", MagicPatches(0)); + { + // Disable memory protection + write16(MEM_PROT, 0); + // Do patches + gprintf("Disabling ISFS Patches: %d\n", Patch_ISFS_Permission(false)); + // Enable memory protection + write16(MEM_PROT, 1); + } } void Nand::Init_ISFS()