First of all sorry for my english, it is realy bad :( But i hope someone will help me anyway.
I need cfw-plugin that dumps region of memory to memory stick,
the region from where sceIoRead() was called.
I wrote it, but i have one little problem -
it works fine is XMB, but dont works at all in a game(i added it in seplugins/game.txt).
I added my source code below, what am i doing wrong? What should i do to make it work in game?
Actually I need this plugin in a game, not XMB.
Thanks.
Code: Select all
#include<pspkernel.h>
#include<pspctrl.h>
#include "apihook.h"
PSP_MODULE_INFO("psplugin", 0x1000, 1, 0);
PSP_MAIN_THREAD_ATTR(0);
u32 ret;
int Caught=0, active=0;
int dump (void)
{
int fd = sceIoOpen ("ms0:/memdump.bin",PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
sceIoWrite (fd, (void*) (ret-1000), 5000);
sceIoClose (fd);
Caught=0;
return 0;
}
int sce_io_read(int fd, void* buff, int size)
{
if (active) {
asm ("move %0, $ra\n": "=r" (ret));
Caught=1;
active=0;
}
int res=sceIoRead(fd,buff,size);
return res;
}
int plugin_thread (SceSize argc, void* argp)
{
SceModule *pMod;
SceCtrlData pad;
pMod = sceKernelFindModuleByName("sceIOFileManager");
apiHookByName(pMod->modid, "IoFileMgrForKernel", "sceIoRead", sce_io_read);
while (1) {
sceCtrlPeekBufferPositive (&pad, 1);
if (pad.Buttons & PSP_CTRL_SELECT) active=1;
if (Caught) dump();
sceKernelDelayThread(100000);
}
sceKernelExitDeleteThread(0);
return 0;
}
int module_start (SceSize argc, void* argp)
{
SceUID thread = sceKernelCreateThread("plugin_thread", plugin_thread, 15, 0x800, 0, NULL);
if (thread >= 0) {
sceKernelStartThread (thread, argc, argp);
}
return 0;
}
I dont know for sure if $ra points to adress near sceIoRead call(probably it can point anywhere),
but XMB memdump shows that i'm right.
Code: Select all
0x000003D0: 0x00000000 '....' - nop
0x000003D4: 0x00000000 '....' - nop
0x000003D8: 0x408E6000 '.`.@' - mtc0 $t6, Status
0x000003DC: 0x00000000 '....' - nop
0x000003E0: 0x01E0F809 '....' - jalr $t7 <--- SceIoRead call (?)
0x000003E4: 0x00000000 '....' - nop
0x000003E8: 0x00000000 '....' - nop <--- $ra points here
0x000003EC: 0x70000026 '&..p' - mtic $zr, $0
0x000003F0: 0x00000000 '....' - nop
0x000003F4: 0x3C0FCCCC '...<' - lui $t7, 0xCCCC
0x000003F8: 0x35EFCCCC '...5' - ori $t7, $t7, 0xCCCC
0x000003FC: 0x3C0EBC00 '...<' - lui $t6, 0xBC00
0x00000400: 0x00000000 '....' - nop