Here's the sample: please don't argue on coding style...continuous changes and cut'npaste to test things quite deteriorated it. You can compile it as a pikey plugin or as a standalone vsh plugin. It should put "OSK Hook Test" string every time OSK gets called (without showing you anything) creating a small log file called jLog.txt on MS root.
Here's the code:
oskHookOut.c:
Code: Select all
// don't know if i'm really using all this stuff, but..hey, it's a test, who cares?
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspsdk.h>
#include <psputility.h>
#include <psppower.h>
#include <stdio.h>
#include <string.h>
#include <pspreg.h>
#include "../sdk/outputdriver.h"
#include "../sdk/outputframework.h"
#include <psputility_osk.h>
//PSP_MODULE_INFO("piKeyOSKHookOut", 0x1000, 1, 1); // for pikey module usage
PSP_MODULE_INFO("piKeyOSKHookOut", 0x1006, 1, 1); // for stand-alone usage
#define DRIVERVER "1"
#define REQUIREDVER 1
SceUID mainthread;
typedef struct MainHook
{
u32 hookid;
char modname[32];
char libname[32];
u32 nid;
void *func;
} MainHook;
int sceUtilityOskInitStart_Hook(SceUtilityOskParams* params);
int sceUtilityOskShutdownStart_Hook(void);
int sceUtilityOskUpdate_Hook(int n);
int sceUtilityOskGetStatus_Hook(void);
void jLog(char * text);
MainHook mainHookSave[] =
{
{ 0, "sceUtility_Driver", "sceUtility", 0xF6269B82, sceUtilityOskInitStart_Hook }, // maybe NIDs are wrong????
{ 0, "sceUtility_Driver", "sceUtility", 0x3DFAEBA9, sceUtilityOskShutdownStart_Hook },
{ 0, "sceUtility_Driver", "sceUtility", 0x4B85C861, sceUtilityOskUpdate_Hook },
{ 0, "sceUtility_Driver", "sceUtility", 0xF3F76017, sceUtilityOskGetStatus_Hook },
{ 0, "", "", 0, NULL }
};
int getDriverInfo(DRIVERINFO *infostruct){ // required if you wish to use this as a pikey module
unsigned int k1 = pspSdkSetK1(0);
strcpy(infostruct->driverVersion, DRIVERVER);
if(infostruct->apiVersion < REQUIREDVER) {
pspSdkSetK1(k1);
return PIKEY_ERROR_VERSION;
} else {
strcpy(infostruct->driverName, "OSK");
infostruct->apiVersion = PIKEY_THIS_VERSION;
infostruct->unicodeSupported = FALSE;
pspSdkSetK1(k1);
return PIKEY_SUCCESS;
}
pspSdkSetK1(k1); //never reached....again, who cares?
}
int oskoutMain(SceSize args, void *argp) {
jLog("\r\njModule starting\r\n");
int x;
jLog("waiting for OSK module to load...\r\n");
waitForModule("sceUtility_Driver");
jLog("OSK module loaded\r\n");
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); // don't really need this
jLog("Patching syscall table...\r\n");
for (x=0;mainHookSave[x].func != NULL;x++)
{
mainHookSave[x].hookid = apiHookByNid(mainHookSave[x].modname, mainHookSave[x].libname,
mainHookSave[x].nid,
mainHookSave[x].func);
if (mainHookSave[x].hookid == -1)
jLog("-no good\r\n");
else
jLog("-ok\r\n");
}
jLog("Finished patching. ready\r\n\r\n\r\n");
sceKernelSleepThreadCB();
jLog("!!!END REACHED!!!\r\n\r\n\r\n");
return 0;
}
int main(void) {
mainthread = sceKernelCreateThread("oskHookOut", oskoutMain, 16, 0x800, 0, NULL);
if (mainthread >= 0)
sceKernelStartThread(mainthread, 0, NULL);
return 0;
}
void module_stop(void)
{
// should un-hook fns
}
void* getModuleInfo(void) {
return (void *) &module_info;
}
int module_start(SceSize args, void *argp) __attribute__((alias("_start")));
int _start(SceSize args, void *argp)
{
return main();
}
//---------------------------- hook functions ------------------------
int sceUtilityOskInitStart_Hook(SceUtilityOskParams* params) // please notice that in all hook functions i'm avoiding calls to original fns...
{
unsigned char test[] = { 'O','S','K',' ','H','o','o','k',' ','T','e','s','t', 0 }; // test string to place in outtext
unsigned char * p = (unsigned char *)params->data->outtext;
int len = params->data->outtextlength;
int i=0;
while (test[i] && i<len)
{
*p = test[i];
p++;
i++;
}
*p = 0; // make sure string is terminated
jLog("* called sceUtilityOskInitStart\r\n");
return 0; // all OK!
}
int sceUtilityOskShutdownStart_Hook(void)
{
jLog("* called sceUtilityOskShutdownStart\r\n");
// ignore for now
return 0; // all OK!
}
int sceUtilityOskUpdate_Hook(int n)
{
jLog("* called sceUtilityOskUpdate\r\n");
// ignore for now
return 0; // all OK!
}
int sceUtilityOskGetStatus_Hook(void)
{
jLog("* called sceUtilityOskGetStatus\r\n");
return PSP_UTILITY_DIALOG_FINISHED;
}
void jLog(char * text)
{
int nChars = 0;
int fdout = sceIoOpen("ms0:/jLog.txt", PSP_O_WRONLY | PSP_O_CREAT /*| PSP_O_TRUNC*/ | PSP_O_APPEND, 0777);
char * oText = text;
while (*text)
{
text++;
nChars++;
}
int bw = sceIoWrite(fdout, oText, nChars);
sceIoClose(fdout);
}
Code: Select all
PSP_BEGIN_EXPORTS
PSP_EXPORT_START(syslib, 0, 0x8000)
PSP_EXPORT_FUNC_HASH(module_start)
PSP_EXPORT_VAR_HASH(module_info)
PSP_EXPORT_END
PSP_EXPORT_START(piKeyOSKout, 0, 0x0001)
PSP_EXPORT_FUNC_HASH(getDriverInfo)
PSP_EXPORT_END
PSP_END_EXPORTS
Code: Select all
TARGET = piKeyOSKHookOut
OBJS = oskHookOut.o
USE_KERNEL_LIBS = 1
USE_KERNEL_LIBC = 1
PSP_FW_VERSION = 390
BUILD_PRX = 1
PRX_EXPORTS = exports.exp
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS = -mno-crt0
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
LIBS += -lpsppower_driver -lpspreg_driver ../sdk/framework_stub.o
LDFLAGS += -specs=../sdk/prxspecs
Hope we'll make it work!
jean