Fix reboot patch and argument handling

This commit is contained in:
TuxSH 2017-05-20 00:18:41 +02:00
parent 6ccc0f0538
commit 2349370960
4 changed files with 34 additions and 20 deletions

View File

@ -181,6 +181,8 @@ nand_mount: .dcw "nand"
blo copy_loop32
bx lr
.pool
copy_launch_stub_end:
flushCaches:
@ -209,5 +211,4 @@ nand_mount: .dcw "nand"
bx lr
.pool
.close

View File

@ -189,8 +189,8 @@ void loadPayload(u32 pressed, const char *payloadPath)
char path[62] = {0},
absPath[92] = {0};
char mountPoint[5] = {0};
for(u32 i = 0; i < 4 && launchedPath[i] != ':'; i++)
u16 mountPoint[5] = {0};
for(u32 i = 0; i < 4 && launchedPath[i] != u':'; i++)
mountPoint[i] = launchedPath[i];
if(payloadPath == NULL)
@ -222,7 +222,7 @@ void loadPayload(u32 pressed, const char *payloadPath)
if(!info.fname[0]) return;
sprintf(path, "payloads/%s", info.altname);
if(memcmp(mountPoint, "nand", 4))
if(memcmp(mountPoint, u"nand", 8))
sprintf(absPath, "nand:/rw/luma/payloads/%s", info.altname);
else
sprintf(absPath, "%s:/luma/payloads/%s", mountPoint, info.altname);
@ -231,7 +231,7 @@ void loadPayload(u32 pressed, const char *payloadPath)
}
else
{
if(memcmp(mountPoint, "nand", 4))
if(memcmp(mountPoint, u"nand", 8))
sprintf(absPath, "nand:/rw/luma/payloads/%s", payloadPath);
else
sprintf(absPath, "%s:/luma/payloads/%s", mountPoint, payloadPath);

View File

@ -49,17 +49,19 @@ void main(int argc, char **argv)
FirmwareType firmType;
FirmwareSource nandType;
char errbuf[128];
switch(argc)
{
case 0:
error("Unsupported launcher.");
error("Unsupported launcher (argc = 0).");
break;
case 1: //Normal boot
{
u32 i;
for(i = 0; i < 40 && launchedPath[i] != 0; i++) //Copy and convert the path to utf16
launchedPath[2 * i] = argv[0][i];
for(i = 0; i < 40 && argv[0][i] != 0; i++) //Copy and convert the path to utf16
launchedPath[i] = argv[0][i];
for(; i < 41; i++)
launchedPath[i] = 0;
@ -71,7 +73,7 @@ void main(int argc, char **argv)
{
u32 i;
u16 *p = (u16 *)argv[0];
for(i = 0; i < 40 && launchedPath[i] != 0; i++)
for(i = 0; i < 40 && p[i] != 0; i++)
launchedPath[i] = p[i];
for(; i < 41; i++)
launchedPath[i] = 0;
@ -79,28 +81,40 @@ void main(int argc, char **argv)
memcpy(launchedFirmTidLow, (u16 *)argv[1], 16);
break;
}
default:
sprintf(errbuf, "Unsupported launcher (argc = %d > 2).", argc);
error(errbuf);
break;
}
char mountPoint[5] = {0};
for(u32 i = 0; i < 4 && argv[0][i] != ':'; i++)
mountPoint[i] = argv[0][i];
u16 mountPoint[5] = {0};
for(u32 i = 0; i < 4 && launchedPath[i] != u':'; i++)
mountPoint[i] = launchedPath[i];
//Mount SD or CTRNAND
bool isSdMode;
if(memcmp(mountPoint, "sdmc", 4) == 0)
if(memcmp(mountPoint, u"sdmc", 8) == 0)
{
if(!mountFs(true, false)) error("Failed to mount SD.");
isSdMode = true;
}
else if(memcmp(mountPoint, "nand", 4) == 0)
else if(memcmp(mountPoint, u"nand", 8) == 0)
{
firmSource = FIRMWARE_SYSNAND;
if(!mountFs(false, true)) error("Failed to mount SD and CTRNAND.");
isSdMode = false;
}
else
error("Launched from an unsupported location");
{
char mount8[5] = {0};
for(u32 i = 0 ; i < 4; i++)
mount8[i] = (char)mountPoint[i];
sprintf(errbuf, "Launched from an unsupported location: %s.", mount8);
error(errbuf);
}
//Attempt to read the configuration file
needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION;
@ -305,9 +319,8 @@ boot:
if(res != 0)
{
char patchesError[43];
sprintf(patchesError, "Failed to apply %u FIRM patch(es).", res);
error(patchesError);
sprintf(errbuf, "Failed to apply %u FIRM patch(es).", res);
error(errbuf);
}
launchFirm(firmType, loadFromStorage);

View File

@ -135,8 +135,8 @@ u32 patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr)
u32 *pos_fopen = (u32 *)memsearch(off, "OPEN", reboot_bin_size, 4);
*pos_fopen = fOpenOffset;
u16 *fname = (u16 *)memsearch(off, u"sd", reboot_bin_size, 4);
memcpy(fname, launchedPath, 82);
u16 *fname = (u16 *)memsearch(off, u"sdmc", reboot_bin_size, 8);
memcpy(fname, launchedPath, sizeof(launchedPath));
return 0;
}