From 89350b1edd0946f758ad5bedce32b471b5a132c8 Mon Sep 17 00:00:00 2001 From: Aurora Date: Wed, 13 Apr 2016 01:08:13 +0200 Subject: [PATCH] Fixed config.bin getting recreated on each boot --- screeninit/source/start.s | 2 +- source/config.c | 7 +++---- source/crypto.c | 18 +++++++++--------- source/draw.c | 14 +++++--------- source/fatfs/sdmmc/sdmmc.c | 2 +- source/firm.c | 2 +- source/fs.c | 5 +++++ source/utils.c | 4 ++-- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/screeninit/source/start.s b/screeninit/source/start.s index f46f77f..40392d1 100644 --- a/screeninit/source/start.s +++ b/screeninit/source/start.s @@ -7,4 +7,4 @@ _start: b main - .word 0 \ No newline at end of file + .word 0 diff --git a/source/config.c b/source/config.c index 9f02d18..71eb2c8 100644 --- a/source/config.c +++ b/source/config.c @@ -101,8 +101,7 @@ void configureCFW(const char *configPath) while(!(pressed & MENU_BUTTONS)); //Remember the previously selected option - static u32 oldSelectedOption; - oldSelectedOption = selectedOption; + u32 oldSelectedOption = selectedOption; if(pressed != BUTTON_A) { @@ -126,7 +125,7 @@ void configureCFW(const char *configPath) continue; } - //The user moved to a different option, print the old option in white and the new one in white. Only print 'x's if necessary + //The user moved to a different option, print the old option in white and the new one in red. Only print 'x's if necessary if(oldSelectedOption < multiOptionsAmount) { drawString(multiOptionsText[oldSelectedOption], 10, multiOptions[oldSelectedOption].posY, COLOR_WHITE); @@ -182,4 +181,4 @@ void configureCFW(const char *configPath) //Reboot i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2); while(1); -} +} \ No newline at end of file diff --git a/source/crypto.c b/source/crypto.c index 5b1b6d7..3321044 100755 --- a/source/crypto.c +++ b/source/crypto.c @@ -324,7 +324,7 @@ u32 ctrNandRead(u32 sector, u32 sectorCount, u8 *outbuf) //Decrypt aes_use_keyslot(nandSlot); - aes(outbuf, outbuf, (sectorCount * 0x200) / AES_BLOCK_SIZE, tmpCTR, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL); + aes(outbuf, outbuf, sectorCount * 0x200 / AES_BLOCK_SIZE, tmpCTR, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL); return result; } @@ -334,11 +334,11 @@ u32 ctrNandWrite(u32 sector, u32 sectorCount, u8 *inbuf) { u8 tmpCTR[0x10]; memcpy(tmpCTR, nandCTR, 0x10); - aes_advctr(tmpCTR, ((sector + fatStart) * 0x200) / AES_BLOCK_SIZE, AES_INPUT_BE | AES_INPUT_NORMAL); + aes_advctr(tmpCTR, (sector + fatStart) * 0x200 / AES_BLOCK_SIZE, AES_INPUT_BE | AES_INPUT_NORMAL); //Encrypt aes_use_keyslot(nandSlot); - aes(inbuf, inbuf, (sectorCount * 0x200) / AES_BLOCK_SIZE, tmpCTR, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL); + aes(inbuf, inbuf, sectorCount * 0x200 / AES_BLOCK_SIZE, tmpCTR, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL); //Write if(!firmSource) @@ -351,19 +351,19 @@ u32 ctrNandWrite(u32 sector, u32 sectorCount, u8 *inbuf) //Decrypt a FIRM ExeFS void decryptExeFs(u8 *inbuf) { - u32 exeFsOffset = (u32)inbuf + *(u32 *)(inbuf + 0x1A0) * 0x200; + u8 *exeFsOffset = inbuf + *(u32 *)(inbuf + 0x1A0) * 0x200; u32 exeFsSize = *(u32 *)(inbuf + 0x1A4) * 0x200; u8 ncchCTR[0x10]; memset32(ncchCTR, 0, 0x10); - for(u32 i=0; i<8; i++) - ncchCTR[7-i] = *(inbuf + 0x108 + i); + for(u32 i = 0; i < 8; i++) + ncchCTR[7 - i] = *(inbuf + 0x108 + i); ncchCTR[8] = 2; aes_setkey(0x2C, inbuf, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL); aes_setiv(ncchCTR, AES_INPUT_BE | AES_INPUT_NORMAL); aes_use_keyslot(0x2C); - aes(inbuf - 0x200, (void *)exeFsOffset, exeFsSize/AES_BLOCK_SIZE, ncchCTR, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL); + aes(inbuf - 0x200, exeFsOffset, exeFsSize / AES_BLOCK_SIZE, ncchCTR, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL); } //ARM9Loader replacement @@ -382,7 +382,7 @@ void arm9Loader(u8 *arm9Section, u32 mode) u32 arm9BinSize = 0; //http://stackoverflow.com/questions/12791077/atoi-implementation-in-c for(u8 *tmp = arm9Section + 0x30; *tmp; tmp++) - arm9BinSize = (arm9BinSize << 3) + (arm9BinSize << 1) + (*tmp) - '0'; + arm9BinSize = (arm9BinSize << 3) + (arm9BinSize << 1) + *tmp - '0'; if(mode) { @@ -415,7 +415,7 @@ void arm9Loader(u8 *arm9Section, u32 mode) { aes(decKey, keyData, 1, NULL, AES_ECB_DECRYPT_MODE, 0); aes_setkey(slot, decKey, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL); - *(keyData + 0xF) += 1; + keyData[0xF] += 1; } } } \ No newline at end of file diff --git a/source/draw.c b/source/draw.c index 74f9a65..65238c5 100644 --- a/source/draw.c +++ b/source/draw.c @@ -58,24 +58,20 @@ void drawCharacter(char character, int posX, int posY, u32 color) char charPos = font[character * 8 + y]; for(int x = 7; x >= 0; x--) - { - int screenPos = (posX * SCREEN_TOP_HEIGHT * 3 + (SCREEN_TOP_HEIGHT - y - posY - 1) * 3) + (7 - x) * 3 * SCREEN_TOP_HEIGHT; - if ((charPos >> x) & 1) { + int screenPos = (posX * SCREEN_TOP_HEIGHT * 3 + (SCREEN_TOP_HEIGHT - y - posY - 1) * 3) + (7 - x) * 3 * SCREEN_TOP_HEIGHT; + select[screenPos] = color >> 16; select[screenPos + 1] = color >> 8; select[screenPos + 2] = color; } - } } } int drawString(const char *string, int posX, int posY, u32 color) { - int length = strlen(string); - - for(int i = 0, line_i = 0; i < length; i++, line_i++) + for(int i = 0, line_i = 0; i < strlen(string); i++, line_i++) { if(string[i] == '\n') { @@ -87,8 +83,8 @@ int drawString(const char *string, int posX, int posY, u32 color) { // Make sure we never get out of the screen. posY += SPACING_Y; - line_i = 2; // Little offset so we know the same string continues. - if(string[i] == ' ') i++; // Spaces at the start look weird + line_i = 2; //Little offset so we know the same string continues. + if(string[i] == ' ') i++; //Spaces at the start look weird } drawCharacter(string[i], posX + line_i * SPACING_X, posY, color); diff --git a/source/fatfs/sdmmc/sdmmc.c b/source/fatfs/sdmmc/sdmmc.c index bee13d7..a3de273 100644 --- a/source/fatfs/sdmmc/sdmmc.c +++ b/source/fatfs/sdmmc/sdmmc.c @@ -402,7 +402,7 @@ int sdmmc_sdcard_init() return result | SD_Init(); } -int sdmmc_get_cid( int isNand, uint32_t *info) +int sdmmc_get_cid(int isNand, uint32_t *info) { struct mmcdevice *device; if(isNand) diff --git a/source/firm.c b/source/firm.c index 60094b6..dd0571b 100755 --- a/source/firm.c +++ b/source/firm.c @@ -173,7 +173,7 @@ void main(void) /* If the boot configuration is different from previously, overwrite it. Just the no-forcing flag being set is not enough */ - if((newConfig & 0x2F) != (config & 0xFF)) + if((newConfig & 0x2F) != (config & 0x3F)) { //Preserve user settings (first 2 bytes) newConfig |= config & 0xFFFFFFC0; diff --git a/source/fs.c b/source/fs.c index 45d0886..3f07333 100644 --- a/source/fs.c +++ b/source/fs.c @@ -15,6 +15,7 @@ u32 mountFs(void) { if(f_mount(&sdFs, "0:", 1) != FR_OK) return 0; f_mount(&nandFs, "1:", 0); + return 1; } @@ -32,6 +33,7 @@ u32 fileRead(void *dest, const char *path, u32 size) } f_close(&fp); + return fr ? 0 : 1; } @@ -45,6 +47,7 @@ u32 fileWrite(const void *buffer, const char *path, u32 size) if(fr == FR_OK) fr = f_write(&fp, buffer, size, &br); f_close(&fp); + return fr ? 0 : 1; } @@ -57,6 +60,7 @@ u32 fileSize(const char *path) size = f_size(&fp); f_close(&fp); + return size; } @@ -68,6 +72,7 @@ u32 fileExists(const char *path) if(f_open(&fp, path, FA_READ) == FR_OK) exists = 1; f_close(&fp); + return exists; } diff --git a/source/utils.c b/source/utils.c index cf6f650..1a72965 100644 --- a/source/utils.c +++ b/source/utils.c @@ -12,8 +12,8 @@ u32 waitInput(void) { - u32 pressedKey = 0; - u32 key; + u32 pressedKey = 0, + key; //Wait for no keys to be pressed while(HID_PAD);