Readability stuff
This commit is contained in:
parent
760aa99709
commit
52999db43a
@ -3,7 +3,7 @@
|
||||
#include "patcher.h"
|
||||
#include "ifile.h"
|
||||
|
||||
static CFWInfo info = {0};
|
||||
static CFWInfo info;
|
||||
|
||||
static int memcmp(const void *buf1, const void *buf2, u32 size)
|
||||
{
|
||||
@ -97,11 +97,10 @@ static void loadCFWInfo(void)
|
||||
if(!infoLoaded)
|
||||
{
|
||||
svcGetCFWInfo(&info);
|
||||
|
||||
IFile file;
|
||||
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);
|
||||
}
|
||||
|
||||
infoLoaded = true;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "memory.h"
|
||||
#include "cache.h"
|
||||
|
||||
extern u32 payloadSize; //defined in start.s
|
||||
extern u32 payloadSize; //Defined in start.s
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
@ -64,7 +64,7 @@ void writeConfig(const char *configPath, u32 configTemp)
|
||||
}
|
||||
}
|
||||
|
||||
void configure(void)
|
||||
void configMenu(void)
|
||||
{
|
||||
initScreens();
|
||||
|
||||
|
@ -43,4 +43,4 @@ extern cfgData configData;
|
||||
|
||||
bool readConfig(const char *configPath);
|
||||
void writeConfig(const char *configPath, u32 configTemp);
|
||||
void configure(void);
|
||||
void configMenu(void);
|
@ -137,11 +137,11 @@ void main(void)
|
||||
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));
|
||||
bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & BUTTON_SELECT) && !(pressed & BUTTON_L1));
|
||||
|
||||
if(shouldLoadConfigurationMenu)
|
||||
if(shouldLoadConfigMenu)
|
||||
{
|
||||
configure();
|
||||
configMenu();
|
||||
|
||||
if(!pinExists && CONFIG(8)) newPin();
|
||||
|
||||
@ -164,7 +164,7 @@ void main(void)
|
||||
if(CONFIG(7) && loadSplash()) pressed = HID_PAD;
|
||||
|
||||
/* 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));
|
||||
|
||||
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(pressed & BUTTON_R1)
|
||||
{
|
||||
nandType = (useSysAsDefault) ? FIRMWARE_EMUNAND : FIRMWARE_SYSNAND;
|
||||
firmSource = (useSysAsDefault) ? FIRMWARE_SYSNAND : FIRMWARE_EMUNAND;
|
||||
nandType = useSysAsDefault ? FIRMWARE_EMUNAND : FIRMWARE_SYSNAND;
|
||||
firmSource = useSysAsDefault ? FIRMWARE_SYSNAND : FIRMWARE_EMUNAND;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
break;
|
||||
case SAFE_FIRM:
|
||||
patchSafeFirm();
|
||||
case NATIVE_FIRM2X:
|
||||
patch2xNativeAndSafeFirm();
|
||||
break;
|
||||
default:
|
||||
//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)
|
||||
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
|
||||
@ -328,11 +329,10 @@ static inline void patchLegacyFirm(FirmwareType firmType)
|
||||
|
||||
applyLegacyFirmPatches((u8 *)firm, firmType);
|
||||
|
||||
if(firmType == TWL_FIRM && CONFIG(5))
|
||||
patchTwlBg((u8 *)firm + section[1].offset);
|
||||
if(firmType == TWL_FIRM && CONFIG(5)) patchTwlBg((u8 *)firm + section[1].offset);
|
||||
}
|
||||
|
||||
static inline void patchSafeFirm(void)
|
||||
static inline void patch2xNativeAndSafeFirm(void)
|
||||
{
|
||||
u8 *arm9Section = (u8 *)firm + section[2].offset;
|
||||
|
||||
@ -344,7 +344,7 @@ static inline void patchSafeFirm(void)
|
||||
|
||||
patchFirmWrites(arm9Section, section[2].size);
|
||||
}
|
||||
else patchFirmWriteSafe(arm9Section, section[2].size);
|
||||
else patchOldFirmWrites(arm9Section, section[2].size);
|
||||
}
|
||||
|
||||
static inline void copySection0AndInjectSystemModules(void)
|
||||
|
@ -57,6 +57,6 @@ typedef enum ConfigurationStatus
|
||||
static inline u32 loadFirm(FirmwareType *firmType, FirmwareSource firmSource);
|
||||
static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lh);
|
||||
static inline void patchLegacyFirm(FirmwareType firmType);
|
||||
static inline void patchSafeFirm(void);
|
||||
static inline void patch2xNativeAndSafeFirm(void);
|
||||
static inline void copySection0AndInjectSystemModules(void);
|
||||
static inline void launchFirm(FirmwareType firmType);
|
@ -113,17 +113,17 @@ void patchFirmWrites(u8 *pos, u32 size)
|
||||
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
|
||||
const u8 pattern[] = {0x04, 0x1E, 0x1D, 0xDB};
|
||||
|
||||
u16 *off = (u16 *)memsearch(pos, pattern, size, 4);
|
||||
|
||||
off[0] = writeBlockSafe[0];
|
||||
off[1] = writeBlockSafe[1];
|
||||
off[0] = writeBlockOld[0];
|
||||
off[1] = writeBlockOld[1];
|
||||
}
|
||||
|
||||
void reimplementSvcBackdoor(u8 *pos, u32 size)
|
||||
@ -175,7 +175,7 @@ void implementSvcGetCFWInfo(u8 *pos, u32 size)
|
||||
}
|
||||
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);
|
||||
|
||||
@ -235,15 +235,15 @@ void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType)
|
||||
|
||||
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
|
||||
|
||||
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)),
|
||||
*src2 = (u16 *)(pos + ((isN3DS) ? 0xE54 : 0xE58));
|
||||
u16 *src1 = (u16 *)(pos + (isN3DS ? 0xE38 : 0xE3C)),
|
||||
*src2 = (u16 *)(pos + (isN3DS ? 0xE54 : 0xE58));
|
||||
|
||||
//Construct BLX instructions:
|
||||
src1[0] = 0xF000 | ((((u32)dst - (u32)src1 - 4) & (0xFFF << 11)) >> 12);
|
||||
|
@ -54,7 +54,7 @@ void patchSignatureChecks(u8 *pos, u32 size);
|
||||
void patchTitleInstallMinVersionCheck(u8 *pos, u32 size);
|
||||
void patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr);
|
||||
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 implementSvcGetCFWInfo(u8 *pos, u32 size);
|
||||
void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType);
|
||||
|
19
source/pin.c
19
source/pin.c
@ -47,7 +47,7 @@ bool readPin(PINData *out)
|
||||
|
||||
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)
|
||||
@ -66,8 +66,8 @@ void newPin(void)
|
||||
|
||||
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.
|
||||
u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0}; // pad to AES block length
|
||||
//Pad to AES block length with zeroes
|
||||
u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0};
|
||||
|
||||
u32 cnt = 0;
|
||||
int charDrawPos = 20 * SPACING_X;
|
||||
@ -84,10 +84,11 @@ void newPin(void)
|
||||
pressed &= PIN_BUTTONS & ~BUTTON_START;
|
||||
|
||||
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);
|
||||
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("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};
|
||||
|
||||
u32 cnt = 0;
|
||||
@ -145,9 +146,9 @@ void verifyPin(PINData *in)
|
||||
if(!pressed) continue;
|
||||
|
||||
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);
|
||||
charDrawPos += 2 * SPACING_X;
|
||||
|
||||
|
@ -49,5 +49,6 @@ typedef enum FirmwareType
|
||||
NATIVE_FIRM = 0,
|
||||
TWL_FIRM = 1,
|
||||
AGB_FIRM = 2,
|
||||
SAFE_FIRM = 3
|
||||
SAFE_FIRM = 3,
|
||||
NATIVE_FIRM2X = 4
|
||||
} FirmwareType;
|
Reference in New Issue
Block a user