From 96211813e3ca8f865d78c3f8a584f07b8a31c8ea Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sat, 2 Jul 2016 14:44:01 +0200 Subject: [PATCH] Use bool instead of u32 where it's relevant --- injector/source/patcher.c | 16 ++++++++-------- source/config.c | 8 ++++---- source/config.h | 2 +- source/crypto.h | 3 ++- source/draw.c | 8 ++++---- source/draw.h | 2 +- source/firm.c | 36 +++++++++++++++++++----------------- source/firm.h | 4 ++-- source/fs.c | 6 +++--- source/fs.h | 2 +- source/patches.c | 8 ++++---- source/patches.h | 2 +- source/screen.c | 8 ++++---- source/screen.h | 2 +- source/types.h | 1 + 15 files changed, 56 insertions(+), 52 deletions(-) diff --git a/injector/source/patcher.c b/injector/source/patcher.c index 286724e..04180b8 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -5,7 +5,7 @@ #ifndef PATH_MAX #define PATH_MAX 255 -#define CONFIG(a) ((loadConfig() >> (a + 16)) & 1) +#define CONFIG(a) (((loadConfig() >> (a + 16)) & 1) != 0) #define MULTICONFIG(a) ((loadConfig() >> (a * 2 + 6)) & 3) #define BOOTCONFIG(a, b) ((loadConfig() >> a) & b) #endif @@ -90,21 +90,21 @@ static int fileOpen(IFile *file, FS_ArchiveID archiveId, const char *path, int f return IFile_Open(file, archiveId, archivePath, filePath, flags); } -static u32 secureInfoExists(void) +static bool secureInfoExists(void) { - static u32 secureInfoExists = 0; + static bool exists = false; - if(!secureInfoExists) + if(!exists) { IFile file; if(R_SUCCEEDED(fileOpen(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ))) { - secureInfoExists = 1; + exists = true; IFile_Close(&file); } } - return secureInfoExists; + return exists; } static u32 loadConfig(void) @@ -263,8 +263,8 @@ static void patchCfgGetLanguage(u8 *code, u32 size, u8 languageId, u8 *CFGU_GetC if(instr[3] == 0xEB) //We're looking for BL { u8 *calledFunction = instr; - u32 i = 0, - found; + u32 i = 0; + bool found; do { diff --git a/source/config.c b/source/config.c index a11bcb8..aa52161 100644 --- a/source/config.c +++ b/source/config.c @@ -12,7 +12,7 @@ void configureCFW(const char *configPath) { - u32 needToDeinit = initScreens(); + bool needToDeinit = initScreens(); drawString(CONFIG_TITLE, 10, 10, COLOR_TITLE); drawString("Press A to select, START to save", 10, 30, COLOR_WHITE); @@ -46,7 +46,7 @@ void configureCFW(const char *configPath) struct singleOption { int posY; - u32 enabled; + bool enabled; } singleOptions[singleOptionsAmount]; //Parse the existing options @@ -151,7 +151,7 @@ void configureCFW(const char *configPath) } else { - u32 oldEnabled = singleOptions[selectedOption - multiOptionsAmount].enabled; + bool oldEnabled = singleOptions[selectedOption - multiOptionsAmount].enabled; singleOptions[selectedOption - multiOptionsAmount].enabled = !oldEnabled; if(oldEnabled) drawCharacter(selected, 10 + SPACING_X, singleOptions[selectedOption - multiOptionsAmount].posY, COLOR_BLACK); } @@ -174,7 +174,7 @@ void configureCFW(const char *configPath) for(u32 i = 0; i < multiOptionsAmount; i++) config |= multiOptions[i].enabled << (i * 2 + 6); for(u32 i = 0; i < singleOptionsAmount; i++) - config |= singleOptions[i].enabled << (i + 16); + config |= (singleOptions[i].enabled ? 1 : 0) << (i + 16); fileWrite(&config, configPath, 4); diff --git a/source/config.h b/source/config.h index a667930..8f1a3f5 100644 --- a/source/config.h +++ b/source/config.h @@ -6,7 +6,7 @@ #include "types.h" -#define CONFIG(a) ((config >> (a + 16)) & 1) +#define CONFIG(a) (((config >> (a + 16)) & 1) != 0) #define MULTICONFIG(a) ((config >> (a * 2 + 6)) & 3) #define BOOTCONFIG(a, b) ((config >> a) & b) diff --git a/source/crypto.h b/source/crypto.h index 157c143..93637cc 100755 --- a/source/crypto.h +++ b/source/crypto.h @@ -79,7 +79,8 @@ #define SHA_224_HASH_SIZE (224 / 8) #define SHA_1_HASH_SIZE (160 / 8) -extern u32 emuOffset, isN3DS; +extern u32 emuOffset; +extern bool isN3DS; extern FirmwareSource firmSource; void ctrNandInit(void); diff --git a/source/draw.c b/source/draw.c index e818847..df4adba 100644 --- a/source/draw.c +++ b/source/draw.c @@ -19,15 +19,15 @@ static inline int strlen(const char *string) return stringEnd - string; } -u32 loadSplash(void) +bool loadSplash(void) { initScreens(); //Don't delay boot if no splash image is on the SD if(fileRead(fb->top_left, "/luma/splash.bin") + - fileRead(fb->bottom, "/luma/splashbottom.bin")) - return 1; - return 0; + fileRead(fb->bottom, "/luma/splashbottom.bin") != 0) + return true; + return false; } void drawCharacter(char character, int posX, int posY, u32 color) diff --git a/source/draw.h b/source/draw.h index 401d2c7..f64b245 100644 --- a/source/draw.h +++ b/source/draw.h @@ -21,6 +21,6 @@ extern volatile struct fb *const fb; -u32 loadSplash(void); +bool loadSplash(void); void drawCharacter(char character, int posX, int posY, u32 color); int drawString(const char *string, int posX, int posY, u32 color); \ No newline at end of file diff --git a/source/firm.c b/source/firm.c index 89d4f22..eaf815b 100755 --- a/source/firm.c +++ b/source/firm.c @@ -20,16 +20,18 @@ static firmHeader *const firm = (firmHeader *)0x24000000; static const firmSectionHeader *section; u32 config, - isN3DS, emuOffset; +bool isN3DS; + FirmwareSource firmSource; void main(void) { - u32 isFirmlaunch, - updatedSys, - newConfig, + bool isFirmlaunch, + updatedSys; + + u32 newConfig, emuHeader, nbChronoStarted = 0; @@ -54,7 +56,7 @@ void main(void) { if(needConfig == CREATE_CONFIGURATION) mcuReboot(); - isFirmlaunch = 1; + isFirmlaunch = true; //'0' = NATIVE_FIRM, '1' = TWL_FIRM, '2' = AGB_FIRM firmType = *(vu8 *)0x23F00009 == '3' ? SAFE_FIRM : (FirmwareType)(*(vu8 *)0x23F00005 - '0'); @@ -85,11 +87,11 @@ void main(void) pressed = HID_PAD; } - isFirmlaunch = 0; + isFirmlaunch = false; firmType = NATIVE_FIRM; //Determine if booting with A9LH - u32 a9lhBoot = !PDN_SPI_CNT; + bool a9lhBoot = !PDN_SPI_CNT; //Determine if A9LH is installed and the user has an updated sysNAND if(a9lhBoot || CONFIG(2)) @@ -100,7 +102,7 @@ void main(void) else { a9lhMode = NO_A9LH; - updatedSys = 0; + updatedSys = false; } newConfig = (u32)a9lhMode << 3; @@ -142,7 +144,7 @@ void main(void) } //Boot options aren't being forced - if(needConfig) + if(needConfig != DONT_CONFIGURE) { /* If L and R/A/Select or one of the single payload buttons are pressed, chainload an external payload */ @@ -227,13 +229,13 @@ void main(void) launchFirm(firmType, isFirmlaunch); } -static inline void loadFirm(FirmwareType firmType, u32 externalFirm) +static inline void loadFirm(FirmwareType firmType, bool externalFirm) { section = firm->section; - u32 externalFirmLoaded = externalFirm && - fileRead(firm, "/luma/firmware.bin") && - (((u32)section[2].address >> 8) & 0xFF) == (isN3DS ? 0x60 : 0x68); + bool externalFirmLoaded = externalFirm && + fileRead(firm, "/luma/firmware.bin") && + (((u32)section[2].address >> 8) & 0xFF) == (isN3DS ? 0x60 : 0x68); /* If the conditions to load the external FIRM aren't met, or reading fails, or the FIRM doesn't match the console, load FIRM from CTRNAND */ @@ -244,7 +246,7 @@ static inline void loadFirm(FirmwareType firmType, u32 externalFirm) { "00000202", "20000202" }, { "00000003", "20000003" }}; - firmRead(firm, firmFolders[(u32)firmType][isN3DS]); + firmRead(firm, firmFolders[(u32)firmType][isN3DS ? 1 : 0]); decryptExeFs((u8 *)firm); } } @@ -253,7 +255,7 @@ static inline void patchNativeFirm(FirmwareSource nandType, u32 emuHeader, A9LHM { u8 *arm9Section = (u8 *)firm + section[2].offset; - u32 is90Firm; + bool is90Firm; if(isN3DS) { @@ -294,7 +296,7 @@ static inline void patchNativeFirm(FirmwareSource nandType, u32 emuHeader, A9LHM patchSignatureChecks(process9Offset, process9Size); //Apply emuNAND patches - if(nandType) + if(nandType != FIRMWARE_SYSNAND) { u32 branchAdditive = (u32)firm + section[2].offset - (u32)section[2].address; patchEmuNAND(arm9Section, section[2].size, process9Offset, process9Size, emuOffset, emuHeader, branchAdditive); @@ -355,7 +357,7 @@ static inline void copySection0AndInjectLoader(void) memcpy(section[0].address + loaderOffset + injector_size, arm11Section0 + loaderOffset + loaderSize, section[0].size - (loaderOffset + loaderSize)); } -static inline void launchFirm(FirmwareType firmType, u32 isFirmlaunch) +static inline void launchFirm(FirmwareType firmType, bool isFirmlaunch) { //If we're booting NATIVE_FIRM, section0 needs to be copied separately to inject 3ds_injector u32 sectionNum; diff --git a/source/firm.h b/source/firm.h index 31eeffc..320b266 100644 --- a/source/firm.h +++ b/source/firm.h @@ -42,9 +42,9 @@ typedef enum A9LHMode A9LH_WITH_SFIRM_FIRMPROT = 2 } A9LHMode; -static inline void loadFirm(FirmwareType firmType, u32 externalFirm); +static inline void loadFirm(FirmwareType firmType, bool externalFirm); static inline void patchNativeFirm(FirmwareSource nandType, u32 emuHeader, A9LHMode a9lhMode); static inline void patchLegacyFirm(FirmwareType firmType); static inline void patchSafeFirm(void); static inline void copySection0AndInjectLoader(void); -static inline void launchFirm(FirmwareType firmType, u32 isFirmlaunch); \ No newline at end of file +static inline void launchFirm(FirmwareType firmType, bool isFirmlaunch); \ No newline at end of file diff --git a/source/fs.c b/source/fs.c index 83a35f4..09a1b35 100644 --- a/source/fs.c +++ b/source/fs.c @@ -13,12 +13,12 @@ static FATFS sdFs, nandFs; -u32 mountFs(void) +bool mountFs(void) { - if(f_mount(&sdFs, "0:", 1) != FR_OK) return 0; + if(f_mount(&sdFs, "0:", 1) != FR_OK) return false; f_mount(&nandFs, "1:", 0); - return 1; + return true; } u32 fileRead(void *dest, const char *path) diff --git a/source/fs.h b/source/fs.h index 0263888..1b58468 100644 --- a/source/fs.h +++ b/source/fs.h @@ -8,7 +8,7 @@ #define PATTERN(a) a "_*.bin" -u32 mountFs(void); +bool mountFs(void); u32 fileRead(void *dest, const char *path); void fileWrite(const void *buffer, const char *path, u32 size); void loadPayload(u32 pressed); diff --git a/source/patches.c b/source/patches.c index 2882d39..de9966f 100644 --- a/source/patches.c +++ b/source/patches.c @@ -121,7 +121,7 @@ void patchTitleInstallMinVersionCheck(u8 *pos, u32 size) if(off != NULL) off[4] = 0xE0; } -void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType, u32 isN3DS) +void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType, bool isN3DS) { const patchData twlPatches[] = { {{0x1650C0, 0x165D64}, {{ 6, 0x00, 0x20, 0x4E, 0xB0, 0x70, 0xBD }}, 0}, @@ -151,12 +151,12 @@ void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType, u32 isN3DS) switch(patches[i].type) { case 0: - memcpy(pos + patches[i].offset[isN3DS], patches[i].patch.type0 + 1, patches[i].patch.type0[0]); + memcpy(pos + patches[i].offset[isN3DS ? 1 : 0], patches[i].patch.type0 + 1, patches[i].patch.type0[0]); break; case 2: - *(u16 *)(pos + patches[i].offset[isN3DS] + 2) = 0; + *(u16 *)(pos + patches[i].offset[isN3DS ? 1 : 0] + 2) = 0; case 1: - *(u16 *)(pos + patches[i].offset[isN3DS]) = patches[i].patch.type1; + *(u16 *)(pos + patches[i].offset[isN3DS ? 1 : 0]) = patches[i].patch.type1; break; } } diff --git a/source/patches.h b/source/patches.h index c1d1255..70cd2fc 100644 --- a/source/patches.h +++ b/source/patches.h @@ -22,5 +22,5 @@ void patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr); void patchFirmWrites(u8 *pos, u32 size); void patchFirmWriteSafe(u8 *pos, u32 size); void reimplementSvcBackdoor(u8 *pos, u32 size); -void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType, u32 isN3DS); +void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType, bool isN3DS); u32 getLoader(u8 *pos, u32 *loaderSize); \ No newline at end of file diff --git a/source/screen.c b/source/screen.c index 4b50e18..106ddcd 100644 --- a/source/screen.c +++ b/source/screen.c @@ -29,13 +29,13 @@ void __attribute__((naked)) arm11Stub(void) static inline void invokeArm11Function(void (*func)()) { - static u32 hasCopiedStub = 0; + static bool hasCopiedStub = false; if(!hasCopiedStub) { memcpy((void *)ARM11_STUB_ADDRESS, arm11Stub, 0x40); flushDCacheRange((void *)ARM11_STUB_ADDRESS, 0x40); - hasCopiedStub = 1; + hasCopiedStub = true; } *arm11Entry = (u32)func; @@ -122,9 +122,9 @@ void clearScreens(void) invokeArm11Function(ARM11); } -u32 initScreens(void) +bool initScreens(void) { - u32 needToInit = PDN_GPU_CNT == 1; + bool needToInit = PDN_GPU_CNT == 1; void __attribute__((naked)) ARM11(void) { diff --git a/source/screen.h b/source/screen.h index 31866e0..34cc7be 100644 --- a/source/screen.h +++ b/source/screen.h @@ -22,4 +22,4 @@ struct fb { void deinitScreens(void); void updateBrightness(u32 brightnessIndex); void clearScreens(void); -u32 initScreens(void); \ No newline at end of file +bool initScreens(void); \ No newline at end of file diff --git a/source/types.h b/source/types.h index 47b12b7..f8f4dc3 100644 --- a/source/types.h +++ b/source/types.h @@ -6,6 +6,7 @@ #include #include +#include //Common data types typedef uint8_t u8;