From 6539e476ed6c9f0c2ef5f1e9dc1b576c1c5beafc Mon Sep 17 00:00:00 2001 From: israpps <57065102+israpps@users.noreply.github.com> Date: Wed, 28 Feb 2024 09:52:36 -0300 Subject: [PATCH] add IRX loading feature --- Lang/ENG.LNG | 2 ++ Lang/SPA.LNG | 2 ++ include/launchelf.h | 6 +++- src/elf.c | 20 +++++++----- src/filer.c | 2 +- src/main.c | 80 +++++++++++++++++++++++++++++---------------- 6 files changed, 73 insertions(+), 39 deletions(-) diff --git a/Lang/ENG.LNG b/Lang/ENG.LNG index bbedbaa0..9c21738c 100644 --- a/Lang/ENG.LNG +++ b/Lang/ENG.LNG @@ -330,3 +330,5 @@ lang(328, change_timestamp_of, "change timestamp of:") lang(329, title_cfg, "create title.cfg") lang(329, Build_Info, "BuildInfo") lang(330, Loading_Flash_Modules, "Loading Flash Modules...") +lang(331, This_file_isnt_an_IRX, "This file isn't an IRX") +lang(331, confirm_irx_exec, "do you want to load this IRX driver?%c%s") diff --git a/Lang/SPA.LNG b/Lang/SPA.LNG index f75f64cf..b9ef908b 100644 --- a/Lang/SPA.LNG +++ b/Lang/SPA.LNG @@ -331,3 +331,5 @@ lang(328, change_timestamp_of, "cambiar fecha de:") lang(329, title_cfg, "crear title.cfg") lang(329, Build_Info, "BuildInfo") lang(330, Loading_Flash_Modules, "Cargando modulos flash...") +lang(331, This_file_isnt_an_ELF, "Esto no es un driver IRX") +lang(331, confirm_irx_exec, "Desea cargar este driver IRX?%c%s") diff --git a/include/launchelf.h b/include/launchelf.h index 916f3f35..1321a983 100644 --- a/include/launchelf.h +++ b/include/launchelf.h @@ -227,7 +227,11 @@ int IsSupportedFileType(char *path); void loadFlashModules(void); /* elf.c */ -int checkELFheader(char *filename); +#define TYPE_ELF 0 +#define TYPE_IRX 1 +#define ELF_HEADER_ID_EE 0x2 +#define ELF_HEADER_ID_IRX 0xFF80 +int checkELFheader(char *filename, int type); void RunLoaderElf(char *filename, char *); /* draw.c */ diff --git a/src/elf.c b/src/elf.c index 59ee669b..eb9dd00c 100644 --- a/src/elf.c +++ b/src/elf.c @@ -45,14 +45,16 @@ typedef struct //-------------------------------------------------------------- //End of data declarations //-------------------------------------------------------------- -//Start of function code -//-------------------------------------------------------------- -// checkELFheader Tests for valid ELF file -// Modified version of loader from Independence -// (C) 2003 Marcus R. Brown -//-------------------------------------------------------------- -int checkELFheader(char *path) + +/** + * @brief open file and check for ELF header and ELF type + * @param path path + * @param type 0 for EE ELF, 1 for IOP IRX + * @return 0: unknown device, 1:check passed, -1: check failed +*/ +int checkELFheader(char *path, int type) { + u16 MAGICS[2] = {ELF_HEADER_ID_EE, ELF_HEADER_ID_IRX}; elf_header_t elf_head; u8 *boot_elf = (u8 *)&elf_head; elf_header_t *eh = (elf_header_t *)boot_elf; @@ -108,8 +110,8 @@ int checkELFheader(char *path) genLseek(fd, 0, SEEK_SET); genRead(fd, boot_elf, sizeof(elf_header_t)); genClose(fd); - - if ((_lw((u32)&eh->ident) != ELF_MAGIC) || eh->type != 2) + DPRINTF("%s: ELF magic %d\n", __FUNCTION__, eh->type); + if ((_lw((u32)&eh->ident) != ELF_MAGIC) || eh->type != MAGICS[type]) goto error; return 1; //return 1 for successful check diff --git a/src/filer.c b/src/filer.c index 68bcbbcc..0cded167 100644 --- a/src/filer.c +++ b/src/filer.c @@ -3964,7 +3964,7 @@ int getFilePath(char *out, int cnfmode) //pushed R3 for a file (treat as uLE-related) sprintf(out, "%s%s", path, files[browser_sel].name); // Must to include a function for check IRX Header - if (((cnfmode == LK_ELF_CNF) || (cnfmode == NON_CNF)) && (checkELFheader(out) < 0)) { + if (((cnfmode == LK_ELF_CNF) || (cnfmode == NON_CNF)) && (checkELFheader(out, TYPE_ELF) < 0)) { browser_pushed = FALSE; sprintf(msg0, "%s.", LNG(This_file_isnt_an_ELF)); out[0] = 0; diff --git a/src/main.c b/src/main.c index 8a04f503..06b18abf 100644 --- a/src/main.c +++ b/src/main.c @@ -2031,13 +2031,13 @@ int IsSupportedFileType(char *path) if(strchr(path, ':') != NULL) { if ((genCmpFileExt(path, "TXT") || genCmpFileExt(path, "CHT") || genCmpFileExt(path, "CFG") || genCmpFileExt(path, "INI") || genCmpFileExt(path, "CNF") ) || (genCmpFileExt(path, "JPG") || genCmpFileExt(path, "JPEG"))) return 1; else if(genCmpFileExt(path, "IRX")) return 0; - else return(checkELFheader(path) >= 0); + else return(checkELFheader(path, TYPE_ELF) >= 0); } else //No ':', hence no device name in path, which means it is a special action (e.g. MISC/*). return 1; #else if (strchr(path, ':') != NULL) { if (genCmpFileExt(path, "ELF")) { - return (checkELFheader(path) >= 0); + return (checkELFheader(path, TYPE_ELF) >= 0); } else if ((genCmpFileExt(path, "TXT") || genCmpFileExt(path, "CHT") || genCmpFileExt(path, "CFG") || genCmpFileExt(path, "INI") || genCmpFileExt(path, "CNF") ) || (genCmpFileExt(path, "JPG") || genCmpFileExt(path, "JPEG"))) { return 1; } else @@ -2070,7 +2070,7 @@ static void Execute(char *pathin) if (!uLE_related(path, pathin)) //1==uLE_rel 0==missing, -1==other dev return; -Recurse_for_ESR: //Recurse here for PS2Disc command with ESR disc + Recurse_for_ESR: //Recurse here for PS2Disc command with ESR disc pathSep = strchr(path, '/'); @@ -2080,7 +2080,7 @@ static void Execute(char *pathin) goto CheckELF_path; strcpy(fullpath, "mc0:"); strcat(fullpath, path + 3); - if (checkELFheader(fullpath) > 0) + if (checkELFheader(fullpath, TYPE_ELF) > 0) goto ELFchecked; fullpath[2] = '1'; goto CheckELF_fullpath; @@ -2092,7 +2092,7 @@ static void Execute(char *pathin) goto CheckELF_path; } else if (!strncmp(path, "hdd0:/", 6)) { loadHddModules(); - if ((t = checkELFheader(path)) <= 0) + if ((t = checkELFheader(path, TYPE_ELF)) <= 0) goto ELFnotFound; //coming here means the ELF is fine sprintf(party, "hdd0:%s", path + 6); @@ -2100,28 +2100,28 @@ static void Execute(char *pathin) sprintf(fullpath, "pfs0:%s", p); *p = 0; goto ELFchecked; -#ifdef DVRP - } else if (!strncmp(path, "dvr_hdd0:/", 10)) { - loadDVRPHddModules(); - if ((t = checkELFheader(path)) <= 0) - goto ELFnotFound; - //coming here means the ELF is fine - sprintf(party, "dvr_hdd0:%s", path + 10); - p = strchr(party, '/'); - sprintf(fullpath, "dvr_pfs0:%s", p); - *p = 0; - goto ELFchecked; -#endif -#ifdef XFROM + #ifdef DVRP + } else if (!strncmp(path, "dvr_hdd0:/", 10)) { + loadDVRPHddModules(); + if ((t = checkELFheader(path, TYPE_ELF)) <= 0) + goto ELFnotFound; + //coming here means the ELF is fine + sprintf(party, "dvr_hdd0:%s", path + 10); + p = strchr(party, '/'); + sprintf(fullpath, "dvr_pfs0:%s", p); + *p = 0; + goto ELFchecked; + #endif + #ifdef XFROM } else if (!strncmp(path, "xfrom:/", 7)) { loadFlashModules(); - if ((t = checkELFheader(path)) <= 0) + if ((t = checkELFheader(path, TYPE_ELF)) <= 0) goto ELFnotFound; strcpy(fullpath, path); goto ELFchecked; -#endif + #endif } else if (!strncmp(path, "mass", 4)) { - if ((t = checkELFheader(path)) <= 0) + if ((t = checkELFheader(path, TYPE_ELF)) <= 0) goto ELFnotFound; //coming here means the ELF is fine party[0] = 0; @@ -2130,7 +2130,7 @@ static void Execute(char *pathin) if (pathSep && (pathSep - path < 7) && pathSep[-1] == ':') strcpy(fullpath + (pathSep - path), pathSep + 1); goto ELFchecked; -#ifdef ETH + #ifdef ETH } else if (!strncmp(path, "host:", 5)) { initHOST(); party[0] = 0; @@ -2141,7 +2141,7 @@ static void Execute(char *pathin) strcat(fullpath, path + 5); makeHostPath(fullpath, fullpath); goto CheckELF_fullpath; -#endif + #endif } else if (!stricmp(path, setting->Misc_OSDSYS)) { char arg0[20], arg1[20], arg2[20], arg3[40]; char *args[4] = {arg0, arg1, arg2, arg3}; @@ -2305,6 +2305,8 @@ static void Execute(char *pathin) } JpgViewer(tmp); + } else if (genCmpFileExt(tmp, "IRX")) { + goto IRXcheckheader; } else Execute(tmp); } @@ -2316,12 +2318,12 @@ static void Execute(char *pathin) //The method below was used earlier, but causes reset with new ELF loader //party[0]=0; //strcpy(fullpath,"rom0:OSDSYS"); -#ifdef ETH + #ifdef ETH } else if (!stricmp(path, setting->Misc_PS2Net)) { mainMsg[0] = 0; loadNetModules(); return; -#endif + #endif } else if (!stricmp(path, setting->Misc_PS2PowerOff)) { mainMsg[0] = 0; drawMsg(LNG(Powering_Off_Console)); @@ -2395,19 +2397,21 @@ static void Execute(char *pathin) } Show_build_info(); return; -#ifndef SUPPORT_SYSTEM_2X6 + #ifndef SUPPORT_SYSTEM_2X6 } else if (!strncmp(path, "cdfs", 4)) { CDVD_FlushCache(); CDVD_DiskReady(0); party[0] = 0; goto CheckELF_path; -#endif + #endif } else if (!strncmp(path, "rom", 3)) { party[0] = 0; CheckELF_path: strcpy(fullpath, path); CheckELF_fullpath: - if ((t = checkELFheader(fullpath)) <= 0) + if (checkELFheader(fullpath, TYPE_IRX)>0) + goto IRXFound; + if ((t = checkELFheader(fullpath, TYPE_ELF)) <= 0) goto ELFnotFound; ELFchecked: CleanUp(); @@ -2421,6 +2425,26 @@ static void Execute(char *pathin) sprintf(mainMsg, "%s: %s.", LNG(This_file_isnt_an_ELF), fullpath); return; } + return; + IRXcheckheader: + if ((t = checkELFheader(fullpath, TYPE_IRX)) <= 0) { + if (t == 0) + sprintf(mainMsg, "%s %s.", fullpath, LNG(is_Not_Found)); + else + sprintf(mainMsg, "%s: %s.", LNG(This_file_isnt_an_IRX), fullpath); + return; + } + IRXFound: + char *p = strrchr(fullpath, '/'); + sprintf(mainMsg, LNG(confirm_irx_exec), '\n', (p!=NULL) ? p : ""); + if (ynDialog(mainMsg)>0) { + int ret, id; + id = SifLoadStartModule(fullpath, 0, NULL, &ret); + sprintf(mainMsg, "%s: id:%d, ret:%d (%s)", + (p!=NULL) ? p : "MODULE", id, ret + (id>0 && ret!=0) ? LNG(OK) : LNG(Failed)); + DPRINTF("%s\n", mainMsg); + } } //------------------------------ //endfunc Execute