diff --git a/source/config.c b/source/config.c index a5f7c5c..b0fed6a 100644 --- a/source/config.c +++ b/source/config.c @@ -27,6 +27,7 @@ #include "screen.h" #include "draw.h" #include "buttons.h" +#include "pin.h" bool readConfig(const char *configPath) { @@ -64,7 +65,7 @@ void writeConfig(const char *configPath, u32 configTemp) } } -void configMenu(void) +void configMenu(bool oldPinStatus) { initScreens(); @@ -231,6 +232,11 @@ void configMenu(void) for(u32 i = 0; i < singleOptionsAmount; i++) configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 16); + if(CONFIG(8)) newPin(oldPinStatus); + else if(oldPinStatus) fileDelete("/luma/pin.bin"); + //Wait for the pressed buttons to change - while(HID_PAD == BUTTON_START); + while(HID_PAD & PIN_BUTTONS); + + chrono(2); } \ No newline at end of file diff --git a/source/config.h b/source/config.h index 899317a..96f558e 100644 --- a/source/config.h +++ b/source/config.h @@ -43,4 +43,4 @@ extern cfgData configData; bool readConfig(const char *configPath); void writeConfig(const char *configPath, u32 configTemp); -void configMenu(void); \ No newline at end of file +void configMenu(bool oldPinStatus); \ No newline at end of file diff --git a/source/firm.c b/source/firm.c index c6a120d..94da610 100755 --- a/source/firm.c +++ b/source/firm.c @@ -141,11 +141,7 @@ void main(void) if(shouldLoadConfigMenu) { - configMenu(); - - if(!pinExists && CONFIG(8)) newPin(); - - chrono(2); + configMenu(pinExists); //Update pressed buttons pressed = HID_PAD; diff --git a/source/fs.c b/source/fs.c index 59d1c0d..f318026 100644 --- a/source/fs.c +++ b/source/fs.c @@ -76,6 +76,11 @@ bool fileWrite(const void *buffer, const char *path, u32 size) return false; } +void fileDelete(const char *path) +{ + f_unlink(path); +} + void createDirectory(const char *path) { f_mkdir(path); diff --git a/source/fs.h b/source/fs.h index 805c099..7e7d9a9 100644 --- a/source/fs.h +++ b/source/fs.h @@ -32,6 +32,7 @@ void mountFs(void); u32 fileRead(void *dest, const char *path); u32 getFileSize(const char *path); bool fileWrite(const void *buffer, const char *path, u32 size); +void fileDelete(const char *path); void createDirectory(const char *path); void loadPayload(u32 pressed); u32 firmRead(void *dest, u32 firmType); \ No newline at end of file diff --git a/source/pin.c b/source/pin.c index 98718f7..a3b0479 100644 --- a/source/pin.c +++ b/source/pin.c @@ -60,11 +60,12 @@ static inline char PINKeyToLetter(u32 pressed) return keys[31 - i]; } -void newPin(void) +void newPin(bool allowSkipping) { clearScreens(); - drawString("Enter a new PIN to proceed", 10, 10, COLOR_TITLE); + char *title = allowSkipping ? "Press START to skip or enter a new PIN" : "Enter a new PIN to proceed"; + drawString(title, 10, 10, COLOR_TITLE); drawString("PIN: ", 10, 10 + 2 * SPACING_Y, COLOR_WHITE); //Pad to AES block length with zeroes @@ -80,10 +81,12 @@ void newPin(void) { pressed = waitInput(); } - while(!(pressed & PIN_BUTTONS & ~BUTTON_START)); + while(!(pressed & PIN_BUTTONS)); - pressed &= PIN_BUTTONS & ~BUTTON_START; + pressed &= PIN_BUTTONS; + if(!allowSkipping) pressed &= ~BUTTON_START; + if(pressed & BUTTON_START) return; if(!pressed) continue; char key = PINKeyToLetter(pressed); @@ -114,8 +117,6 @@ void newPin(void) if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData))) error("Error writing the PIN file"); } - - while(HID_PAD & PIN_BUTTONS); } void verifyPin(PINData *in) @@ -143,9 +144,7 @@ void verifyPin(PINData *in) if(pressed & BUTTON_START) mcuPowerOff(); - pressed &= PIN_BUTTONS & ~BUTTON_START; - - if(!pressed) continue; + pressed &= PIN_BUTTONS; char key = PINKeyToLetter(pressed); enteredPassword[cnt++] = (u8)key; //Add character to password diff --git a/source/pin.h b/source/pin.h index ce6f370..79b1dd2 100644 --- a/source/pin.h +++ b/source/pin.h @@ -44,5 +44,5 @@ typedef struct __attribute__((packed)) } PINData; bool readPin(PINData* out); -void newPin(void); +void newPin(bool allowSkipping); void verifyPin(PINData *in); \ No newline at end of file