From 396a82725976050674b638681543556ecf473176 Mon Sep 17 00:00:00 2001 From: meetpatty Date: Fri, 3 Jan 2025 02:25:46 +1300 Subject: [PATCH 1/2] Fixes for 150 systemctrl/vshctrl to get vsh menu loading (vsh menu crashes however). --- extras/150kernel/systemctrl150/Makefile | 1 + extras/150kernel/systemctrl150/exports.exp | 2 + extras/150kernel/systemctrl150/src/hooknids.c | 139 ++++++++++++++++++ extras/150kernel/vshctrl150/vshmenu.c | 8 +- 4 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 extras/150kernel/systemctrl150/src/hooknids.c diff --git a/extras/150kernel/systemctrl150/Makefile b/extras/150kernel/systemctrl150/Makefile index 509a46a4..8538f6e8 100644 --- a/extras/150kernel/systemctrl150/Makefile +++ b/extras/150kernel/systemctrl150/Makefile @@ -3,6 +3,7 @@ TARGET = systemctrl150 OBJS = \ main.o \ src/flushcache.o \ + src/hooknids.o \ src/loadexec.o \ src/modulemanager.o \ src/rebootex.o \ diff --git a/extras/150kernel/systemctrl150/exports.exp b/extras/150kernel/systemctrl150/exports.exp index 780a0df4..3148af03 100644 --- a/extras/150kernel/systemctrl150/exports.exp +++ b/extras/150kernel/systemctrl150/exports.exp @@ -12,6 +12,8 @@ PSP_EXPORT_FUNC(sctrlHENSetLoadRebootOverrideHandler) PSP_EXPORT_FUNC(sctrlHENSetRebootexOverride) PSP_EXPORT_FUNC(sctrlHENSetStartModuleHandler) PSP_EXPORT_FUNC(sctrlHENPatchSyscall) +PSP_EXPORT_FUNC(findImportByNID) +PSP_EXPORT_FUNC(hookImportByNID) PSP_EXPORT_END PSP_EXPORT_START(SystemCtrlForUser, 0, 0x4001) diff --git a/extras/150kernel/systemctrl150/src/hooknids.c b/extras/150kernel/systemctrl150/src/hooknids.c new file mode 100644 index 00000000..799fe38e --- /dev/null +++ b/extras/150kernel/systemctrl150/src/hooknids.c @@ -0,0 +1,139 @@ +/* + * This file is part of PRO CFW. + + * PRO CFW is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * PRO CFW is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PRO CFW. If not, see +#include +#include +#include +#include +#include +#include + +// Find Import Library Pointer +SceLibraryStubTable * findImportLib(SceModule2 * pMod, char * library) +{ + // Invalid Arguments + if(pMod == NULL || library == NULL) return NULL; + + // Import Stub Table Start Address + void * stubTab = pMod->stub_top; + + // Iterate Stubs + int i = 0; while(i < pMod->stub_size) + { + // Cast Import Table + SceLibraryStubTable * pImp = (SceLibraryStubTable *)(stubTab + i); + + // Matching Library discovered + if(pImp->libname != NULL && strcmp(pImp->libname, library) == 0) + { + // Return Address + return pImp; + } + + // Move Pointer + i += pImp->len * 4; + } + + // Import Library not found + return NULL; +} + +// Find Import Stub Address +unsigned int findImportByNID(SceModule2 * pMod, char * library, unsigned int nid) +{ + // Find Import Library + SceLibraryStubTable * pImp = findImportLib(pMod, library); + + // Found Import Library + if(pImp != NULL) + { + // Iterate Imports + int i = 0; for(; i < pImp->stubcount; i++) + { + // Matching Function NID + if(pImp->nidtable[i] == nid) + { + // Return Function Stub Address + return (unsigned int)(pImp->stubtable + 8 * i); + } + } + } + + // Import Stub not found + return 0; +} + +// Hook Function in Module Import Stubs +// This function autodetects whether Syscalls are used or not... +// Manual exporting in exports.exp is still required however for Syscalls to work. +int hookImportByNID(SceModule2 * pMod, char * library, unsigned int nid, void * func) +{ + // Invalid Arguments + if(pMod == NULL || library == NULL) return -1; + + // Find Module Import Stub + unsigned int stub = findImportByNID(pMod, library, nid); + + // Import Stub not found + if(stub == 0) return -3; + + // Function as 16-Bit Unsigned Integer + unsigned int func_int = (unsigned int)func; + + // Dummy Return + if(func_int <= 0xFFFF) + { + // Create Dummy Return + _sw(JR_RA, stub); + _sw(LI_V0(func_int), stub + 4); + } + + // Normal Hook + else + { + // Syscall Hook + if ((stub & 0x80000000) == 0 && (func_int & 0x80000000) != 0) + { + // Query Syscall Number + int syscall = sceKernelQuerySystemCall(func); + + // Not properly exported in exports.exp + if(syscall < 0) return -3; + + // Create Syscall Hook + _sw(JR_RA, stub); + _sw(SYSCALL(syscall), stub + 4); + } + + // Direct Jump Hook + else + { + // Create Direct Jump Hook + _sw(JUMP(func), stub); + _sw(NOP, stub + 4); + } + } + + // Invalidate Cache + sceKernelDcacheWritebackInvalidateRange((void *)stub, 8); + sceKernelIcacheInvalidateRange((void *)stub, 8); + + // Return Success + return 0; +} + diff --git a/extras/150kernel/vshctrl150/vshmenu.c b/extras/150kernel/vshctrl150/vshmenu.c index 0c4d38bc..5fe53871 100644 --- a/extras/150kernel/vshctrl150/vshmenu.c +++ b/extras/150kernel/vshctrl150/vshmenu.c @@ -138,8 +138,8 @@ int _sceCtrlReadBufferPositive(SceCtrlData *ctrl, int count) goto exit; } // Block Satellite Menu in OSK - if (sceKernelFindModuleByName("sceVshOSK_Module")) - goto exit; + // if (sceKernelFindModuleByName("sceVshOSK_Module")) + // goto exit; // Block Satellite while using Skype if (sceKernelFindModuleByName("Skyhost")) @@ -150,8 +150,8 @@ int _sceCtrlReadBufferPositive(SceCtrlData *ctrl, int count) goto exit; // Block Satellite while mounting USB - if (sceKernelFindModuleByName("sceUSB_Stor_Driver")) - goto exit; + // if (sceKernelFindModuleByName("sceUSB_Stor_Driver")) + // goto exit; // Block Recovery menu if (sceKernelFindModuleByName("Recovery")) From dd68e97586841700334a93c779389752b94a7e70 Mon Sep 17 00:00:00 2001 From: meetpatty Date: Fri, 3 Jan 2025 02:41:48 +1300 Subject: [PATCH 2/2] Fix 150 vsh menu crashing/not rendering correctly. --- extras/150kernel/vshmenu150/Makefile | 2 +- extras/150kernel/vshmenu150/main.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/extras/150kernel/vshmenu150/Makefile b/extras/150kernel/vshmenu150/Makefile index 0d455e57..56cd5154 100644 --- a/extras/150kernel/vshmenu150/Makefile +++ b/extras/150kernel/vshmenu150/Makefile @@ -14,7 +14,7 @@ PSP_FW_VERSION = 150 PRX_EXPORTS = exports.exp -LIBS = -lpspsystemctrl_user -lcolordebugger +LIBS = -lpspsystemctrl_user LIBDIR = . $(ARKROOT)/libs LDFLAGS = diff --git a/extras/150kernel/vshmenu150/main.c b/extras/150kernel/vshmenu150/main.c index 83bb2d56..54fc6d87 100644 --- a/extras/150kernel/vshmenu150/main.c +++ b/extras/150kernel/vshmenu150/main.c @@ -62,7 +62,6 @@ const char * g_messages_en[]; int module_start(int argc, char *argv[]) { - colorDebug(0xFF); int thid; //sctrlHENGetArkConfig(ark_config); @@ -169,8 +168,6 @@ int TSRThread(SceSize args, void *argp) sceKernelChangeThreadPriority(0, 8); vctrlVSHRegisterVshMenu(EatKey); - colorDebug(0x00FF00); - while(stop_flag == 0) { if( sceDisplayWaitVblankStart() < 0) break; // end of VSH ?