Fix max module size check, static-ify more strings

This commit is contained in:
Aurora Wright 2017-06-09 17:29:26 +02:00
parent a7046909ec
commit 4d47d891d1
7 changed files with 35 additions and 38 deletions

View File

@ -484,7 +484,7 @@ static inline void twlConsoleInfoInit(void)
aes_setkey(2, (u8 *)0x01FFD398, AES_KEYX, AES_INPUT_TWLNORMAL);
if(CFG_TWLUNITINFO != 0)
{
__attribute__((aligned(4))) u8 key2YDev[AES_BLOCK_SIZE] = {0x3B, 0x06, 0x86, 0x57, 0x33, 0x04, 0x88, 0x11, 0x49, 0x04, 0x6B, 0x33, 0x12, 0x02, 0xAC, 0xF3},
__attribute__((aligned(4))) static const u8 key2YDev[AES_BLOCK_SIZE] = {0x3B, 0x06, 0x86, 0x57, 0x33, 0x04, 0x88, 0x11, 0x49, 0x04, 0x6B, 0x33, 0x12, 0x02, 0xAC, 0xF3},
key3YDev[AES_BLOCK_SIZE] = {0xAA, 0xBF, 0x76, 0xF1, 0x7A, 0xB8, 0xE8, 0x66, 0x97, 0x64, 0x6A, 0x26, 0x05, 0x00, 0xA0, 0xE1};
k3X[1] = 0xEE7A4B1E;

View File

@ -39,7 +39,7 @@
bool loadSplash(void)
{
const char *topSplashFile = "splash.bin",
static const char *topSplashFile = "splash.bin",
*bottomSplashFile = "splashbottom.bin";
bool isTopSplashValid = getFileSize(topSplashFile) == SCREEN_TOP_FBSIZE,

View File

@ -60,15 +60,13 @@ void detectAndProcessExceptionDumps(void)
const vu8 *stackDump = (vu8 *)regs + dumpHeader->registerDumpSize + dumpHeader->codeDumpSize;
const vu8 *additionalData = stackDump + dumpHeader->stackDumpSize;
const char *handledExceptionNames[] = {
static const char *handledExceptionNames[] = {
"FIQ", "undefined instruction", "prefetch abort", "data abort"
};
const char *specialExceptions[] = {
},
*specialExceptions[] = {
"kernel panic", "svcBreak"
};
const char *registerNames[] = {
},
*registerNames[] = {
"R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", "R12",
"SP", "LR", "PC", "CPSR", "FPEXC"
};

View File

@ -80,11 +80,9 @@ static inline bool loadFirmFromStorage(FirmwareType firmType)
static inline void mergeSection0(FirmwareType firmType, bool loadFromStorage)
{
u32 srcModuleSize;
const char *extModuleSizeError = "The external FIRM modules are too large.";
u32 srcModuleSize,
nbModules = 0;
u32 nbModules = 0,
isCustomModule = false;
struct
{
char name[8];
@ -108,24 +106,25 @@ static inline void mergeSection0(FirmwareType firmType, bool loadFromStorage)
const char *name = ((Cxi *)src)->exHeader.systemControlInfo.appTitle;
u32 i;
for(i = 0; i < nbModules && memcmp(name, moduleList[i].name, 8) != 0; i++);
if(i == nbModules) isCustomModule = true;
for(i = 0; i < 5 && memcmp(name, moduleList[i].name, 8) != 0; i++);
if(i == 5)
{
nbModules++;
memcpy(moduleList[i].name, ((Cxi *)src)->exHeader.systemControlInfo.appTitle, 8);
}
moduleList[i].src = src;
srcModuleSize = moduleList[i].size = ((Cxi *)src)->ncch.contentSize * 0x200;
}
if(isCustomModule) nbModules++;
}
//3) Read or copy the modules
u8 *dst = firm->section[0].address;
for(u32 i = 0, dstModuleSize; i < nbModules; i++)
const char *extModuleSizeError = "The external FIRM modules are too large.";
for(u32 i = 0, dstModuleSize, maxModuleSize = 0x60000; i < nbModules; i++, dst += dstModuleSize, maxModuleSize -= dstModuleSize)
{
dstModuleSize = 0;
if(loadFromStorage)
{
char fileName[24];
@ -137,7 +136,7 @@ static inline void mergeSection0(FirmwareType firmType, bool loadFromStorage)
if(dstModuleSize != 0)
{
if(dstModuleSize > 0x60000) error(extModuleSizeError);
if(dstModuleSize > maxModuleSize) error(extModuleSizeError);
if(dstModuleSize <= sizeof(Cxi) + 0x200 ||
fileRead(dst, fileName, dstModuleSize) != dstModuleSize ||
@ -145,19 +144,19 @@ static inline void mergeSection0(FirmwareType firmType, bool loadFromStorage)
memcmp(moduleList[i].name, ((Cxi *)dst)->exHeader.systemControlInfo.appTitle, sizeof(((Cxi *)dst)->exHeader.systemControlInfo.appTitle)) != 0)
error("An external FIRM module is invalid or corrupted.");
dst += dstModuleSize;
continue;
}
}
if(!dstModuleSize)
{
memcpy(dst, moduleList[i].src, moduleList[i].size);
dst += moduleList[i].size;
}
dstModuleSize = moduleList[i].size;
if(dstModuleSize > maxModuleSize) error(extModuleSizeError);
memcpy(dst, moduleList[i].src, dstModuleSize);
}
//4) Patch NATIVE_FIRM if necessary
if(isCustomModule)
if(nbModules == 6)
{
if(patchK11ModuleLoading(firm->section[0].size, dst - firm->section[0].address, (u8 *)firm + firm->section[1].offset, firm->section[1].size) != 0)
error("Failed to inject custom sysmodule");

View File

@ -72,7 +72,7 @@ void main(int argc, char **argv, u32 magicWord)
}
else
{
const char argv[] = "firm0:";
static const char argv[] = "firm0:";
for(u32 i = 0; i < sizeof(argv); i++) //Copy and convert the path to UTF-16
launchedPath[i] = argv[i];
}

View File

@ -40,7 +40,7 @@
static char pinKeyToLetter(u32 pressed)
{
const char keys[] = "AB--RLUD--XY";
static const char *keys = "AB--RLUD--XY";
u32 i;
for(i = 31; pressed > 1; i--) pressed /= 2;
@ -151,7 +151,7 @@ bool verifyPin(u32 pinMode)
drawFormattedString(true, 10, 10 + 3 * SPACING_Y, COLOR_WHITE, "PIN (%u digits): ", lengthBlock[0]);
const char *messageFile = "pinmessage.txt";
static const char *messageFile = "pinmessage.txt";
char message[801];
u32 messageSize = fileRead(message, messageFile, sizeof(message) - 1);