Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/PSP-Archive/ARK-4
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAaronLopezGarcia committed Jan 2, 2025
2 parents b364f40 + dd68e97 commit 897757e
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 8 deletions.
1 change: 1 addition & 0 deletions extras/150kernel/systemctrl150/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ TARGET = systemctrl150
OBJS = \
main.o \
src/flushcache.o \
src/hooknids.o \
src/loadexec.o \
src/modulemanager.o \
src/rebootex.o \
Expand Down
2 changes: 2 additions & 0 deletions extras/150kernel/systemctrl150/exports.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
139 changes: 139 additions & 0 deletions extras/150kernel/systemctrl150/src/hooknids.c
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/ .
*/

#include <pspsdk.h>
#include <psputilsforkernel.h>
#include <stdio.h>
#include <string.h>
#include <macros.h>
#include <ark.h>
#include <systemctrl.h>

// 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;
}

8 changes: 4 additions & 4 deletions extras/150kernel/vshctrl150/vshmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion extras/150kernel/vshmenu150/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PSP_FW_VERSION = 150

PRX_EXPORTS = exports.exp

LIBS = -lpspsystemctrl_user -lcolordebugger
LIBS = -lpspsystemctrl_user
LIBDIR = . $(ARKROOT)/libs
LDFLAGS =

Expand Down
3 changes: 0 additions & 3 deletions extras/150kernel/vshmenu150/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const char * g_messages_en[];

int module_start(int argc, char *argv[])
{
colorDebug(0xFF);
int thid;

//sctrlHENGetArkConfig(ark_config);
Expand Down Expand Up @@ -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 ?
Expand Down

0 comments on commit 897757e

Please sign in to comment.