diff --git a/ctr/exec-3dsx/exec_3dsx.c b/ctr/exec-3dsx/exec_3dsx.c index 63e5404852..390f678f57 100644 --- a/ctr/exec-3dsx/exec_3dsx.c +++ b/ctr/exec-3dsx/exec_3dsx.c @@ -13,10 +13,11 @@ extern const loaderFuncs_s loader_Rosalina; static void (*launch_3dsx)(const char* path, argData_s* args, executableMetadata_s* em); -static int exec_3dsx_actual(const char* path, const char* args, bool appendPath){ +static int exec_3dsx_actual(const char* path, const char** args, bool appendPath){ struct stat sBuff; argData_s newProgramArgs; - char* writeableString[0x400]; + unsigned int argChars = 0; + unsigned int argNum = 0; bool fileExists; bool inited; @@ -39,12 +40,16 @@ static int exec_3dsx_actual(const char* path, const char* args, bool appendPath) memset(newProgramArgs.buf, '\0', sizeof(newProgramArgs.buf)); newProgramArgs.dst = (char*)&newProgramArgs.buf[1]; if(appendPath){ - strcpy(writeableString, path); - launchAddArg(&newProgramArgs, writeableString); + strcpy(newProgramArgs.dst, path); + newProgramArgs.dst += strlen(path) + 1; + newProgramArgs.buf[0]++; + } - if(args != NULL && args[0] != '\0'){ - strcpy(writeableString, args); - launchAddArgsFromString(&newProgramArgs, writeableString); + while(args[argNum] != NULL){ + strcpy(newProgramArgs.dst, args[argNum]); + newProgramArgs.dst += strlen(args[argNum]) + 1; + newProgramArgs.buf[0]++; + argNum++; } inited = loader_Rosalina.init(); diff --git a/ctr/exec-3dsx/exec_3dsx.h b/ctr/exec-3dsx/exec_3dsx.h index 888596dba9..d260331cb0 100644 --- a/ctr/exec-3dsx/exec_3dsx.h +++ b/ctr/exec-3dsx/exec_3dsx.h @@ -3,7 +3,7 @@ //since 3dsx programs are not guaranteed access to the OS, the 3dsx bootloader run by the exploit must run the next program //your program must have no extra threads running when this is called, these limits do not apply to exec_cia -int exec_3dsx_no_path_in_args(const char* path, const char* args); -int exec_3dsx(const char* path, const char* args); +int exec_3dsx_no_path_in_args(const char* path, const char** args); +int exec_3dsx(const char* path, const char** args); #endif \ No newline at end of file diff --git a/ctr/exec-3dsx/exec_cia.c b/ctr/exec-3dsx/exec_cia.c index 76ff86964b..7c4c19551d 100644 --- a/ctr/exec-3dsx/exec_cia.c +++ b/ctr/exec-3dsx/exec_cia.c @@ -115,7 +115,7 @@ static int installCia(Handle ciaFile){ return 1; } -int exec_cia(const char* path, const char* args){ +int exec_cia(const char* path, const char** args){ struct stat sBuff; bool fileExists; bool inited; @@ -175,38 +175,12 @@ int exec_cia(const char* path, const char* args){ param.argc = 0; argsLength = 0; - if(args != NULL && args[0] != '\0'){ - bool inSingleQuotes = false; - bool inDoubleQuotes = false; - int argStringLength = strlen(args); - - //build argument list like a terminal command on linux - for(unsigned int argPtr = 0; argPtr <= argStringLength; argPtr++){ - if(args[argPtr] == '\''){ - inSingleQuotes = !inSingleQuotes; - } - else if(args[argPtr] == '\"'){ - inDoubleQuotes = !inDoubleQuotes; - } - else if(args[argPtr] == '\0'){ - //last character in a valid arg string, end of last arg - if(param.args[0] != '\0') - param.argc++; - param.args[argsLength] = args[argPtr]; - argsLength++; - } - else{ - if(!inSingleQuotes && !inDoubleQuotes && args[argPtr] == ' '){ - param.argc++; - param.args[argsLength] = '\0'; - } - else{ - param.args[argsLength] = args[argPtr]; - } - - argsLength++; - } - } + char* argLocation = param.args; + while(args[param.argc] != NULL){ + strcpy(argLocation, args[param.argc]); + argLocation += strlen(args[param.argc]) + 1; + argsLength += strlen(args[param.argc]) + 1; + param.argc++; } res = APT_PrepareToDoApplicationJump(0, ciaInfo.titleID, 0x1); diff --git a/ctr/exec-3dsx/exec_cia.h b/ctr/exec-3dsx/exec_cia.h index 3a131720bf..4c751de922 100644 --- a/ctr/exec-3dsx/exec_cia.h +++ b/ctr/exec-3dsx/exec_cia.h @@ -1,6 +1,6 @@ #ifndef EXEC_CIA_H #define EXEC_CIA_H -int exec_cia(const char* path, const char* args); +int exec_cia(const char* path, const char** args); #endif \ No newline at end of file diff --git a/ctr/exec-3dsx/mini-hb-menu/common.h b/ctr/exec-3dsx/mini-hb-menu/common.h index 633a297f9d..ef354d46d2 100644 --- a/ctr/exec-3dsx/mini-hb-menu/common.h +++ b/ctr/exec-3dsx/mini-hb-menu/common.h @@ -1,95 +1,95 @@ -#pragma once - -// C stdlib includes -#include -#include -#include -#include -#include -#include -#include -#include - -// 3DS includes -#include <3ds.h> - - -#define ENTRY_ARGBUFSIZE 0x400 -#define NUM_SERVICESTHATMATTER 5 - -typedef enum -{ - StrId_Loading = 0, - StrId_Directory, - StrId_DefaultLongTitle, - StrId_DefaultPublisher, - StrId_IOError, - StrId_CouldNotOpenFile, - - StrId_NoAppsFound_Title, - StrId_NoAppsFound_Msg, - - StrId_Reboot, - StrId_ReturnToHome, - - StrId_TitleSelector, - StrId_ErrorReadingTitleMetadata, - StrId_NoTitlesFound, - StrId_SelectTitle, - - StrId_NoTargetTitleSupport, - StrId_MissingTargetTitle, - - StrId_NetLoader, - StrId_NetLoaderUnavailable, - StrId_NetLoaderOffline, - StrId_NetLoaderError, - StrId_NetLoaderActive, - StrId_NetLoaderTransferring, - - StrId_Max, -} StrId; - - -typedef struct -{ - char* dst; - u32 buf[ENTRY_ARGBUFSIZE/sizeof(u32)]; -} argData_s; - -typedef struct -{ - bool scanned; - u32 sectionSizes[3]; - bool servicesThatMatter[NUM_SERVICESTHATMATTER]; -} executableMetadata_s; - -typedef struct -{ - u32 num; - u32 text_end; - u32 data_address; - u32 data_size; - u32 processLinearOffset; - u32 processHookAddress; - u32 processAppCodeAddress; - u32 processHookTidLow, processHookTidHigh; - u32 mediatype; - bool capabilities[0x10]; // {socuAccess, csndAccess, qtmAccess, nfcAccess, httpcAccess, reserved...} -} memmap_header_t; - -typedef struct -{ - u32 src, dst, size; -} memmap_entry_t; - -typedef struct -{ - memmap_header_t header; - memmap_entry_t map[]; -} memmap_t; - -#define memmapSize(m) (sizeof(memmap_header_t) + sizeof(memmap_entry_t)*(m)->header.num) - - -#include "launch.h" +#pragma once + +// C stdlib includes +#include +#include +#include +#include +#include +#include +#include +#include + +// 3DS includes +#include <3ds.h> + + +#define ENTRY_ARGBUFSIZE 0x400 +#define NUM_SERVICESTHATMATTER 5 + +typedef enum +{ + StrId_Loading = 0, + StrId_Directory, + StrId_DefaultLongTitle, + StrId_DefaultPublisher, + StrId_IOError, + StrId_CouldNotOpenFile, + + StrId_NoAppsFound_Title, + StrId_NoAppsFound_Msg, + + StrId_Reboot, + StrId_ReturnToHome, + + StrId_TitleSelector, + StrId_ErrorReadingTitleMetadata, + StrId_NoTitlesFound, + StrId_SelectTitle, + + StrId_NoTargetTitleSupport, + StrId_MissingTargetTitle, + + StrId_NetLoader, + StrId_NetLoaderUnavailable, + StrId_NetLoaderOffline, + StrId_NetLoaderError, + StrId_NetLoaderActive, + StrId_NetLoaderTransferring, + + StrId_Max, +} StrId; + + +typedef struct +{ + char* dst; + u32 buf[ENTRY_ARGBUFSIZE/sizeof(u32)]; +} argData_s; + +typedef struct +{ + bool scanned; + u32 sectionSizes[3]; + bool servicesThatMatter[NUM_SERVICESTHATMATTER]; +} executableMetadata_s; + +typedef struct +{ + u32 num; + u32 text_end; + u32 data_address; + u32 data_size; + u32 processLinearOffset; + u32 processHookAddress; + u32 processAppCodeAddress; + u32 processHookTidLow, processHookTidHigh; + u32 mediatype; + bool capabilities[0x10]; // {socuAccess, csndAccess, qtmAccess, nfcAccess, httpcAccess, reserved...} +} memmap_header_t; + +typedef struct +{ + u32 src, dst, size; +} memmap_entry_t; + +typedef struct +{ + memmap_header_t header; + memmap_entry_t map[]; +} memmap_t; + +#define memmapSize(m) (sizeof(memmap_header_t) + sizeof(memmap_entry_t)*(m)->header.num) + + +#include "launch.h" diff --git a/ctr/exec-3dsx/mini-hb-menu/launch.c b/ctr/exec-3dsx/mini-hb-menu/launch.c index e9f6460427..e5adf30581 100644 --- a/ctr/exec-3dsx/mini-hb-menu/launch.c +++ b/ctr/exec-3dsx/mini-hb-menu/launch.c @@ -1,66 +1,5 @@ #include "common.h" -size_t launchAddArg(argData_s* ad, const char* arg) -{ - size_t len = strlen(arg)+1; - if ((ad->dst+len) >= (char*)(ad+1)) return len; // Overflow - ad->buf[0]++; - strcpy(ad->dst, arg); - ad->dst += len; - return len; -} - -void launchAddArgsFromString(argData_s* ad, char* arg) -{ - char c, *pstr, *str=arg, *endarg = arg+strlen(arg); - - do - { - do - { - c = *str++; - } while ((c == ' ' || c == '\t') && str < endarg); - - pstr = str-1; - - if (c == '\"') - { - pstr++; - while(*str++ != '\"' && str < endarg); - } - else - if (c == '\'') - { - pstr++; - while(*str++ != '\'' && str < endarg); - } - else - { - do - { - c = *str++; - } while (c != ' ' && c != '\t' && str < endarg); - } - - str--; - - if (str == (endarg - 1)) - { - if(*str == '\"' || *str == '\'') - *(str++) = 0; - else - str++; - } - else - { - *(str++) = '\0'; - } - - launchAddArg(ad, pstr); - - } while(str