Hooking Usermode Functions
-
- Posts: 31
- Joined: Sun Mar 23, 2008 2:16 am
- Contact:
Hooking Usermode Functions
Right, this is a bit of pain lately. I'm hooking various functions located in the Paf and I can correctly replace the JAL's with the Syscalls to the function in my kernel module. However, when I try to call the original function (in Paf) it always crashes (obviously). I am however at loss as I do not want to create a usermode module and would rather keep it all in one kernel mode module.
Any help? If you need anymore information just ask.
Thanks a lot.
Any help? If you need anymore information just ask.
Thanks a lot.
-
- Posts: 31
- Joined: Sun Mar 23, 2008 2:16 am
- Contact:
Well, there is an exotic way to do that...
sceKernelSetDdrMemoryProtection((void *)0x08000000, 2*1024*1024, 0xF);
after that you would be able to redirect a user call to a kernel function replacing a jal by other jal, and the function will execute in user mode. Of course, if you call kernel functions inside that function, you may expect a crash...
sceKernelSetDdrMemoryProtection((void *)0x08000000, 2*1024*1024, 0xF);
after that you would be able to redirect a user call to a kernel function replacing a jal by other jal, and the function will execute in user mode. Of course, if you call kernel functions inside that function, you may expect a crash...
-
- Posts: 31
- Joined: Sun Mar 23, 2008 2:16 am
- Contact:
-
- Posts: 31
- Joined: Sun Mar 23, 2008 2:16 am
- Contact:
-
- Posts: 31
- Joined: Sun Mar 23, 2008 2:16 am
- Contact:
-
- Posts: 31
- Joined: Sun Mar 23, 2008 2:16 am
- Contact:
Is there any other alternatives?
Thats my code, all updated for 5.00 but it crashes =/
Got any other suggestions? Moonlight? Anyone?
Code: Select all
#include <pspkernel.h>
#include <pspsysmem_kernel.h>
#include <pspsdk.h>
#include <systemctrl.h>
#include <string.h>
#include "debugutils.h"
PSP_MODULE_INFO("UserHook", 0x1000, 1, 0);
#define MAKE_CALL(a, f) _sw(0x0C000000 | (((u32)(f) >> 2) & 0x03ffffff), a);
int (*scePafMemoryAlloc)(int, int) = NULL;
STMOD_HANDLER previous = NULL;
int scePafMemoryAllocPatched(int allignment, int size)
{
return scePafMemoryAlloc(allignment, size);
}
int OnModuleStart(SceModule2 *mod)
{
char *modname = mod->modname;
u32 text_addr = mod->text_addr;
if (strcmp(modname, "vsh_module") == 0)
{
scePafMemoryAlloc = (void *)FindProc("scePaf_Module", "scePaf", 0x31AC0624);
MAKE_CALL(text_addr + 0xB3D8, scePafMemoryAllocPatched);
sceKernelDcacheWritebackAll();
sceKernelIcacheClearAll();
}
if (!previous)
return 0;
return previous(mod);
}
int module_start(SceSize args, void *argp)
{
sceKernelSetDdrMemoryProtection((void *)0x08000000, 2*1024*1024, 0xF);
previous = sctrlHENSetStartModuleHandler(OnModuleStart);
return 0;
}
Got any other suggestions? Moonlight? Anyone?
Super Sheep wrote:I'd rather not. I believe user memory is very limited in VSH. I'd rather keep away from it.
Uhm....
if you search for a way to do it without another PRX, the way will be more complex and will take up more space than a dumb prx... Plus, there is plenty memory in VSH if you know where to look.
I am assuming you want to call the function then do something with the result rather than just hooking the entry to the function, this makes it harder.
You _could_ implement a trick using exception handlers to do it. Stick in a 'break' instruction in the delay slot of the j address; nop; import for the function in the module you want to hook then it will crash when the function is called. You could catch this and hand off to a function to handle your side of it, when you need to call the original you can either just tweak EPC to point to the actual function and return from the exception, which would not return back to you, or you change the saved RA register then when the function returns it crashes again at an appropriately selected address (so you can decode which function it was) and so an epilog for the function.
Of course it is just simpler to use a dumb user mode prx as adrahil has pointed out :)
You _could_ implement a trick using exception handlers to do it. Stick in a 'break' instruction in the delay slot of the j address; nop; import for the function in the module you want to hook then it will crash when the function is called. You could catch this and hand off to a function to handle your side of it, when you need to call the original you can either just tweak EPC to point to the actual function and return from the exception, which would not return back to you, or you change the saved RA register then when the function returns it crashes again at an appropriately selected address (so you can decode which function it was) and so an epilog for the function.
Of course it is just simpler to use a dumb user mode prx as adrahil has pointed out :)
-
- Posts: 31
- Joined: Sun Mar 23, 2008 2:16 am
- Contact: