From ebe67519b33d4ea421d34dee31cbd517a33d0581 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 24 Nov 2019 14:14:45 +0100 Subject: [PATCH] WIP2 --- .gitignore | 5 +- Makefile | 8 +- data/iconTex.tga | Bin 0 -> 65580 bytes filelist.sh | 57 ++++ makefile.mk | 4 +- src/main.cpp | 709 ++++++++++++++++++++++++++++++----------------- src/romfs_dev.c | 702 ++++++++++++++++++++++++++++++++++++++++++++++ src/romfs_dev.h | 90 ++++++ 8 files changed, 1315 insertions(+), 260 deletions(-) create mode 100644 data/iconTex.tga create mode 100644 filelist.sh create mode 100644 src/romfs_dev.c create mode 100644 src/romfs_dev.h diff --git a/.gitignore b/.gitignore index fb82516..5fc6187 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ build/* -*.mod \ No newline at end of file +*.mod +sysapp.layout +sysapp.cbp +src/filelist.h diff --git a/Makefile b/Makefile index 932d6fc..f03774b 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ MACHDEP = -DESPRESSO -mcpu=750 -meabi -mhard-float # -nostartfiles: Do not use the standard system startup files when linking # -ffunction-sections: split up functions so linker can garbage collect # -fdata-sections: split up data so linker can garbage collect -COMMON_CFLAGS := -O2 -Wall $(MACHDEP) -ffunction-sections -fdata-sections -Wl,-q $(COMMON_CFLAGS) +COMMON_CFLAGS := -O2 -Wall $(MACHDEP) -meabi -ffunction-sections -fdata-sections -Wl,-q $(COMMON_CFLAGS) CFLAGS += -D__WIIU__ -D__WUT__ @@ -102,6 +102,7 @@ LIBDIRS += #--------------------------------------------------------------------------------- ifneq ($(BUILD),$(notdir $(CURDIR))) #--------------------------------------------------------------------------------- +FILELIST := $(shell bash ./filelist.sh) export PROJECTDIR := $(CURDIR) export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET) export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ @@ -238,6 +239,11 @@ $(OUTPUT) : $(OFILES) %.ogg.o : %.ogg @echo $(notdir $<) @bin2s -a 32 $< | $(AS) -o $(@) +#--------------------------------------------------------------------------------- +%.tga.o : %.tga + @echo $(notdir $<) + @bin2s -a 32 $< | $(AS) -o $(@) +#--------------------------------------------------------------------------------- ############################################################################### # Assembly listing rules diff --git a/data/iconTex.tga b/data/iconTex.tga new file mode 100644 index 0000000000000000000000000000000000000000..5350b60ce5fc44ea671e3c27328a775346a72a00 GIT binary patch literal 65580 zcmeIb2Xs_dvM$Ve@2$7~_rLZ2duQg|JK@gQV;kpe;{X^N2OKdD*ajQhIAen`+2ova z5CTak=bUrSLRm-%iJY?u&e`>UU+q5KEzvCrt}t^w^jhU}&OUqBuBz{=+WVYtjujP*y%CuDp^0_8uxMQf=z4D z$C6I{1qPgN17gbKCd4#wULWzAa+7#!`*q?m{_nC5v2UYG$6YP!$6t-H*8ziPCCO*F zWCo9xg4h{S5Hk(^uW%zyys%;Jfxhb}(0Ay>(PJFPTK#N#Y;Ck>_Iq@1uPnS6I9CQ!!-Bja+Gth>6Ge zEA4tYFZFK(hlnM4$Rn?bo5wixx9hNUfh(9-`=TF@%S~ zJ#h>~?l6awH@yv8hidN7F2%hY*!3+E0*dN@u7x4$@Z9aQW zyjtVj-lmIlZSu(E8`e~;RgqXj6Fi4V=%W6>z~mzFXg@#s$+(!D?TK8wN&WMibr;sV z+m!R`Cm?o~j7KacUZwrKr`-&!uhks&pMAIZ&+erXzHETRt$R^I7WD)6sO!L=Hmsij zY%M+ZV_R++`{<7gjO=5a>~Y&>=JF(uJ|zzs0~?=Uzs}=!Ynzt(&Tniu*XQ>7yW^Vm{~BO#t)(|$9k@kvlkxYOa)aWgaaF(R zld+F@Zh-AxQ-BljqA&E*Z`PgQz^&l^RW_lWS1P7H({C29sn<)`(nloK_Z^8}|1$Fb zUhwW|$qX`kp=6&o5vRK~C#c)#`MZ-oORsh0J?p-8Ze3e_x_(s5;k)vlJ^&ZZ5%{

K`!L|2h9ZP;#LSKE*&uhwc!1gZ50M>=E)1@GK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{b1>*;0x^l zA5~}zxjDw%2mS|P|3Tn>uo!zsUSk~ZJNkE{{pTGE%kK8aOKDTvxep-EiTRPL1&IGl z

7hSTd&yM|ZCfH{u11j#Mp@;|(6*-5SOHAl8Ayo3ZyVpN{*)levxBj+nQ#1M8LI zOsqe(@yG|qWoDc;w!3Zrjp{p8!u$c|ip?0|wYKrP2(j)?L0vfnd=8gSlS8QWN2{>j zH+sp52K+8!^ISQMw!_GIXYRF~f3(_ps1)l0Y(7#sS5CEt$(fz8IEFySY_yNlIm|fr z?`9uKUt2HPeJbEHxa;|aAc+LI@T8>F5`e3ah|I95kn(rt3X>h@>=n8 zH#f1x+K(Dx@W$SiT(G1R{Bp?~cl!Rh+m9e#zpem(%y|@e9R=P;E2h|FnzkvfrKV5E zcG>!rVLyR&;0TZEOIODJ+CKl|&Uds7SX?S8$2(u-yAhnjjw9!33;Q1_1Lo&B?vnZZ zk7j521jPRmh`Tsk3S0h(=R8)9?3C!M/dev/null | tr -d '\n\n' | sed 's/[^0-9]*\([0-9]*\).*/\1/') + +count=0 +if [[ $OSTYPE == darwin* ]]; +then + +for i in $(gfind ./data/ -maxdepth 1 -type f \( ! -printf "%f\n" \) | sort -f) +do + files[count]=$i + count=$((count+1)) +done + +else + +for i in $(find ./data/ -maxdepth 1 -type f \( ! -printf "%f\n" \) | sort -f) +do + files[count]=$i + count=$((count+1)) +done + +fi + +if [ "$count_old" != "$count" ] || [ ! -f $outFile ] +then + +echo "Generating filelist.h for $count files." >&2 +cat < $outFile +/**************************************************************************** + * This file is generated automatically. + * Includes $count files. + * + * NOTE: + * Any manual modification of this file will be overwriten by the generation. + ****************************************************************************/ +#ifndef _FILELIST_H_ +#define _FILELIST_H_ + +EOF + +for i in ${files[@]} +do + filename=${i%.*} + extension=${i##*.} + echo 'extern const unsigned char '$filename'_'$extension'[];' >> $outFile + echo 'extern const unsigned int '$filename'_'$extension'_size;' >> $outFile + echo '' >> $outFile +done + +echo '#endif' >> $outFile + +fi diff --git a/makefile.mk b/makefile.mk index f27792a..26ad408 100644 --- a/makefile.mk +++ b/makefile.mk @@ -8,7 +8,7 @@ TARGET := $(notdir $(CURDIR)).mod SOURCES := src src/utils src/fs # Data directories -DATA := +DATA := data # Include directories INCLUDES := src @@ -47,4 +47,4 @@ EXTERNAL_LIBPATHS := # Will be added to the final include paths # -IC:/library1/include #--------------------------------------------------------------------------------- -EXTERNAL_INCLUDE := -I$(WUT_ROOT)/include/libutilswut +EXTERNAL_INCLUDE := diff --git a/src/main.cpp b/src/main.cpp index 3ea5797..f73efe2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,244 +20,105 @@ #include #include #include - -#define TARGET_WIDTH (854) -#define TARGET_HEIGHT (480) +#include "romfs_dev.h" +#include "filelist.h" -WUPS_ALLOW_KERNEL() - -void printVPADButtons(VPADStatus * buffer); - -WUPS_PLUGIN_NAME("Vpad input logger"); -WUPS_PLUGIN_DESCRIPTION("Prints information about vpad inputs and sensors"); -WUPS_PLUGIN_VERSION("v1.0"); +WUPS_PLUGIN_NAME("System Menu Launcher"); +WUPS_PLUGIN_DESCRIPTION("Allows the user to load homebrew from the System Menu"); +WUPS_PLUGIN_VERSION("0.1"); WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_LICENSE("GPL"); -IOSHandle handles[100]; +typedef struct WUT_PACKED FileInfos_ { + char path[256]; + char name[256]; + int32_t source; + bool romfsMounted; +} FileInfos; -struct WUT_PACKED ACPMetaData { - char bootmovie[80696]; - char bootlogo[28604]; -}; - - -extern "C" { - extern void __init_wut_malloc(); - extern void __fini_wut_malloc(); -} - -WUPS_FS_ACCESS() - +FileInfos gFileInfos[100] __attribute__((section(".data"))); ACPMetaXml gLaunchXML __attribute__((section(".data"))); MCPTitleListType template_title __attribute__((section(".data"))); BOOL gHomebrewLaunched __attribute__((section(".data"))); + +WUPS_USE_WUT_CRT() + INITIALIZE_PLUGIN() { memset((void*) &template_title,0,sizeof(template_title)); memset((void*) &gLaunchXML,0,sizeof(gLaunchXML)); + memset((void*) &gFileInfos,0,sizeof(gFileInfos)); gHomebrewLaunched = FALSE; } -ON_APPLICATION_START(args) { - __init_wut_malloc(); - socket_lib_init(); - log_init(); - if(_SYSGetSystemApplicationTitleId(APP_ID_Updater) == OSGetTitleID()) { - gHomebrewLaunched = FALSE; +int EndsWith(const char *str, const char *suffix); + +void listdir(const char *name, int indent) { + DEBUG_FUNCTION_LINE("Reading %s\n",name); + DIR *dir; + struct dirent *entry; + + if (!(dir = opendir(name))) + return; + + while ((entry = readdir(dir)) != NULL) { + if (entry->d_type == DT_DIR) { + char path[1024]; + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; + snprintf(path, sizeof(path), "%s%s", name, entry->d_name); + DEBUG_FUNCTION_LINE("%*s[%s]\n", indent, "", entry->d_name); + listdir(path, indent + 2); + } else { + DEBUG_FUNCTION_LINE("%*s- %s\n", indent, "", entry->d_name); + } } - + closedir(dir); } -ON_APPLICATION_ENDING() { - __fini_wut_malloc(); +ON_APPLICATION_START(args) { + socket_lib_init(); + log_init(); + DEBUG_FUNCTION_LINE("IN PLUGIN\n"); + + if(_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) != OSGetTitleID()) { + DEBUG_FUNCTION_LINE("gHomebrewLaunched to FALSE\n"); + gHomebrewLaunched = FALSE; + } +} + +void unmountAllRomfs(); +ON_APPLICATION_END() { + unmountAllRomfs(); } void fillXmlForTitleID(uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml* out_buf) { out_buf->title_id = ((uint64_t)titleid_upper * 0x100000000) + titleid_lower; - // TODO - char buffer [25]; - snprintf(buffer,25,"/custom/%08X%08X", titleid_upper,titleid_lower); - DEBUG_FUNCTION_LINE("%s\n",buffer); - strncpy(out_buf->longname_en,buffer,strlen(buffer)); - strncpy(out_buf->shortname_en,buffer,strlen(buffer)); + strncpy(out_buf->longname_en,gFileInfos[titleid_lower].name,511); + strncpy(out_buf->shortname_en,gFileInfos[titleid_lower].name,255); + strncpy(out_buf->publisher_en,gFileInfos[titleid_lower].name,255); out_buf->e_manual = 1; - out_buf->e_manual_version = 1; + out_buf->e_manual_version = 0; + out_buf->title_version = 1; + out_buf->network_use = 1; + out_buf->launching_flag = 4; + out_buf->online_account_use = 1; + out_buf->os_version = 0x000500101000400A; out_buf->region = 0xFFFFFFFF; + out_buf->common_save_size = 0x0000000001790000; + out_buf->group_id = 0x400; + out_buf->drc_use = 1; + out_buf->version = 1; + out_buf->reserved_flag0 = 0x00010001; + out_buf->reserved_flag6 = 0x00000003; + out_buf->pc_usk = 128; + strncpy(out_buf->product_code,"WUP-P-HBLD",strlen("WUP-P-HBLD")); + strncpy(out_buf->content_platform,"WUP",strlen("WUP")); + strncpy(out_buf->company_code,"0001",strlen("0001")); } -DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t* outTitleCount, MCPTitleListType* titleList, uint32_t size) { - int32_t result = real_MCP_TitleList(handle, outTitleCount, titleList, size); - uint32_t titlecount = *outTitleCount; - - DirList dirList("sd:/wiiu/apps", ".rpx", DirList::Files | DirList::CheckSubfolders, 1); - dirList.SortList(); - int j = 0; - for(int i = 0; i < dirList.GetFilecount(); i++) { - //! skip our own application in the listing - if(strcasecmp(dirList.GetFilename(i), "homebrew_launcher.elf") == 0) - continue; - //! skip our own application in the listing - if(strcasecmp(dirList.GetFilename(i), "homebrew_launcher.rpx") == 0) - continue; - - //! skip hidden linux and mac files - if(dirList.GetFilename(i)[0] == '.' || dirList.GetFilename(i)[0] == '_') - continue; - - char buffer [25]; - snprintf(buffer,25,"/custom/%08X%08X", 0x0005000F, j); - strcpy(template_title.path,buffer); - - const char * indexedDevice = "mlc"; - strcpy(template_title.indexedDevice,indexedDevice); - template_title.appType = MCP_APP_TYPE_SystemApps; // for some reason we need to act like an system app. - template_title.titleId = 0x0005000F00000000 + j; - template_title.titleVersion = 1; - template_title.groupId = 0x400; - template_title.osVersion = OSGetOSID(); - template_title.sdkVersion = __OSGetProcessSDKVersion(); - template_title.unk0x60 = 1; - - memcpy(&(titleList[titlecount]), &template_title,sizeof(template_title)); - titlecount++; - j++; - } - - *outTitleCount = titlecount; - - for(int i = 0; i< *outTitleCount; i++) { - DEBUG_FUNCTION_LINE("%s %08X %016llX %08X %08X %s \n",titleList[i].path, titleList[i].appType, titleList[i].osVersion, titleList[i].sdkVersion,titleList[i].groupId,titleList[i].indexedDevice); - //dumpHex(&titleList[i],sizeof(MCPTitleListType)); - } - - return result; -} - -DECL_FUNCTION(int32_t, MCP_GetTitleInfoByTitleAndDevice, uint32_t mcp_handle, uint32_t titleid_lower_1, uint32_t titleid_upper, uint32_t titleid_lower_2, uint32_t unknown, MCPTitleListType* title) { - - if(gHomebrewLaunched) { - memcpy(title, &(template_title), sizeof(MCPTitleListType)); - } else if(titleid_upper == 0x0005000F) { - char buffer [25]; - snprintf(buffer,25,"/custom/%08X%08X", titleid_lower_2, titleid_upper); - strcpy(template_title.path,buffer); - template_title.titleId = 0x0005000F00000000 + titleid_lower_1; - memcpy(title, &(template_title), sizeof(MCPTitleListType)); - DEBUG_FUNCTION_LINE("%s %08X %016llX %08X \n",title->path, title->appType, title->osVersion, title->sdkVersion); - return 0; - } - int result = real_MCP_GetTitleInfoByTitleAndDevice(mcp_handle, titleid_lower_1, titleid_upper, titleid_lower_2, unknown, title); - - return result; -} - - -DECL_FUNCTION(int32_t, ACPCheckTitleLaunchByTitleListTypeEx, MCPTitleListType* title, uint32_t u2) { - if(title->titleId & 0x0005000F00000000) { - DEBUG_FUNCTION_LINE("Started homebrew\n"); - gHomebrewLaunched = TRUE; - fillXmlForTitleID((title->titleId & 0xFFFFFFFF00000000) >> 32,(title->titleId & 0xFFFFFFFF), &gLaunchXML); - return 0; - } - - int result = real_ACPCheckTitleLaunchByTitleListTypeEx(title, u2); - return result; - -} - -int EndsWith(const char *str, const char *suffix) { - if (!str || !suffix) - return 0; - size_t lenstr = strlen(str); - size_t lensuffix = strlen(suffix); - if (lensuffix > lenstr) - return 0; - return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0; -} - -DECL_FUNCTION(void, FSInit) { - socket_lib_init(); - log_init(); - OSDynLoad_Module sModuleHandle = NULL; - OSDynLoad_Acquire("nn_acp.rpl", &sModuleHandle); - void *functionptr = NULL; - OSDynLoad_FindExport(sModuleHandle, FALSE, "ACPGetTitleMetaDir", &functionptr); - DEBUG_FUNCTION_LINE("%08X %08X\n",functionptr, OSEffectiveToPhysical((uint32_t)functionptr)); - return real_FSInit(); -} - -DECL_FUNCTION(int, FSOpenFile, FSClient *pClient, FSCmdBlock *pCmd, char *path, const char *mode, int *handle, int error) { - char * start = "/vol/storage_mlc01/sys/title/0005000F"; - char * icon = "iconTex.tga"; - - if(EndsWith(path,icon)) { - if(gHomebrewLaunched || strncmp(path,start,strlen(start)) == 0) { - strcpy(path,"/vol/storage_mlc01/usr/title/00050000/10172000/meta/iconTex.tga"); - } - } - - int result = real_FSOpenFile(pClient, pCmd, path, mode, handle, error); - DEBUG_FUNCTION_LINE("%s! Result %08X %d\n",path,*handle, result); - return result; -} - -DECL_FUNCTION(FSStatus, FSReadFile, FSClient *client, FSCmdBlock *block, uint8_t *buffer, uint32_t size, uint32_t count, FSFileHandle handle,uint32_t unk1, uint32_t flags) { - FSStatus result = real_FSReadFile(client, block, buffer, size, count, handle, unk1, flags); - DEBUG_FUNCTION_LINE("%08X %d\n", handle, result); - return result; -} - -DECL_FUNCTION(FSStatus,FSBindMount,FSClient *client, - FSCmdBlock *cmd, - const char *source, - const char *target, - uint32_t flags) { - FSStatus result = real_FSBindMount(client, cmd, source, target, flags); - DEBUG_FUNCTION_LINE("%s %s %d\n", source,target, result); - return result; -} - -DECL_FUNCTION(FSStatus, FSReadDir, FSClient *client, FSCmdBlock *block, FSDirectoryHandle handle, FSDirectoryEntry *entry, uint32_t flags) { - FSStatus result = real_FSReadDir(client, block, handle, entry, flags); - DEBUG_FUNCTION_LINE("%s %d\n", entry->name, result); - return result; -} - -DECL_FUNCTION(int32_t, ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml* out_buf, uint32_t device, uint32_t u1) { - DEBUG_FUNCTION_LINE("\n"); - int result = real_ACPGetTitleMetaXmlByDevice(titleid_upper, titleid_lower, out_buf, device,u1); - - if(titleid_upper == 0x00050000 && titleid_lower == 0x13374842) { - //dumpHex((void*)out_buf,0x3500); - } - - if(titleid_upper == 0x0005000F) { - fillXmlForTitleID(titleid_upper,titleid_lower, out_buf); - result = 0; - } - - DEBUG_FUNCTION_LINE("TitleID: %08X%08X res:%016llX device: %d %08X = %08X \n",titleid_upper,titleid_lower,out_buf->title_id, device,u1,result); - return result; -} - -DECL_FUNCTION(int32_t, ACPGetTitleMetaDirByDevice, uint32_t titleid_upper, uint32_t titleid_lower, char* out_buf, uint32_t size, int device) { - DEBUG_FUNCTION_LINE("\n"); - int result = real_ACPGetTitleMetaDirByDevice(titleid_upper, titleid_lower, out_buf, size, device); - - if(titleid_upper == 0x0005000F) { - strcpy(out_buf,"/vol/storage_mlc01/usr/title/00050000/10119b00"); - return -1; - } - - DEBUG_FUNCTION_LINE("TitleID: %08X%08X path:%s (%d)device: %d = %08X \n",titleid_upper,titleid_lower,out_buf,size, device,result); - - return result; -} - - // You must free the result if result is non-NULL. char *str_replace(char *orig, char *rep, char *with) { char *result; // the return string @@ -305,25 +166,354 @@ char *str_replace(char *orig, char *rep, char *with) { return result; } +DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t* outTitleCount, MCPTitleListType* titleList, uint32_t size) { + int32_t result = real_MCP_TitleList(handle, outTitleCount, titleList, size); + uint32_t titlecount = *outTitleCount; + + DirList dirList("fs:/vol/external01/wiiu/apps", ".rpx,.wbf", DirList::Files | DirList::CheckSubfolders, 1); + dirList.SortList(); + + int j = 0; + for(int i = 0; i < dirList.GetFilecount(); i++) { + //! skip our own application in the listing + if(strcasecmp(dirList.GetFilename(i), "homebrew_launcher.rpx") == 0) { + continue; + } + //! skip our own application in the listing + if(strcasecmp(dirList.GetFilename(i), "temp.rpx") == 0) { + continue; + } + + //! skip hidden linux and mac files + if(dirList.GetFilename(i)[0] == '.' || dirList.GetFilename(i)[0] == '_') { + continue; + } + + char buffer [25]; + snprintf(buffer,25,"/custom/%08X%08X", 0x0005000F, j); + strcpy(template_title.path,buffer); + + char * repl = (char*)"fs:/vol/external01/"; + char * with = (char*)""; + char * input = (char*) dirList.GetFilepath(i); + + char * path = str_replace(input,repl, with); + if(path != NULL) { + strncpy(gFileInfos[j].path,path, 255); + free(path); + } + + strncpy(gFileInfos[j].name, dirList.GetFilename(i),255); + gFileInfos[j].source = 0; //SD Card; + + //DEBUG_FUNCTION_LINE("%s\n",gFileInfos[j].path); + + const char * indexedDevice = "mlc"; + strcpy(template_title.indexedDevice,indexedDevice); + if(EndsWith(gFileInfos[j].name, ".wbf")) { + + template_title.appType = MCP_APP_TYPE_GAME; + } else { + // System apps don't have a splash screen. + template_title.appType = MCP_APP_TYPE_SYSTEM_APPS; + } + template_title.titleId = 0x0005000F00000000 + j; + template_title.titleVersion = 1; + template_title.groupId = 0x400; + + template_title.osVersion = OSGetOSID(); + template_title.sdkVersion = __OSGetProcessSDKVersion(); + template_title.unk0x60 = 0; + + memcpy(&(titleList[titlecount]), &template_title,sizeof(template_title)); + titlecount++; + j++; + } + + *outTitleCount = titlecount; + + return result; +} + +DECL_FUNCTION(int32_t, MCP_GetTitleInfoByTitleAndDevice, uint32_t mcp_handle, uint32_t titleid_lower_1, uint32_t titleid_upper, uint32_t titleid_lower_2, uint32_t unknown, MCPTitleListType* title) { + if(gHomebrewLaunched) { + memcpy(title, &(template_title), sizeof(MCPTitleListType)); + } else if(titleid_upper == 0x0005000F) { + char buffer [25]; + snprintf(buffer,25,"/custom/%08X%08X", titleid_upper, titleid_lower_2); + strcpy(template_title.path,buffer); + template_title.titleId = 0x0005000F00000000 + titleid_lower_1; + memcpy(title, &(template_title), sizeof(MCPTitleListType)); + return 0; + } + int result = real_MCP_GetTitleInfoByTitleAndDevice(mcp_handle, titleid_lower_1, titleid_upper, titleid_lower_2, unknown, title); + + return result; +} + +typedef struct __attribute((packed)) { + uint32_t command; + uint32_t target; + uint32_t filesize; + uint32_t fileoffset; + char path[256]; +} +LOAD_REQUEST; + +int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo * info); + +DECL_FUNCTION(int32_t, ACPCheckTitleLaunchByTitleListTypeEx, MCPTitleListType* title, uint32_t u2) { + DEBUG_FUNCTION_LINE("Started homebrew??\n"); + if((title->titleId & 0x0005000F00000000) == 0x0005000F00000000) { + DEBUG_FUNCTION_LINE("Started homebrew\n"); + gHomebrewLaunched = TRUE; + fillXmlForTitleID((title->titleId & 0xFFFFFFFF00000000) >> 32,(title->titleId & 0xFFFFFFFF), &gLaunchXML); + + LOAD_REQUEST request; + memset(&request, 0, sizeof(request)); + + + request.command = 0xFC; // IPC_CUSTOM_LOAD_CUSTOM_RPX; + request.target = 0; // LOAD_FILE_TARGET_SD_CARD + request.filesize = 0; // unknown + request.fileoffset = 0; // + + romfs_fileInfo info; + int res = getRPXInfoForID((title->titleId & 0xFFFFFFFF),&info); + if(res >= 0) { + request.filesize = ((uint32_t*)&info.length)[1]; + request.fileoffset = ((uint32_t*)&info.offset)[1]; + } + DEBUG_FUNCTION_LINE("%d\n", res); + + strncpy(request.path, gFileInfos[(uint32_t)(title->titleId & 0xFFFFFFFF)].path, 255); + + DEBUG_FUNCTION_LINE("Loading file %s size: %08X offset: %08X\n", request.path, request.filesize, request.fileoffset); + + DCFlushRange(&request, sizeof(LOAD_REQUEST)); + + int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode)0); + if(mcpFd >= 0) { + int out = 0; + IOS_Ioctl(mcpFd, 100, &request, sizeof(request), &out, sizeof(out)); + IOS_Close(mcpFd); + } + return 0; + } + + int result = real_ACPCheckTitleLaunchByTitleListTypeEx(title, u2); + return result; + +} + +int EndsWith(const char *str, const char *suffix) { + if (!str || !suffix) + return 0; + size_t lenstr = strlen(str); + size_t lensuffix = strlen(suffix); + if (lensuffix > lenstr) + return 0; + return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0; +} + +bool mountRomfs(uint32_t id) { + if(!gFileInfos[id].romfsMounted) { + char buffer [256]; + snprintf(buffer,256,"fs:/vol/external01/%s", gFileInfos[id].path); + char romName [10]; + snprintf(romName,10,"%08X", id); + DEBUG_FUNCTION_LINE("Mount %s as %s\n", buffer, romName); + if(romfsMount(romName,buffer) == 0) { + DEBUG_FUNCTION_LINE("Mounted successfully \n"); + gFileInfos[id].romfsMounted = true; + return true; + } else { + return false; + } + } + return true; +} + +void unmountRomfs(uint32_t id) { + if(gFileInfos[id].romfsMounted) { + char romName [10]; + snprintf(romName,10,"%08X", id); + //DEBUG_FUNCTION_LINE("Unmounting %s\n", romName); + int res = romfsUnmount(romName); + //DEBUG_FUNCTION_LINE("res: %d\n",res); + gFileInfos[id].romfsMounted = false; + } +} + +void unmountAllRomfs() { + for(int i = 0; i < 100; i++) { + unmountRomfs(i); + } +} + +int32_t FSOpenFile_for_ID(uint32_t id, const char * filepath, int * handle) { + if(!mountRomfs(id)) { + return -1; + } + char romName [10]; + snprintf(romName,10,"%08X", id); + + char * test = (char *) malloc(strlen(filepath)+1); + char last = 0; + int j = 0; + for(int i = 0; filepath[i] != 0; i++) { + if(filepath[i] == '/' ) { + if(filepath[i] != last) { + test[j++] = filepath[i]; + } + } else { + test[j++] = filepath[i]; + } + last = filepath[i]; + } + test[j++] = 0; + + char buffer [256]; + snprintf(buffer,256,"%s:/%s",romName, test); + + int fd = open(buffer,0); + if(fd >= 0) { + DEBUG_FUNCTION_LINE("Opened %s from %s \n",buffer, romName ); + *handle = 0xFF000000 + fd; + return 0; + } + + return -2; +} + +int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo * info) { + if(!mountRomfs(id)) { + return -1; + } + DIR *dir; + struct dirent *entry; + char romName [10]; + snprintf(romName,10,"%08X", id); + + char root[12]; + snprintf(root,12,"%08X:/", id); + + if (!(dir = opendir(root))) { + return -2; + } + bool found = false; + int res = -3; + while ((entry = readdir(dir)) != NULL) { + if(EndsWith(entry->d_name, ".rpx")) { + if(romfs_GetFileInfoPerPath(romName, entry->d_name, info) >= 0) { + found = true; + res = 0; + } + break; + } + } + + closedir(dir); + + if(!found) { + return -4; + } + return res; +} + +DECL_FUNCTION(int, FSOpenFile, FSClient *client, FSCmdBlock *block, char *path, const char *mode, int *handle, int error) { + char * start = "/vol/storage_mlc01/sys/title/0005000F"; + char * icon = ".tga"; + char * iconTex = "iconTex.tga"; + char * sound = ".btsnd"; + + if(EndsWith(path,icon) || EndsWith(path,sound)) { + if(strncmp(path,start,strlen(start)) == 0/* || (gHomebrewLaunched && EndsWith(path,iconTex))*/) { + int res = FS_STATUS_NOT_FOUND; + if(EndsWith(path,iconTex)) { + // fallback to dummy icon if loaded homebrew is no .wbf + *handle = 0x1337; + res = FS_STATUS_OK; + } + + uint32_t val; + char * id = path+1+strlen(start); + id[8] = 0; + char * ending = id+9; + sscanf(id,"%08X", &val); + if(FSOpenFile_for_ID(val, ending, handle) < 0) { + return res; + } + return FS_STATUS_OK; + } + } + + int result = real_FSOpenFile(client, block, path, mode, handle, error); + return result; +} + +DECL_FUNCTION(FSStatus, FSCloseFile, FSClient *client, FSCmdBlock *block, FSFileHandle handle, uint32_t flags) { + if(handle == 0x1337) { + return FS_STATUS_OK; + } + if((handle & 0xFF000000) == 0xFF000000) { + int32_t fd = (handle & 0x00FFFFFF); + close(fd); + return FS_STATUS_OK; + } + return real_FSCloseFile(client,block,handle,flags); +} + +DECL_FUNCTION(FSStatus, FSReadFile, FSClient *client, FSCmdBlock *block, uint8_t *buffer, uint32_t size, uint32_t count, FSFileHandle handle,uint32_t unk1, uint32_t flags) { + if(handle == 0x1337) { + int cpySize = size*count; + if(iconTex_tga_size < cpySize) { + cpySize = iconTex_tga_size; + } + memcpy(buffer, iconTex_tga, cpySize); + return (FSStatus)(cpySize/size); + } + if((handle & 0xFF000000) == 0xFF000000) { + int32_t fd = (handle & 0x00FFFFFF); + return (FSStatus)(read(fd, buffer, size*count) /size); + } + FSStatus result = real_FSReadFile(client, block, buffer, size, count, handle, unk1, flags); + return result; +} + +DECL_FUNCTION(int32_t, ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml* out_buf, uint32_t device, uint32_t u1) { + int result = real_ACPGetTitleMetaXmlByDevice(titleid_upper, titleid_lower, out_buf, device,u1); + if(titleid_upper == 0x0005000F) { + fillXmlForTitleID(titleid_upper,titleid_lower, out_buf); + result = 0; + } + return result; +} + +DECL_FUNCTION(int32_t, ACPGetTitleMetaDirByDevice, uint32_t titleid_upper, uint32_t titleid_lower, char* out_buf, uint32_t size, int device) { + if(titleid_upper == 0x0005000F) { + snprintf(out_buf,53,"/vol/storage_mlc01/sys/title/%08X/%08X/meta", titleid_upper, titleid_lower); + return 0; + } + int result = real_ACPGetTitleMetaDirByDevice(titleid_upper, titleid_lower, out_buf, size, device); + return result; +} + + + DECL_FUNCTION(int32_t, _SYSLaunchTitleByPathFromLauncher, char* pathToLoad, uint32_t u2) { - DEBUG_FUNCTION_LINE("\n"); const char * start = "/custom/"; if(strncmp(pathToLoad,start,strlen(start)) == 0) { strcpy(template_title.path,pathToLoad); - - // always load H&S app - strcpy(pathToLoad,"/vol/storage_mlc01/usr/title/00050000/10119b00"); + uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY); + snprintf(pathToLoad,47,"/vol/storage_mlc01/sys/title/%08x/%08x", (uint32_t) (titleID >> 32), (uint32_t) (0x00000000FFFFFFFF & titleID)); } int32_t result = real__SYSLaunchTitleByPathFromLauncher(pathToLoad, strlen(pathToLoad)); - - DEBUG_FUNCTION_LINE("%s %08X result %08X \n",pathToLoad,u2,result); return result; } DECL_FUNCTION(int32_t, ACPGetLaunchMetaXml, ACPMetaXml * metaxml) { - DEBUG_FUNCTION_LINE("\n"); - int result = real_ACPGetLaunchMetaXml(metaxml); if(gHomebrewLaunched) { memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML)); @@ -331,52 +521,59 @@ DECL_FUNCTION(int32_t, ACPGetLaunchMetaXml, ACPMetaXml * metaxml) { return result; } +DECL_FUNCTION(uint32_t, ACPGetApplicationBox,uint32_t * u1, uint32_t * u2, uint32_t u3, uint32_t u4) { + if(u3 == 0x0005000F) { + uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY); + u3 = (uint32_t) (titleID >> 32); + u4 = (uint32_t) (0x00000000FFFFFFFF & titleID); + } + uint32_t result = real_ACPGetApplicationBox(u1,u2,u3,u4); + return result; +} + +DECL_FUNCTION(uint32_t, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, uint32_t * param ) { + if(param[2] == 0x0005000F) { + uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY); + param[2] = (uint32_t) (titleID >> 32); + param[3] = (uint32_t) (0x00000000FFFFFFFF & titleID); + } + uint32_t result = real_PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg(param); + DEBUG_FUNCTION_LINE("%08X\n", result); + return result; +} + +DECL_FUNCTION(uint32_t, MCP_RightCheckLaunchable, uint32_t * u1, uint32_t * u2, uint32_t u3, uint32_t u4, uint32_t u5) { + if(u3 == 0x0005000F) { + uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY); + u3 = (uint32_t) (titleID >> 32); + u4 = (uint32_t) (0x00000000FFFFFFFF & titleID); + } + uint32_t result = real_MCP_RightCheckLaunchable(u1,u2,u3,u4,u5); + return result; +} + DECL_FUNCTION(int32_t, HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml* metaxml, uint32_t device) { if(gHomebrewLaunched) { memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML)); return 0; } int result = real_HBM_NN_ACP_ACPGetTitleMetaXmlByDevice(titleid_upper, titleid_lower, metaxml, device); - return result; } -DECL_FUNCTION(int32_t, EMANUAL_NN_ACP_ACPGetTitleMetaXml, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml* metaxml, uint32_t device) { - DEBUG_FUNCTION_LINE("%08X %08X %08X %08X\n",titleid_upper,titleid_lower,metaxml,device); +WUPS_MUST_REPLACE_PHYSICAL(HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, 0x2E36CE44, 0x0E36CE44); +WUPS_MUST_REPLACE(ACPGetApplicationBox, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetApplicationBox ); +WUPS_MUST_REPLACE(PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, WUPS_LOADER_LIBRARY_DRMAPP, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg ); +WUPS_MUST_REPLACE(MCP_RightCheckLaunchable, WUPS_LOADER_LIBRARY_COREINIT, MCP_RightCheckLaunchable ); - if(gHomebrewLaunched) { - memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML)); - return 0; - } - int result = real_EMANUAL_NN_ACP_ACPGetTitleMetaXml(titleid_upper, titleid_lower, metaxml, device); +WUPS_MUST_REPLACE(FSReadFile, WUPS_LOADER_LIBRARY_COREINIT, FSReadFile); +WUPS_MUST_REPLACE(FSOpenFile, WUPS_LOADER_LIBRARY_COREINIT, FSOpenFile); +WUPS_MUST_REPLACE(FSCloseFile, WUPS_LOADER_LIBRARY_COREINIT, FSCloseFile); +WUPS_MUST_REPLACE(MCP_TitleList, WUPS_LOADER_LIBRARY_COREINIT, MCP_TitleList); +WUPS_MUST_REPLACE(MCP_GetTitleInfoByTitleAndDevice, WUPS_LOADER_LIBRARY_COREINIT, MCP_GetTitleInfoByTitleAndDevice ); - return result; -} - -DECL_FUNCTION(int32_t, EMANUAL_NN_ACP_ACPGetTitleMetaDir, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml* metaxml, uint32_t device) { - DEBUG_FUNCTION_LINE("%08X %08X %08X %08X\n",titleid_upper,titleid_lower,metaxml,device); - - if(gHomebrewLaunched) { - //memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML)); - //return 0; - } - int result = real_EMANUAL_NN_ACP_ACPGetTitleMetaDir(titleid_upper, titleid_lower, metaxml, device); - - return result; -} - -WUPS_MUST_REPLACE_PHYSICAL(EMANUAL_NN_ACP_ACPGetTitleMetaDir, 0x4FA0A6F4, 0x0FA0A6F4); -WUPS_MUST_REPLACE_PHYSICAL(EMANUAL_NN_ACP_ACPGetTitleMetaXml, 0x4FA0C280, 0x0FA0C280); -WUPS_MUST_REPLACE_PHYSICAL(HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, 0x2E36CE44, 0x0E36CE44); -WUPS_MUST_REPLACE(FSInit, WUPS_LOADER_LIBRARY_COREINIT, FSInit); -WUPS_MUST_REPLACE(FSBindMount, WUPS_LOADER_LIBRARY_COREINIT, FSBindMount); -WUPS_MUST_REPLACE(FSReadDir, WUPS_LOADER_LIBRARY_COREINIT, FSReadDir); -WUPS_MUST_REPLACE(FSReadFile, WUPS_LOADER_LIBRARY_COREINIT, FSReadFile); -WUPS_MUST_REPLACE(FSOpenFile, WUPS_LOADER_LIBRARY_COREINIT, FSOpenFile); -WUPS_MUST_REPLACE(MCP_TitleList, WUPS_LOADER_LIBRARY_COREINIT, MCP_TitleList); -WUPS_MUST_REPLACE(MCP_GetTitleInfoByTitleAndDevice, WUPS_LOADER_LIBRARY_COREINIT, MCP_GetTitleInfoByTitleAndDevice ); -WUPS_MUST_REPLACE(ACPCheckTitleLaunchByTitleListTypeEx, WUPS_LOADER_LIBRARY_NN_ACP, ACPCheckTitleLaunchByTitleListTypeEx ); -WUPS_MUST_REPLACE(ACPGetTitleMetaXmlByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaXmlByDevice ); -WUPS_MUST_REPLACE(ACPGetLaunchMetaXml, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetLaunchMetaXml ); -WUPS_MUST_REPLACE(ACPGetTitleMetaDirByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaDirByDevice ); -WUPS_MUST_REPLACE(_SYSLaunchTitleByPathFromLauncher, WUPS_LOADER_LIBRARY_SYSAPP, _SYSLaunchTitleByPathFromLauncher); +WUPS_MUST_REPLACE(ACPCheckTitleLaunchByTitleListTypeEx, WUPS_LOADER_LIBRARY_NN_ACP, ACPCheckTitleLaunchByTitleListTypeEx ); +WUPS_MUST_REPLACE(ACPGetTitleMetaXmlByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaXmlByDevice ); +WUPS_MUST_REPLACE(ACPGetLaunchMetaXml, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetLaunchMetaXml ); +WUPS_MUST_REPLACE(ACPGetTitleMetaDirByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaDirByDevice ); +WUPS_MUST_REPLACE(_SYSLaunchTitleByPathFromLauncher, WUPS_LOADER_LIBRARY_SYSAPP, _SYSLaunchTitleByPathFromLauncher); diff --git a/src/romfs_dev.c b/src/romfs_dev.c new file mode 100644 index 0000000..34e9986 --- /dev/null +++ b/src/romfs_dev.c @@ -0,0 +1,702 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "romfs_dev.h" + +typedef enum { + RomfsSource_FileDescriptor, +} RomfsSource; + +typedef struct romfs_mount { + devoptab_t device; + bool setup; + RomfsSource fd_type; + int32_t id; + int32_t fd; + time_t mtime; + uint64_t offset; + romfs_header header; + romfs_dir *cwd; + uint32_t *dirHashTable, *fileHashTable; + void *dirTable, *fileTable; + char name[32]; +} romfs_mount; + +extern int __system_argc; +extern char** __system_argv; + +//static char __thread __component[PATH_MAX+1]; +static char __component[PATH_MAX+1]; + +#define romFS_root(m) ((romfs_dir*)(m)->dirTable) +#define romFS_dir(m,x) ((romfs_dir*) ((uint8_t*)(m)->dirTable + (x))) +#define romFS_file(m,x) ((romfs_file*)((uint8_t*)(m)->fileTable + (x))) +#define romFS_none ((uint32_t)~0) +#define romFS_dir_mode (S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH) +#define romFS_file_mode (S_IFREG | S_IRUSR | S_IRGRP | S_IROTH) + +uint64_t swapLong(uint64_t X) { + uint64_t x = (uint64_t) X; + x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32; + x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16; + x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8; + return x; +} + +#define REVERSE_SHORT(n) ((unsigned short) (((n & 0xFF) << 8) | \ + ((n & 0xFF00) >> 8))) +#define REVERSE_INT(n) ((unsigned int) (((n & 0xFF) << 24) | \ + ((n & 0xFF00) << 8) | \ + ((n & 0xFF0000) >> 8) | \ + ((n & 0xFF000000) >> 24))) + +static ssize_t _romfs_read(romfs_mount *mount, uint64_t offset, void* buffer, uint64_t size) { + uint64_t pos = mount->offset + offset; + size_t _read = 0; + if(mount->fd_type == RomfsSource_FileDescriptor) { + off_t seek_offset = lseek(mount->fd, pos, SEEK_SET); + if(pos != seek_offset) { + return -1; + } + _read = read(mount->fd, buffer, size); + } + return _read; +} + +static bool _romfs_read_chk(romfs_mount *mount, uint64_t offset, void* buffer, uint64_t size) { + return _romfs_read(mount, offset, buffer, size) == size; +} + +//----------------------------------------------------------------------------- + +static int romfs_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode); +static int romfs_close(struct _reent *r, void *fd); +static ssize_t romfs_read(struct _reent *r, void *fd, char *ptr, size_t len); +static off_t romfs_seek(struct _reent *r, void *fd, off_t pos, int dir); +static int romfs_fstat(struct _reent *r, void *fd, struct stat *st); +static int romfs_stat(struct _reent *r, const char *path, struct stat *st); +static int romfs_chdir(struct _reent *r, const char *path); +static DIR_ITER* romfs_diropen(struct _reent *r, DIR_ITER *dirState, const char *path); +static int romfs_dirreset(struct _reent *r, DIR_ITER *dirState); +static int romfs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat); +static int romfs_dirclose(struct _reent *r, DIR_ITER *dirState); + +typedef struct { + romfs_mount *mount; + romfs_file *file; + uint64_t offset, pos; +} romfs_fileobj; + +typedef struct { + romfs_mount *mount; + romfs_dir* dir; + uint32_t state; + uint32_t childDir; + uint32_t childFile; +} romfs_diriter; + +static devoptab_t romFS_devoptab = { + .structSize = sizeof(romfs_fileobj), + .open_r = romfs_open, + .close_r = romfs_close, + .read_r = romfs_read, + .seek_r = romfs_seek, + .fstat_r = romfs_fstat, + .stat_r = romfs_stat, + .chdir_r = romfs_chdir, + .dirStateSize = sizeof(romfs_diriter), + .diropen_r = romfs_diropen, + .dirreset_r = romfs_dirreset, + .dirnext_r = romfs_dirnext, + .dirclose_r = romfs_dirclose, +}; + +static bool romfs_initialised = false; +static romfs_mount romfs_mounts[32]; + +//----------------------------------------------------------------------------- + +static int32_t romfsMountCommon(const char *name, romfs_mount *mount); +static void romfsInitMtime(romfs_mount *mount); + +static void _romfsResetMount(romfs_mount *mount, int32_t id) { + memset(mount, 0, sizeof(*mount)); + memcpy(&mount->device, &romFS_devoptab, sizeof(romFS_devoptab)); + mount->device.name = mount->name; + mount->device.deviceData = mount; + mount->id = id; +} + +static void _romfsInit(void) { + uint32_t i; + uint32_t total = sizeof(romfs_mounts) / sizeof(romfs_mount); + + if(!romfs_initialised) { + for(i = 0; i < total; i++) { + _romfsResetMount(&romfs_mounts[i], i); + } + + romfs_initialised = true; + } +} + +static romfs_mount *romfsFindMount(const char *name) { + uint32_t i; + uint32_t total = sizeof(romfs_mounts) / sizeof(romfs_mount); + romfs_mount *mount = NULL; + + _romfsInit(); + + for(i=0; isetup) + return mount; + } else if(mount->setup) { //Find the mount with the input name. + if(strncmp(mount->name, name, sizeof(mount->name))==0) + return mount; + } + } + + return NULL; +} + +__attribute__((weak)) const char* __romfs_path = NULL; + +static romfs_mount* romfs_alloc(void) { + return romfsFindMount(NULL); +} + +static void romfs_free(romfs_mount *mount) { + free(mount->fileTable); + free(mount->fileHashTable); + free(mount->dirTable); + free(mount->dirHashTable); + _romfsResetMount(mount, mount->id); +} + +static void romfs_mountclose(romfs_mount *mount) { + if(mount->fd_type == RomfsSource_FileDescriptor) { + close(mount->fd); + } + romfs_free(mount); +} + +int32_t romfsMount(const char *name, const char * filepath) { + romfs_mount *mount = romfs_alloc(); + if(mount == NULL) + return 99; + + // Regular RomFS + mount->fd_type = RomfsSource_FileDescriptor; + + mount->fd = open(filepath, 0); + if (mount->fd == -1) { + romfs_free(mount); + return -1; + } + + romfsInitMtime(mount); + return romfsMountCommon(name, mount); + +_fail0: + romfs_mountclose(mount); + return 10; +} + +int32_t romfsMountCommon(const char *name, romfs_mount *mount) { + memset(mount->name, 0, sizeof(mount->name)); + strncpy(mount->name, name, sizeof(mount->name)-1); + + if (_romfs_read(mount, 0, &mount->header, sizeof(mount->header)) != sizeof(mount->header)) + goto fail; + + mount->dirHashTable = (uint32_t*)malloc(swapLong(mount->header.dirHashTableSize)); + if (!mount->dirHashTable) + goto fail; + if (!_romfs_read_chk(mount, swapLong(mount->header.dirHashTableOff), mount->dirHashTable, swapLong(mount->header.dirHashTableSize))) + goto fail; + + mount->dirTable = malloc(swapLong(mount->header.dirTableSize)); + if (!mount->dirTable) + goto fail; + if (!_romfs_read_chk(mount, swapLong(mount->header.dirTableOff), mount->dirTable, swapLong(mount->header.dirTableSize))) + goto fail; + mount->fileHashTable = (uint32_t*)malloc(swapLong(mount->header.fileHashTableSize)); + if (!mount->fileHashTable) + goto fail; + if (!_romfs_read_chk(mount, swapLong(mount->header.fileHashTableOff), mount->fileHashTable, swapLong(mount->header.fileHashTableSize))) + goto fail; + mount->fileTable = malloc(swapLong(mount->header.fileTableSize)); + if (!mount->fileTable) + goto fail; + + if (!_romfs_read_chk(mount, swapLong(mount->header.fileTableOff), mount->fileTable, swapLong(mount->header.fileTableSize))) + goto fail; + mount->cwd = romFS_root(mount); + + // add device if this is the first one + if(AddDevice(&mount->device) < 0) + goto fail; + mount->setup = true; + return 0; + +fail: + romfs_mountclose(mount); + return 10; +} + +static void romfsInitMtime(romfs_mount *mount) { + mount->mtime = time(NULL); +} + +int32_t romfsUnmount(const char *name) { + romfs_mount *mount; + char tmpname[34]; + + mount = romfsFindMount(name); + if (mount == NULL) + return -1; + + // Remove device + memset(tmpname, 0, sizeof(tmpname)); + strncpy(tmpname, mount->name, sizeof(tmpname)-2); + strncat(tmpname, ":", sizeof(tmpname)-strlen(tmpname)-1); + + RemoveDevice(tmpname); + + romfs_mountclose(mount); + + return 0; +} + +//----------------------------------------------------------------------------- + +static uint32_t calcHash(uint32_t parent, const uint8_t* name, uint32_t namelen, uint32_t total) { + uint32_t hash = parent ^ 123456789; + uint32_t i; + for (i = 0; i < namelen; i ++) { + hash = (hash >> 5) | (hash << 27); + hash ^= name[i]; + } + return hash % total; +} + +static romfs_dir* searchForDir(romfs_mount *mount, romfs_dir* parent, const uint8_t* name, uint32_t namelen) { + uint64_t parentOff = (uintptr_t)parent - (uintptr_t)mount->dirTable; + uint32_t hash = calcHash(parentOff, name, namelen, swapLong(mount->header.dirHashTableSize)/4); + romfs_dir* curDir = NULL; + uint32_t curOff; + for (curOff = REVERSE_INT(mount->dirHashTable[hash]); curOff != romFS_none; curOff = REVERSE_INT(curDir->nextHash)) { + curDir = romFS_dir(mount, curOff); + if (REVERSE_INT(curDir->parent) != parentOff) + continue; + if (REVERSE_INT(curDir->nameLen) != namelen) + continue; + if (memcmp(curDir->name, name, namelen) != 0) + continue; + return curDir; + } + return NULL; +} + +static romfs_file* searchForFile(romfs_mount *mount, romfs_dir* parent, const uint8_t* name, uint32_t namelen) { + uint64_t parentOff = (uintptr_t)parent - (uintptr_t)mount->dirTable; + uint32_t hash = calcHash(parentOff, name, namelen, swapLong(mount->header.fileHashTableSize)/4); + romfs_file* curFile = NULL; + uint32_t curOff; + for (curOff = REVERSE_INT(mount->fileHashTable[hash]); curOff != romFS_none; curOff = REVERSE_INT(curFile->nextHash)) { + curFile = romFS_file(mount, curOff); + if (REVERSE_INT(curFile->parent) != parentOff) + continue; + if (REVERSE_INT(curFile->nameLen) != namelen) + continue; + if (memcmp(curFile->name, name, namelen) != 0) + continue; + return curFile; + } + return NULL; +} + +static int navigateToDir(romfs_mount *mount, romfs_dir** ppDir, const char** pPath, bool isDir) { + char* colonPos = strchr(*pPath, ':'); + if (colonPos) + *pPath = colonPos+1; + if (!**pPath) + return EILSEQ; + + *ppDir = mount->cwd; + if (**pPath == '/') { + *ppDir = romFS_root(mount); + (*pPath)++; + } + + while (**pPath) { + char* slashPos = strchr(*pPath, '/'); + char* component = __component; + + if (slashPos) { + uint32_t len = slashPos - *pPath; + if (!len) + return EILSEQ; + if (len > PATH_MAX) + return ENAMETOOLONG; + + memcpy(component, *pPath, len); + component[len] = 0; + *pPath = slashPos+1; + } else if (isDir) { + component = (char*)*pPath; + *pPath += strlen(component); + } else + return 0; + + if (component[0]=='.') { + if (!component[1]) + continue; + if (component[1]=='.' && !component[2]) { + *ppDir = romFS_dir(mount, REVERSE_INT((*ppDir)->parent)); + continue; + } + } + + *ppDir = searchForDir(mount, *ppDir, (uint8_t*)component, strlen(component)); + if (!*ppDir) + return EEXIST; + } + + if (!isDir && !**pPath) + return EILSEQ; + + return 0; +} + +static ino_t dir_inode(romfs_mount *mount, romfs_dir *dir) { + return (uint32_t*)dir - (uint32_t*)mount->dirTable; +} + +static off_t dir_size(romfs_dir *dir) { + return sizeof(romfs_dir) + (REVERSE_INT(dir->nameLen)+3)/4; +} + +static nlink_t dir_nlink(romfs_mount *mount, romfs_dir *dir) { + nlink_t count = 2; // one for self, one for parent + uint32_t offset = REVERSE_INT(dir->childDir); + + while(offset != romFS_none) { + romfs_dir *tmp = romFS_dir(mount, offset); + ++count; + offset = REVERSE_INT(tmp->sibling); + } + + offset = REVERSE_INT(dir->childFile); + while(offset != romFS_none) { + romfs_file *tmp = romFS_file(mount, offset); + ++count; + offset = REVERSE_INT(tmp->sibling); + } + + return count; +} + +static ino_t file_inode(romfs_mount *mount, romfs_file *file) { + return ((uint32_t*)file - (uint32_t*)mount->fileTable) + swapLong(mount->header.dirTableSize)/4; +} + +int romfs_GetFileInfoPerPath(const char* romfs, const char *path, romfs_fileInfo* out) { + if(out == NULL){ + return -1; + } + romfs_mount* mount = (romfs_mount*)romfsFindMount(romfs); + if(mount == NULL){ + return -2; + } + romfs_dir* curDir = NULL; + int errno2 = navigateToDir(mount, &curDir, &path, false); + if (errno2 != 0){ + return -3; + } + + romfs_file* file = searchForFile(mount, curDir, (uint8_t*)path, strlen(path)); + if (!file) { + return -4; + } + + out->length = swapLong(file->dataSize); + out->offset = swapLong(mount->header.fileDataOff) + swapLong(file->dataOff); + + return 0; +} + + +//----------------------------------------------------------------------------- + +int romfs_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode) { + romfs_fileobj* fileobj = (romfs_fileobj*)fileStruct; + + fileobj->mount = (romfs_mount*)r->deviceData; + + if ((flags & O_ACCMODE) != O_RDONLY) { + r->_errno = EROFS; + return -1; + } + + romfs_dir* curDir = NULL; + r->_errno = navigateToDir(fileobj->mount, &curDir, &path, false); + if (r->_errno != 0) + return -1; + + romfs_file* file = searchForFile(fileobj->mount, curDir, (uint8_t*)path, strlen(path)); + if (!file) { + if(flags & O_CREAT) + r->_errno = EROFS; + else + r->_errno = ENOENT; + return -1; + } else if((flags & O_CREAT) && (flags & O_EXCL)) { + r->_errno = EEXIST; + return -1; + } + + fileobj->file = file; + fileobj->offset = swapLong(fileobj->mount->header.fileDataOff) + swapLong(file->dataOff); + fileobj->pos = 0; + + return 0; +} + +int romfs_close(struct _reent *r, void *fd) { + return 0; +} + +ssize_t romfs_read(struct _reent *r, void *fd, char *ptr, size_t len) { + romfs_fileobj* file = (romfs_fileobj*)fd; + uint64_t endPos = file->pos + len; + + /* check if past end-of-file */ + if(file->pos >= swapLong(file->file->dataSize)) + return 0; + + /* truncate the read to end-of-file */ + if(endPos > swapLong(file->file->dataSize)) + endPos = swapLong(file->file->dataSize); + len = endPos - file->pos; + + ssize_t adv = _romfs_read(file->mount, file->offset + file->pos, ptr, len); + if(adv >= 0) { + file->pos += adv; + return adv; + } + + r->_errno = EIO; + return -1; +} + +off_t romfs_seek(struct _reent *r, void *fd, off_t pos, int dir) { + romfs_fileobj* file = (romfs_fileobj*)fd; + off_t start; + switch (dir) { + case SEEK_SET: + start = 0; + break; + + case SEEK_CUR: + start = file->pos; + break; + + case SEEK_END: + start = swapLong(file->file->dataSize); + break; + + default: + r->_errno = EINVAL; + return -1; + } + + /* don't allow negative position */ + if(pos < 0) { + if(start + pos < 0) { + r->_errno = EINVAL; + return -1; + } + } + /* check for overflow */ + else if(INT64_MAX - pos < start) { + r->_errno = EOVERFLOW; + return -1; + } + + file->pos = start + pos; + return file->pos; +} + +int romfs_fstat(struct _reent *r, void *fd, struct stat *st) { + romfs_fileobj* file = (romfs_fileobj*)fd; + memset(st, 0, sizeof(struct stat)); + st->st_ino = file_inode(file->mount, file->file); + st->st_mode = romFS_file_mode; + st->st_nlink = 1; + st->st_size = (off_t)swapLong(file->file->dataSize); + st->st_blksize = 512; + st->st_blocks = (st->st_blksize + 511) / 512; + st->st_atime = st->st_mtime = st->st_ctime = file->mount->mtime; + + return 0; +} + +int romfs_stat(struct _reent *r, const char *path, struct stat *st) { + romfs_mount* mount = (romfs_mount*)r->deviceData; + romfs_dir* curDir = NULL; + r->_errno = navigateToDir(mount, &curDir, &path, false); + if(r->_errno != 0) + return -1; + + romfs_dir* dir = searchForDir(mount, curDir, (uint8_t*)path, strlen(path)); + if(dir) { + memset(st, 0, sizeof(*st)); + st->st_ino = dir_inode(mount, dir); + st->st_mode = romFS_dir_mode; + st->st_nlink = dir_nlink(mount, dir); + st->st_size = dir_size(dir); + st->st_blksize = 512; + st->st_blocks = (st->st_blksize + 511) / 512; + st->st_atime = st->st_mtime = st->st_ctime = mount->mtime; + + return 0; + } + + romfs_file* file = searchForFile(mount, curDir, (uint8_t*)path, strlen(path)); + if(file) { + memset(st, 0, sizeof(*st)); + st->st_ino = file_inode(mount, file); + st->st_mode = romFS_file_mode; + st->st_nlink = 1; + st->st_size = swapLong(file->dataSize); + st->st_blksize = 512; + st->st_blocks = (st->st_blksize + 511) / 512; + st->st_atime = st->st_mtime = st->st_ctime = mount->mtime; + + return 0; + } + + r->_errno = ENOENT; + return 1; +} + +int romfs_chdir(struct _reent *r, const char *path) { + romfs_mount* mount = (romfs_mount*)r->deviceData; + romfs_dir* curDir = NULL; + r->_errno = navigateToDir(mount, &curDir, &path, false); + if (r->_errno != 0) + return -1; + + mount->cwd = curDir; + return 0; +} + +DIR_ITER* romfs_diropen(struct _reent *r, DIR_ITER *dirState, const char *path) { + romfs_diriter* iter = (romfs_diriter*)(dirState->dirStruct); + romfs_dir* curDir = NULL; + iter->mount = (romfs_mount*)r->deviceData; + + r->_errno = navigateToDir(iter->mount, &curDir, &path, true); + if(r->_errno != 0) + return NULL; + + iter->dir = curDir; + iter->state = 0; + iter->childDir = REVERSE_INT(curDir->childDir); + iter->childFile = REVERSE_INT(curDir->childFile); + + return dirState; +} + +int romfs_dirreset(struct _reent *r, DIR_ITER *dirState) { + romfs_diriter* iter = (romfs_diriter*)(dirState->dirStruct); + + iter->state = 0; + iter->childDir = REVERSE_INT(iter->dir->childDir); + iter->childFile = REVERSE_INT(iter->dir->childFile); + + return 0; +} + +int romfs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat) { + romfs_diriter* iter = (romfs_diriter*)(dirState->dirStruct); + + if(iter->state == 0) { + /* '.' entry */ + memset(filestat, 0, sizeof(*filestat)); + filestat->st_ino = dir_inode(iter->mount, iter->dir); + filestat->st_mode = romFS_dir_mode; + + strcpy(filename, "."); + iter->state = 1; + return 0; + } else if(iter->state == 1) { + /* '..' entry */ + romfs_dir* dir = romFS_dir(iter->mount, REVERSE_INT(iter->dir->parent)); + + memset(filestat, 0, sizeof(*filestat)); + filestat->st_ino = dir_inode(iter->mount, dir); + filestat->st_mode = romFS_dir_mode; + + strcpy(filename, ".."); + iter->state = 2; + return 0; + } + + if(iter->childDir != romFS_none) { + romfs_dir* dir = romFS_dir(iter->mount, iter->childDir); + iter->childDir = REVERSE_INT(dir->sibling); + + memset(filestat, 0, sizeof(*filestat)); + filestat->st_ino = dir_inode(iter->mount, dir); + filestat->st_mode = romFS_dir_mode; + + memset(filename, 0, NAME_MAX); + + if(REVERSE_INT(dir->nameLen) >= NAME_MAX) { + r->_errno = ENAMETOOLONG; + return -1; + } + + strncpy(filename, (char*)dir->name, REVERSE_INT(dir->nameLen)); + + return 0; + } else if(iter->childFile != romFS_none) { + romfs_file* file = romFS_file(iter->mount, iter->childFile); + iter->childFile = REVERSE_INT(file->sibling); + + memset(filestat, 0, sizeof(*filestat)); + filestat->st_ino = file_inode(iter->mount, file); + filestat->st_mode = romFS_file_mode; + + memset(filename, 0, NAME_MAX); + + if(REVERSE_INT(file->nameLen) >= NAME_MAX) { + r->_errno = ENAMETOOLONG; + return -1; + } + + strncpy(filename, (char*)file->name, REVERSE_INT(file->nameLen)); + + return 0; + } + + r->_errno = ENOENT; + return -1; +} + +int romfs_dirclose(struct _reent *r, DIR_ITER *dirState) { + return 0; +} diff --git a/src/romfs_dev.h b/src/romfs_dev.h new file mode 100644 index 0000000..367f202 --- /dev/null +++ b/src/romfs_dev.h @@ -0,0 +1,90 @@ +/** + * @file romfs_dev.h + * @brief RomFS driver. + * @author yellows8 + * @author mtheall + * @author fincs + * @copyright libnx Authors + */ +#pragma once + +#include + +/// RomFS header. +typedef struct { + uint64_t headerSize; ///< Size of the header. + uint64_t dirHashTableOff; ///< Offset of the directory hash table. + uint64_t dirHashTableSize; ///< Size of the directory hash table. + uint64_t dirTableOff; ///< Offset of the directory table. + uint64_t dirTableSize; ///< Size of the directory table. + uint64_t fileHashTableOff; ///< Offset of the file hash table. + uint64_t fileHashTableSize; ///< Size of the file hash table. + uint64_t fileTableOff; ///< Offset of the file table. + uint64_t fileTableSize; ///< Size of the file table. + uint64_t fileDataOff; ///< Offset of the file data. +} romfs_header; + +/// RomFS directory. +typedef struct { + uint32_t parent; ///< Offset of the parent directory. + uint32_t sibling; ///< Offset of the next sibling directory. + uint32_t childDir; ///< Offset of the first child directory. + uint32_t childFile; ///< Offset of the first file. + uint32_t nextHash; ///< Directory hash table pointer. + uint32_t nameLen; ///< Name length. + uint8_t name[]; ///< Name. (UTF-8) +} romfs_dir; + +/// RomFS file. +typedef struct { + uint32_t parent; ///< Offset of the parent directory. + uint32_t sibling; ///< Offset of the next sibling file. + uint64_t dataOff; ///< Offset of the file's data. + uint64_t dataSize; ///< Length of the file's data. + uint32_t nextHash; ///< File hash table pointer. + uint32_t nameLen; ///< Name length. + uint8_t name[]; ///< Name. (UTF-8) +} romfs_file; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Mounts the Application's RomFS. + * @param name Device mount name. + */ +int32_t romfsMount(const char *name, const char * path); + + +/** + * @brief Mounts RomFS from an open file. + * @param file FsFile of the RomFS image. + * @param offset Offset of the RomFS within the file. + * @param name Device mount name. +bool romfsMountFromFile(FsFile file, uint64_t offset, const char *name); +*/ +/* +static inline bool romfsInitFromFile(int32_t fd, uint64_t offset) { + return romfsMountFromFile(fd, offset, "romfs"); +}*/ + +/// Unmounts the RomFS device. +int32_t romfsUnmount(const char *name); +/* +static inline bool romfsExit(void) { + return romfsUnmount("romfs"); +}*/ + +/// RomFS file. +typedef struct { + uint64_t length; ///< Offset of the file's data. + uint64_t offset; ///< Length of the file's data. +} romfs_fileInfo; + +int romfs_GetFileInfoPerPath(const char* romfs, const char *path, romfs_fileInfo* out); + +#ifdef __cplusplus +} +#endif +