Do the same for romfs redit => get rid of armips; update README.md
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include "memory.h"
|
||||
#include "strings.h"
|
||||
#include "fsldr.h"
|
||||
#include "../build/bundled.h"
|
||||
#include "romfsredir.h"
|
||||
|
||||
static u32 patchMemory(u8 *start, u32 size, const void *pattern, u32 patSize, s32 offset, const void *replace, u32 repSize, u32 count)
|
||||
{
|
||||
@@ -204,7 +204,7 @@ static inline bool findLayeredFsPayloadOffset(u8 *code, u32 size, u32 roSize, u3
|
||||
roundedDataSize = ((dataSize + 4095) & 0xFFFFF000);
|
||||
|
||||
//First check for sufficient padding at the end of the .text segment
|
||||
if(roundedTextSize - size >= romfsredir_bin_size) *payloadOffset = size;
|
||||
if(roundedTextSize - size >= romfsRedirPatchSize) *payloadOffset = size;
|
||||
else
|
||||
{
|
||||
//If there isn't enough padding look for the "throwFatalError" function to replace
|
||||
@@ -528,43 +528,18 @@ static inline bool patchLayeredFs(u64 progId, u8 *code, u32 size, u32 textSize,
|
||||
|
||||
//Setup the payload
|
||||
u8 *payload = code + payloadOffset;
|
||||
memcpy(payload, romfsredir_bin, romfsredir_bin_size);
|
||||
|
||||
//Insert symbols in the payload
|
||||
u32 *payload32 = (u32 *)payload;
|
||||
for(u32 i = 0; i < romfsredir_bin_size / 4; i++)
|
||||
{
|
||||
switch(payload32[i])
|
||||
{
|
||||
case 0xdead0000:
|
||||
payload32[i] = *(u32 *)(code + fsOpenFileDirectly);
|
||||
break;
|
||||
case 0xdead0001:
|
||||
payload32[i] = MAKE_BRANCH(payloadOffset + i * 4, fsOpenFileDirectly + 4);
|
||||
break;
|
||||
case 0xdead0002:
|
||||
payload32[i] = *(u32 *)(code + fsTryOpenFile);
|
||||
break;
|
||||
case 0xdead0003:
|
||||
payload32[i] = MAKE_BRANCH(payloadOffset + i * 4, fsTryOpenFile + 4);
|
||||
break;
|
||||
case 0xdead0004:
|
||||
payload32[i] = pathAddress;
|
||||
break;
|
||||
case 0xdead0005:
|
||||
payload32[i] = 0x100000 + fsMountArchive;
|
||||
break;
|
||||
case 0xdead0006:
|
||||
payload32[i] = 0x100000 + fsRegisterArchive;
|
||||
break;
|
||||
case 0xdead0007:
|
||||
payload32[i] = archiveId;
|
||||
break;
|
||||
case 0xdead0008:
|
||||
memcpy(payload32 + i, updateRomFsMounts[updateRomFsIndex], 4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
romfsRedirPatchSubstituted1 = *(u32 *)(code + fsOpenFileDirectly);
|
||||
romfsRedirPatchHook1 = MAKE_BRANCH(payloadOffset + (u32)&romfsRedirPatchHook1 - (u32)romfsRedirPatch, fsOpenFileDirectly + 4);
|
||||
romfsRedirPatchSubstituted1 = *(u32 *)(code + fsTryOpenFile);
|
||||
romfsRedirPatchHook2 = MAKE_BRANCH(payloadOffset + (u32)&romfsRedirPatchHook2 - (u32)romfsRedirPatch, fsTryOpenFile + 4);
|
||||
romfsRedirPatchCustomPath = pathAddress;
|
||||
romfsRedirPatchFsMountArchive = 0x100000 + fsMountArchive;
|
||||
romfsRedirPatchFsRegisterArchive = 0x100000 + fsRegisterArchive;
|
||||
romfsRedirPatchArchiveId = archiveId;
|
||||
memcpy(&romfsRedirPatchRomFsMount, updateRomFsMounts[updateRomFsIndex], 4);
|
||||
|
||||
memcpy(payload, romfsRedirPatch, romfsRedirPatchSize);
|
||||
|
||||
memcpy(code + pathOffset, "lf:", 3);
|
||||
memcpy(code + pathOffset + 3, path, sizeof(path));
|
||||
|
||||
17
sysmodules/loader/source/romfsredir.h
Normal file
17
sysmodules/loader/source/romfsredir.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
|
||||
extern const u8 romfsRedirPatch[];
|
||||
extern const u32 romfsRedirPatchSize;
|
||||
|
||||
extern u32 romfsRedirPatchSubstituted1, romfsRedirPatchHook1;
|
||||
extern u32 romfsRedirPatchSubstituted2, romfsRedirPatchHook2;
|
||||
|
||||
extern u32 romfsRedirPatchArchiveName;
|
||||
extern u32 romfsRedirPatchFsMountArchive;
|
||||
extern u32 romfsRedirPatchFsRegisterArchive;
|
||||
extern u32 romfsRedirPatchArchiveId;
|
||||
extern u32 romfsRedirPatchRomFsMount;
|
||||
extern u32 romfsRedirPatchUpdateRomFsMount;
|
||||
extern u32 romfsRedirPatchCustomPath;
|
||||
130
sysmodules/loader/source/romfsredir.s
Normal file
130
sysmodules/loader/source/romfsredir.s
Normal file
@@ -0,0 +1,130 @@
|
||||
@ Patch by delebile
|
||||
|
||||
.section .data.romfsRedirPatch, "aw", %progbits
|
||||
.align 4
|
||||
|
||||
.global romfsRedirPatch
|
||||
romfsRedirPatch:
|
||||
@ Jumps here before the fsOpenFileDirectly call
|
||||
_mountArchive:
|
||||
b mountArchive
|
||||
.global romfsRedirPatchSubstituted1
|
||||
romfsRedirPatchSubstituted1:
|
||||
.word 0xdead0000 @ Substituted opcode
|
||||
.global romfsRedirPatchHook1
|
||||
romfsRedirPatchHook1:
|
||||
.word 0xdead0001 @ Branch to hooked function
|
||||
|
||||
@ Jumps here before every iFileOpen call
|
||||
_fsRedir:
|
||||
b fsRedir
|
||||
.global romfsRedirPatchSubstituted2
|
||||
romfsRedirPatchSubstituted2:
|
||||
.word 0xdead0002 @ Substituted opcode
|
||||
.global romfsRedirPatchHook2
|
||||
romfsRedirPatchHook2:
|
||||
.word 0xdead0002 @ Branch to hooked function
|
||||
|
||||
@ Mounts the archive and registers it as 'lf:'
|
||||
mountArchive:
|
||||
cmp r3, #3
|
||||
bne romfsRedirPatchSubstituted1
|
||||
stmfd sp!, {r0-r4, lr}
|
||||
sub sp, sp, #4
|
||||
adr r1, romfsRedirPatchArchiveId
|
||||
mov r0, sp
|
||||
ldr r4, romfsRedirPatchFsMountArchive
|
||||
blx r4
|
||||
mov r3, #0
|
||||
mov r2, #0
|
||||
ldr r1, [sp]
|
||||
adr r0, romfsRedirPatchArchiveName
|
||||
ldr r4, romfsRedirPatchFsRegisterArchive
|
||||
blx r4
|
||||
add sp, sp, #4
|
||||
ldmfd sp!, {r0-r4, lr}
|
||||
b romfsRedirPatchSubstituted1
|
||||
|
||||
@ Check the path passed to iFileOpen.
|
||||
@ If it is trying to access a RomFS file, we try to
|
||||
@ open it from the LayeredFS folder.
|
||||
@ If the file cannot be opened, we just open
|
||||
@ it from its original archive like nothing happened
|
||||
fsRedir:
|
||||
stmfd sp!, {r0-r12, lr}
|
||||
adr r3, romfsRedirPatchRomFsMount
|
||||
bl compare
|
||||
adrne r3, romfsRedirPatchUpdateRomFsMount
|
||||
blne compare
|
||||
bne endRedir
|
||||
sub sp, sp, #0x400
|
||||
pathRedir:
|
||||
stmfd sp!, {r0-r3}
|
||||
add r0, sp, #0x10
|
||||
ldr r3, romfsRedirPatchCustomPath
|
||||
pathRedir_1:
|
||||
ldrb r2, [r3], #1
|
||||
cmp r2, #0
|
||||
strneh r2, [r0], #2
|
||||
bne pathRedir_1
|
||||
pathRedir_2:
|
||||
ldrh r2, [r1], #2
|
||||
cmp r2, #0x3A @ ':'
|
||||
bne pathRedir_2
|
||||
@ Skip a slash if there are two after the mountpoint,
|
||||
@ as some games mistakenly have those
|
||||
ldrh r3, [r1, #2]
|
||||
cmp r3, #0x2F @ '/'
|
||||
pathRedir_3:
|
||||
ldrh r2, [r1], #2
|
||||
strneh r2, [r0], #2
|
||||
cmp r2, #0
|
||||
bne pathRedir_3
|
||||
ldmfd sp!, {r0-r3}
|
||||
mov r1, sp
|
||||
bl romfsRedirPatchSubstituted2
|
||||
add sp, sp, #0x400
|
||||
cmp r0, #0
|
||||
|
||||
endRedir:
|
||||
ldmfd sp!, {r0-r12, lr}
|
||||
moveq r0, #0
|
||||
bxeq lr
|
||||
b romfsRedirPatchSubstituted2
|
||||
|
||||
compare:
|
||||
mov r9, r1
|
||||
add r10, r3, #4
|
||||
loop:
|
||||
ldrb r12, [r3], #1
|
||||
ldrb r11, [r9], #2
|
||||
cmp r11, r12
|
||||
bxne lr
|
||||
cmp r10, r3
|
||||
bne loop
|
||||
bx lr
|
||||
|
||||
.pool
|
||||
.balign 4
|
||||
|
||||
.global romfsRedirPatchArchiveName
|
||||
.global romfsRedirPatchFsMountArchive
|
||||
.global romfsRedirPatchFsRegisterArchive
|
||||
.global romfsRedirPatchArchiveId
|
||||
.global romfsRedirPatchRomFsMount
|
||||
.global romfsRedirPatchUpdateRomFsMount
|
||||
.global romfsRedirPatchCustomPath
|
||||
|
||||
romfsRedirPatchArchiveName : .ascii "lf:\0"
|
||||
romfsRedirPatchFsMountArchive : .word 0xdead0005
|
||||
romfsRedirPatchFsRegisterArchive : .word 0xdead0006
|
||||
romfsRedirPatchArchiveId : .word 0xdead0007
|
||||
romfsRedirPatchRomFsMount : .ascii "rom:"
|
||||
romfsRedirPatchUpdateRomFsMount : .word 0xdead0008
|
||||
romfsRedirPatchCustomPath : .word 0xdead0004
|
||||
|
||||
_romfsRedirPatchEnd:
|
||||
|
||||
.global romfsRedirPatchSize
|
||||
romfsRedirPatchSize:
|
||||
.word _romfsRedirPatchEnd - romfsRedirPatch
|
||||
Reference in New Issue
Block a user