From 87073f0ff76f8791461a27c96bc6b43826c5547f Mon Sep 17 00:00:00 2001 From: <@> Date: Thu, 22 Dec 2016 21:53:38 -0500 Subject: [PATCH 01/26] Added new menu entries. Added Kecleon to title. --- Makefile | 2 +- source/config.c | 12 ++++++++++-- source/config.h | 6 +++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index c8f6d19fa..0359682b8 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ endif include $(DEVKITARM)/base_tools -name := Luma3DS +name := Luma3DS Kecloen patch revision := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/i') commit := $(shell git rev-parse --short=8 HEAD) diff --git a/source/config.c b/source/config.c index f5b954b16..720690173 100644 --- a/source/config.c +++ b/source/config.c @@ -83,7 +83,9 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) "( ) Enable game patching", "( ) Show NAND or user string in System Settings", "( ) Show GBA boot screen in patched AGB_FIRM", - "( ) Patch SVC/service/archive/ARM9 access" + "( ) Patch SVC/service/archive/ARM9 access", + "( ) Kecleon: Disable giveaway patches", + "( ) Kecleon: Hide all boot menus" }; const char *optionsDescription[] = { "Select the default EmuNAND.\n\n" @@ -190,6 +192,10 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) "9.3 and 10.4.\n\n" "Only change this if you know what you\n" "are doing!", + "Disable patches that can giveaway that\n" + "this 3DS is running custom firmware.\n" + "This includes signature checks and twl\n" + "checks." }; struct multiOption { @@ -218,6 +224,8 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) { .visible = true }, { .visible = true }, { .visible = true }, + { .visible = true }, + { .visible = true }, { .visible = true } }; @@ -394,4 +402,4 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) while(HID_PAD & PIN_BUTTONS); wait(2000ULL); -} \ No newline at end of file +} diff --git a/source/config.h b/source/config.h index acfd4b943..f54308d77 100644 --- a/source/config.h +++ b/source/config.h @@ -29,8 +29,8 @@ #define BOOTCONFIG(a, b) ((configData.config >> a) & b) #define CONFIG_FILE "config.bin" -#define CONFIG_VERSIONMAJOR 1 -#define CONFIG_VERSIONMINOR 7 +#define CONFIG_VERSIONMAJOR 24816 +#define CONFIG_VERSIONMINOR 1 #define BOOTCFG_NAND BOOTCONFIG(0, 7) #define BOOTCFG_FIRM BOOTCONFIG(3, 7) @@ -68,4 +68,4 @@ typedef enum ConfigurationStatus bool readConfig(void); void writeConfig(ConfigurationStatus needConfig, u32 configTemp); -void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode); \ No newline at end of file +void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode); From 271546c5e06254f3781a80aa7b2d5fde93d68ba2 Mon Sep 17 00:00:00 2001 From: <@> Date: Thu, 22 Dec 2016 21:57:58 -0500 Subject: [PATCH 02/26] Added description for last option. --- Makefile | 4 ++-- source/config.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 0359682b8..7244d463f 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ endif include $(DEVKITARM)/base_tools -name := Luma3DS Kecloen patch +name := Luma3DS-Kecleon revision := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/i') commit := $(shell git rev-parse --short=8 HEAD) @@ -96,7 +96,7 @@ $(dir_build)/%.bin: $(dir_patches)/%.s $(dir_build) @armips $< $(dir_build)/memory.o $(dir_build)/strings.o: CFLAGS += -O3 -$(dir_build)/config.o: CFLAGS += -DCONFIG_TITLE="\"$(name) $(revision) configuration\"" +$(dir_build)/config.o: CFLAGS += -DCONFIG_TITLE="\"$(name) $(revision)\"" $(dir_build)/patches.o: CFLAGS += -DREVISION=\"$(revision)\" -DCOMMIT_HASH="0x$(commit)" $(dir_build)/%.o: $(dir_source)/%.c $(bundled) diff --git a/source/config.c b/source/config.c index 720690173..bab17f69b 100644 --- a/source/config.c +++ b/source/config.c @@ -195,7 +195,9 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) "Disable patches that can giveaway that\n" "this 3DS is running custom firmware.\n" "This includes signature checks and twl\n" - "checks." + "checks.", + "Ignore all key-presses at startup,\n" + "disabling chainloading and startup menus." }; struct multiOption { From 21901d5c67abbf78e8dab4c098a077f445480b57 Mon Sep 17 00:00:00 2001 From: <@> Date: Thu, 22 Dec 2016 22:14:56 -0500 Subject: [PATCH 03/26] Reworded two new options. --- source/config.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/config.c b/source/config.c index bab17f69b..c3bbfb9fa 100644 --- a/source/config.c +++ b/source/config.c @@ -84,8 +84,8 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) "( ) Show NAND or user string in System Settings", "( ) Show GBA boot screen in patched AGB_FIRM", "( ) Patch SVC/service/archive/ARM9 access", - "( ) Kecleon: Disable giveaway patches", - "( ) Kecleon: Hide all boot menus" + "( ) Kecleon: Disable Signature/TWL patches", + "( ) Kecleon: Disable chainloading/boot menu" }; const char *optionsDescription[] = { "Select the default EmuNAND.\n\n" @@ -192,12 +192,12 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) "9.3 and 10.4.\n\n" "Only change this if you know what you\n" "are doing!", - "Disable patches that can giveaway that\n" - "this 3DS is running custom firmware.\n" - "This includes signature checks and twl\n" - "checks.", - "Ignore all key-presses at startup,\n" - "disabling chainloading and startup menus." + "This disables patches that can give away\n" + "that this 3DS is running CFW.\n" + "This includes signature and TWL patches.", + "This disables menus and chainloading\n" + "that can give away that this 3DS is\n" + "running CFW." }; struct multiOption { From 658e055fb19b5b53a33378026d7ab223217fd4f3 Mon Sep 17 00:00:00 2001 From: <@> Date: Thu, 22 Dec 2016 23:32:22 -0500 Subject: [PATCH 04/26] Added Kecleon config enums. --- source/config.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/config.h b/source/config.h index f54308d77..9c4f330ed 100644 --- a/source/config.h +++ b/source/config.h @@ -56,7 +56,9 @@ enum singleOptions PATCHGAMES, PATCHVERSTRING, SHOWGBABOOT, - PATCHACCESS + PATCHACCESS, + KECPATCH, + KECMENU }; typedef enum ConfigurationStatus From a444c837de3e76252d15aa57dc546a78d137870e Mon Sep 17 00:00:00 2001 From: <@> Date: Thu, 22 Dec 2016 23:54:16 -0500 Subject: [PATCH 05/26] Implemented option to disable boot menu. --- source/main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/main.c b/source/main.c index e1e976f1f..0ab371799 100644 --- a/source/main.c +++ b/source/main.c @@ -91,8 +91,9 @@ void main(void) firmType = NATIVE_FIRM; isA9lhInstalled = ISA9LH; - //Get pressed buttons - u32 pressed = HID_PAD; + + //Get pressed buttons only if chainloading/boot menus aren't disabled + u32 pressed = CONFIG(KECMENU) ? 0 : HID_PAD; //Save old options and begin saving the new boot configuration configTemp = (configData.config & 0xFFFFFF00) | ((u32)ISA9LH << 6); @@ -270,4 +271,4 @@ void main(void) } launchFirm(firmType, loadFromStorage); -} \ No newline at end of file +} From b652937493a49241997cf30d39a12a6e3e23fdc4 Mon Sep 17 00:00:00 2001 From: <@> Date: Fri, 23 Dec 2016 00:59:25 -0500 Subject: [PATCH 06/26] Implemented option to disable sig/twl patches. --- source/patches.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/patches.c b/source/patches.c index aa382acf8..910b62b6a 100644 --- a/source/patches.c +++ b/source/patches.c @@ -102,6 +102,8 @@ u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space, u32 * u32 patchSignatureChecks(u8 *pos, u32 size) { + if (CONFIG(KECPATCH)) return 0; + //Look for signature checks const u8 pattern[] = {0xC0, 0x1C, 0x76, 0xE7}, pattern2[] = {0xB5, 0x22, 0x4D, 0x0C}; @@ -478,6 +480,8 @@ u32 patchUnitInfoValueSet(u8 *pos, u32 size) u32 patchLgySignatureChecks(u8 *pos, u32 size) { + if (CONFIG(KECPATCH)) return 0; + const u8 pattern[] = {0x47, 0xC1, 0x17, 0x49}; u8 *temp = memsearch(pos, pattern, size, sizeof(pattern)); @@ -494,6 +498,8 @@ u32 patchLgySignatureChecks(u8 *pos, u32 size) u32 patchTwlInvalidSignatureChecks(u8 *pos, u32 size) { + if (CONFIG(KECPATCH)) return 0; + const u8 pattern[] = {0x20, 0xF6, 0xE7, 0x7F}; u8 *temp = memsearch(pos, pattern, size, sizeof(pattern)); @@ -508,6 +514,8 @@ u32 patchTwlInvalidSignatureChecks(u8 *pos, u32 size) u32 patchTwlNintendoLogoChecks(u8 *pos, u32 size) { + if (CONFIG(KECPATCH)) return 0; + const u8 pattern[] = {0xC0, 0x30, 0x06, 0xF0}; u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern)); @@ -522,6 +530,8 @@ u32 patchTwlNintendoLogoChecks(u8 *pos, u32 size) u32 patchTwlWhitelistChecks(u8 *pos, u32 size) { + if (CONFIG(KECPATCH)) return 0; + const u8 pattern[] = {0x22, 0x00, 0x20, 0x30}; u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern)); @@ -536,6 +546,8 @@ u32 patchTwlWhitelistChecks(u8 *pos, u32 size) u32 patchTwlFlashcartChecks(u8 *pos, u32 size, u32 firmVersion) { + if (CONFIG(KECPATCH)) return 0; + const u8 pattern[] = {0x25, 0x20, 0x00, 0x0E}; u8 *temp = memsearch(pos, pattern, size, sizeof(pattern)); @@ -556,6 +568,8 @@ u32 patchTwlFlashcartChecks(u8 *pos, u32 size, u32 firmVersion) u32 patchOldTwlFlashcartChecks(u8 *pos, u32 size) { + if (CONFIG(KECPATCH)) return 0; + const u8 pattern[] = {0x06, 0xF0, 0xA0, 0xFD}; u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern)); @@ -570,6 +584,8 @@ u32 patchOldTwlFlashcartChecks(u8 *pos, u32 size) u32 patchTwlShaHashChecks(u8 *pos, u32 size) { + if (CONFIG(KECPATCH)) return 0; + const u8 pattern[] = {0x10, 0xB5, 0x14, 0x22}; u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern)); From 9fb2d97e66f6dcae9abeb9570132e6a734f8f62b Mon Sep 17 00:00:00 2001 From: <@> Date: Fri, 23 Dec 2016 01:27:15 -0500 Subject: [PATCH 07/26] Fixed text in options. --- source/config.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/source/config.c b/source/config.c index c3bbfb9fa..16934dd2b 100644 --- a/source/config.c +++ b/source/config.c @@ -85,7 +85,7 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) "( ) Show GBA boot screen in patched AGB_FIRM", "( ) Patch SVC/service/archive/ARM9 access", "( ) Kecleon: Disable Signature/TWL patches", - "( ) Kecleon: Disable chainloading/boot menu" + "( ) Kecleon: Disable Chainloading/Boot Menus" }; const char *optionsDescription[] = { "Select the default EmuNAND.\n\n" @@ -192,12 +192,19 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) "9.3 and 10.4.\n\n" "Only change this if you know what you\n" "are doing!", - "This disables patches that can give away\n" - "that this 3DS is running CFW.\n" - "This includes signature and TWL patches.", - "This disables menus and chainloading\n" - "that can give away that this 3DS is\n" - "running CFW." + "This disables patches that can give\n" + "away that this 3DS is running CFW,\n" + "such as region free cartridges.\n" + "This includes signature, TWL and\n" + "FlashCart patches.", + "This disables startup menus and\n" + "chainloading that can give away that\n" + "this 3DS is running CFW.\n\n" + "Warning: config.bin must be deleted\n" + "to re-enable chainloading and\n" + "startup menus.\n" + "Also note that config.bin may be\n" + "located on your CTRNAND in '/rw/luma'." }; struct multiOption { From 1473456b2a4f6e865df2804ba81794e166e8c9de Mon Sep 17 00:00:00 2001 From: <@> Date: Fri, 23 Dec 2016 01:46:36 -0500 Subject: [PATCH 08/26] Again rephrased text to be more accurate. --- source/config.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/source/config.c b/source/config.c index 16934dd2b..f8d5f44bd 100644 --- a/source/config.c +++ b/source/config.c @@ -85,7 +85,7 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) "( ) Show GBA boot screen in patched AGB_FIRM", "( ) Patch SVC/service/archive/ARM9 access", "( ) Kecleon: Disable Signature/TWL patches", - "( ) Kecleon: Disable Chainloading/Boot Menus" + "( ) Kecleon: Ignore all Button Presses on boot." }; const char *optionsDescription[] = { "Select the default EmuNAND.\n\n" @@ -193,13 +193,14 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) "Only change this if you know what you\n" "are doing!", "This disables patches that can give\n" - "away that this 3DS is running CFW,\n" - "such as region free cartridges.\n" - "This includes signature, TWL and\n" - "FlashCart patches.", - "This disables startup menus and\n" - "chainloading that can give away that\n" - "this 3DS is running CFW.\n\n" + "away this 3DS is running CFW,\n" + "such as out-of-region cartridges.\n" + "Specifically this disables signature,\n" + "TWL and Flashcart patches.", + "This makes Luma3DS ignore all Button\n" + "Presses on boot, hiding chainloading\n" + "and boot menus that give away this\n" + "3DS is running CFW.\n" "Warning: config.bin must be deleted\n" "to re-enable chainloading and\n" "startup menus.\n" From 3475d76bc31f741edb8f545bc40f457732b1e59f Mon Sep 17 00:00:00 2001 From: <@> Date: Fri, 23 Dec 2016 01:54:34 -0500 Subject: [PATCH 09/26] Choose config version that makes more sense. --- source/config.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/config.h b/source/config.h index 9c4f330ed..e8675c5a9 100644 --- a/source/config.h +++ b/source/config.h @@ -29,8 +29,9 @@ #define BOOTCONFIG(a, b) ((configData.config >> a) & b) #define CONFIG_FILE "config.bin" -#define CONFIG_VERSIONMAJOR 24816 -#define CONFIG_VERSIONMINOR 1 +/* Corresponds to downstream 1.7 */ +#define CONFIG_VERSIONMAJOR 24801 +#define CONFIG_VERSIONMINOR 7 #define BOOTCFG_NAND BOOTCONFIG(0, 7) #define BOOTCFG_FIRM BOOTCONFIG(3, 7) From dd4aec17b212403facf6a904605fd9da64ce5e87 Mon Sep 17 00:00:00 2001 From: <@> Date: Fri, 23 Dec 2016 12:03:20 -0500 Subject: [PATCH 10/26] Added option to save to CTRNAND. --- source/config.c | 11 ++++++++--- source/config.h | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/source/config.c b/source/config.c index f8d5f44bd..3bfb1e0c5 100644 --- a/source/config.c +++ b/source/config.c @@ -85,7 +85,8 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) "( ) Show GBA boot screen in patched AGB_FIRM", "( ) Patch SVC/service/archive/ARM9 access", "( ) Kecleon: Disable Signature/TWL patches", - "( ) Kecleon: Ignore all Button Presses on boot." + "( ) Kecleon: Ignore all Button Presses on boot.", + "( ) Kecleon: Save config.bin in CTRNAND." }; const char *optionsDescription[] = { "Select the default EmuNAND.\n\n" @@ -195,7 +196,7 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) "This disables patches that can give\n" "away this 3DS is running CFW,\n" "such as out-of-region cartridges.\n" - "Specifically this disables signature,\n" + "Specifically this disables Signature,\n" "TWL and Flashcart patches.", "This makes Luma3DS ignore all Button\n" "Presses on boot, hiding chainloading\n" @@ -205,7 +206,10 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) "to re-enable chainloading and\n" "startup menus.\n" "Also note that config.bin may be\n" - "located on your CTRNAND in '/rw/luma'." + "located on your CTRNAND in '/rw/luma'.\n" + "Use GodMode9 to delete it.", + "Save configuration file in CTRNAND\n" + "at '/rw/luma/config.bin'." }; struct multiOption { @@ -236,6 +240,7 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) { .visible = true }, { .visible = true }, { .visible = true }, + { .visible = true }, { .visible = true } }; diff --git a/source/config.h b/source/config.h index e8675c5a9..7690c2b7a 100644 --- a/source/config.h +++ b/source/config.h @@ -59,7 +59,8 @@ enum singleOptions SHOWGBABOOT, PATCHACCESS, KECPATCH, - KECMENU + KECMENU, + KECNAND }; typedef enum ConfigurationStatus From f64c095282f5b6fb822f9eebdc82b949413e9221 Mon Sep 17 00:00:00 2001 From: <@> Date: Sat, 24 Dec 2016 12:29:16 -0500 Subject: [PATCH 11/26] Implemented load config.bin from CTRNAND. --- source/main.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/source/main.c b/source/main.c index 0ab371799..f1e0d0b78 100644 --- a/source/main.c +++ b/source/main.c @@ -44,14 +44,19 @@ void main(void) FirmwareSource nandType; ConfigurationStatus needConfig; - //Mount SD or CTRNAND - bool isSdMode; - if(mountFs(true, false)) isSdMode = true; - else - { + // Attempt to mount SD card. + bool isSdMode = mountFs(true, false); + if (isSdMode) { + // Attempt to load configuration. + needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; + } + // If either of those fail, attempt to mount CTRNAND. + if (!isSDMode || needConfig == CREATE_CONFIGURATION) { firmSource = FIRMWARE_SYSNAND; if(!mountFs(false, true)) error("Failed to mount SD and CTRNAND."); isSdMode = false; + // Attempt to load configuration file. + needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; } //Attempt to read the configuration file From 2250728c6858c99464e4c6a9a37f41c040db9ece Mon Sep 17 00:00:00 2001 From: <@> Date: Sat, 24 Dec 2016 14:01:13 -0500 Subject: [PATCH 12/26] Implemented config.bin saving features. --- source/fs.c | 8 +++++++- source/fs.h | 3 ++- source/main.c | 14 +++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/source/fs.c b/source/fs.c index 831c0309c..93403988d 100644 --- a/source/fs.c +++ b/source/fs.c @@ -57,6 +57,12 @@ bool mountFs(bool isSd, bool switchToCtrNand) f_mount(&nandFs, "1:", 1) == FR_OK && (!switchToCtrNand || (f_chdrive("1:") == FR_OK && switchToMainDir(false))); } +bool changeDrive(bool switchToSd) +{ + return switchToSd ? f_chdrive("0:") == FR_OK && switchToMainDir(true) : + f_chdrive("1:") == FR_OK && switchToMainDir(false); +} + u32 fileRead(void *dest, const char *path, u32 maxSize) { FIL file; @@ -328,4 +334,4 @@ void findDumpFile(const char *path, char *fileName) } if(result == FR_OK) f_closedir(&dir); -} \ No newline at end of file +} diff --git a/source/fs.h b/source/fs.h index 14f26c0c4..0bc160b1d 100644 --- a/source/fs.h +++ b/source/fs.h @@ -27,6 +27,7 @@ #define PATTERN(a) a "_*.bin" bool mountFs(bool isSd, bool switchToCtrNand); +bool changeDrive(bool switchToSd); u32 fileRead(void *dest, const char *path, u32 maxSize); u32 getFileSize(const char *path); bool fileWrite(const void *buffer, const char *path, u32 size); @@ -34,4 +35,4 @@ void fileDelete(const char *path); void loadPayload(u32 pressed, const char *payloadPath); void payloadMenu(void); u32 firmRead(void *dest, u32 firmType); -void findDumpFile(const char *path, char *fileName); \ No newline at end of file +void findDumpFile(const char *path, char *fileName); diff --git a/source/main.c b/source/main.c index f1e0d0b78..0b0fa4ce9 100644 --- a/source/main.c +++ b/source/main.c @@ -45,13 +45,15 @@ void main(void) ConfigurationStatus needConfig; // Attempt to mount SD card. - bool isSdMode = mountFs(true, false); - if (isSdMode) { + bool isSdAvailible = mountFs(true, false); + bool isSdMode; + if (isSdAvailible) { // Attempt to load configuration. needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; + isSdMode = true; } // If either of those fail, attempt to mount CTRNAND. - if (!isSDMode || needConfig == CREATE_CONFIGURATION) { + if (!isSdMode || needConfig == CREATE_CONFIGURATION) { firmSource = FIRMWARE_SYSNAND; if(!mountFs(false, true)) error("Failed to mount SD and CTRNAND."); isSdMode = false; @@ -239,6 +241,12 @@ void main(void) if(!ISFIRMLAUNCH) { configTemp |= (u32)nandType | ((u32)firmSource << 3); + + /* Change to SD card if writing config to SD card. */ + if (isSdAvailible && !(CONFIG(KECNAND)) { + if (!changeDrive(true)) error("SD card unavailible."); + } + writeConfig(needConfig, configTemp); } From a36c959fb4bf2bca3e8f4b7402ec94d9bf270f42 Mon Sep 17 00:00:00 2001 From: <@> Date: Sat, 24 Dec 2016 14:31:13 -0500 Subject: [PATCH 13/26] Fixed config.bin write to CTRNAND. --- source/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/main.c b/source/main.c index 0b0fa4ce9..196643730 100644 --- a/source/main.c +++ b/source/main.c @@ -46,7 +46,7 @@ void main(void) // Attempt to mount SD card. bool isSdAvailible = mountFs(true, false); - bool isSdMode; + bool isSdMode = isSdAvailible; if (isSdAvailible) { // Attempt to load configuration. needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; @@ -98,7 +98,6 @@ void main(void) firmType = NATIVE_FIRM; isA9lhInstalled = ISA9LH; - //Get pressed buttons only if chainloading/boot menus aren't disabled u32 pressed = CONFIG(KECMENU) ? 0 : HID_PAD; @@ -243,7 +242,7 @@ void main(void) configTemp |= (u32)nandType | ((u32)firmSource << 3); /* Change to SD card if writing config to SD card. */ - if (isSdAvailible && !(CONFIG(KECNAND)) { + if (isSdAvailible && !CONFIG(KECNAND)) { if (!changeDrive(true)) error("SD card unavailible."); } From bb0973e6f39505c5e6cc371cfd0c410985ee3317 Mon Sep 17 00:00:00 2001 From: <@> Date: Sat, 24 Dec 2016 14:52:21 -0500 Subject: [PATCH 14/26] Hide save to CTRNAND option when SD card is not inserted. --- source/config.c | 5 +++-- source/config.h | 3 ++- source/main.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/config.c b/source/config.c index 3bfb1e0c5..facfaf78c 100644 --- a/source/config.c +++ b/source/config.c @@ -66,7 +66,8 @@ void writeConfig(ConfigurationStatus needConfig, u32 configTemp) error("Error writing the configuration file"); } -void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) +void configMenu(bool isSdMode, bool isSdAvailible, + bool oldPinStatus, u32 oldPinMode) { const char *multiOptionsText[] = { "Default EmuNAND: 1( ) 2( ) 3( ) 4( )", "Screen brightness: 4( ) 3( ) 2( ) 1( )", @@ -241,7 +242,7 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) { .visible = true }, { .visible = true }, { .visible = true }, - { .visible = true } + { .visible = isSdAvailible } }; //Calculate the amount of the various kinds of options and pre-select the first single one diff --git a/source/config.h b/source/config.h index 7690c2b7a..a02398c05 100644 --- a/source/config.h +++ b/source/config.h @@ -72,4 +72,5 @@ typedef enum ConfigurationStatus bool readConfig(void); void writeConfig(ConfigurationStatus needConfig, u32 configTemp); -void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode); +void configMenu(bool isSdMode, bool isSdAvailible, + bool oldPinStatus, u32 oldPinMode); diff --git a/source/main.c b/source/main.c index 196643730..ada9d6866 100644 --- a/source/main.c +++ b/source/main.c @@ -138,7 +138,7 @@ void main(void) if(shouldLoadConfigMenu) { - configMenu(isSdMode, pinExists, pinMode); + configMenu(isSdMode, isSdAvailible, pinExists, pinMode); //Update pressed buttons pressed = HID_PAD; From eee449ad901bbe1ff440acced5f76b3a84231583 Mon Sep 17 00:00:00 2001 From: <@> Date: Sun, 25 Dec 2016 00:01:17 -0500 Subject: [PATCH 15/26] Removed PIN. --- source/config.c | 23 +---- source/config.h | 6 +- source/main.c | 13 +-- source/pin.c | 220 ------------------------------------------------ source/pin.h | 36 -------- 5 files changed, 7 insertions(+), 291 deletions(-) delete mode 100644 source/pin.c delete mode 100644 source/pin.h diff --git a/source/config.c b/source/config.c index facfaf78c..506da8e6a 100644 --- a/source/config.c +++ b/source/config.c @@ -27,7 +27,6 @@ #include "screen.h" #include "draw.h" #include "buttons.h" -#include "pin.h" CfgData configData; @@ -66,13 +65,11 @@ void writeConfig(ConfigurationStatus needConfig, u32 configTemp) error("Error writing the configuration file"); } -void configMenu(bool isSdMode, bool isSdAvailible, - bool oldPinStatus, u32 oldPinMode) +void configMenu(bool isSdMode, bool isSdAvailible) { const char *multiOptionsText[] = { "Default EmuNAND: 1( ) 2( ) 3( ) 4( )", "Screen brightness: 4( ) 3( ) 2( ) 1( )", "Splash: Off( ) Before( ) After( ) payloads", - "PIN lock: Off( ) 4( ) 6( ) 8( ) digits", "New 3DS CPU: Off( ) Clock( ) L2( ) Clock+L2( )", "Dev. features: Off( ) ErrDisp( ) UNITINFO( )" }; @@ -104,15 +101,6 @@ void configMenu(bool isSdMode, bool isSdAvailible, "\t* 'After payloads' displays it\n" "afterwards.", - "Activate a PIN lock.\n\n" - "The PIN will be asked each time\n" - "Luma3DS boots.\n\n" - "4, 6 or 8 digits can be selected.\n\n" - "The ABXY buttons and the directional\n" - "pad buttons can be used as keys.\n\n" - "A message can also be displayed\n" - "(refer to the wiki for instructions).", - "Select the New 3DS CPU mode.\n\n" "This won't apply to\n" "New 3DS exclusive/enhanced games.\n\n" @@ -194,11 +182,13 @@ void configMenu(bool isSdMode, bool isSdAvailible, "9.3 and 10.4.\n\n" "Only change this if you know what you\n" "are doing!", + "This disables patches that can give\n" "away this 3DS is running CFW,\n" "such as out-of-region cartridges.\n" "Specifically this disables Signature,\n" "TWL and Flashcart patches.", + "This makes Luma3DS ignore all Button\n" "Presses on boot, hiding chainloading\n" "and boot menus that give away this\n" @@ -209,6 +199,7 @@ void configMenu(bool isSdMode, bool isSdAvailible, "Also note that config.bin may be\n" "located on your CTRNAND in '/rw/luma'.\n" "Use GodMode9 to delete it.", + "Save configuration file in CTRNAND\n" "at '/rw/luma/config.bin'." }; @@ -222,7 +213,6 @@ void configMenu(bool isSdMode, bool isSdAvailible, { .posXs = {19, 24, 29, 34}, .visible = isSdMode }, { .posXs = {21, 26, 31, 36}, .visible = true }, { .posXs = {12, 22, 31, 0}, .visible = true }, - { .posXs = {14, 19, 24, 29}, .visible = true }, { .posXs = {17, 26, 32, 44}, .visible = ISN3DS }, { .posXs = {19, 30, 42, 0}, .visible = true } }; @@ -411,11 +401,6 @@ void configMenu(bool isSdMode, bool isSdAvailible, for(u32 i = 0; i < singleOptionsAmount; i++) configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 20); - u32 newPinMode = MULTICONFIG(PIN); - - if(newPinMode != 0) newPin(oldPinStatus && newPinMode == oldPinMode, newPinMode); - else if(oldPinStatus) fileDelete(PIN_FILE); - while(HID_PAD & PIN_BUTTONS); wait(2000ULL); } diff --git a/source/config.h b/source/config.h index a02398c05..0ea61204d 100644 --- a/source/config.h +++ b/source/config.h @@ -24,7 +24,7 @@ #include "types.h" -#define CONFIG(a) (((configData.config >> (a + 20)) & 1) != 0) +#define CONFIG(a) (((configData.config >> (a + 18)) & 1) != 0) #define MULTICONFIG(a) ((configData.config >> (a * 2 + 8)) & 3) #define BOOTCONFIG(a, b) ((configData.config >> a) & b) @@ -43,7 +43,6 @@ enum multiOptions DEFAULTEMU = 0, BRIGHTNESS, SPLASH, - PIN, NEWCPU, DEVOPTIONS }; @@ -72,5 +71,4 @@ typedef enum ConfigurationStatus bool readConfig(void); void writeConfig(ConfigurationStatus needConfig, u32 configTemp); -void configMenu(bool isSdMode, bool isSdAvailible, - bool oldPinStatus, u32 oldPinMode); +void configMenu(bool isSdMode, bool isSdAvailible); diff --git a/source/main.c b/source/main.c index ada9d6866..1f8924d9e 100644 --- a/source/main.c +++ b/source/main.c @@ -29,7 +29,6 @@ #include "draw.h" #include "strings.h" #include "buttons.h" -#include "pin.h" extern CfgData configData; extern FirmwareSource firmSource; @@ -130,15 +129,12 @@ void main(void) } } - u32 pinMode = MULTICONFIG(PIN); - bool pinExists = pinMode != 0 && verifyPin(pinMode); - //If no configuration file exists or SELECT is held, load configuration menu bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & (BUTTON_SELECT | BUTTON_L1)) == BUTTON_SELECT); if(shouldLoadConfigMenu) { - configMenu(isSdMode, isSdAvailible, pinExists, pinMode); + configMenu(isSdMode, isSdAvailible); //Update pressed buttons pressed = HID_PAD; @@ -151,13 +147,6 @@ void main(void) isSafeMode = true; - //If the PIN has been verified, wait to make it easier to press the SAFE_MODE combo - if(pinExists && !shouldLoadConfigMenu) - { - while(HID_PAD & PIN_BUTTONS); - wait(2000ULL); - } - goto boot; } diff --git a/source/pin.c b/source/pin.c deleted file mode 100644 index 942666167..000000000 --- a/source/pin.c +++ /dev/null @@ -1,220 +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. -*/ - -/* -* Code originally by reworks -*/ - -#include "draw.h" -#include "config.h" -#include "screen.h" -#include "utils.h" -#include "memory.h" -#include "buttons.h" -#include "fs.h" -#include "pin.h" -#include "crypto.h" - -static char pinKeyToLetter(u32 pressed) -{ - const char keys[] = "AB--RLUD--XY"; - - u32 i; - for(i = 31; pressed > 1; i--) pressed /= 2; - - return keys[31 - i]; -} - -void newPin(bool allowSkipping, u32 pinMode) -{ - clearScreens(false); - - u8 length = 4 + 2 * (pinMode - 1); - - drawString("Enter a new PIN using ABXY and the DPad", true, 10, 10, COLOR_TITLE); - drawString(allowSkipping ? "Press START to skip, SELECT to reset" : "Press SELECT to reset", true, 10, 10 + SPACING_Y, COLOR_TITLE); - - drawString("PIN ( digits): ", true, 10, 10 + 3 * SPACING_Y, COLOR_WHITE); - drawCharacter('0' + length, true, 10 + 5 * SPACING_X, 10 + 3 * SPACING_Y, COLOR_WHITE); - - //Pad to AES block length with zeroes - __attribute__((aligned(4))) u8 enteredPassword[AES_BLOCK_SIZE] = {0}; - - bool reset = false; - u8 cnt = 0; - - while(cnt < length) - { - if(reset) - { - for(u32 i = 0; i < cnt; i++) - drawCharacter((char)enteredPassword[i], true, 10 + (16 + 2 * i) * SPACING_X, 10 + 3 * SPACING_Y, COLOR_BLACK); - - cnt = 0; - reset = false; - } - - u32 pressed; - do - { - pressed = waitInput(false); - } - while(!(pressed & PIN_BUTTONS)); - - pressed &= PIN_BUTTONS; - if(!allowSkipping) pressed &= ~BUTTON_START; - - if(pressed & BUTTON_START) return; - - if(pressed & BUTTON_SELECT) - { - reset = true; - continue; - } - - if(!pressed) continue; - - //Add character to password - enteredPassword[cnt] = (u8)pinKeyToLetter(pressed); - - //Visualize character on screen - drawCharacter(enteredPassword[cnt], true, 10 + (16 + 2 * cnt) * SPACING_X, 10 + 3 * SPACING_Y, COLOR_WHITE); - - cnt++; - } - - PinData pin; - - memcpy(pin.magic, "PINF", 4); - pin.formatVersionMajor = PIN_VERSIONMAJOR; - pin.formatVersionMinor = PIN_VERSIONMINOR; - - __attribute__((aligned(4))) u8 tmp[SHA_256_HASH_SIZE], - lengthBlock[AES_BLOCK_SIZE] = {0}; - lengthBlock[0] = length; - - computePinHash(tmp, lengthBlock); - memcpy(pin.lengthHash, tmp, sizeof(tmp)); - - computePinHash(tmp, enteredPassword); - memcpy(pin.hash, tmp, sizeof(tmp)); - - if(!fileWrite(&pin, PIN_FILE, sizeof(PinData))) - error("Error writing the PIN file"); -} - -bool verifyPin(u32 pinMode) -{ - PinData pin; - - if(fileRead(&pin, PIN_FILE, sizeof(PinData)) != sizeof(PinData) || - memcmp(pin.magic, "PINF", 4) != 0 || - pin.formatVersionMajor != PIN_VERSIONMAJOR || - pin.formatVersionMinor != PIN_VERSIONMINOR) - return false; - - __attribute__((aligned(4))) u8 tmp[SHA_256_HASH_SIZE], - lengthBlock[AES_BLOCK_SIZE] = {0}; - lengthBlock[0] = 4 + 2 * (pinMode - 1); - - computePinHash(tmp, lengthBlock); - - //Test vector verification (check if SD card has been used on another console or PIN length changed) - if(memcmp(pin.lengthHash, tmp, sizeof(tmp)) != 0) return false; - - initScreens(); - - drawString("Enter the PIN using ABXY and the DPad to proceed", true, 10, 10, COLOR_TITLE); - drawString("Press START to shutdown, SELECT to clear", true, 10, 10 + SPACING_Y, COLOR_TITLE); - - drawString("PIN ( digits): ", true, 10, 10 + 3 * SPACING_Y, COLOR_WHITE); - drawCharacter('0' + lengthBlock[0], true, 10 + 5 * SPACING_X, 10 + 3 * SPACING_Y, COLOR_WHITE); - - const char *messageFile = "pinmessage.txt"; - char message[801]; - - u32 messageSize = fileRead(message, messageFile, sizeof(message) - 1); - - if(messageSize != 0) - { - message[messageSize] = 0; - drawString(message, false, 10, 10, COLOR_WHITE); - } - - //Pad to AES block length with zeroes - __attribute__((aligned(4))) u8 enteredPassword[AES_BLOCK_SIZE] = {0}; - - bool unlock = false, - reset = false; - u8 cnt = 0; - - while(!unlock) - { - if(reset) - { - for(u32 i = 0; i < cnt; i++) - drawCharacter((char)enteredPassword[i], true, 10 + (16 + 2 * i) * SPACING_X, 10 + 3 * SPACING_Y, COLOR_BLACK); - - cnt = 0; - reset = false; - } - - u32 pressed; - do - { - pressed = waitInput(false); - } - while(!(pressed & PIN_BUTTONS)); - - if(pressed & BUTTON_START) mcuPowerOff(); - - pressed &= PIN_BUTTONS; - - if(pressed & BUTTON_SELECT) - { - reset = true; - continue; - } - - if(!pressed) continue; - - //Add character to password - enteredPassword[cnt] = (u8)pinKeyToLetter(pressed); - - //Visualize character on screen - drawCharacter((char)enteredPassword[cnt], true, 10 + (16 + 2 * cnt) * SPACING_X, 10 + 3 * SPACING_Y, COLOR_WHITE); - - if(++cnt < lengthBlock[0]) continue; - - computePinHash(tmp, enteredPassword); - unlock = memcmp(pin.hash, tmp, sizeof(tmp)) == 0; - - if(!unlock) - { - reset = true; - - drawString("Wrong PIN, try again", true, 10, 10 + 5 * SPACING_Y, COLOR_RED); - } - } - - return true; -} \ No newline at end of file diff --git a/source/pin.h b/source/pin.h deleted file mode 100644 index c781508ad..000000000 --- a/source/pin.h +++ /dev/null @@ -1,36 +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. -*/ - -/* -* Code originally by reworks -*/ - -#pragma once - -#include "types.h" - -#define PIN_FILE "pin.bin" -#define PIN_VERSIONMAJOR 1 -#define PIN_VERSIONMINOR 3 - -void newPin(bool allowSkipping, u32 pinMode); -bool verifyPin(u32 pinMode); \ No newline at end of file From 53d0e44c19961b547abc4366b4eeb8092e43f82a Mon Sep 17 00:00:00 2001 From: <@> Date: Mon, 26 Dec 2016 14:17:44 -0500 Subject: [PATCH 16/26] Added key-combo option to menu. --- source/config.c | 33 ++++++++++++++++++--------------- source/config.h | 3 ++- source/patches.c | 2 -- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/source/config.c b/source/config.c index 506da8e6a..17072ba51 100644 --- a/source/config.c +++ b/source/config.c @@ -82,9 +82,10 @@ void configMenu(bool isSdMode, bool isSdAvailible) "( ) Show NAND or user string in System Settings", "( ) Show GBA boot screen in patched AGB_FIRM", "( ) Patch SVC/service/archive/ARM9 access", - "( ) Kecleon: Disable Signature/TWL patches", - "( ) Kecleon: Ignore all Button Presses on boot.", - "( ) Kecleon: Save config.bin in CTRNAND." + "( ) Kecleon: Save config.bin in CTRNAND.", + "( ) Kecleon: Disable Region-Free/Flashcart\n patches", + "( ) Kecleon: Ignore all Button Presses on boot", + "( ) Kecleon: Set key-combo to remove above lock" }; const char *optionsDescription[] = { "Select the default EmuNAND.\n\n" @@ -183,25 +184,26 @@ void configMenu(bool isSdMode, bool isSdAvailible) "Only change this if you know what you\n" "are doing!", + "Save configuration file in CTRNAND\n" + "at '/rw/luma/config.bin'.", + "This disables patches that can give\n" "away this 3DS is running CFW,\n" - "such as out-of-region cartridges.\n" - "Specifically this disables Signature,\n" - "TWL and Flashcart patches.", + "such as out-of-region cartridges,\n" + "out-of-region download play,\n" + "or banned flashcarts.", "This makes Luma3DS ignore all Button\n" "Presses on boot, hiding chainloading\n" "and boot menus that give away this\n" - "3DS is running CFW.\n" + "3DS is running CFW.\n\n" "Warning: config.bin must be deleted\n" - "to re-enable chainloading and\n" - "startup menus.\n" - "Also note that config.bin may be\n" - "located on your CTRNAND in '/rw/luma'.\n" - "Use GodMode9 to delete it.", + "to re-enable chainloading menus\n" + "if Key Combo is not set.\n", - "Save configuration file in CTRNAND\n" - "at '/rw/luma/config.bin'." + "Set a Key Combo to make menu appear\n" + "on startup, when the above option\n" + "is set." }; struct multiOption { @@ -230,9 +232,10 @@ void configMenu(bool isSdMode, bool isSdAvailible) { .visible = true }, { .visible = true }, { .visible = true }, + { .visible = isSdAvailible }, { .visible = true }, { .visible = true }, - { .visible = isSdAvailible } + { .visible = true } }; //Calculate the amount of the various kinds of options and pre-select the first single one diff --git a/source/config.h b/source/config.h index 0ea61204d..5eacf06ed 100644 --- a/source/config.h +++ b/source/config.h @@ -57,9 +57,10 @@ enum singleOptions PATCHVERSTRING, SHOWGBABOOT, PATCHACCESS, + KECNAND, KECPATCH, KECMENU, - KECNAND + KECCOMBO }; typedef enum ConfigurationStatus diff --git a/source/patches.c b/source/patches.c index 910b62b6a..95b824e6e 100644 --- a/source/patches.c +++ b/source/patches.c @@ -102,8 +102,6 @@ u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space, u32 * u32 patchSignatureChecks(u8 *pos, u32 size) { - if (CONFIG(KECPATCH)) return 0; - //Look for signature checks const u8 pattern[] = {0xC0, 0x1C, 0x76, 0xE7}, pattern2[] = {0xB5, 0x22, 0x4D, 0x0C}; From 263f6ed45fda8695311fc6c2ff7577cbb42dbc76 Mon Sep 17 00:00:00 2001 From: <@> Date: Mon, 26 Dec 2016 17:46:43 -0500 Subject: [PATCH 17/26] Implemented disable patches option. --- injector/source/patcher.c | 17 +++++++++-------- injector/source/patcher.h | 9 ++++++--- source/config.h | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/injector/source/patcher.c b/injector/source/patcher.c index 8ec7a3fed..f6b96b1ee 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -499,14 +499,15 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size) { loadCFWInfo(); - if(((progId == 0x0004003000008F02LL || //USA Home Menu - progId == 0x0004003000008202LL || //JPN Home Menu - progId == 0x0004003000009802LL) //EUR Home Menu - && progVer > 4) || - (progId == 0x000400300000A902LL //KOR Home Menu - && progVer > 0) || - progId == 0x000400300000A102LL || //CHN Home Menu - progId == 0x000400300000B102LL) //TWN Home Menu + if((((progId == 0x0004003000008F02LL || //USA Home Menu + progId == 0x0004003000008202LL || //JPN Home Menu + progId == 0x0004003000009802LL) //EUR Home Menu + && progVer > 4) || + (progId == 0x000400300000A902LL //KOR Home Menu + && progVer > 0) || + progId == 0x000400300000A102LL || //CHN Home Menu + progId == 0x000400300000B102LL) //TWN Home Menu + && !CONFIG(KECPATCH)) { static const u8 pattern[] = { 0x0A, 0x0C, 0x00, 0x10 diff --git a/injector/source/patcher.h b/injector/source/patcher.h index 236a1b0a4..bc76b68b0 100644 --- a/injector/source/patcher.h +++ b/injector/source/patcher.h @@ -20,7 +20,6 @@ enum multiOptions DEFAULTEMU = 0, BRIGHTNESS, SPLASH, - PIN, NEWCPU, DEVOPTIONS }; @@ -34,7 +33,11 @@ enum singleOptions PATCHGAMES, PATCHVERSTRING, SHOWGBABOOT, - PATCHACCESS + PATCHACCESS, + KECNAND, + KECPATCH, + KECMENU, + KECCOMBO }; enum flags @@ -43,4 +46,4 @@ enum flags ISSAFEMODE }; -void patchCode(u64 progId, u16 progVer, u8 *code, u32 size); \ No newline at end of file +void patchCode(u64 progId, u16 progVer, u8 *code, u32 size); diff --git a/source/config.h b/source/config.h index 5eacf06ed..b3f778754 100644 --- a/source/config.h +++ b/source/config.h @@ -24,7 +24,7 @@ #include "types.h" -#define CONFIG(a) (((configData.config >> (a + 18)) & 1) != 0) +#define CONFIG(a) (((configData.config >> (a + 20)) & 1) != 0) #define MULTICONFIG(a) ((configData.config >> (a * 2 + 8)) & 3) #define BOOTCONFIG(a, b) ((configData.config >> a) & b) From 552e4cfaf69a547e998ebb381451a1e2f51a481f Mon Sep 17 00:00:00 2001 From: <@> Date: Tue, 27 Dec 2016 13:36:39 -0500 Subject: [PATCH 18/26] Changed to 64bit config. --- source/config.c | 4 ++-- source/types.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/config.c b/source/config.c index 17072ba51..4b08eed30 100644 --- a/source/config.c +++ b/source/config.c @@ -49,7 +49,7 @@ void writeConfig(ConfigurationStatus needConfig, u32 configTemp) { /* If the configuration is different from previously, overwrite it. Just the no-forcing flag being set is not enough */ - if(needConfig != CREATE_CONFIGURATION && (configTemp & 0xFFFFFF7F) == configData.config) return; + if(needConfig != CREATE_CONFIGURATION && (configTemp & 0xFFFFFFFFFFFFFF7F) == configData.config) return; if(needConfig == CREATE_CONFIGURATION) { @@ -59,7 +59,7 @@ void writeConfig(ConfigurationStatus needConfig, u32 configTemp) } //Merge the new options and new boot configuration - configData.config = (configData.config & 0xFFFFFF00) | (configTemp & 0xFF); + configData.config = (configData.config & 0xFFFFFFFFFFFFFF00) | (configTemp & 0xFF); if(!fileWrite(&configData, CONFIG_FILE, sizeof(CfgData))) error("Error writing the configuration file"); diff --git a/source/types.h b/source/types.h index 4b22de8b8..8c1672c99 100644 --- a/source/types.h +++ b/source/types.h @@ -55,7 +55,7 @@ typedef struct __attribute__((packed)) char magic[4]; u16 formatVersionMajor, formatVersionMinor; - u32 config; + u64 config; } CfgData; typedef struct __attribute__((packed)) @@ -101,4 +101,4 @@ typedef enum FirmwareType NATIVE_FIRM1X2X } FirmwareType; -extern u16 launchedFirmTidLow[8]; //Defined in start.s \ No newline at end of file +extern u16 launchedFirmTidLow[8]; //Defined in start.s From d14e1290a693df865e7ec0d2a9c59b47047e701e Mon Sep 17 00:00:00 2001 From: <@> Date: Thu, 29 Dec 2016 22:37:24 -0500 Subject: [PATCH 19/26] Implemented key combo --- source/config.c | 19 +++++++++++++++++++ source/main.c | 8 +++++++- source/types.h | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/source/config.c b/source/config.c index 4b08eed30..5e0fbbf7c 100644 --- a/source/config.c +++ b/source/config.c @@ -65,6 +65,23 @@ void writeConfig(ConfigurationStatus needConfig, u32 configTemp) error("Error writing the configuration file"); } +u32 getPAD() +{ + initScreens(); + + drawString("Set key combo with ABXY, START, SELECT & D-Pad.\n" + "Press R while holding down combo to finish.", + true, 10, 10, COLOR_WHITE); + + u32 pressed; + do { + pressed = waitInput(true); + } + while(!(pressed & BUTTON_R1)); + + return pressed & PIN_BUTTONS; +} + void configMenu(bool isSdMode, bool isSdAvailible) { const char *multiOptionsText[] = { "Default EmuNAND: 1( ) 2( ) 3( ) 4( )", @@ -404,6 +421,8 @@ void configMenu(bool isSdMode, bool isSdAvailible) for(u32 i = 0; i < singleOptionsAmount; i++) configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 20); + if (CONFIG(KECCOMBO)) configData.combo = getPAD(); + while(HID_PAD & PIN_BUTTONS); wait(2000ULL); } diff --git a/source/main.c b/source/main.c index 1f8924d9e..01a1d8fab 100644 --- a/source/main.c +++ b/source/main.c @@ -100,6 +100,9 @@ void main(void) //Get pressed buttons only if chainloading/boot menus aren't disabled u32 pressed = CONFIG(KECMENU) ? 0 : HID_PAD; + //Should load menu via key combo + bool keyComboPressed = CONFIG(KECCOMBO) && configData.combo == HID_PAD; + //Save old options and begin saving the new boot configuration configTemp = (configData.config & 0xFFFFFF00) | ((u32)ISA9LH << 6); @@ -130,7 +133,10 @@ void main(void) } //If no configuration file exists or SELECT is held, load configuration menu - bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & (BUTTON_SELECT | BUTTON_L1)) == BUTTON_SELECT); + bool shouldLoadConfigMenu = + needConfig == CREATE_CONFIGURATION || + ((pressed & (BUTTON_SELECT | BUTTON_L1)) == BUTTON_SELECT) || + keyComboPressed; if(shouldLoadConfigMenu) { diff --git a/source/types.h b/source/types.h index 8c1672c99..ffadcea4a 100644 --- a/source/types.h +++ b/source/types.h @@ -56,6 +56,7 @@ typedef struct __attribute__((packed)) u16 formatVersionMajor, formatVersionMinor; u64 config; + u32 combo; } CfgData; typedef struct __attribute__((packed)) From 55b7ea600bf8d666867ddbe83d1610e71dea1f34 Mon Sep 17 00:00:00 2001 From: <@> Date: Fri, 30 Dec 2016 11:28:48 -0500 Subject: [PATCH 20/26] Rewrote some of the descriptions. --- injector/source/patcher.c | 4 ++-- source/config.c | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/injector/source/patcher.c b/injector/source/patcher.c index f6b96b1ee..40d4780e5 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -592,7 +592,7 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size) )) goto error; } - else if(progId == 0x0004013000008002LL) //NS + else if(progId == 0x0004013000008002LL && !CONFIG(KECPATCH)) //NS { if(progVer > 4) { @@ -732,7 +732,7 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size) ) != 3) goto error; } - else if(progId == 0x0004013000002802LL && progVer > 0) //DLP + else if(progId == 0x0004013000002802LL && progVer > 0 && !CONFIG(KECPATCH)) //DLP { static const u8 pattern[] = { 0x0C, 0xAC, 0xC0, 0xD8 diff --git a/source/config.c b/source/config.c index 5e0fbbf7c..1bb892922 100644 --- a/source/config.c +++ b/source/config.c @@ -215,12 +215,13 @@ void configMenu(bool isSdMode, bool isSdAvailible) "and boot menus that give away this\n" "3DS is running CFW.\n\n" "Warning: config.bin must be deleted\n" - "to re-enable chainloading menus\n" + "to re-enable configuration menus\n" "if Key Combo is not set.\n", - "Set a Key Combo to make menu appear\n" - "on startup, when the above option\n" - "is set." + "Set a Key Combo to make this\n" + "configuration menu appear on\n" + "startup, when the above option is\n" + "set." }; struct multiOption { From a36745c1ce55cbd9767354610ff1c37d399c8dc0 Mon Sep 17 00:00:00 2001 From: <@> Date: Fri, 30 Dec 2016 14:44:49 -0500 Subject: [PATCH 21/26] Fixed first time boot to EmuNAND. --- source/config.c | 4 ++-- source/config.h | 2 +- source/main.c | 11 ++++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/source/config.c b/source/config.c index 1bb892922..fefb7eb7b 100644 --- a/source/config.c +++ b/source/config.c @@ -82,7 +82,7 @@ u32 getPAD() return pressed & PIN_BUTTONS; } -void configMenu(bool isSdMode, bool isSdAvailible) +void configMenu(bool isSdMode) { const char *multiOptionsText[] = { "Default EmuNAND: 1( ) 2( ) 3( ) 4( )", "Screen brightness: 4( ) 3( ) 2( ) 1( )", @@ -250,7 +250,7 @@ void configMenu(bool isSdMode, bool isSdAvailible) { .visible = true }, { .visible = true }, { .visible = true }, - { .visible = isSdAvailible }, + { .visible = isSdMode }, { .visible = true }, { .visible = true }, { .visible = true } diff --git a/source/config.h b/source/config.h index b3f778754..25924c18a 100644 --- a/source/config.h +++ b/source/config.h @@ -72,4 +72,4 @@ typedef enum ConfigurationStatus bool readConfig(void); void writeConfig(ConfigurationStatus needConfig, u32 configTemp); -void configMenu(bool isSdMode, bool isSdAvailible); +void configMenu(bool isSdMode); diff --git a/source/main.c b/source/main.c index 01a1d8fab..42b6547c8 100644 --- a/source/main.c +++ b/source/main.c @@ -44,18 +44,15 @@ void main(void) ConfigurationStatus needConfig; // Attempt to mount SD card. - bool isSdAvailible = mountFs(true, false); - bool isSdMode = isSdAvailible; - if (isSdAvailible) { + bool isSdMode = mountFs(true, false); + if (isSdMode) { // Attempt to load configuration. needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; - isSdMode = true; } // If either of those fail, attempt to mount CTRNAND. if (!isSdMode || needConfig == CREATE_CONFIGURATION) { firmSource = FIRMWARE_SYSNAND; if(!mountFs(false, true)) error("Failed to mount SD and CTRNAND."); - isSdMode = false; // Attempt to load configuration file. needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; } @@ -140,7 +137,7 @@ void main(void) if(shouldLoadConfigMenu) { - configMenu(isSdMode, isSdAvailible); + configMenu(isSdMode); //Update pressed buttons pressed = HID_PAD; @@ -237,7 +234,7 @@ void main(void) configTemp |= (u32)nandType | ((u32)firmSource << 3); /* Change to SD card if writing config to SD card. */ - if (isSdAvailible && !CONFIG(KECNAND)) { + if (isSdMode && !CONFIG(KECNAND)) { if (!changeDrive(true)) error("SD card unavailible."); } From d3fcf76b82bc1e639c2a827ba18505a8dc6ef9e0 Mon Sep 17 00:00:00 2001 From: <@> Date: Fri, 30 Dec 2016 15:41:13 -0500 Subject: [PATCH 22/26] Fixed luma folder on SD card. --- source/fs.c | 16 ++++++++++++++++ source/fs.h | 1 + source/main.c | 7 ++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/source/fs.c b/source/fs.c index 93403988d..5bbb595e3 100644 --- a/source/fs.c +++ b/source/fs.c @@ -35,6 +35,22 @@ static FATFS sdFs, nandFs; +void rmEmptyDir() +{ + DIR dir; + FILINFO fno; + + if (f_chdir("/") != FR_OK) error("Filesystem Error!"); + if (f_opendir(&dir, "luma") != FR_OK) error("Directory luma does not exist"); + f_readdir(&dir, &fno); + f_closedir(&dir); + + if (fno.fname[0] == 0) { + f_unlink("luma"); + } + +} + static bool switchToMainDir(bool isSd) { const char *mainDir = isSd ? "/luma" : "/rw/luma"; diff --git a/source/fs.h b/source/fs.h index 0bc160b1d..5cc81abb5 100644 --- a/source/fs.h +++ b/source/fs.h @@ -26,6 +26,7 @@ #define PATTERN(a) a "_*.bin" +void rmEmptyDir(); bool mountFs(bool isSd, bool switchToCtrNand); bool changeDrive(bool switchToSd); u32 fileRead(void *dest, const char *path, u32 maxSize); diff --git a/source/main.c b/source/main.c index 42b6547c8..6a1c87337 100644 --- a/source/main.c +++ b/source/main.c @@ -47,7 +47,12 @@ void main(void) bool isSdMode = mountFs(true, false); if (isSdMode) { // Attempt to load configuration. - needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; + if (readConfig()) { + needConfig = MODIFY_CONFIGURATION; + } else { + needConfig = CREATE_CONFIGURATION; + rmEmptyDir(); + } } // If either of those fail, attempt to mount CTRNAND. if (!isSdMode || needConfig == CREATE_CONFIGURATION) { From c2e856bed904bc488bddb52dcafa89eeb439c9dd Mon Sep 17 00:00:00 2001 From: <@> Date: Tue, 31 Jan 2017 16:32:09 -0500 Subject: [PATCH 23/26] Updated README.md. --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 92460ad7c..0ce2a1209 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +# Luma3DS - Kecleon + +Please read the [gbatemp thread](https://gbatemp.net/threads/release-kecleon-patch-for-luma3ds.455090/). + +Original Readme: + # Luma3DS *Noob-proof (N)3DS "Custom Firmware"* From f70388548a6e504d8349bcd4c3da676c46dcdfa8 Mon Sep 17 00:00:00 2001 From: <@> Date: Tue, 31 Jan 2017 17:17:21 -0500 Subject: [PATCH 24/26] Cleaned up minor things in source code. --- source/config.c | 7 ++++--- source/main.c | 3 --- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/source/config.c b/source/config.c index 1e8e3b499..b9013394e 100644 --- a/source/config.c +++ b/source/config.c @@ -70,7 +70,8 @@ u32 getPAD() initScreens(); drawString("Set key combo with ABXY, START, SELECT & D-Pad.\n" - "Press R while holding down combo to finish.", + "Press R while holding down combo to finish.\n" + "This may take a few seconds.", true, 10, 10, COLOR_WHITE); u32 pressed; @@ -250,9 +251,10 @@ void configMenu(bool isSdMode) { .visible = true }, { .visible = true }, { .visible = true }, - { .visible = isSdMode }, { .visible = true }, { .visible = true }, + { .visible = true }, + { .visible = true } }; //Calculate the amount of the various kinds of options and pre-select the first single one @@ -423,6 +425,5 @@ void configMenu(bool isSdMode) if (CONFIG(KECCOMBO)) configData.combo = getPAD(); - while(HID_PAD & PIN_BUTTONS); wait(2000ULL); } diff --git a/source/main.c b/source/main.c index 6a1c87337..688913bf6 100644 --- a/source/main.c +++ b/source/main.c @@ -62,9 +62,6 @@ void main(void) needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; } - //Attempt to read the configuration file - needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; - //Determine if this is a firmlaunch boot if(ISFIRMLAUNCH) { From 72c039929f208edab281c28d91f910deda338b46 Mon Sep 17 00:00:00 2001 From: <@> Date: Thu, 2 Feb 2017 16:51:35 -0500 Subject: [PATCH 25/26] Load payloads only from SD card. --- source/fs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/fs.c b/source/fs.c index 5bbb595e3..7e2679127 100644 --- a/source/fs.c +++ b/source/fs.c @@ -138,6 +138,8 @@ void fileDelete(const char *path) void loadPayload(u32 pressed, const char *payloadPath) { + changeDrive(true); + u32 *loaderAddress = (u32 *)0x24FFFE00; u8 *payloadAddress = (u8 *)0x24F00000; u32 payloadSize = 0, From 004f07ba92854c999ef9215983742523d05cd7a7 Mon Sep 17 00:00:00 2001 From: <@> Date: Fri, 3 Feb 2017 12:21:50 -0500 Subject: [PATCH 26/26] Fixed payload loading. Payload loading bug fixed. Payloads will now be searched for on SD card first, and upon fail, from CTRNAND. --- source/fs.c | 48 +++++++++++++++++++++++++++++++++++------------- source/fs.h | 6 +++--- source/main.c | 4 ++-- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/source/fs.c b/source/fs.c index 7e2679127..f9ff70f65 100644 --- a/source/fs.c +++ b/source/fs.c @@ -41,12 +41,16 @@ void rmEmptyDir() FILINFO fno; if (f_chdir("/") != FR_OK) error("Filesystem Error!"); - if (f_opendir(&dir, "luma") != FR_OK) error("Directory luma does not exist"); + if (f_opendir(&dir, "luma") != FR_OK) + error("Directory /luma does not exist"); f_readdir(&dir, &fno); f_closedir(&dir); if (fno.fname[0] == 0) { f_unlink("luma"); + } else { + if (f_opendir(&dir, "luma") != FR_OK) + error("Directory /luma does not exist"); } } @@ -67,9 +71,9 @@ static bool switchToMainDir(bool isSd) } } -bool mountFs(bool isSd, bool switchToCtrNand) +bool mountFs(bool isSdMode, bool switchToCtrNand) { - return isSd ? f_mount(&sdFs, "0:", 1) == FR_OK && switchToMainDir(true) : + return isSdMode ? f_mount(&sdFs, "0:", 1) == FR_OK && switchToMainDir(true) : f_mount(&nandFs, "1:", 1) == FR_OK && (!switchToCtrNand || (f_chdrive("1:") == FR_OK && switchToMainDir(false))); } @@ -136,9 +140,21 @@ void fileDelete(const char *path) f_unlink(path); } -void loadPayload(u32 pressed, const char *payloadPath) +void loadPayload(u32 pressed, const char *payloadPath, bool isSdMode) { - changeDrive(true); + DIR dir; + FILINFO info; + char path[22] = "payloads"; + FRESULT result; + + /* Test SD for payloads. On fail, use NAND. */ + if (isSdMode) { + changeDrive(true); + result = f_findfirst(&dir, &info, path, "*.bin"); + if (result != FR_OK) { + changeDrive(false); + } + } u32 *loaderAddress = (u32 *)0x24FFFE00; u8 *payloadAddress = (u8 *)0x24F00000; @@ -161,11 +177,6 @@ void loadPayload(u32 pressed, const char *payloadPath) else if(pressed & BUTTON_A) pattern = PATTERN("a"); else pattern = PATTERN("select"); - DIR dir; - FILINFO info; - FRESULT result; - char path[22] = "payloads"; - result = f_findfirst(&dir, &info, path, pattern); if(result != FR_OK) return; @@ -194,14 +205,25 @@ void loadPayload(u32 pressed, const char *payloadPath) ((void (*)())loaderAddress)(); } -void payloadMenu(void) +void payloadMenu(bool isSdMode) { DIR dir; + FILINFO info; char path[62] = "payloads"; + FRESULT result; + + /* Test SD for payloads. On fail, use NAND. */ + if (isSdMode) { + changeDrive(true); + result = f_findfirst(&dir, &info, path, "*.bin"); + if (result != FR_OK) { + changeDrive(false); + } + } + if(f_opendir(&dir, path) != FR_OK) return; - FILINFO info; u32 payloadNum = 0; char payloadList[20][49]; @@ -279,7 +301,7 @@ void payloadMenu(void) concatenateStrings(path, "/"); concatenateStrings(path, payloadList[selectedPayload]); concatenateStrings(path, ".bin"); - loadPayload(0, path); + loadPayload(0, path, isSdMode); error("The payload is too large or corrupted."); } diff --git a/source/fs.h b/source/fs.h index 5cc81abb5..c0cfacd3f 100644 --- a/source/fs.h +++ b/source/fs.h @@ -27,13 +27,13 @@ #define PATTERN(a) a "_*.bin" void rmEmptyDir(); -bool mountFs(bool isSd, bool switchToCtrNand); +bool mountFs(bool isSdMode, bool switchToCtrNand); bool changeDrive(bool switchToSd); u32 fileRead(void *dest, const char *path, u32 maxSize); u32 getFileSize(const char *path); bool fileWrite(const void *buffer, const char *path, u32 size); void fileDelete(const char *path); -void loadPayload(u32 pressed, const char *payloadPath); -void payloadMenu(void); +void loadPayload(u32 pressed, const char *payloadPath, bool isSdMode); +void payloadMenu(bool isSdMode); u32 firmRead(void *dest, u32 firmType); void findDumpFile(const char *path, char *fileName); diff --git a/source/main.c b/source/main.c index 688913bf6..21f995676 100644 --- a/source/main.c +++ b/source/main.c @@ -161,11 +161,11 @@ void main(void) if((pressed & (BUTTON_START | BUTTON_L1)) == BUTTON_START) { - payloadMenu(); + payloadMenu(isSdMode); pressed = HID_PAD; } else if(((pressed & SINGLE_PAYLOAD_BUTTONS) && !(pressed & (BUTTON_L1 | BUTTON_R1 | BUTTON_A))) || - ((pressed & L_PAYLOAD_BUTTONS) && (pressed & BUTTON_L1))) loadPayload(pressed, NULL); + ((pressed & L_PAYLOAD_BUTTONS) && (pressed & BUTTON_L1))) loadPayload(pressed, NULL, isSdMode); if(splashMode == 2) loadSplash();