diff --git a/Makefile b/Makefile index 5d2e982..66ad4fe 100644 --- a/Makefile +++ b/Makefile @@ -35,8 +35,8 @@ objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \ $(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \ $(call rwildcard, $(dir_source), *.s *.c))) -bundled = $(dir_build)/rebootpatch.h $(dir_build)/emunandpatch.h $(dir_build)/k11modulespatch.h $(dir_build)/svcGetCFWInfopatch.h $(dir_build)/twl_k11modulespatch.h \ - $(dir_build)/arm9_exceptions.h $(dir_build)/arm11_exceptions.h $(dir_build)/injector.h $(dir_build)/loader.h +bundled = $(dir_build)/rebootpatch.h $(dir_build)/emunandpatch.h $(dir_build)/svcGetCFWInfopatch.h $(dir_build)/injector.h \ + $(dir_build)/loader.h $(dir_build)/k11modulespatch.h $(dir_build)/arm9_exceptions.h $(dir_build)/arm11_exceptions.h .PHONY: all all: launcher a9lh ninjhax @@ -107,11 +107,6 @@ $(dir_build)/svcGetCFWInfopatch.h: $(dir_patches)/svcGetCFWInfo.s @armips $< @bin2c -o $@ -n svcGetCFWInfo $(@D)/svcGetCFWInfo.bin -$(dir_build)/twl_k11modulespatch.h: $(dir_patches)/twl_k11modules.s - @mkdir -p "$(@D)" - @armips $< - @bin2c -o $@ -n twl_k11modules $(@D)/twl_k11modules.bin - $(dir_build)/injector.h: $(dir_injector)/Makefile @mkdir -p "$(@D)" @$(MAKE) -C $(dir_injector) diff --git a/injector/source/patcher.c b/injector/source/patcher.c index ee6284d..918fc6f 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -142,12 +142,12 @@ static void loadTitleCodeSection(u64 progId, u8 *code, u32 size) if(R_SUCCEEDED(ret)) { - u64 fileSize, total; - + u64 fileSize; ret = IFile_GetSize(&file, &fileSize); if(R_SUCCEEDED(ret) && fileSize <= size) { + u64 total; ret = IFile_Read(&file, &total, code, fileSize); IFile_Close(&file); } diff --git a/patches/twl_k11modules.s b/patches/twl_k11modules.s deleted file mode 100644 index aaec02c..0000000 --- a/patches/twl_k11modules.s +++ /dev/null @@ -1,146 +0,0 @@ -; -; This file is part of Luma3DS -; Copyright (C) 2016 Aurora Wright, TuxSH -; -; This program is free software: you can redistribute it and/or modify -; it under the terms of the GNU General Public License as published by -; the Free Software Foundation, either version 3 of the License, or -; (at your option) any later version. -; -; This program is distributed in the hope that it will be useful, -; but WITHOUT ANY WARRANTY; without even the implied warranty of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; GNU General Public License for more details. -; -; You should have received a copy of the GNU General Public License -; along with this program. If not, see . -; -; Additional Terms 7.b of GPLv3 applies to this file: Requiring preservation of specified -; reasonable legal notices or author attributions in that material or in the Appropriate Legal -; Notices displayed by works containing it. -; - -.arm.little - -.create "build/twl_k11modules.bin", 0 - -.align 4 -.arm - -patch: - ; r4: Pointer to a pointer to the exheader of the current NCCH - ; sp + 0xb0 - 0xa4: Pointer to the memory location where the NCCH text was loaded - - add r3, sp, #(0xb0 - 0xa4) - add r1, sp, #(0xb0 - 0xac) - - push {r0-r11, lr} - - ldr r9, [r3] ; load the address of the code section - ldr r8, [r4] ; load the address of the exheader - - ldr r7, [r8, #0x200] ; low titleID - ldr r6, =#0x000001ff - cmp r7, r6 - bne end - - ldr r7, [launcher] ; offset of the dev launcher (will be replaced later) - add r7, r9 - - adr r5, patchesStart - add r6, r5, #(patchesEnd - patchesStart) - - patchLoop: - ldrh r0, [r5, #4] - cmp r0, #0 - moveq r4, r9 - movne r4, r7 - - ldrh r2, [r5, #6] - add r1, r5, #8 - ldr r0, [r5] - add r0, r4 - blx memcmp - cmp r0, #0 - bne skipPatch - - ldrh r2, [r5, #6] - add r1, r5, #0x08 - add r1, r2 - ldr r0, [r5] - add r0, r4 - blx memcpy - - skipPatch: - - ldrh r0, [r5, #6] - add r5, r5, #0x08 - add r5, r0,lsl#1 - cmp r5, r6 - blo patchLoop - - end: - - pop {r0-r11, pc} - -launcher: .ascii "LAUN" - -.align 2 -.thumb - -memcmp: - push {r4-r7, lr} - mov r4, #0 - cmp_loop: - cmp r4, r2 - bhs cmp_loop_end - ldrb r6, [r0, r4] - ldrb r7, [r1, r4] - add r4, #1 - sub r6, r7 - cmp r6, #0 - beq cmp_loop - - cmp_loop_end: - mov r0, r6 - pop {r4-r7, pc} - -memcpy: - push {r4-r5, lr} - mov r4, #0 - - copy_loop: - cmp r4, r2 - bhs copy_loop_end - ldrb r5, [r1, r4] - strb r5, [r0, r4] - add r4, #1 - b copy_loop - - copy_loop_end: - pop {r4-r5, pc} - -.align 4 - -; Available space for patches: 152 bytes on N3DS, 666 on O3DS - -patchesStart: - ; SCFG_EXT bit31 patches, based on https://github.com/ahezard/twl_firm_patcher (credits where they're due) - - .word 0x07368 ; offset - .halfword 1 ; type (0: relative to the start of TwlBg's code; 1: relative to the start of the dev SRL launcher) - .halfword 4 ; size (must be a multiple of 4) - .byte 0x94, 0x09, 0xfc, 0xed ; expected data (decrypted = 0x08, 0x60, 0x87, 0x05) - .byte 0x24, 0x09, 0xbc, 0xe9 ; patched data (decrypted = 0xb8, 0x60, 0xc7, 0x01) - - .word 0xa5888 - .halfword 1 - .halfword 8 - .byte 0x83, 0x30, 0x2e, 0xa4, 0xb0, 0xe2, 0xc2, 0xd6 ; (decrypted = 0x02, 0x01, 0x1a, 0xe3, 0x08, 0x60, 0x87, 0x05) - .byte 0x83, 0x50, 0xf2, 0xa4, 0xb0, 0xe2, 0xc2, 0xd6 ; (decrypted = 0x02, 0x61, 0xc6, 0xe3, 0x08, 0x60, 0x87, 0xe5) - -patchesEnd: - -.pool - -.close \ No newline at end of file diff --git a/source/config.c b/source/config.c index f21f71e..440bcb5 100644 --- a/source/config.c +++ b/source/config.c @@ -80,7 +80,6 @@ void configMenu(bool oldPinStatus) "( ) Use second EmuNAND as default", "( ) Enable region/language emu. and ext. .code", "( ) Show current NAND in System Settings", - "( ) Enable experimental TwlBg patches", "( ) Show GBA boot screen in patched AGB_FIRM", "( ) Display splash screen before payloads", "( ) Use a PIN", @@ -234,7 +233,7 @@ void configMenu(bool oldPinStatus) for(u32 i = 0; i < singleOptionsAmount; i++) configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 16); - if(CONFIG(8)) newPin(oldPinStatus); + if(CONFIG(7)) newPin(oldPinStatus); else if(oldPinStatus) fileDelete("/luma/pin.bin"); //Wait for the pressed buttons to change diff --git a/source/firm.c b/source/firm.c index 2c978c1..f89278c 100755 --- a/source/firm.c +++ b/source/firm.c @@ -94,9 +94,6 @@ void main(void) } else { - //Get pressed buttons - u32 pressed = HID_PAD; - isFirmlaunch = false; firmType = NATIVE_FIRM; @@ -105,6 +102,9 @@ void main(void) if(isA9lh) installArm9Handlers(); + //Get pressed buttons + u32 pressed = HID_PAD; + //Save old options and begin saving the new boot configuration configTemp = (configData.config & 0xFFFFFFC0) | ((u32)isA9lh << 3); @@ -135,7 +135,7 @@ void main(void) //Boot options aren't being forced if(needConfig != DONT_CONFIGURE) { - bool pinExists = CONFIG(8) && verifyPin(); + bool pinExists = CONFIG(7) && verifyPin(); //If no configuration file exists or SELECT is held, load configuration menu bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & BUTTON_SELECT) && !(pressed & BUTTON_L1)); @@ -165,7 +165,7 @@ void main(void) } else { - if(CONFIG(7) && loadSplash()) pressed = HID_PAD; + if(CONFIG(6) && loadSplash()) pressed = HID_PAD; /* If L and R/A/Select or one of the single payload buttons are pressed, chainload an external payload */ @@ -173,7 +173,7 @@ void main(void) if(shouldLoadPayload) loadPayload(pressed); - if(!CONFIG(7)) loadSplash(); + if(!CONFIG(6)) loadSplash(); //Determine if the user chose to use the SysNAND FIRM as default for a R boot bool useSysAsDefault = isA9lh ? CONFIG(1) : false; @@ -358,7 +358,7 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 patchKernel11Panic(arm11Section1, section[1].size); } - if(CONFIG(9)) + if(CONFIG(8)) { patchArm11SvcAccessChecks(arm11SvcHandler); patchK11ModuleChecks(arm11Section1, section[1].size, &freeK11Space); @@ -381,8 +381,6 @@ static inline void patchLegacyFirm(FirmwareType firmType) if(DEV_OPTIONS == 1) patchUnitInfoValueSet(arm9Section, section[3].size); applyLegacyFirmPatches((u8 *)firm, firmType); - - if(firmType == TWL_FIRM && CONFIG(5)) patchTwlBg((u8 *)firm + section[1].offset); } static inline void patch1x2xNativeAndSafeFirm(void) diff --git a/source/patches.c b/source/patches.c index c733cee..b00dd37 100644 --- a/source/patches.c +++ b/source/patches.c @@ -26,7 +26,6 @@ #include "../build/rebootpatch.h" #include "../build/svcGetCFWInfopatch.h" #include "../build/k11modulespatch.h" -#include "../build/twl_k11modulespatch.h" u8 *getProcess9(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr) { @@ -136,7 +135,6 @@ void reimplementSvcBackdoor(u8 *pos, u32 *arm11SvcTable, u8 **freeK11Space) } } - void implementSvcGetCFWInfo(u8 *pos, u32 *arm11SvcTable, u8 **freeK11Space) { memcpy(*freeK11Space, svcGetCFWInfo, svcGetCFWInfo_size); @@ -193,7 +191,7 @@ void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType) /* Calculate the amount of patches to apply. Only count the boot screen patch for AGB_FIRM if the matching option was enabled (keep it as last) */ u32 numPatches = firmType == TWL_FIRM ? (sizeof(twlPatches) / sizeof(patchData)) : - (sizeof(agbPatches) / sizeof(patchData) - !CONFIG(6)); + (sizeof(agbPatches) / sizeof(patchData) - !CONFIG(5)); const patchData *patches = firmType == TWL_FIRM ? twlPatches : agbPatches; //Patch @@ -213,26 +211,6 @@ void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType) } } -void patchTwlBg(u8 *pos) -{ - u8 *dst = pos + (isN3DS ? 0xFEA4 : 0xFCA0); - - memcpy(dst, twl_k11modules, twl_k11modules_size); //Install K11 hook - - u32 *off = (u32 *)memsearch(dst, "LAUN", twl_k11modules_size, 4); - *off = isN3DS ? 0xCDE88 : 0xCD5F8; //Dev SRL launcher offset - - u16 *src1 = (u16 *)(pos + (isN3DS ? 0xE38 : 0xE3C)), - *src2 = (u16 *)(pos + (isN3DS ? 0xE54 : 0xE58)); - - //Construct BLX instructions: - src1[0] = 0xF000 | ((((u32)dst - (u32)src1 - 4) & (0xFFF << 11)) >> 12); - src1[1] = 0xE800 | ((((u32)dst - (u32)src1 - 4) & 0xFFF) >> 1); - - src2[0] = 0xF000 | ((((u32)dst - (u32)src2 - 4) & (0xFFF << 11)) >> 12); - src2[1] = 0xE800 | ((((u32)dst - (u32)src2 - 4) & 0xFFF) >> 1); -} - void patchArm9ExceptionHandlersInstall(u8 *pos, u32 size) { const u8 pattern[] = {0x03, 0xA0, 0xE3, 0x18}; diff --git a/source/patches.h b/source/patches.h index 3e6c504..f8c5f53 100644 --- a/source/patches.h +++ b/source/patches.h @@ -59,7 +59,6 @@ void patchOldFirmWrites(u8 *pos, u32 size); void reimplementSvcBackdoor(u8 *pos, u32 *arm11SvcTable, u8 **freeK11Space); void implementSvcGetCFWInfo(u8 *pos, u32 *arm11SvcTable, u8 **freeK11Space); void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType); -void patchTwlBg(u8 *pos); void patchArm9ExceptionHandlersInstall(u8 *pos, u32 size); u32 getInfoForArm11ExceptionHandlers(u8 *pos, u32 size, u32 *codeSetOffset);