Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5aa63936c | ||
|
|
62a57d0f47 | ||
|
|
958fb4c739 | ||
|
|
e231275cbe | ||
|
|
5a404c3a35 | ||
|
|
b1c07c6204 | ||
|
|
60f158d488 | ||
|
|
1887c6fae3 | ||
|
|
725a825762 | ||
|
|
b81f59d5ae | ||
|
|
39c2b8927b | ||
|
|
89dfdac7bf | ||
|
|
c087edf2ba | ||
|
|
db33c315f2 | ||
|
|
c7e7dd8248 | ||
|
|
b10d82a883 | ||
|
|
e151b3d4ef | ||
|
|
5ccf4a45c1 | ||
|
|
c5369a5cad | ||
|
|
b5eba765a5 | ||
|
|
a5ddc38477 | ||
|
|
8d102256a2 | ||
|
|
2e561f7ea9 | ||
|
|
9656fe1b6f | ||
|
|
48c23f2a43 |
10
.github/ISSUE_TEMPLATE.md
vendored
10
.github/ISSUE_TEMPLATE.md
vendored
@@ -2,18 +2,12 @@
|
||||
#
|
||||
# THIS IS NOT A SUPPORT FORUM! For support please go to:
|
||||
# Luma3DS GBATemp thread: https://gbatemp.net/threads/luma3ds-noob-proof-3ds-custom-firmware.411110/
|
||||
# /r/3dshacks: http://reddit.com/r/3dshacks/
|
||||
# Nintendo Hacking: https://discordapp.com/invite/C29hYvh
|
||||
# IRC: #3dshacks@rizon
|
||||
# Nintendo Hacking: https://discord.gg/MjzatM8y
|
||||
#
|
||||
# Also check the Wiki (https://github.com/AuroraWright/Luma3DS/wiki) before making an issue.
|
||||
#
|
||||
# For those with GBA/DSiWare/DS/AGB_FIRM/TWL_FIRM problems: https://3ds.guide/troubleshooting
|
||||
#
|
||||
# Please make sure to read "Enable region/language emulation and external .code" https://github.com/AuroraWright/Luma3DS/wiki/Options-and-usage before posting any issues about the "Enable region/language emulation and external .code" option(s).
|
||||
# Keep in mind that Wiki page only applies to nightly builds. It will NOT WORK with 6.6 Stable Luma3DS.
|
||||
# As of 0.02 (https://github.com/Possum/LumaLocaleSwitcher/releases) LumaLocaleSwitcher's path(s) are for 6.6 Stable and won't work with Luma3DS nightly builds newer or equal to https://github.com/AuroraWright/Luma3DS/commit/b5336c81cc82b6c5e8115249342beb5b065cdce9.
|
||||
# Use this version for Luma3DS nightlies newer or equal to https://github.com/AuroraWright/Luma3DS/commit/b5336c81cc82b6c5e8115249342beb5b065cdce9 :
|
||||
# https://puu.sh/uC5zW/5470adc347.7z (from https://github.com/Possum/LumaLocaleSwitcher/issues/9#issuecomment-285564014)
|
||||
# Please make sure to read "Enable game patching" https://github.com/AuroraWright/Luma3DS/wiki/Options-and-usage before posting any issues about the "Enable game patching" option(s).
|
||||
#
|
||||
-->
|
||||
|
||||
@@ -2050,7 +2050,8 @@ FRESULT load_obj_dir (
|
||||
dp->obj.fs = obj->fs;
|
||||
dp->obj.sclust = obj->c_scl;
|
||||
dp->obj.stat = (BYTE)obj->c_size;
|
||||
dp->obj.objsize = obj->c_size & 0xFFFFFF00;
|
||||
dp->obj.objsize = obj->c_size & 0xFFFFFF00;
|
||||
dp->obj.n_frag = 0;
|
||||
dp->blk_ofs = obj->c_ofs;
|
||||
|
||||
res = dir_sdi(dp, dp->blk_ofs); /* Goto object's entry block */
|
||||
@@ -2326,19 +2327,22 @@ FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too many S
|
||||
if (res != FR_OK) return res;
|
||||
dp->blk_ofs = dp->dptr - SZDIRE * (nent - 1); /* Set the allocated entry block offset */
|
||||
|
||||
if (dp->obj.sclust != 0 && (dp->obj.stat & 4)) { /* Has the sub-directory been stretched? */
|
||||
dp->obj.objsize += (DWORD)fs->csize * SS(fs); /* Increase the directory size by cluster size */
|
||||
res = fill_first_frag(&dp->obj); /* Fill first fragment on the FAT if needed */
|
||||
if (res != FR_OK) return res;
|
||||
res = fill_last_frag(&dp->obj, dp->clust, 0xFFFFFFFF); /* Fill last fragment on the FAT if needed */
|
||||
if (res != FR_OK) return res;
|
||||
res = load_obj_dir(&dj, &dp->obj); /* Load the object status */
|
||||
if (res != FR_OK) return res;
|
||||
st_qword(fs->dirbuf + XDIR_FileSize, dp->obj.objsize); /* Update the allocation status */
|
||||
st_qword(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize);
|
||||
fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1;
|
||||
res = store_xdir(&dj); /* Store the object status */
|
||||
if (dp->obj.stat & 4) { /* Has the directory been stretched? */
|
||||
dp->obj.stat &= ~4;
|
||||
res = fill_first_frag(&dp->obj); /* Fill the first fragment on the FAT if needed */
|
||||
if (res != FR_OK) return res;
|
||||
res = fill_last_frag(&dp->obj, dp->clust, 0xFFFFFFFF); /* Fill the last fragment on the FAT if needed */
|
||||
if (res != FR_OK) return res;
|
||||
if (dp->obj.sclust != 0) { /* Is it a sub directory? */
|
||||
res = load_obj_dir(&dj, &dp->obj); /* Load the object status */
|
||||
if (res != FR_OK) return res;
|
||||
dp->obj.objsize += (DWORD)fs->csize * SS(fs); /* Increase the directory size by cluster size */
|
||||
st_qword(fs->dirbuf + XDIR_FileSize, dp->obj.objsize); /* Update the allocation status */
|
||||
st_qword(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize);
|
||||
fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1;
|
||||
res = store_xdir(&dj); /* Store the object status */
|
||||
if (res != FR_OK) return res;
|
||||
}
|
||||
}
|
||||
|
||||
create_xdir(fs->dirbuf, fs->lfnbuf); /* Create on-memory directory block to be written later */
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
_start:
|
||||
|
||||
; Jumps here before the fsOpenFileDirectly call
|
||||
_mountSd:
|
||||
b mountSd
|
||||
_mountArchive:
|
||||
b mountArchive
|
||||
.word 0xdead0000 ; Substituted opcode
|
||||
.word 0xdead0001 ; Branch to hooked function
|
||||
|
||||
@@ -25,42 +25,43 @@ _start:
|
||||
.word 0xdead0002 ; Substituted opcode
|
||||
.word 0xdead0003 ; Branch to hooked function
|
||||
|
||||
; Mounts SDMC and registers the archive as 'sdmc:'
|
||||
mountSd:
|
||||
; Mounts the archive and registers it as 'lf:'
|
||||
mountArchive:
|
||||
cmp r3, #3
|
||||
bne _mountSd+4
|
||||
bne _mountArchive + 4
|
||||
stmfd sp!, {r0-r4, lr}
|
||||
sub sp, sp, #4
|
||||
load r1, archive
|
||||
load r1, archiveId
|
||||
mov r0, sp
|
||||
load r4, fsMountArchive
|
||||
blx r4
|
||||
mov r3, #0
|
||||
mov r2, #0
|
||||
ldr r1, [sp]
|
||||
addr r0, sdmcArchiveName
|
||||
addr r0, archiveName
|
||||
load r4, fsRegisterArchive
|
||||
blx r4
|
||||
add sp, sp, #4
|
||||
ldmfd sp!, {r0-r4, lr}
|
||||
b _mountSd+4
|
||||
b _mountArchive + 4
|
||||
|
||||
; Check the path passed to iFileOpen.
|
||||
; If it is trying to access a RomFS file, we try to
|
||||
; open it from the title folder on the sdcard.
|
||||
; If the file cannot be opened from the sdcard, we just open
|
||||
; 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}
|
||||
ldrb r12, [r1]
|
||||
cmp r12, #0x72 ; 'r', should include "rom:" and "rom2:"
|
||||
cmpne r12, #0x70 ; 'p', should include "patch:"
|
||||
bne endRedir
|
||||
addr r3, romFsMount
|
||||
bl compare
|
||||
addne r3, pc, #updateRomFsMount-.-8
|
||||
blne compare
|
||||
bne endRedir
|
||||
sub sp, sp, #0x400
|
||||
pathRedir:
|
||||
stmfd sp!, {r0-r3}
|
||||
add r0, sp, #0x10
|
||||
addr r3, sdmcCustomPath
|
||||
load r3, customPath
|
||||
pathRedir_1:
|
||||
ldrb r2, [r3], #1
|
||||
strh r2, [r0], #2
|
||||
@@ -69,7 +70,7 @@ _start:
|
||||
sub r0, r0, #2
|
||||
pathRedir_2:
|
||||
ldrh r2, [r1], #2
|
||||
cmp r2, #0x3A ; ':'
|
||||
cmp r2, #0x3A ; ':'
|
||||
bne pathRedir_2
|
||||
pathRedir_3:
|
||||
ldrh r2, [r1], #2
|
||||
@@ -78,7 +79,7 @@ _start:
|
||||
bne pathRedir_3
|
||||
ldmfd sp!, {r0-r3}
|
||||
mov r1, sp
|
||||
bl _fsRedir+4
|
||||
bl _fsRedir + 4
|
||||
add sp, sp, #0x400
|
||||
cmp r0, #0
|
||||
|
||||
@@ -86,16 +87,28 @@ _start:
|
||||
ldmfd sp!, {r0-r12, lr}
|
||||
moveq r0, #0
|
||||
bxeq lr
|
||||
b _fsRedir+4
|
||||
b _fsRedir + 4
|
||||
|
||||
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
|
||||
.align 4
|
||||
sdmcArchiveName : .word 0xdead0007
|
||||
.dcb ":", 0
|
||||
.align 4
|
||||
fsMountArchive : .word 0xdead0005
|
||||
fsRegisterArchive : .word 0xdead0006
|
||||
archive : .word 0xdead0008
|
||||
sdmcCustomPath : .word 0xdead0004
|
||||
archiveName : .dcb "lf:", 0
|
||||
fsMountArchive : .word 0xdead0005
|
||||
fsRegisterArchive : .word 0xdead0006
|
||||
archiveId : .word 0xdead0007
|
||||
romFsMount : .dcb "rom:"
|
||||
updateRomFsMount : .word 0xdead0008
|
||||
customPath : .word 0xdead0004
|
||||
|
||||
.close
|
||||
|
||||
@@ -163,19 +163,4 @@ Result FSLDR_OpenDirectory(Handle* out, FS_Archive archive, FS_Path path)
|
||||
if(out) *out = cmdbuf[3];
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result FSDIRLDR_Close(Handle handle)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x802,0,0); // 0x8020000
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(handle))) return ret;
|
||||
|
||||
ret = cmdbuf[1];
|
||||
if(R_SUCCEEDED(ret)) ret = svcCloseHandle(handle);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -9,5 +9,4 @@ Result FSLDR_SetPriority(u32 priority);
|
||||
Result FSLDR_OpenFileDirectly(Handle* out, FS_ArchiveID archiveId, FS_Path archivePath, FS_Path filePath, u32 openFlags, u32 attributes);
|
||||
Result FSLDR_OpenArchive(FS_Archive* archive, FS_ArchiveID id, FS_Path path);
|
||||
Result FSLDR_CloseArchive(FS_Archive archive);
|
||||
Result FSLDR_OpenDirectory(Handle* out, FS_Archive archive, FS_Path path);
|
||||
Result FSDIRLDR_Close(Handle handle);
|
||||
Result FSLDR_OpenDirectory(Handle* out, FS_Archive archive, FS_Path path);
|
||||
@@ -158,7 +158,7 @@ static Result load_code(u64 progid, prog_addrs_t *shared, u64 prog_handle, int i
|
||||
u16 progver = g_exheader.codesetinfo.flags.remasterversion[0] | (g_exheader.codesetinfo.flags.remasterversion[1] << 8);
|
||||
|
||||
// patch
|
||||
patchCode(progid, progver, (u8 *)shared->text_addr, shared->total_size << 12, g_exheader.codesetinfo.text.codesize, g_exheader.codesetinfo.ro.codesize);
|
||||
patchCode(progid, progver, (u8 *)shared->text_addr, shared->total_size << 12, g_exheader.codesetinfo.text.codesize, g_exheader.codesetinfo.ro.codesize, g_exheader.codesetinfo.data.codesize, g_exheader.codesetinfo.ro.address, g_exheader.codesetinfo.data.address);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ static u32 dirCheck(FS_ArchiveID archiveId, const char *path)
|
||||
else
|
||||
{
|
||||
ret = R_SUCCEEDED(FSLDR_OpenDirectory(&handle, archive, dirPath)) ? 0 : 2;
|
||||
if(ret) FSDIRLDR_Close(handle);
|
||||
if(!ret) FSDIR_Close(handle);
|
||||
FSLDR_CloseArchive(archive);
|
||||
}
|
||||
|
||||
@@ -87,8 +87,7 @@ static inline void loadCFWInfo(void)
|
||||
svcGetCFWInfo(&info);
|
||||
|
||||
IFile file;
|
||||
if(LOADERFLAG(ISSAFEMODE) && R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, "/", FS_OPEN_READ))) //Init SD card if SAFE_MODE is being booted
|
||||
IFile_Close(&file);
|
||||
if(LOADERFLAG(ISSAFEMODE)) fileOpen(&file, ARCHIVE_SDMC, "/", FS_OPEN_READ); //Init SD card if SAFE_MODE is being booted
|
||||
|
||||
infoLoaded = true;
|
||||
}
|
||||
@@ -187,17 +186,16 @@ static inline u8 *getCfgOffsets(u8 *code, u32 size, u32 *CFGUHandleOffset)
|
||||
|
||||
for(u8 *CFGU_GetConfigInfoBlk2_endPos = code; CFGU_GetConfigInfoBlk2_endPos <= code + size - 12; CFGU_GetConfigInfoBlk2_endPos += 4)
|
||||
{
|
||||
static const u32 CFGU_GetConfigInfoBlk2_endPattern[] = {0xE8BD8010, 0x00010082};
|
||||
|
||||
//There might be multiple implementations of GetConfigInfoBlk2 but let's search for the one we want
|
||||
u32 *cmp = (u32 *)CFGU_GetConfigInfoBlk2_endPos;
|
||||
|
||||
if(cmp[0] != CFGU_GetConfigInfoBlk2_endPattern[0] || cmp[1] != CFGU_GetConfigInfoBlk2_endPattern[1]) continue;
|
||||
if(cmp[0] != 0xE8BD8010 || cmp[1] != 0x00010082) continue;
|
||||
|
||||
for(u32 i = 0; i < n; i++)
|
||||
if(possible[i] == cmp[2])
|
||||
{
|
||||
*CFGUHandleOffset = cmp[2];
|
||||
|
||||
return CFGU_GetConfigInfoBlk2_endPos;
|
||||
}
|
||||
|
||||
@@ -257,14 +255,12 @@ static inline void patchCfgGetRegion(u8 *code, u32 size, u8 regionId, u32 CFGUHa
|
||||
{
|
||||
for(u8 *cmdPos = code; cmdPos <= code + size - 28; cmdPos += 4)
|
||||
{
|
||||
static const u32 cfgSecureInfoGetRegionCmdPattern[] = {0xEE1D0F70, 0xE3A00802};
|
||||
|
||||
u32 *cmp = (u32 *)cmdPos;
|
||||
|
||||
if(*cmp != cfgSecureInfoGetRegionCmdPattern[1]) continue;
|
||||
if(*cmp != 0xE3A00802) continue;
|
||||
|
||||
for(u32 i = 1; i < 3; i++)
|
||||
if((*(cmp - i) & 0xFFFF0FFF) == cfgSecureInfoGetRegionCmdPattern[0] && *((u16 *)cmdPos + 5) == 0xE59F &&
|
||||
if((*(cmp - i) & 0xFFFF0FFF) == 0xEE1D0F70 && *((u16 *)cmdPos + 5) == 0xE59F &&
|
||||
*(u32 *)(cmdPos + 16 + *((u16 *)cmdPos + 4)) == CFGUHandleOffset)
|
||||
{
|
||||
cmp[3] = 0xE3A00000 | regionId; //mov r0, =regionId
|
||||
@@ -278,7 +274,7 @@ static inline void patchCfgGetRegion(u8 *code, u32 size, u8 regionId, u32 CFGUHa
|
||||
}
|
||||
}
|
||||
|
||||
static u32 findFunctionStart(u8* code, u32 pos)
|
||||
static u32 findFunctionStart(u8 *code, u32 pos)
|
||||
{
|
||||
while(pos >= 4)
|
||||
{
|
||||
@@ -289,81 +285,117 @@ static u32 findFunctionStart(u8* code, u32 pos)
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
static inline bool findLayeredFsSymbols(u8* code, u32 size, u32 *fsMountArchive, u32 *fsRegisterArchive, u32 *fsTryOpenFile, u32 *fsOpenFileDirectly)
|
||||
static inline bool findLayeredFsSymbols(u8 *code, u32 size, u32 *fsMountArchive, u32 *fsRegisterArchive, u32 *fsTryOpenFile, u32 *fsOpenFileDirectly)
|
||||
{
|
||||
u32 found = 0,
|
||||
*temp = NULL;
|
||||
|
||||
for(u32 addr = 0; addr <= size - 4; addr += 4)
|
||||
{
|
||||
if(*fsMountArchive == 0xFFFFFFFF)
|
||||
u32 *addr32 = (u32 *)(code + addr);
|
||||
|
||||
switch(*addr32)
|
||||
{
|
||||
if(addr <= size - 12 && *(u32 *)(code + addr) == 0xE5970010)
|
||||
{
|
||||
if((*(u32 *)(code + addr + 4) == 0xE1CD20D8) && ((*(u32 *)(code + addr + 8) & 0xFFFFFF) == 0x008D0000))
|
||||
*fsMountArchive = findFunctionStart(code, addr);
|
||||
}
|
||||
else if(addr <= size - 16 && *(u32 *)(code + addr) == 0xE24DD028)
|
||||
{
|
||||
if((*(u32 *)(code + addr + 4) == 0xE1A04000) && (*(u32 *)(code + addr + 8) == 0xE59F60A8) && (*(u32 *)(code + addr + 0xC) == 0xE3A0C001))
|
||||
*fsMountArchive = findFunctionStart(code, addr);
|
||||
}
|
||||
case 0xE5970010:
|
||||
if(addr <= size - 12 && *fsMountArchive == 0xFFFFFFFF && addr32[1] == 0xE1CD20D8 && (addr32[2] & 0xFFFFFF) == 0x008D0000) temp = fsMountArchive;
|
||||
break;
|
||||
case 0xE24DD028:
|
||||
if(addr <= size - 16 && *fsMountArchive == 0xFFFFFFFF && addr32[1] == 0xE1A04000 && addr32[2] == 0xE59F60A8 && addr32[3] == 0xE3A0C001) temp = fsMountArchive;
|
||||
break;
|
||||
case 0xE3500008:
|
||||
if(addr <= size - 12 && *fsRegisterArchive == 0xFFFFFFFF && (addr32[1] & 0xFFF00FF0) == 0xE1800400 && (addr32[2] & 0xFFF00FF0) == 0xE1800FC0) temp = fsRegisterArchive;
|
||||
break;
|
||||
case 0xE351003A:
|
||||
if(addr <= size - 0x40 && *fsTryOpenFile == 0xFFFFFFFF && addr32[1] == 0x1AFFFFFC && addr32[0xD] == 0xE590C000 && addr32[0xF] == 0xE12FFF3C) temp = fsTryOpenFile;
|
||||
break;
|
||||
case 0x08030204:
|
||||
if(*fsOpenFileDirectly == 0xFFFFFFFF) temp = fsOpenFileDirectly;
|
||||
break;
|
||||
}
|
||||
|
||||
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(temp != NULL)
|
||||
{
|
||||
*temp = 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)))
|
||||
*fsTryOpenFile = findFunctionStart(code, addr);
|
||||
if(*temp != 0xFFFFFFFF)
|
||||
{
|
||||
found++;
|
||||
if(found == 4) break;
|
||||
}
|
||||
|
||||
if(*fsOpenFileDirectly == 0xFFFFFFFF && *(u32 *)(code + addr) == 0x08030204)
|
||||
*fsOpenFileDirectly = findFunctionStart(code, addr);
|
||||
|
||||
if(*fsMountArchive != 0xFFFFFFFF && *fsRegisterArchive != 0xFFFFFFFF && *fsTryOpenFile != 0xFFFFFFFF && *fsOpenFileDirectly != 0xFFFFFFFF) return true;
|
||||
temp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return found == 4;
|
||||
}
|
||||
|
||||
static inline bool findLayeredFsPayloadOffset(u8* code, u32 size, u32 *payloadOffset)
|
||||
static inline bool findLayeredFsPayloadOffset(u8 *code, u32 size, u32 roSize, u32 dataSize, u32 roAddress, u32 dataAddress, u32 *payloadOffset, u32 *pathOffset, u32 *pathAddress)
|
||||
{
|
||||
u32 roundedTextSize = ((size + 4095) & 0xFFFFF000),
|
||||
roundedRoSize = ((roSize + 4095) & 0xFFFFF000),
|
||||
roundedDataSize = ((dataSize + 4095) & 0xFFFFF000);
|
||||
|
||||
//First check for sufficient padding at the end of the .text segment
|
||||
if(((size + 4095) & 0xfffff000) - size >= romfsredir_bin_size)
|
||||
if(roundedTextSize - size >= romfsredir_bin_size) *payloadOffset = size;
|
||||
else
|
||||
{
|
||||
*payloadOffset = size;
|
||||
return true;
|
||||
}
|
||||
//If there isn't enough padding look for the "throwFatalError" function to replace
|
||||
u32 svcConnectToPort = 0xFFFFFFFF;
|
||||
|
||||
//If there isn't enough padding look for the "throwFatalError" function to replace
|
||||
u32 svcConnectToPort = 0xFFFFFFFF;
|
||||
|
||||
for(u32 addr = 4; svcConnectToPort == 0xFFFFFFFF && addr <= size - 4; addr += 4)
|
||||
{
|
||||
if(*(u32 *)(code + addr) == 0xEF00002D)
|
||||
svcConnectToPort = addr - 4;
|
||||
}
|
||||
|
||||
if(svcConnectToPort != 0xFFFFFFFF)
|
||||
{
|
||||
u32 func = 0xFFFFFFFF;
|
||||
|
||||
for(u32 i = 4; func == 0xFFFFFFFF && i <= size - 4; i += 4)
|
||||
for(u32 addr = 4; svcConnectToPort == 0xFFFFFFFF && addr <= size - 4; addr += 4)
|
||||
{
|
||||
if(*(u32 *)(code + i) != MAKE_BRANCH_LINK(i, svcConnectToPort)) continue;
|
||||
|
||||
func = findFunctionStart(code, i);
|
||||
|
||||
for(u32 pos = func + 4; func != 0xFFFFFFFF && pos <= size - 4 && *(u16 *)(code + pos + 2) != 0xE92D; pos += 4)
|
||||
if(*(u32 *)(code + pos) == 0xE200167E) func = 0xFFFFFFFF;
|
||||
if(*(u32 *)(code + addr) == 0xEF00002D)
|
||||
svcConnectToPort = addr - 4;
|
||||
}
|
||||
|
||||
if(func != 0xFFFFFFFF)
|
||||
if(svcConnectToPort != 0xFFFFFFFF)
|
||||
{
|
||||
*payloadOffset = func;
|
||||
return true;
|
||||
u32 func = 0xFFFFFFFF;
|
||||
|
||||
for(u32 i = 4; func == 0xFFFFFFFF && i <= size - 4; i += 4)
|
||||
{
|
||||
if(*(u32 *)(code + i) != MAKE_BRANCH_LINK(i, svcConnectToPort)) continue;
|
||||
|
||||
func = findFunctionStart(code, i);
|
||||
|
||||
for(u32 pos = func + 4; func != 0xFFFFFFFF && pos <= size - 4 && *(u16 *)(code + pos + 2) != 0xE92D; pos += 4)
|
||||
if(*(u32 *)(code + pos) == 0xE200167E) func = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
if(func != 0xFFFFFFFF)
|
||||
*payloadOffset = func;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
if(roundedRoSize - roSize >= 39)
|
||||
{
|
||||
*pathOffset = roundedTextSize + roSize;
|
||||
*pathAddress = roAddress + roSize;
|
||||
}
|
||||
else if(roundedDataSize - dataSize >= 39)
|
||||
{
|
||||
*pathOffset = roundedTextSize + roundedRoSize + dataSize;
|
||||
*pathAddress = dataAddress + dataSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 strSpace = 0xFFFFFFFF;
|
||||
|
||||
for(u32 addr = 0; strSpace == 0xFFFFFFFF && addr <= size - 4; addr += 4)
|
||||
{
|
||||
if(*(u32 *)(code + addr) == 0xE3A00B42)
|
||||
strSpace = findFunctionStart(code, addr);
|
||||
}
|
||||
|
||||
if(strSpace != 0xFFFFFFFF)
|
||||
{
|
||||
*pathOffset = strSpace;
|
||||
*pathAddress = 0x100000 + strSpace;
|
||||
}
|
||||
}
|
||||
|
||||
return *payloadOffset != 0 && *pathOffset != 0;
|
||||
}
|
||||
|
||||
static inline bool applyCodeIpsPatch(u64 progId, u8 *code, u32 size)
|
||||
@@ -475,13 +507,13 @@ static inline bool loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageI
|
||||
|
||||
if(R_FAILED(IFile_Read(&file, &total, buf, fileSize))) goto exit;
|
||||
|
||||
u32 i,
|
||||
j;
|
||||
static const char *regions[] = {"JPN", "USA", "EUR", "AUS", "CHN", "KOR", "TWN"},
|
||||
*languages[] = {"JP", "EN", "FR", "DE", "IT", "ES", "ZH", "KO", "NL", "PT", "RU", "TW"};
|
||||
|
||||
for(i = 0; i < 7; i++)
|
||||
u32 i;
|
||||
|
||||
for(i = 0; i < sizeof(regions) / sizeof(char *); i++)
|
||||
{
|
||||
static const char *regions[] = {"JPN", "USA", "EUR", "AUS", "CHN", "KOR", "TWN"};
|
||||
|
||||
if(memcmp(buf, regions[i], 3) == 0)
|
||||
{
|
||||
*regionId = (u8)i;
|
||||
@@ -489,26 +521,26 @@ static inline bool loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageI
|
||||
}
|
||||
}
|
||||
|
||||
for(j = 0; j < 12; j++)
|
||||
if(i != sizeof(regions) / sizeof(char *))
|
||||
{
|
||||
static const char *languages[] = {"JP", "EN", "FR", "DE", "IT", "ES", "ZH", "KO", "NL", "PT", "RU", "TW"};
|
||||
|
||||
if(memcmp(buf + 4, languages[j], 2) == 0)
|
||||
for(i = 0; i < sizeof(languages) / sizeof(char *); i++)
|
||||
{
|
||||
*languageId = (u8)j;
|
||||
break;
|
||||
if(memcmp(buf + 4, languages[i], 2) == 0)
|
||||
{
|
||||
*languageId = (u8)i;
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret = i != 7 && j != 12;
|
||||
|
||||
exit:
|
||||
IFile_Close(&file);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline bool patchLayeredFs(u64 progId, u8* code, u32 size)
|
||||
static inline bool patchLayeredFs(u64 progId, u8 *code, u32 size, u32 textSize, u32 roSize, u32 dataSize, u32 roAddress, u32 dataAddress)
|
||||
{
|
||||
/* Here we look for "/luma/titles/[u64 titleID in hex, uppercase]/romfs"
|
||||
If it exists it should be a folder containing ROMFS files */
|
||||
@@ -516,20 +548,31 @@ static inline bool patchLayeredFs(u64 progId, u8* code, u32 size)
|
||||
char path[] = "/luma/titles/0000000000000000/romfs";
|
||||
progIdToStr(path + 28, progId);
|
||||
|
||||
u32 archive = checkLumaDir(path);
|
||||
u32 archiveId = checkLumaDir(path);
|
||||
|
||||
if(!archive) return true;
|
||||
|
||||
const char *mount = archive == ARCHIVE_SDMC ? "sdmc:" : "nand:";
|
||||
if(!archiveId) return true;
|
||||
|
||||
u32 fsMountArchive = 0xFFFFFFFF,
|
||||
fsRegisterArchive = 0xFFFFFFFF,
|
||||
fsTryOpenFile = 0xFFFFFFFF,
|
||||
fsOpenFileDirectly = 0xFFFFFFFF,
|
||||
payloadOffset;
|
||||
payloadOffset = 0,
|
||||
pathOffset = 0,
|
||||
pathAddress;
|
||||
|
||||
if(!findLayeredFsSymbols(code, size, &fsMountArchive, &fsRegisterArchive, &fsTryOpenFile, &fsOpenFileDirectly) ||
|
||||
!findLayeredFsPayloadOffset(code, size, &payloadOffset)) return false;
|
||||
if(!findLayeredFsSymbols(code, textSize, &fsMountArchive, &fsRegisterArchive, &fsTryOpenFile, &fsOpenFileDirectly) ||
|
||||
!findLayeredFsPayloadOffset(code, textSize, roSize, dataSize, roAddress, dataAddress, &payloadOffset, &pathOffset, &pathAddress)) return false;
|
||||
|
||||
static const char *updateRomFsMounts[] = { "rom2:",
|
||||
"rex:",
|
||||
"patch:",
|
||||
"ext:",
|
||||
"rom:" };
|
||||
u32 updateRomFsIndex;
|
||||
|
||||
//Locate update RomFSes
|
||||
for(updateRomFsIndex = 0; updateRomFsIndex < sizeof(updateRomFsMounts) / sizeof(char *) - 1; updateRomFsIndex++)
|
||||
if(memsearch(code, updateRomFsMounts[updateRomFsIndex], size, strnlen(updateRomFsMounts[updateRomFsIndex], 255)) != NULL) break;
|
||||
|
||||
//Setup the payload
|
||||
u8 *payload = code + payloadOffset;
|
||||
@@ -539,7 +582,7 @@ static inline bool patchLayeredFs(u64 progId, u8* code, u32 size)
|
||||
u32 *payload32 = (u32 *)payload;
|
||||
for(u32 i = 0; i < romfsredir_bin_size / 4; i++)
|
||||
{
|
||||
switch (payload32[i])
|
||||
switch(payload32[i])
|
||||
{
|
||||
case 0xdead0000:
|
||||
payload32[i] = *(u32 *)(code + fsOpenFileDirectly);
|
||||
@@ -554,8 +597,7 @@ 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, mount, 5);
|
||||
memcpy((u8 *)(payload32 + i) + 5, path, sizeof(path));
|
||||
payload32[i] = pathAddress;
|
||||
break;
|
||||
case 0xdead0005:
|
||||
payload32[i] = 0x100000 + fsMountArchive;
|
||||
@@ -564,14 +606,17 @@ static inline bool patchLayeredFs(u64 progId, u8* code, u32 size)
|
||||
payload32[i] = 0x100000 + fsRegisterArchive;
|
||||
break;
|
||||
case 0xdead0007:
|
||||
memcpy(payload32 + i, mount, 4);
|
||||
payload32[i] = archiveId;
|
||||
break;
|
||||
case 0xdead0008:
|
||||
payload32[i] = archive;
|
||||
memcpy(payload32 + i, updateRomFsMounts[updateRomFsIndex], 4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(code + pathOffset, "lf:", 3);
|
||||
memcpy(code + pathOffset + 3, path, sizeof(path));
|
||||
|
||||
//Place the hooks
|
||||
*(u32 *)(code + fsOpenFileDirectly) = MAKE_BRANCH(fsOpenFileDirectly, payloadOffset);
|
||||
*(u32 *)(code + fsTryOpenFile) = MAKE_BRANCH(fsTryOpenFile, payloadOffset + 12);
|
||||
@@ -579,7 +624,7 @@ static inline bool patchLayeredFs(u64 progId, u8* code, u32 size)
|
||||
return true;
|
||||
}
|
||||
|
||||
void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 roSize)
|
||||
void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 roSize, u32 dataSize, u32 roAddress, u32 dataAddress)
|
||||
{
|
||||
loadCFWInfo();
|
||||
|
||||
@@ -743,7 +788,7 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 ro
|
||||
patch[] = u"C";
|
||||
|
||||
//Use SecureInfo_C
|
||||
if(patchMemory(code + textSize, roSize,
|
||||
if(patchMemory(code + ((textSize + 4095) & 0xFFFFF000), roSize,
|
||||
pattern,
|
||||
sizeof(pattern) - 2, 22,
|
||||
patch,
|
||||
@@ -833,25 +878,29 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 ro
|
||||
)) goto error;
|
||||
}
|
||||
|
||||
if(CONFIG(PATCHGAMES) && (u32)((progId >> 0x20) & 0xFFFFFFEDULL) == 0x00040000)
|
||||
if(CONFIG(PATCHGAMES))
|
||||
{
|
||||
u8 regionId = 0xFF,
|
||||
languageId;
|
||||
|
||||
if(!loadTitleCodeSection(progId, code, size) ||
|
||||
!applyCodeIpsPatch(progId, code, size) ||
|
||||
!loadTitleLocaleConfig(progId, ®ionId, &languageId) ||
|
||||
!patchLayeredFs(progId, code, textSize)) goto error;
|
||||
!applyCodeIpsPatch(progId, code, size)) goto error;
|
||||
|
||||
if(regionId != 0xFF)
|
||||
if((u32)((progId >> 0x20) & 0xFFFFFFEDULL) == 0x00040000)
|
||||
{
|
||||
u32 CFGUHandleOffset;
|
||||
u8 *CFGU_GetConfigInfoBlk2_endPos = getCfgOffsets(code, textSize, &CFGUHandleOffset);
|
||||
u8 regionId = 0xFF,
|
||||
languageId;
|
||||
|
||||
if(CFGU_GetConfigInfoBlk2_endPos == NULL ||
|
||||
!patchCfgGetLanguage(code, textSize, languageId, CFGU_GetConfigInfoBlk2_endPos)) goto error;
|
||||
if(!loadTitleLocaleConfig(progId, ®ionId, &languageId) ||
|
||||
!patchLayeredFs(progId, code, size, textSize, roSize, dataSize, roAddress, dataAddress)) goto error;
|
||||
|
||||
patchCfgGetRegion(code, textSize, regionId, CFGUHandleOffset);
|
||||
if(regionId != 0xFF)
|
||||
{
|
||||
u32 CFGUHandleOffset;
|
||||
u8 *CFGU_GetConfigInfoBlk2_endPos = getCfgOffsets(code, textSize, &CFGUHandleOffset);
|
||||
|
||||
if(CFGU_GetConfigInfoBlk2_endPos == NULL ||
|
||||
!patchCfgGetLanguage(code, textSize, languageId, CFGU_GetConfigInfoBlk2_endPos)) goto error;
|
||||
|
||||
patchCfgGetRegion(code, textSize, regionId, CFGUHandleOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,4 +44,4 @@ enum flags
|
||||
ISSAFEMODE
|
||||
};
|
||||
|
||||
void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 roSize);
|
||||
void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 roSize, u32 dataSize, u32 roAddress, u32 dataAddress);
|
||||
|
||||
@@ -155,8 +155,14 @@ void detectAndProcessExceptionDumps(void)
|
||||
|
||||
if(dumpHeader->processor == 11 && dumpHeader->additionalDataSize != 0)
|
||||
{
|
||||
char processName[] = "Current process: ";
|
||||
memcpy(processName + sizeof(processName) - 9, (void *)additionalData, 8);
|
||||
char processName[45] = "Current process: ";
|
||||
memcpy(processName + 17, (void *)additionalData, 8);
|
||||
hexItoa(*(vu32 *)(additionalData + 12), hexString, 8, true);
|
||||
concatenateStrings(processName, " (");
|
||||
concatenateStrings(processName, hexString);
|
||||
hexItoa(*(vu32 *)(additionalData + 8), hexString, 8, true);
|
||||
concatenateStrings(processName, hexString);
|
||||
concatenateStrings(processName, ")");
|
||||
posY = drawString(processName, true, 10, posY + SPACING_Y, COLOR_WHITE);
|
||||
}
|
||||
|
||||
|
||||
@@ -2050,7 +2050,8 @@ FRESULT load_obj_dir (
|
||||
dp->obj.fs = obj->fs;
|
||||
dp->obj.sclust = obj->c_scl;
|
||||
dp->obj.stat = (BYTE)obj->c_size;
|
||||
dp->obj.objsize = obj->c_size & 0xFFFFFF00;
|
||||
dp->obj.objsize = obj->c_size & 0xFFFFFF00;
|
||||
dp->obj.n_frag = 0;
|
||||
dp->blk_ofs = obj->c_ofs;
|
||||
|
||||
res = dir_sdi(dp, dp->blk_ofs); /* Goto object's entry block */
|
||||
@@ -2326,19 +2327,22 @@ FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too many S
|
||||
if (res != FR_OK) return res;
|
||||
dp->blk_ofs = dp->dptr - SZDIRE * (nent - 1); /* Set the allocated entry block offset */
|
||||
|
||||
if (dp->obj.sclust != 0 && (dp->obj.stat & 4)) { /* Has the sub-directory been stretched? */
|
||||
dp->obj.objsize += (DWORD)fs->csize * SS(fs); /* Increase the directory size by cluster size */
|
||||
res = fill_first_frag(&dp->obj); /* Fill first fragment on the FAT if needed */
|
||||
if (res != FR_OK) return res;
|
||||
res = fill_last_frag(&dp->obj, dp->clust, 0xFFFFFFFF); /* Fill last fragment on the FAT if needed */
|
||||
if (res != FR_OK) return res;
|
||||
res = load_obj_dir(&dj, &dp->obj); /* Load the object status */
|
||||
if (res != FR_OK) return res;
|
||||
st_qword(fs->dirbuf + XDIR_FileSize, dp->obj.objsize); /* Update the allocation status */
|
||||
st_qword(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize);
|
||||
fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1;
|
||||
res = store_xdir(&dj); /* Store the object status */
|
||||
if (dp->obj.stat & 4) { /* Has the directory been stretched? */
|
||||
dp->obj.stat &= ~4;
|
||||
res = fill_first_frag(&dp->obj); /* Fill the first fragment on the FAT if needed */
|
||||
if (res != FR_OK) return res;
|
||||
res = fill_last_frag(&dp->obj, dp->clust, 0xFFFFFFFF); /* Fill the last fragment on the FAT if needed */
|
||||
if (res != FR_OK) return res;
|
||||
if (dp->obj.sclust != 0) { /* Is it a sub directory? */
|
||||
res = load_obj_dir(&dj, &dp->obj); /* Load the object status */
|
||||
if (res != FR_OK) return res;
|
||||
dp->obj.objsize += (DWORD)fs->csize * SS(fs); /* Increase the directory size by cluster size */
|
||||
st_qword(fs->dirbuf + XDIR_FileSize, dp->obj.objsize); /* Update the allocation status */
|
||||
st_qword(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize);
|
||||
fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1;
|
||||
res = store_xdir(&dj); /* Store the object status */
|
||||
if (res != FR_OK) return res;
|
||||
}
|
||||
}
|
||||
|
||||
create_xdir(fs->dirbuf, fs->lfnbuf); /* Create on-memory directory block to be written later */
|
||||
|
||||
@@ -240,7 +240,8 @@ boot:
|
||||
bool loadFromStorage = CONFIG(LOADEXTFIRMSANDMODULES);
|
||||
u32 firmVersion = loadFirm(&firmType, firmSource, loadFromStorage, isSafeMode);
|
||||
|
||||
bool doUnitinfoPatch = CONFIG(PATCHUNITINFO), enableExceptionHandlers = CONFIG(ENABLEEXCEPTIONHANDLERS);
|
||||
bool doUnitinfoPatch = CONFIG(PATCHUNITINFO),
|
||||
enableExceptionHandlers = CONFIG(ENABLEEXCEPTIONHANDLERS);
|
||||
u32 res;
|
||||
switch(firmType)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user