From 24186a7148d342567ca3cee0f2563c6d5af51871 Mon Sep 17 00:00:00 2001 From: Aurora Date: Sat, 2 Apr 2016 18:48:31 +0200 Subject: [PATCH] Some more tidying up --- Makefile | 2 +- injector/source/loader.c | 2 +- injector/source/patcher.c | 74 +++++++++++++++++++++------------------ injector/source/patcher.h | 2 +- source/draw.c | 3 +- source/firm.c | 3 +- source/memory.c | 4 +++ source/utils.c | 6 ++-- 8 files changed, 54 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 1a9fad3..da77732 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,6 @@ dir_out := out ASFLAGS := -mlittle-endian -mcpu=arm946e-s -march=armv5te CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2 -ffast-math -CFLAGS += -DCONFIG_TITLE="\"$(name) $(version) configuration\"" FLAGS := name=$(name).dat dir_out=$(abspath $(dir_out)) ICON=$(abspath icon.png) APP_DESCRIPTION="Noob-friendly 3DS CFW." APP_AUTHOR="Reisyukaku/Aurora Wright" --no-print-directory objects_cfw = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \ @@ -97,6 +96,7 @@ $(dir_build)/main.elf: $(objects_cfw) $(CC) -nostartfiles $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^ $(dir_build)/memory.o : CFLAGS+=-O3 +$(dir_build)/utils.o : CFLAGS += -DCONFIG_TITLE="\"$(name) $(version) configuration\"" $(dir_build)/%.o: $(dir_source)/%.c $(dir_build)/patches.h $(dir_build)/loader.h $(dir_build)/screeninit.h @mkdir -p "$(@D)" diff --git a/injector/source/loader.c b/injector/source/loader.c index 8eff8cc..0834771 100644 --- a/injector/source/loader.c +++ b/injector/source/loader.c @@ -158,7 +158,7 @@ static Result load_code(u64 progid, prog_addrs_t *shared, u64 prog_handle, int i } // patch - patch_code(progid, (u8 *)shared->text_addr, shared->total_size << 12); + patchCode(progid, (u8 *)shared->text_addr, shared->total_size << 12); return 0; } diff --git a/injector/source/patcher.c b/injector/source/patcher.c index 5410956..b70642f 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -36,31 +36,31 @@ static u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSiz return NULL; } -static u32 patch_memory(u8 *start, u32 size, const void *pattern, u32 patsize, int offset, const void *replace, u32 repsize, u32 count) +static u32 patchMemory(u8 *start, u32 size, const void *pattern, u32 patSize, int offset, const void *replace, u32 repSize, u32 count) { u32 i; for(i = 0; i < count; i++) { - u8 *found = memsearch(start, pattern, size, patsize); + u8 *found = memsearch(start, pattern, size, patSize); if(found == NULL) break; - memcpy(found + offset, replace, repsize); + memcpy(found + offset, replace, repSize); u32 at = (u32)(found - start); - if(at + patsize > size) size = 0; - else size = size - (at + patsize); + if(at + patSize > size) size = 0; + else size = size - (at + patSize); - start = found + patsize; + start = found + patSize; } return i; } -static int file_open(IFile *file, FS_ArchiveID id, const char *path, int flags) +static int fileOpen(IFile *file, FS_ArchiveID id, const char *path, int flags) { FS_Archive archive; FS_Path ppath; @@ -76,7 +76,7 @@ static int file_open(IFile *file, FS_ArchiveID id, const char *path, int flags) return IFile_Open(file, archive, ppath, flags); } -static int load_secureinfo() +static int loadSecureinfo() { IFile file; Result ret; @@ -85,7 +85,7 @@ static int load_secureinfo() if(secureinfo[0] == 0xFF) return 0; - ret = file_open(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ); + ret = fileOpen(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ); if(R_SUCCEEDED(ret)) { ret = IFile_Read(&file, &total, secureinfo, sizeof(secureinfo)); @@ -97,7 +97,7 @@ static int load_secureinfo() return ret; } -static int load_config() +static int loadConfig() { IFile file; Result ret; @@ -106,7 +106,7 @@ static int load_config() if(config) return 0; - ret = file_open(&file, ARCHIVE_SDMC, "/aurei/config.bin", FS_OPEN_READ); + ret = fileOpen(&file, ARCHIVE_SDMC, "/aurei/config.bin", FS_OPEN_READ); if(R_SUCCEEDED(ret)) { ret = IFile_Read(&file, &total, (void *)&config, 3); @@ -116,7 +116,7 @@ static int load_config() return ret; } -u32 patch_code(u64 progid, u8 *code, u32 size) +void patchCode(u64 progid, u8 *code, u32 size) { switch(progid) { @@ -134,7 +134,8 @@ u32 patch_code(u64 progid, u8 *code, u32 size) 0x01, 0x00, 0xA0, 0xE3, 0x1E, 0xFF, 0x2F, 0xE1 }; - patch_memory(code, size, + //Patch SMDH region checks + patchMemory(code, size, regionFreePattern, sizeof(regionFreePattern), -16, regionFreePatch, @@ -152,27 +153,30 @@ u32 patch_code(u64 progid, u8 *code, u32 size) static const u8 blockAutoUpdatesPatch[] = { 0xE3, 0xA0 }; - static const u8 blockEShopUpdateCheckPattern[] = { + static const u8 skipEshopUpdateCheckPattern[] = { 0x30, 0xB5, 0xF1, 0xB0 }; - static const u8 blockEShopUpdateCheckPatch[] = { + static const u8 skipEshopUpdateCheckPatch[] = { 0x00, 0x20, 0x08, 0x60, 0x70, 0x47 }; - patch_memory(code, size, + //Block silent auto-updates + patchMemory(code, size, blockAutoUpdatesPattern, sizeof(blockAutoUpdatesPattern), 0, blockAutoUpdatesPatch, sizeof(blockAutoUpdatesPatch), 1 ); - patch_memory(code, size, - blockEShopUpdateCheckPattern, - sizeof(blockEShopUpdateCheckPattern), 0, - blockEShopUpdateCheckPatch, - sizeof(blockEShopUpdateCheckPatch), 1 + + //Skip update checks to access the EShop + patchMemory(code, size, + skipEshopUpdateCheckPattern, + sizeof(skipEshopUpdateCheckPattern), 0, + skipEshopUpdateCheckPatch, + sizeof(skipEshopUpdateCheckPatch), 1 ); - if(R_SUCCEEDED(load_secureinfo())) + if(R_SUCCEEDED(loadSecureinfo())) { static const char countryRespPattern[] = { 0x01, 0x20, 0x01, 0x90, 0x22, 0x46, 0x06, 0x9B @@ -194,14 +198,14 @@ u32 patch_code(u64 progid, u8 *code, u32 size) case 6: country = "TW"; break; default: case 0: country = "JP"; break; } - // patch XML response Country + //Patch XML response Country memcpy(countryRespPatch, countryRespPatchModel, sizeof(countryRespPatchModel) ); countryRespPatch[6] = country[0]; countryRespPatch[10] = country[1]; - patch_memory(code, size, + patchMemory(code, size, countryRespPattern, sizeof(countryRespPattern), 0, countryRespPatch, @@ -219,13 +223,14 @@ u32 patch_code(u64 progid, u8 *code, u32 size) case 0x0004001000027000LL: // KOR MSET case 0x0004001000028000LL: // TWN MSET { - if(R_SUCCEEDED(load_config()) && ((config >> 5) & 1)) + if(R_SUCCEEDED(loadConfig()) && ((config >> 5) & 1)) { static const u16 verPattern[] = u"Ver."; const u32 currentFirm = ((config >> 12) & 1); const u32 currentNand = ((config >> 13) & 3); - patch_memory(code, size, + //Patch Ver. string + patchMemory(code, size, verPattern, sizeof(verPattern) - sizeof(u16), 0, currentNand ? ((currentNand == 1) ? ((currentFirm == 1) ? u" Emu" : u"Emu9") : u"Emu2") : @@ -246,7 +251,8 @@ u32 patch_code(u64 progid, u8 *code, u32 size) 0x0B, 0x18, 0x21, 0xC8 }; - patch_memory(code, size, + //Disable updates from foreign carts (makes carts region-free) + patchMemory(code, size, stopCartUpdatesPattern, sizeof(stopCartUpdatesPattern), 0, stopCartUpdatesPatch, @@ -265,21 +271,21 @@ u32 patch_code(u64 progid, u8 *code, u32 size) 0x00, 0x26 }; - // disable SecureInfo signature check - patch_memory(code, size, + //Disable SecureInfo signature check + patchMemory(code, size, secureinfoSigCheckPattern, sizeof(secureinfoSigCheckPattern), 0, secureinfoSigCheckPatch, sizeof(secureinfoSigCheckPatch), 1 ); - if(R_SUCCEEDED(load_secureinfo())) + if(R_SUCCEEDED(loadSecureinfo())) { static const u16 secureinfoFilenamePattern[] = u"SecureInfo_"; static const u16 secureinfoFilenamePatch[] = u"C"; - // use SecureInfo_C - patch_memory(code, size, + //Use SecureInfo_C + patchMemory(code, size, secureinfoFilenamePattern, sizeof(secureinfoFilenamePattern) - sizeof(u16), sizeof(secureinfoFilenamePattern) - sizeof(u16), @@ -291,6 +297,4 @@ u32 patch_code(u64 progid, u8 *code, u32 size) break; } } - - return 0; -} +} \ No newline at end of file diff --git a/injector/source/patcher.h b/injector/source/patcher.h index 8c4545c..4c74d99 100644 --- a/injector/source/patcher.h +++ b/injector/source/patcher.h @@ -2,4 +2,4 @@ #include <3ds/types.h> -u32 patch_code(u64 progid, u8 *code, u32 size); +void patchCode(u64 progid, u8 *code, u32 size); \ No newline at end of file diff --git a/source/draw.c b/source/draw.c index cee5928..eedd46f 100644 --- a/source/draw.c +++ b/source/draw.c @@ -80,7 +80,8 @@ int drawString(const char *string, int posX, int posY, u32 color) posY += SPACING_Y; line_i = 0; i++; - } else if(line_i >= (SCREEN_TOP_WIDTH - posX) / SPACING_X) + } + else if(line_i >= (SCREEN_TOP_WIDTH - posX) / SPACING_X) { // Make sure we never get out of the screen. posY += SPACING_Y; diff --git a/source/firm.c b/source/firm.c index 5a34c72..107e8f1 100755 --- a/source/firm.c +++ b/source/firm.c @@ -128,7 +128,8 @@ void setupCFW(void) { //If not 9.0 FIRM and B is pressed, attempt booting the second emuNAND emuNAND = (mode && ((!(pressed & BUTTON_B)) == ((config >> 4) & 1))) ? 2 : 1; - } else emuNAND = 0; + } + else emuNAND = 0; /* If tha FIRM patches version is different or user switched to/from A9LH, delete all patched FIRMs */ diff --git a/source/memory.c b/source/memory.c index b409d2d..93f6e04 100644 --- a/source/memory.c +++ b/source/memory.c @@ -12,6 +12,7 @@ void memcpy(void *dest, const void *src, u32 size) { u8 *destc = (u8 *)dest; const u8 *srcc = (const u8 *)src; + for(u32 i = 0; i < size; i++) destc[i] = srcc[i]; } @@ -19,6 +20,7 @@ void memcpy(void *dest, const void *src, u32 size) void memset(void *dest, int filler, u32 size) { u8 *destc = (u8 *)dest; + for(u32 i = 0; i < size; i++) destc[i] = (u8)filler; } @@ -26,6 +28,7 @@ void memset(void *dest, int filler, u32 size) void memset32(void *dest, u32 filler, u32 size) { u32 *dest32 = (u32 *)dest; + for (u32 i = 0; i < size / 4; i++) dest32[i] = filler; } @@ -34,6 +37,7 @@ int memcmp(const void *buf1, const void *buf2, u32 size) { const u8 *buf1c = (const u8 *)buf1; const u8 *buf2c = (const u8 *)buf2; + for(u32 i = 0; i < size; i++) { int cmp = buf1c[i] - buf2c[i]; diff --git a/source/utils.c b/source/utils.c index b3eafd3..c1c0963 100644 --- a/source/utils.c +++ b/source/utils.c @@ -40,7 +40,8 @@ static u16 waitInput(void) if(key != HID_PAD) break; if(i == 1) pressedKey = 1; } - } while(!pressedKey); + } + while(!pressedKey); return key; } @@ -85,7 +86,8 @@ void configureCFW(const char *configPath, const char *firm90Path) } pressed = waitInput(); - } while(!(pressed & MENU_BUTTONS)); + } + while(!(pressed & MENU_BUTTONS)); switch(pressed) {