Readability stuff

This commit is contained in:
Aurora 2016-08-28 13:49:15 +02:00
parent 760aa99709
commit 52999db43a
13 changed files with 46 additions and 45 deletions

View File

@ -3,7 +3,7 @@
#include "patcher.h" #include "patcher.h"
#include "ifile.h" #include "ifile.h"
static CFWInfo info = {0}; static CFWInfo info;
static int memcmp(const void *buf1, const void *buf2, u32 size) static int memcmp(const void *buf1, const void *buf2, u32 size)
{ {
@ -97,11 +97,10 @@ static void loadCFWInfo(void)
if(!infoLoaded) if(!infoLoaded)
{ {
svcGetCFWInfo(&info); svcGetCFWInfo(&info);
IFile file; IFile file;
if(BOOTCONFIG(5, 1) && R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, "/", FS_OPEN_READ))) //Init SD card if SAFE_MODE is being booted if(BOOTCONFIG(5, 1) && R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, "/", FS_OPEN_READ))) //Init SD card if SAFE_MODE is being booted
{
IFile_Close(&file); IFile_Close(&file);
}
infoLoaded = true; infoLoaded = true;
} }

View File

@ -23,7 +23,7 @@
#include "memory.h" #include "memory.h"
#include "cache.h" #include "cache.h"
extern u32 payloadSize; //defined in start.s extern u32 payloadSize; //Defined in start.s
void main(void) void main(void)
{ {

View File

@ -64,7 +64,7 @@ void writeConfig(const char *configPath, u32 configTemp)
} }
} }
void configure(void) void configMenu(void)
{ {
initScreens(); initScreens();

View File

@ -43,4 +43,4 @@ extern cfgData configData;
bool readConfig(const char *configPath); bool readConfig(const char *configPath);
void writeConfig(const char *configPath, u32 configTemp); void writeConfig(const char *configPath, u32 configTemp);
void configure(void); void configMenu(void);

View File

@ -137,11 +137,11 @@ void main(void)
if(pinExists) verifyPin(&pin); if(pinExists) verifyPin(&pin);
//If no configuration file exists or SELECT is held, load configuration menu //If no configuration file exists or SELECT is held, load configuration menu
bool shouldLoadConfigurationMenu = needConfig == CREATE_CONFIGURATION || ((pressed & BUTTON_SELECT) && !(pressed & BUTTON_L1)); bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & BUTTON_SELECT) && !(pressed & BUTTON_L1));
if(shouldLoadConfigurationMenu) if(shouldLoadConfigMenu)
{ {
configure(); configMenu();
if(!pinExists && CONFIG(8)) newPin(); if(!pinExists && CONFIG(8)) newPin();
@ -164,7 +164,7 @@ void main(void)
if(CONFIG(7) && loadSplash()) pressed = HID_PAD; if(CONFIG(7) && loadSplash()) pressed = HID_PAD;
/* If L and R/A/Select or one of the single payload buttons are pressed, /* If L and R/A/Select or one of the single payload buttons are pressed,
chainload an external payload (the PIN, if any, has been verified)*/ chainload an external payload */
bool shouldLoadPayload = (pressed & SINGLE_PAYLOAD_BUTTONS) || ((pressed & BUTTON_L1) && (pressed & L_PAYLOAD_BUTTONS)); bool shouldLoadPayload = (pressed & SINGLE_PAYLOAD_BUTTONS) || ((pressed & BUTTON_L1) && (pressed & L_PAYLOAD_BUTTONS));
if(shouldLoadPayload) loadPayload(pressed); if(shouldLoadPayload) loadPayload(pressed);
@ -177,8 +177,8 @@ void main(void)
//If R is pressed, boot the non-updated NAND with the FIRM of the opposite one //If R is pressed, boot the non-updated NAND with the FIRM of the opposite one
if(pressed & BUTTON_R1) if(pressed & BUTTON_R1)
{ {
nandType = (useSysAsDefault) ? FIRMWARE_EMUNAND : FIRMWARE_SYSNAND; nandType = useSysAsDefault ? FIRMWARE_EMUNAND : FIRMWARE_SYSNAND;
firmSource = (useSysAsDefault) ? FIRMWARE_SYSNAND : FIRMWARE_EMUNAND; firmSource = useSysAsDefault ? FIRMWARE_SYSNAND : FIRMWARE_EMUNAND;
} }
/* Else, boot the NAND the user set to autoboot or the opposite one, depending on L, /* Else, boot the NAND the user set to autoboot or the opposite one, depending on L,
@ -221,7 +221,8 @@ void main(void)
patchNativeFirm(firmVersion, nandType, emuHeader, isA9lh); patchNativeFirm(firmVersion, nandType, emuHeader, isA9lh);
break; break;
case SAFE_FIRM: case SAFE_FIRM:
patchSafeFirm(); case NATIVE_FIRM2X:
patch2xNativeAndSafeFirm();
break; break;
default: default:
//Skip patching on unsupported O3DS AGB/TWL FIRMs //Skip patching on unsupported O3DS AGB/TWL FIRMs
@ -247,9 +248,9 @@ static inline u32 loadFirm(FirmwareType *firmType, FirmwareSource firmSource)
if(firmSource != FIRMWARE_SYSNAND || firmVersion < 9) if(firmSource != FIRMWARE_SYSNAND || firmVersion < 9)
error("An old unsupported NAND has been detected.\nLuma3DS is unable to boot it"); error("An old unsupported NAND has been detected.\nLuma3DS is unable to boot it");
if(BOOTCONFIG(5, 1)) error("SAFE_MODE is not supported on 2.x FIRM!"); if(BOOTCONFIG(5, 1)) error("SAFE_MODE is not supported on 2.x FIRM");
*firmType = SAFE_FIRM; *firmType = NATIVE_FIRM2X;
} }
//We can't boot a 3.x/4.x NATIVE_FIRM, load one from SD //We can't boot a 3.x/4.x NATIVE_FIRM, load one from SD
@ -328,11 +329,10 @@ static inline void patchLegacyFirm(FirmwareType firmType)
applyLegacyFirmPatches((u8 *)firm, firmType); applyLegacyFirmPatches((u8 *)firm, firmType);
if(firmType == TWL_FIRM && CONFIG(5)) if(firmType == TWL_FIRM && CONFIG(5)) patchTwlBg((u8 *)firm + section[1].offset);
patchTwlBg((u8 *)firm + section[1].offset);
} }
static inline void patchSafeFirm(void) static inline void patch2xNativeAndSafeFirm(void)
{ {
u8 *arm9Section = (u8 *)firm + section[2].offset; u8 *arm9Section = (u8 *)firm + section[2].offset;
@ -344,7 +344,7 @@ static inline void patchSafeFirm(void)
patchFirmWrites(arm9Section, section[2].size); patchFirmWrites(arm9Section, section[2].size);
} }
else patchFirmWriteSafe(arm9Section, section[2].size); else patchOldFirmWrites(arm9Section, section[2].size);
} }
static inline void copySection0AndInjectSystemModules(void) static inline void copySection0AndInjectSystemModules(void)

View File

@ -57,6 +57,6 @@ typedef enum ConfigurationStatus
static inline u32 loadFirm(FirmwareType *firmType, FirmwareSource firmSource); static inline u32 loadFirm(FirmwareType *firmType, FirmwareSource firmSource);
static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lh); static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lh);
static inline void patchLegacyFirm(FirmwareType firmType); static inline void patchLegacyFirm(FirmwareType firmType);
static inline void patchSafeFirm(void); static inline void patch2xNativeAndSafeFirm(void);
static inline void copySection0AndInjectSystemModules(void); static inline void copySection0AndInjectSystemModules(void);
static inline void launchFirm(FirmwareType firmType); static inline void launchFirm(FirmwareType firmType);

View File

@ -48,7 +48,7 @@ static void findFreeK11Space(u8 *pos, u32 size)
{ {
if(freeK11Space == NULL) if(freeK11Space == NULL)
{ {
const u8 pattern[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; const u8 pattern[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
freeK11Space = memsearch(pos, pattern, size, 5) + 1; freeK11Space = memsearch(pos, pattern, size, 5) + 1;
} }
@ -113,23 +113,23 @@ void patchFirmWrites(u8 *pos, u32 size)
off2[1] = writeBlock[1]; off2[1] = writeBlock[1];
} }
void patchFirmWriteSafe(u8 *pos, u32 size) void patchOldFirmWrites(u8 *pos, u32 size)
{ {
const u16 writeBlockSafe[2] = {0x2400, 0xE01D}; const u16 writeBlockOld[2] = {0x2400, 0xE01D};
//Look for FIRM writing code //Look for FIRM writing code
const u8 pattern[] = {0x04, 0x1E, 0x1D, 0xDB}; const u8 pattern[] = {0x04, 0x1E, 0x1D, 0xDB};
u16 *off = (u16 *)memsearch(pos, pattern, size, 4); u16 *off = (u16 *)memsearch(pos, pattern, size, 4);
off[0] = writeBlockSafe[0]; off[0] = writeBlockOld[0];
off[1] = writeBlockSafe[1]; off[1] = writeBlockOld[1];
} }
void reimplementSvcBackdoor(u8 *pos, u32 size) void reimplementSvcBackdoor(u8 *pos, u32 size)
{ {
//Official implementation of svcBackdoor //Official implementation of svcBackdoor
const u8 svcBackdoor[40] = {0xFF, 0x10, 0xCD, 0xE3, //bic r1, sp, #0xff const u8 svcBackdoor[40] = {0xFF, 0x10, 0xCD, 0xE3, //bic r1, sp, #0xff
0x0F, 0x1C, 0x81, 0xE3, //orr r1, r1, #0xf00 0x0F, 0x1C, 0x81, 0xE3, //orr r1, r1, #0xf00
0x28, 0x10, 0x81, 0xE2, //add r1, r1, #0x28 0x28, 0x10, 0x81, 0xE2, //add r1, r1, #0x28
0x00, 0x20, 0x91, 0xE5, //ldr r2, [r1] 0x00, 0x20, 0x91, 0xE5, //ldr r2, [r1]
@ -175,7 +175,7 @@ void implementSvcGetCFWInfo(u8 *pos, u32 size)
} }
else isRelease = rev[4] == 0; else isRelease = rev[4] == 0;
info->flags = 0 /* master branch */ | (((isRelease) ? 1 : 0) << 1) /* is release */; info->flags = 0 /* master branch */ | ((isRelease ? 1 : 0) << 1) /* is release */;
findArm11SvcTable(pos, size); findArm11SvcTable(pos, size);
@ -235,15 +235,15 @@ void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType)
void patchTwlBg(u8 *pos) void patchTwlBg(u8 *pos)
{ {
u8 *dst = pos + ((isN3DS) ? 0xFEA4 : 0xFCA0); u8 *dst = pos + (isN3DS ? 0xFEA4 : 0xFCA0);
memcpy(dst, twl_k11modules, twl_k11modules_size); //Install K11 hook memcpy(dst, twl_k11modules, twl_k11modules_size); //Install K11 hook
u32 *off = (u32 *)memsearch(dst, "LAUN", twl_k11modules_size, 4); u32 *off = (u32 *)memsearch(dst, "LAUN", twl_k11modules_size, 4);
*off = (isN3DS) ? 0xCDE88 : 0xCD5F8; //Dev SRL launcher offset *off = isN3DS ? 0xCDE88 : 0xCD5F8; //Dev SRL launcher offset
u16 *src1 = (u16 *)(pos + ((isN3DS) ? 0xE38 : 0xE3C)), u16 *src1 = (u16 *)(pos + (isN3DS ? 0xE38 : 0xE3C)),
*src2 = (u16 *)(pos + ((isN3DS) ? 0xE54 : 0xE58)); *src2 = (u16 *)(pos + (isN3DS ? 0xE54 : 0xE58));
//Construct BLX instructions: //Construct BLX instructions:
src1[0] = 0xF000 | ((((u32)dst - (u32)src1 - 4) & (0xFFF << 11)) >> 12); src1[0] = 0xF000 | ((((u32)dst - (u32)src1 - 4) & (0xFFF << 11)) >> 12);

View File

@ -54,7 +54,7 @@ void patchSignatureChecks(u8 *pos, u32 size);
void patchTitleInstallMinVersionCheck(u8 *pos, u32 size); void patchTitleInstallMinVersionCheck(u8 *pos, u32 size);
void patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr); void patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr);
void patchFirmWrites(u8 *pos, u32 size); void patchFirmWrites(u8 *pos, u32 size);
void patchFirmWriteSafe(u8 *pos, u32 size); void patchOldFirmWrites(u8 *pos, u32 size);
void reimplementSvcBackdoor(u8 *pos, u32 size); void reimplementSvcBackdoor(u8 *pos, u32 size);
void implementSvcGetCFWInfo(u8 *pos, u32 size); void implementSvcGetCFWInfo(u8 *pos, u32 size);
void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType); void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType);

View File

@ -47,7 +47,7 @@ bool readPin(PINData *out)
computePINHash(tmp, zeroes, 1); 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) return memcmp(out->testHash, tmp, 32) == 0; //Test vector verification (SD card has, or hasn't been used on another console)
} }
static inline char PINKeyToLetter(u32 pressed) static inline char PINKeyToLetter(u32 pressed)
@ -66,8 +66,8 @@ void newPin(void)
drawString("Enter your NEW PIN: ", 10, 10, COLOR_WHITE); drawString("Enter your NEW PIN: ", 10, 10, COLOR_WHITE);
// Set the default value as 0x00 so we can check if there are any unentered characters. //Pad to AES block length with zeroes
u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0}; // pad to AES block length u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0};
u32 cnt = 0; u32 cnt = 0;
int charDrawPos = 20 * SPACING_X; int charDrawPos = 20 * SPACING_X;
@ -84,10 +84,11 @@ void newPin(void)
pressed &= PIN_BUTTONS & ~BUTTON_START; pressed &= PIN_BUTTONS & ~BUTTON_START;
if(!pressed) continue; if(!pressed) continue;
char key = PINKeyToLetter(pressed);
enteredPassword[cnt++] = (u8)key; // add character to password.
// visualize character on screen. char key = PINKeyToLetter(pressed);
enteredPassword[cnt++] = (u8)key; //Add character to password
//Visualize character on screen
drawCharacter(key, 10 + charDrawPos, 10, COLOR_WHITE); drawCharacter(key, 10 + charDrawPos, 10, COLOR_WHITE);
charDrawPos += 2 * SPACING_X; charDrawPos += 2 * SPACING_X;
} }
@ -123,7 +124,7 @@ void verifyPin(PINData *in)
drawString("Press START to shutdown or enter pin to proceed.", 10, 10, COLOR_WHITE); drawString("Press START to shutdown or enter pin to proceed.", 10, 10, COLOR_WHITE);
drawString("Pin: ", 10, 10 + 2 * SPACING_Y, COLOR_WHITE); drawString("Pin: ", 10, 10 + 2 * SPACING_Y, COLOR_WHITE);
// Set the default characters as 0x00 so we can check if there are any unentered characters. //Pad to AES block length with zeroes
u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0}; u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0};
u32 cnt = 0; u32 cnt = 0;
@ -145,9 +146,9 @@ void verifyPin(PINData *in)
if(!pressed) continue; if(!pressed) continue;
char key = PINKeyToLetter(pressed); char key = PINKeyToLetter(pressed);
enteredPassword[cnt++] = (u8)key; // add character to password. enteredPassword[cnt++] = (u8)key; //Add character to password
// visualize character on screen. //Visualize character on screen
drawCharacter(key, 10 + charDrawPos, 10 + 2 * SPACING_Y, COLOR_WHITE); drawCharacter(key, 10 + charDrawPos, 10 + 2 * SPACING_Y, COLOR_WHITE);
charDrawPos += 2 * SPACING_X; charDrawPos += 2 * SPACING_X;

View File

@ -49,5 +49,6 @@ typedef enum FirmwareType
NATIVE_FIRM = 0, NATIVE_FIRM = 0,
TWL_FIRM = 1, TWL_FIRM = 1,
AGB_FIRM = 2, AGB_FIRM = 2,
SAFE_FIRM = 3 SAFE_FIRM = 3,
NATIVE_FIRM2X = 4
} FirmwareType; } FirmwareType;