From 8d102256a2cc39b29908da7583d7138fdefbb360 Mon Sep 17 00:00:00 2001 From: Aurora Wright Date: Sun, 23 Apr 2017 18:44:46 +0200 Subject: [PATCH] Improve fsTryOpenFile pattern (fixes Zelda Triforce Heroes) --- injector/patches/romfsredir.s | 4 ++-- injector/source/patcher.c | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/injector/patches/romfsredir.s b/injector/patches/romfsredir.s index 0636829..cc817ea 100644 --- a/injector/patches/romfsredir.s +++ b/injector/patches/romfsredir.s @@ -25,7 +25,7 @@ _start: .word 0xdead0002 ; Substituted opcode .word 0xdead0003 ; Branch to hooked function - ; Mounts the archive and registers it as 'lfs:' + ; Mounts the archive and registers it as 'lf:' mountArchive: cmp r3, #3 bne _mountArchive + 4 @@ -90,7 +90,7 @@ _start: .pool .align 4 - archiveName : .dcb "lfs:" + archiveName : .dcb "lf:", 0 fsMountArchive : .word 0xdead0005 fsRegisterArchive : .word 0xdead0006 archiveId : .word 0xdead0007 diff --git a/injector/source/patcher.c b/injector/source/patcher.c index 7743b17..152c6b3 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -310,9 +310,8 @@ static inline bool findLayeredFsSymbols(u8* code, u32 size, u32 *fsMountArchive, if(addr <= size - 12 && *fsRegisterArchive == 0xFFFFFFFF && *(u32 *)(code + addr) == 0xE3500008 && (*(u32 *)(code + addr + 4) & 0xFFF00FF0) == 0xE1800400 && (*(u32 *)(code + addr + 8) & 0xFFF00FF0) == 0xE1800FC0) *fsRegisterArchive = findFunctionStart(code, addr); - if(addr <= size - 16 && *fsTryOpenFile == 0xFFFFFFFF && *(u32 *)(code + addr + 0xC) == 0xE12FFF3C && - ((*(u32 *)(code + addr) == 0xE1A0100D) || (*(u32 *)(code + addr) == 0xE28D1010)) && (*(u32 *)(code + addr + 4) == 0xE590C000) && - ((*(u32 *)(code + addr + 8) == 0xE1A00004) || (*(u32 *)(code + addr + 8) == 0xE1A00005))) + if(addr <= size - 0x40 && *fsTryOpenFile == 0xFFFFFFFF && *(u32 *)(code + addr + 4) == 0x1AFFFFFC && *(u32 *)(code + addr) == 0xE351003A && + *(u32 *)(code + addr + 0x34) == 0xE590C000 && *(u32 *)(code + addr + 0x3C) == 0xE12FFF3C) *fsTryOpenFile = findFunctionStart(code, addr); if(*fsOpenFileDirectly == 0xFFFFFFFF && *(u32 *)(code + addr) == 0x08030204) @@ -520,7 +519,7 @@ static inline bool patchLayeredFs(u64 progId, u8* code, u32 size) if(!archiveId) return true; - static const char *archiveName = "lfs:"; + static const char *archiveName = "lf:"; u32 fsMountArchive = 0xFFFFFFFF, fsRegisterArchive = 0xFFFFFFFF, @@ -554,8 +553,8 @@ static inline bool patchLayeredFs(u64 progId, u8* code, u32 size) payload32[i] = MAKE_BRANCH(payloadOffset + i * 4, fsTryOpenFile + 4); break; case 0xdead0004: - memcpy(payload32 + i, archiveName, 4); - memcpy((u8 *)(payload32 + i) + 4, path, sizeof(path)); + memcpy(payload32 + i, archiveName, 3); + memcpy((u8 *)(payload32 + i) + 3, path, sizeof(path)); break; case 0xdead0005: payload32[i] = 0x100000 + fsMountArchive;