Skip to content

Commit

Permalink
Improve fsTryOpenFile pattern (fixes Zelda Triforce Heroes)
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraWright committed Apr 23, 2017
1 parent 2e561f7 commit 8d10225
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions injector/patches/romfsredir.s
Expand Up @@ -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
Expand Down Expand Up @@ -90,7 +90,7 @@ _start:

.pool
.align 4
archiveName : .dcb "lfs:"
archiveName : .dcb "lf:", 0
fsMountArchive : .word 0xdead0005
fsRegisterArchive : .word 0xdead0006
archiveId : .word 0xdead0007
Expand Down
11 changes: 5 additions & 6 deletions injector/source/patcher.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8d10225

Please sign in to comment.