vshctrl (vshmenu) + hooking vshCtrlReadBufferPositive

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

vshctrl (vshmenu) + hooking vshCtrlReadBufferPositive

Post by Torch »

While patching syscall to vshCtrlReadBufferPositive, the M33 VSHMenu doesn't work anymore, obviously.

I see this function in vshctrl.h
int vctrlVSHRegisterVshMenu(int (* ctrl)(SceCtrlData *, int));

Is this useful to have menu working while calling your own patched function or what? I don't understand how to use it.

I just need to modify the original pad_data.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

EDIT...
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

That function is to register a VSH menu, it is not useful for anything else.
Basically satelite.prx (vshmenu) needs to register itself using that function.

Your patch destroys M33 one

Code: Select all

SceModule2 *mod = sceKernelFindModuleByName("sceVshBridge_Driver");

if (!config.novshmenu)
{
	MAKE_CALL(mod->text_addr+0x264, sceCtrlReadBufferPositivePatched);
	PatchSyscall(FindProc("sceController_Service", "sceCtrl", 0x1F803938), sceCtrlReadBufferPositivePatched);
}	
Well, you could still do something, patch sceCtrlReadBufferPostive function directly by getting his address using sctrlHENFindFunction, and patching two first instructions to cause a jump+nop to your function. Once in your function, you would have to restore original two insturctions to call it, and then patch it again.

Since that aproach is very innefeicient, the best is to have a third function written in asm that has as two first instructions the same two first instructions as sceCtrlReadBufferPositive, and as third/four instructionsa jump to sceCtrlReadBufferPositive+8. In this way you would call that third function each time you want to call original sceCtrlReadBufferPositive.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

moonlight wrote: Your patch destroys M33 one

Code: Select all

SceModule2 *mod = sceKernelFindModuleByName("sceVshBridge_Driver");

if (!config.novshmenu)
{
	MAKE_CALL(mod->text_addr+0x264, sceCtrlReadBufferPositivePatched);
	PatchSyscall(FindProc("sceController_Service", "sceCtrl", 0x1F803938), sceCtrlReadBufferPositivePatched);
}	
Since the M33 one hooks sceCtrl function, I just changed my module to call original vshCtrl function from my patched function to get the original pad_data instead of calling original sceCtrl one, now VSHMenu is working.

How ever I'd like to know about the ASM patch. Do I just declare the function like this and call it or what?

Code: Select all

int sceCtrlReadBufferPositive_Loader(SceCtrlData *pad_data, int count)
{
asm("original 2 instructions here
     jump to +8");
}
And for patching the 2 instructions in original function like this?

Code: Select all

void * addr = sctrlHENFindFunction(....)
addr[0] = 0xXX; (hex bytes here)
addr[1] = 0xXX;
addr[2] = 0xXX;
addr[3] = 0xXX;
....
Post Reply