Minor cleanup
This commit is contained in:
parent
fbe3088744
commit
55b2db4a8d
35
source/fs.c
35
source/fs.c
@ -129,44 +129,35 @@ static __attribute__((noinline)) bool overlaps(u32 as, u32 ae, u32 bs, u32 be)
|
|||||||
|
|
||||||
static bool checkFirmPayload(void)
|
static bool checkFirmPayload(void)
|
||||||
{
|
{
|
||||||
if(memcmp(firm->magic, "FIRM", 4) != 0)
|
if(memcmp(firm->magic, "FIRM", 4) != 0 || firm->arm9Entry == NULL) //Allow for the ARM11 entrypoint to be zero in which case nothing is done on the ARM11 side
|
||||||
return false;
|
|
||||||
|
|
||||||
if(firm->arm9Entry == NULL) //allow for the arm11 entrypoint to be zero in which case nothing is done on the arm11 side
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
u32 size = 0x200;
|
u32 size = 0x200;
|
||||||
for(u32 i = 0; i < 4; i++)
|
for(u32 i = 0; i < 4; i++)
|
||||||
size += firm->section[i].size;
|
size += firm->section[i].size;
|
||||||
|
|
||||||
bool arm9EpFound = false, arm11EpFound = false;
|
bool arm9EpFound = false,
|
||||||
|
arm11EpFound = false;
|
||||||
|
|
||||||
for(u32 i = 0; i < 4; i++)
|
for(u32 i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
__attribute__((aligned(4))) u8 hash[0x20];
|
__attribute__((aligned(4))) u8 hash[0x20];
|
||||||
|
|
||||||
FirmSection *section = &firm->section[i];
|
FirmSection *section = &firm->section[i];
|
||||||
|
|
||||||
// allow empty sections
|
//Allow empty sections
|
||||||
if(section->size == 0)
|
if(section->size == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(section->offset < 0x200)
|
if((section->offset < 0x200) ||
|
||||||
return false;
|
(section->address + section->size < section->address) || //Overflow check
|
||||||
|
((u32)section->address & 3) || (section->offset & 0x1FF) || (section->size & 0x1FF) || //Alignment check
|
||||||
if(section->address + section->size < section->address) //overflow check
|
(overlaps((u32)section->address, (u32)section->address + section->size, 0x27FFE000 - 0x1000, 0x28000000)) ||
|
||||||
return false;
|
(overlaps((u32)section->address, (u32)section->address + section->size, (u32)firm, (u32)firm + size)))
|
||||||
|
|
||||||
if(((u32)section->address & 3) || (section->offset & 0x1FF) || (section->size & 0x1FF)) //alignment check
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(overlaps((u32)section->address, (u32)section->address + section->size, 0x27FFE000, 0x28000000))
|
|
||||||
return false;
|
|
||||||
else if(overlaps((u32)section->address, (u32)section->address + section->size, 0x27FFE000 - 0x1000, 0x27FFE000))
|
|
||||||
return false;
|
|
||||||
else if(overlaps((u32)section->address, (u32)section->address + section->size, (u32)firm, (u32)firm + size))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
sha(hash, (u8 *)firm + section->offset, section->size, SHA_256_MODE);
|
sha(hash, (u8 *)firm + section->offset, section->size, SHA_256_MODE);
|
||||||
|
|
||||||
if(memcmp(hash, section->hash, 0x20) != 0)
|
if(memcmp(hash, section->hash, 0x20) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -186,8 +177,8 @@ void loadPayload(u32 pressed, const char *payloadPath)
|
|||||||
u32 payloadSize = 0,
|
u32 payloadSize = 0,
|
||||||
maxPayloadSize = (u32)((u8 *)loaderAddress - (u8 *)firm);
|
maxPayloadSize = (u32)((u8 *)loaderAddress - (u8 *)firm);
|
||||||
|
|
||||||
char absPath[24 + _MAX_LFN] = {0};
|
char absPath[24 + _MAX_LFN];
|
||||||
char path[10 + _MAX_LFN] = {0};
|
char path[10 + _MAX_LFN];
|
||||||
|
|
||||||
if(payloadPath == NULL)
|
if(payloadPath == NULL)
|
||||||
{
|
{
|
||||||
|
@ -61,7 +61,6 @@ void main(int argc, char **argv)
|
|||||||
u32 i;
|
u32 i;
|
||||||
for(i = 0; i < 40 && argv[0][i] != 0; i++) //Copy and convert the path to utf16
|
for(i = 0; i < 40 && argv[0][i] != 0; i++) //Copy and convert the path to utf16
|
||||||
launchedPath[i] = argv[0][i];
|
launchedPath[i] = argv[0][i];
|
||||||
for(; i < 41; i++)
|
|
||||||
launchedPath[i] = 0;
|
launchedPath[i] = 0;
|
||||||
|
|
||||||
isFirmlaunch = false;
|
isFirmlaunch = false;
|
||||||
@ -74,7 +73,6 @@ void main(int argc, char **argv)
|
|||||||
u16 *p = (u16 *)argv[0];
|
u16 *p = (u16 *)argv[0];
|
||||||
for(i = 0; i < 40 && p[i] != 0; i++)
|
for(i = 0; i < 40 && p[i] != 0; i++)
|
||||||
launchedPath[i] = p[i];
|
launchedPath[i] = p[i];
|
||||||
for(; i < 41; i++)
|
|
||||||
launchedPath[i] = 0;
|
launchedPath[i] = 0;
|
||||||
|
|
||||||
isFirmlaunch = true;
|
isFirmlaunch = true;
|
||||||
@ -82,12 +80,10 @@ void main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
|
||||||
sprintf(errbuf, "Unsupported launcher (argc = %d).", argc);
|
sprintf(errbuf, "Unsupported launcher (argc = %d).", argc);
|
||||||
error(errbuf);
|
error(errbuf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//Mount SD or CTRNAND
|
//Mount SD or CTRNAND
|
||||||
bool isSdMode;
|
bool isSdMode;
|
||||||
@ -100,14 +96,18 @@ void main(int argc, char **argv)
|
|||||||
else if(memcmp(launchedPath, u"nand", 8) == 0)
|
else if(memcmp(launchedPath, u"nand", 8) == 0)
|
||||||
{
|
{
|
||||||
firmSource = FIRMWARE_SYSNAND;
|
firmSource = FIRMWARE_SYSNAND;
|
||||||
if(!mountFs(false, true)) error("Failed to mount SD and CTRNAND.");
|
if(!mountFs(false, true)) error("Failed to mount CTRNAND.");
|
||||||
isSdMode = false;
|
isSdMode = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char mountPoint[5] = {0};
|
char mountPoint[5];
|
||||||
for(u32 i = 0; i < 4 && launchedPath[i] != u':'; i++)
|
|
||||||
|
u32 i;
|
||||||
|
for(i = 0; i < 4 && launchedPath[i] != u':'; i++)
|
||||||
mountPoint[i] = (char)launchedPath[i];
|
mountPoint[i] = (char)launchedPath[i];
|
||||||
|
mountPoint[i] = 0;
|
||||||
|
|
||||||
sprintf(errbuf, "Launched from an unsupported location: %s.", mountPoint);
|
sprintf(errbuf, "Launched from an unsupported location: %s.", mountPoint);
|
||||||
error(errbuf);
|
error(errbuf);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user