Add more mountpoint names for LayeredFS updates (#1994)

* Add more mountpoint names for LayeredFS updates

* Move `pat1` to the bottom of the list

* Isolate Mario Kart 7 mountpoint

* Apply suggestions from code review

Co-authored-by: PabloMK7 <hackyglitch2@gmail.com>

---------

Co-authored-by: PabloMK7 <hackyglitch2@gmail.com>
This commit is contained in:
CyberYoshi64 2024-02-02 14:42:57 +01:00 committed by GitHub
parent e2778a45cf
commit a3c5746e06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -579,14 +579,32 @@ static inline bool patchLayeredFs(u64 progId, u8 *code, u32 size, u32 textSize,
if(!findLayeredFsSymbols(code, textSize, &fsMountArchive, &fsRegisterArchive, &fsTryOpenFile, &fsOpenFileDirectly) || if(!findLayeredFsSymbols(code, textSize, &fsMountArchive, &fsRegisterArchive, &fsTryOpenFile, &fsOpenFileDirectly) ||
!findLayeredFsPayloadOffset(code, textSize, roSize, dataSize, roAddress, dataAddress, &payloadOffset, &pathOffset, &pathAddress)) return false; !findLayeredFsPayloadOffset(code, textSize, roSize, dataSize, roAddress, dataAddress, &payloadOffset, &pathOffset, &pathAddress)) return false;
static const char *updateRomFsMounts[] = { "rom2:", static const char *updateRomFsMounts[] = { "ro2:",
"rom2:",
"rex:", "rex:",
"patch:", "patch:",
"ext:", "ext:",
"rom:" }; "rom:" };
bool isMarioKart7 = (u32)progId == 0x00030600 || //JPN MK7
(u32)progId == 0x00030700 || //EUR MK7
(u32)progId == 0x00030800 || //USA MK7
(u32)progId == 0x00030A00 || //KOR MK7
(u32)progId == 0x0008B400; //TWN MK7
// Exclude CHN as it never got updates
const char *updateRomFsMount;
if (isMarioKart7)
{
updateRomFsMount = "pat1"; // Isolated to prevent false-positives
}
else
{
u32 updateRomFsIndex; u32 updateRomFsIndex;
//Locate update RomFSes //Locate update RomFS
for(updateRomFsIndex = 0; updateRomFsIndex < sizeof(updateRomFsMounts) / sizeof(char *) - 1; updateRomFsIndex++) for(updateRomFsIndex = 0; updateRomFsIndex < sizeof(updateRomFsMounts) / sizeof(char *) - 1; updateRomFsIndex++)
{ {
u32 patternSize = strlen(updateRomFsMounts[updateRomFsIndex]); u32 patternSize = strlen(updateRomFsMounts[updateRomFsIndex]);
@ -595,6 +613,8 @@ static inline bool patchLayeredFs(u64 progId, u8 *code, u32 size, u32 textSize,
memcpy(temp + 1, updateRomFsMounts[updateRomFsIndex], patternSize); memcpy(temp + 1, updateRomFsMounts[updateRomFsIndex], patternSize);
if(memsearch(code, temp, size, patternSize + 1) != NULL) break; if(memsearch(code, temp, size, patternSize + 1) != NULL) break;
} }
updateRomFsMount = updateRomFsMounts[updateRomFsIndex];
}
//Setup the payload //Setup the payload
u8 *payload = code + payloadOffset; u8 *payload = code + payloadOffset;
@ -607,7 +627,7 @@ static inline bool patchLayeredFs(u64 progId, u8 *code, u32 size, u32 textSize,
romfsRedirPatchFsMountArchive = 0x100000 + fsMountArchive; romfsRedirPatchFsMountArchive = 0x100000 + fsMountArchive;
romfsRedirPatchFsRegisterArchive = 0x100000 + fsRegisterArchive; romfsRedirPatchFsRegisterArchive = 0x100000 + fsRegisterArchive;
romfsRedirPatchArchiveId = archiveId; romfsRedirPatchArchiveId = archiveId;
memcpy(&romfsRedirPatchUpdateRomFsMount, updateRomFsMounts[updateRomFsIndex], 4); memcpy(&romfsRedirPatchUpdateRomFsMount, updateRomFsMount, 4);
memcpy(payload, romfsRedirPatch, romfsRedirPatchSize); memcpy(payload, romfsRedirPatch, romfsRedirPatchSize);