From e5dcca1c2babe37cbff38d9b4251aaa5c6430cce Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 16 Aug 2016 01:59:23 +0200 Subject: [PATCH 1/5] Update gitignore --- .gitignore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 29fb8eb6..0f61a0bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,12 @@ out build loader/build -screeninit/build injector/build +exceptions/arm9/build +exceptions/arm11/build *.bin *.3dsx *.smdh *.o *.d -*.elf -*.bat \ No newline at end of file +*.elf \ No newline at end of file From ee3720f0b706692cbe128cb213d5dc96abb4ac15 Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 16 Aug 2016 18:47:27 +0200 Subject: [PATCH 2/5] Make loader more readable, use an array instead of a fixed location for the emuNAND test sector --- loader/source/main.c | 4 +++- loader/source/start.s | 2 ++ source/emunand.c | 2 +- source/pin.c | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/loader/source/main.c b/loader/source/main.c index d7886ac5..4605d255 100644 --- a/loader/source/main.c +++ b/loader/source/main.c @@ -23,11 +23,13 @@ #include "memory.h" #include "cache.h" +extern u32 payloadSize; //defined in start.s + void main(void) { void *payloadAddress = (void *)0x23F00000; - memcpy(payloadAddress, (void*)0x24F00000, *(u32 *)0x24FFFF04); + memcpy(payloadAddress, (void*)0x24F00000, payloadSize); flushCaches(); diff --git a/loader/source/start.s b/loader/source/start.s index a9a443ff..8dd57472 100644 --- a/loader/source/start.s +++ b/loader/source/start.s @@ -24,4 +24,6 @@ _start: b main +.global payloadSize +payloadSize: .word 0 diff --git a/source/emunand.c b/source/emunand.c index 66468a99..2b6f02c0 100644 --- a/source/emunand.c +++ b/source/emunand.c @@ -27,7 +27,7 @@ void locateEmuNAND(u32 *off, u32 *head, FirmwareSource *emuNAND) { - static u8 *const temp = (u8 *)0x24300000; + static u8 temp[0x200]; const u32 nandSize = getMMCDevice(0)->total_size; u32 nandOffset = *emuNAND == FIRMWARE_EMUNAND ? 0 : diff --git a/source/pin.c b/source/pin.c index 26f17c3d..83963d07 100644 --- a/source/pin.c +++ b/source/pin.c @@ -170,4 +170,4 @@ void verifyPin(PINData *in, bool allowQuit) else break; } } -} +} \ No newline at end of file From 40369d44df964660a2249ba7e84c3ccda9a05858 Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 16 Aug 2016 22:37:57 +0200 Subject: [PATCH 3/5] Pin cleanup --- source/firm.c | 7 +++---- source/pin.c | 5 ++--- source/pin.h | 7 ++----- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/source/firm.c b/source/firm.c index 386abcc5..97faef9e 100755 --- a/source/firm.c +++ b/source/firm.c @@ -33,7 +33,6 @@ #include "screen.h" #include "buttons.h" #include "pin.h" -#include "i2c.h" #include "../build/injector.h" extern u16 launchedFirmTIDLow[8]; //defined in start.s @@ -48,8 +47,6 @@ bool isN3DS, isDevUnit; FirmwareSource firmSource; -PINData pin; - void main(void) { bool isFirmlaunch, @@ -133,6 +130,8 @@ void main(void) //Boot options aren't being forced if(needConfig != DONT_CONFIGURE) { + PINData pin; + bool pinExists = CONFIG(7) && readPin(&pin); //If we get here we should check the PIN (if it exists) in all cases @@ -145,7 +144,7 @@ void main(void) { configureCFW(configPath); - if(!pinExists && CONFIG(7)) pin = newPin(); + if(!pinExists && CONFIG(7)) newPin(); chrono(2); diff --git a/source/pin.c b/source/pin.c index 83963d07..4932ad29 100644 --- a/source/pin.c +++ b/source/pin.c @@ -31,7 +31,6 @@ #include "memory.h" #include "buttons.h" #include "fs.h" -#include "i2c.h" #include "pin.h" #include "crypto.h" @@ -44,6 +43,7 @@ bool readPin(PINData *out) if(memcmp(out->magic, "PINF", 4) != 0) return false; computePINHash(tmp, zeroes, 1); + return memcmp(out->testHash, tmp, 32) == 0; //test vector verification (SD card has (or hasn't) been used on another console) } @@ -57,7 +57,7 @@ static inline char PINKeyToLetter(u32 pressed) return keys[31 - i]; } -PINData newPin(void) +void newPin(void) { clearScreens(); @@ -106,7 +106,6 @@ PINData newPin(void) memcpy(pin.hash, tmp, 32); fileWrite(&pin, "/luma/pin.bin", sizeof(PINData)); - return pin; } } diff --git a/source/pin.h b/source/pin.h index 462d73f2..c89fbb24 100644 --- a/source/pin.h +++ b/source/pin.h @@ -30,9 +30,7 @@ #include "types.h" -#ifndef PIN_LENGTH - #define PIN_LENGTH 4 -#endif +#define PIN_LENGTH 4 typedef struct __attribute__((packed)) { @@ -44,6 +42,5 @@ typedef struct __attribute__((packed)) } PINData; bool readPin(PINData* out); - -PINData newPin(void); +void newPin(void); void verifyPin(PINData *in, bool allowQuit); \ No newline at end of file From 4d9cbc4e19e311a75e2dace4338d40fad41b048c Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 16 Aug 2016 22:46:41 +0200 Subject: [PATCH 4/5] Fix fail --- source/pin.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/source/pin.c b/source/pin.c index 4932ad29..ff3fe088 100644 --- a/source/pin.c +++ b/source/pin.c @@ -69,7 +69,7 @@ void newPin(void) u32 cnt = 0; int charDrawPos = 20 * SPACING_X; - while(true) + while(cnt < PIN_LENGTH) { u32 pressed; do @@ -87,27 +87,23 @@ void newPin(void) // visualize character on screen. drawCharacter(key, 10 + charDrawPos, 10, COLOR_WHITE); charDrawPos += 2 * SPACING_X; - - // we leave the rest of the array zeroed out. - if(cnt >= PIN_LENGTH) - { - PINData pin = {0}; - u8 __attribute__((aligned(4))) tmp[32] = {0}; - u8 __attribute__((aligned(4))) zeroes[16] = {0}; - - memcpy(pin.magic, "PINF", 4); - pin.formatVersionMajor = 1; - pin.formatVersionMinor = 0; - - computePINHash(tmp, zeroes, 1); - memcpy(pin.testHash, tmp, 32); - - computePINHash(tmp, enteredPassword, (PIN_LENGTH + 15) / 16); - memcpy(pin.hash, tmp, 32); - - fileWrite(&pin, "/luma/pin.bin", sizeof(PINData)); - } } + + PINData pin = {0}; + u8 __attribute__((aligned(4))) tmp[32] = {0}; + u8 __attribute__((aligned(4))) zeroes[16] = {0}; + + memcpy(pin.magic, "PINF", 4); + pin.formatVersionMajor = 1; + pin.formatVersionMinor = 0; + + computePINHash(tmp, zeroes, 1); + memcpy(pin.testHash, tmp, 32); + + computePINHash(tmp, enteredPassword, (PIN_LENGTH + 15) / 16); + memcpy(pin.hash, tmp, 32); + + fileWrite(&pin, "/luma/pin.bin", sizeof(PINData)); while(HID_PAD & PIN_BUTTONS); } @@ -123,10 +119,10 @@ void verifyPin(PINData *in, bool allowQuit) u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0}; u32 cnt = 0; - bool unlock; + bool unlock = false; int charDrawPos = 5 * SPACING_X; - while(true) + while(!unlock) { u32 pressed; do @@ -166,7 +162,6 @@ void verifyPin(PINData *in, bool allowQuit) drawString("Pin: ", 10, 10 + 2 * SPACING_Y, COLOR_WHITE); drawString("Wrong pin! Try again!", 10, 10 + 3 * SPACING_Y, COLOR_RED); } - else break; } } } \ No newline at end of file From 4f8c66b2b7da868e942115426fd789f9954df4b1 Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 16 Aug 2016 22:59:25 +0200 Subject: [PATCH 5/5] There would not be an use for this --- source/firm.c | 2 +- source/pin.c | 6 +++--- source/pin.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/firm.c b/source/firm.c index 97faef9e..ef35cc77 100755 --- a/source/firm.c +++ b/source/firm.c @@ -135,7 +135,7 @@ void main(void) bool pinExists = CONFIG(7) && readPin(&pin); //If we get here we should check the PIN (if it exists) in all cases - if(pinExists) verifyPin(&pin, true); + if(pinExists) verifyPin(&pin); //If no configuration file exists or SELECT is held, load configuration menu bool shouldLoadConfigurationMenu = needConfig == CREATE_CONFIGURATION || ((pressed & BUTTON_SELECT) && !(pressed & BUTTON_L1)); diff --git a/source/pin.c b/source/pin.c index ff3fe088..6d69e68e 100644 --- a/source/pin.c +++ b/source/pin.c @@ -108,7 +108,7 @@ void newPin(void) while(HID_PAD & PIN_BUTTONS); } -void verifyPin(PINData *in, bool allowQuit) +void verifyPin(PINData *in) { initScreens(); @@ -131,8 +131,8 @@ void verifyPin(PINData *in, bool allowQuit) } while(!(pressed & PIN_BUTTONS)); - pressed &= PIN_BUTTONS;// & ~BUTTON_START; - if(!allowQuit) pressed &= ~BUTTON_START; + pressed &= PIN_BUTTONS & ~BUTTON_START; + if(!pressed) continue; if(pressed & BUTTON_START) mcuPowerOff(); diff --git a/source/pin.h b/source/pin.h index c89fbb24..c75ba00a 100644 --- a/source/pin.h +++ b/source/pin.h @@ -43,4 +43,4 @@ typedef struct __attribute__((packed)) bool readPin(PINData* out); void newPin(void); -void verifyPin(PINData *in, bool allowQuit); \ No newline at end of file +void verifyPin(PINData *in); \ No newline at end of file