diff --git a/loader/source/main.c b/loader/source/main.c index d7886ac..4605d25 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 a9a443f..8dd5747 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 66468a9..2b6f02c 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/firm.c b/source/firm.c index e6f409f..82e1df5 100755 --- a/source/firm.c +++ b/source/firm.c @@ -34,7 +34,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 @@ -49,8 +48,6 @@ bool isN3DS, isDevUnit; FirmwareSource firmSource; -PINData pin; - void main(void) { bool isFirmlaunch, @@ -137,10 +134,12 @@ 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 - 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)); @@ -149,7 +148,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 26f17c3..6d69e68 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(); @@ -69,7 +69,7 @@ PINData newPin(void) u32 cnt = 0; int charDrawPos = 20 * SPACING_X; - while(true) + while(cnt < PIN_LENGTH) { u32 pressed; do @@ -87,33 +87,28 @@ PINData 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)); - return pin; - } } + + 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); } -void verifyPin(PINData *in, bool allowQuit) +void verifyPin(PINData *in) { initScreens(); @@ -124,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 @@ -136,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(); @@ -167,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 diff --git a/source/pin.h b/source/pin.h index 462d73f..c75ba00 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 verifyPin(PINData *in, bool allowQuit); \ No newline at end of file +void newPin(void); +void verifyPin(PINData *in); \ No newline at end of file