OSK hook for PSPZ/piKey/...[doesn't work]

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

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

OSK hook for PSPZ/piKey/...[doesn't work]

Post by jean »

I admit it...even if i wrote a document on PSP architecture (in italian language, someone willing to host??) i never got into that little idiosyncrasies around PSP_MODULE_INFO or into user-kernel wars. Long ago I wrote a (very coarse) [vsh module]/[pikey plugin] to hook sony's OSK, because i think THAT's the way things are to be done to add an input periferal to non-predisposed software. Not faking presses. But it never worked, despite its simplicity: maybe i'm missing something very stupid. Since i usually start 1000 projects together and rarely finish one, i'll publish this so one of you can make it work (it would be nice to make it work with jube's touchscreen)
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&#40;"piKeyOSKHookOut", 0x1000, 1, 1&#41;; // for pikey module usage
PSP_MODULE_INFO&#40;"piKeyOSKHookOut", 0x1006, 1, 1&#41;; // for stand-alone usage

#define	DRIVERVER	"1"
#define REQUIREDVER	1

SceUID mainthread;

typedef struct MainHook
&#123;
 u32  hookid;
 char modname&#91;32&#93;;
 char libname&#91;32&#93;;
 u32 nid;
 void *func;
&#125; MainHook;

int sceUtilityOskInitStart_Hook&#40;SceUtilityOskParams* params&#41;;
int sceUtilityOskShutdownStart_Hook&#40;void&#41;;
int sceUtilityOskUpdate_Hook&#40;int n&#41;;
int sceUtilityOskGetStatus_Hook&#40;void&#41;;

void jLog&#40;char * text&#41;;

MainHook mainHookSave&#91;&#93; =
&#123;
	&#123; 0, "sceUtility_Driver", "sceUtility",		0xF6269B82, sceUtilityOskInitStart_Hook &#125;,    // maybe NIDs are wrong????
	&#123; 0, "sceUtility_Driver", "sceUtility",		0x3DFAEBA9, sceUtilityOskShutdownStart_Hook &#125;,
	&#123; 0, "sceUtility_Driver", "sceUtility",		0x4B85C861, sceUtilityOskUpdate_Hook &#125;,
	&#123; 0, "sceUtility_Driver", "sceUtility",		0xF3F76017, sceUtilityOskGetStatus_Hook &#125;,
	&#123; 0, "", "", 0, NULL &#125;
&#125;;

int getDriverInfo&#40;DRIVERINFO *infostruct&#41;&#123; // required if you wish to use this as a pikey module

	unsigned int k1 = pspSdkSetK1&#40;0&#41;; 

	strcpy&#40;infostruct->driverVersion, DRIVERVER&#41;;
	if&#40;infostruct->apiVersion < REQUIREDVER&#41; &#123;
		pspSdkSetK1&#40;k1&#41;; 	
		return PIKEY_ERROR_VERSION;
	&#125; else &#123;
		strcpy&#40;infostruct->driverName, "OSK"&#41;;
		infostruct->apiVersion = PIKEY_THIS_VERSION;
		infostruct->unicodeSupported = FALSE;
		pspSdkSetK1&#40;k1&#41;; 
		return PIKEY_SUCCESS;
	&#125;
	pspSdkSetK1&#40;k1&#41;; //never reached....again, who cares?
&#125;

int oskoutMain&#40;SceSize args, void *argp&#41; &#123;

	jLog&#40;"\r\njModule starting\r\n"&#41;;

	int x;
	
	jLog&#40;"waiting for OSK module to load...\r\n"&#41;;
	waitForModule&#40;"sceUtility_Driver"&#41;;
	jLog&#40;"OSK module loaded\r\n"&#41;;

	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;; // don't really need this

	jLog&#40;"Patching syscall table...\r\n"&#41;;

	for &#40;x=0;mainHookSave&#91;x&#93;.func != NULL;x++&#41;
	&#123;
	  mainHookSave&#91;x&#93;.hookid = apiHookByNid&#40;mainHookSave&#91;x&#93;.modname,	mainHookSave&#91;x&#93;.libname,
																			mainHookSave&#91;x&#93;.nid,
																			mainHookSave&#91;x&#93;.func&#41;;
			if &#40;mainHookSave&#91;x&#93;.hookid == -1&#41;
				jLog&#40;"-no good\r\n"&#41;;
			else 
				jLog&#40;"-ok\r\n"&#41;;
	&#125;

	jLog&#40;"Finished patching. ready\r\n\r\n\r\n"&#41;;
	
	sceKernelSleepThreadCB&#40;&#41;;

	jLog&#40;"!!!END REACHED!!!\r\n\r\n\r\n"&#41;;

	return 0;
&#125;

int main&#40;void&#41; &#123;
	mainthread = sceKernelCreateThread&#40;"oskHookOut", oskoutMain, 16, 0x800, 0, NULL&#41;;
	if &#40;mainthread >= 0&#41;
		sceKernelStartThread&#40;mainthread, 0, NULL&#41;;
	
	return 0;
&#125;

void module_stop&#40;void&#41; 
&#123;
	// should un-hook fns
&#125;

void* getModuleInfo&#40;void&#41; &#123;
	return &#40;void *&#41; &module_info;
&#125;

int module_start&#40;SceSize args, void *argp&#41; __attribute__&#40;&#40;alias&#40;"_start"&#41;&#41;&#41;;

int _start&#40;SceSize args, void *argp&#41;
&#123;
	return main&#40;&#41;;
&#125;

//---------------------------- hook functions ------------------------

int sceUtilityOskInitStart_Hook&#40;SceUtilityOskParams* params&#41; // please notice that in all hook functions i'm avoiding calls to original fns...
&#123;
	unsigned char test&#91;&#93; = &#123; 'O','S','K',' ','H','o','o','k',' ','T','e','s','t', 0 &#125;; // test string to place in outtext
	unsigned char * p = &#40;unsigned char *&#41;params->data->outtext;
	
	int len = params->data->outtextlength;
	
	int i=0;
	while &#40;test&#91;i&#93; && i<len&#41;
	&#123;
		*p = test&#91;i&#93;;
		p++;
		i++;
	&#125;
	*p = 0; // make sure string is terminated

	jLog&#40;"* called sceUtilityOskInitStart\r\n"&#41;;

	return 0; // all OK!
&#125;

int sceUtilityOskShutdownStart_Hook&#40;void&#41;
&#123;
	jLog&#40;"* called sceUtilityOskShutdownStart\r\n"&#41;;
	// ignore for now	
	return 0; // all OK!
&#125;

int sceUtilityOskUpdate_Hook&#40;int n&#41;
&#123;
	jLog&#40;"* called sceUtilityOskUpdate\r\n"&#41;;
	// ignore for now
	return 0; // all OK!
&#125;

int sceUtilityOskGetStatus_Hook&#40;void&#41;
&#123;
	jLog&#40;"* called sceUtilityOskGetStatus\r\n"&#41;;
	return PSP_UTILITY_DIALOG_FINISHED;
&#125;

void jLog&#40;char * text&#41;
&#123;
	int nChars = 0;
	int fdout = sceIoOpen&#40;"ms0&#58;/jLog.txt", PSP_O_WRONLY | PSP_O_CREAT /*| PSP_O_TRUNC*/ | PSP_O_APPEND, 0777&#41;;	

	char * oText = text;

	while &#40;*text&#41; 
	&#123;
		text++;
		nChars++;
	&#125;

	int bw = sceIoWrite&#40;fdout, oText, nChars&#41;;	
	
	sceIoClose&#40;fdout&#41;;

&#125;

exports.exp:

Code: Select all

PSP_BEGIN_EXPORTS
PSP_EXPORT_START&#40;syslib, 0, 0x8000&#41;
PSP_EXPORT_FUNC_HASH&#40;module_start&#41;
PSP_EXPORT_VAR_HASH&#40;module_info&#41;
PSP_EXPORT_END
PSP_EXPORT_START&#40;piKeyOSKout, 0, 0x0001&#41;
PSP_EXPORT_FUNC_HASH&#40;getDriverInfo&#41;
PSP_EXPORT_END
PSP_END_EXPORTS
Makefile:

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 = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS = -mno-crt0

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak

LIBS += -lpsppower_driver -lpspreg_driver ../sdk/framework_stub.o
LDFLAGS += -specs=../sdk/prxspecs
...because of some include, should be compiled standing in pikey\src\oskHookOut (obviously of a working pikey's source like the one i posted months ago and now is down because my site no longer exists...)

Hope we'll make it work!

jean
Post Reply