Searching a prx source code for PSP 4.01 M33..

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

Moderators: cheriff, TyRaNiD

Post Reply
mydipper
Posts: 6
Joined: Sun Oct 05, 2008 2:51 am

Searching a prx source code for PSP 4.01 M33..

Post by mydipper »

Hi Everyone~

I am still trying to compile the prx of "RemaPSP" application to work on PSP 4.01 M33 firmware...

http://localhost.geek.nz/remapsp/remapspsrc.zip

Please help me to complete this job..



1.

I have installed 'devkitPro' tool on my windowsXP PC, and set the path with the PSP bin folder.

Is this tool everthing required to compile a prx file?

Just run 'make' in the directory of source directory?


2.

Could anyone tell me where I can find a open source code of a prx file including 'makefile' which works on PSP 4.01 M33 firmware ?

The required function is very simple..
: A text menu pops up when the specific buttons are pressed during a game.

just like 'alternative VSH' or 'cwcheat'..



3.

This is the hardest part to me..

'RemaPSP' interferes with every control signal by hooking the controller function such as :

sceCtrlPeekBufferPositive
sceCtrlPeekBufferNegative
sceCtrlReadBufferPositive
sceCtrlReadBufferNegative
sceCtrlPeekLatch
sceCtrlReadLatch

I have extracted the related codes below.

Does this code still work on PSP 4.01 M33 firmware?

I doubt the address values of the 'mainHookSave' variable..

Are these values changed for each firmware? How can I get them?


-------------------------------------------------------------------------------------

< main.c : function hook >

Code: Select all


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


MainHook mainHookSave&#91;MAIN_HOOK_NBR&#93; =
&#123;
	&#123; &#123; 0, NULL &#125;, "sceController_Service", "sceCtrl", 0x3A622550, sceCtrlPeekBufferPositiveFake &#125;,
	&#123; &#123; 0, NULL &#125;, "sceController_Service", "sceCtrl", 0xC152080A, sceCtrlPeekBufferNegativeFake &#125;,
	&#123; &#123; 0, NULL &#125;, "sceController_Service", "sceCtrl", 0x1F803938, sceCtrlReadBufferPositiveFake &#125;,
	&#123; &#123; 0, NULL &#125;, "sceController_Service", "sceCtrl", 0x60B81F86, sceCtrlReadBufferNegativeFake &#125;,

	&#123; &#123; 0, NULL &#125;, "sceController_Service", "sceCtrl", 0xb1d0e5cd, sceCtrlPeekLatchFake &#125;,
	&#123; &#123; 0, NULL &#125;, "sceController_Service", "sceCtrl", 0x0b588501, sceCtrlReadLatchFake &#125;,
&#125;;


mainThread&#40;&#41;
&#123;
.....
	// Patch syscall table, here the program use jmp func in stub table, so patch not applied here but in all user modules
	for &#40;x=0;x<MAIN_HOOK_NBR;x++&#41;
	&#123;
		ret = moduleHookFunc&#40;&mainHookSave&#91;x&#93;.modfunc, sceKernelSearchModuleByName&#40;mainHookSave&#91;x&#93;.modname&#41;, mainHookSave&#91;x&#93;.libname, mainHookSave&#91;x&#93;.nid, mainHookSave&#91;x&#93;.func&#41;;
	&#125;
.....
&#125;


int module_start &#40;SceSize args, void *argp&#41;
&#123;
.....
	thid = sceKernelCreateThread&#40;"RemapspMain",mainThread,8,0x10000,0,NULL&#41;;
	if &#40;thid >= 0&#41; sceKernelStartThread&#40;thid,args,argp&#41;;
.....
&#125;

< module.c >

Code: Select all


u32 moduleHookFunc &#40;ModuleFunc *modfunc, SceUID modid, const char *library, SceUID nid, void *func&#41;
&#123;
 u32 *addr;

 // Verify parameters
 if &#40;&#40;!&#40;modfunc&#41;&#41; || &#40;!&#40;library&#41;&#41; || &#40;!&#40;func&#41;&#41;&#41; return 1;

 // Find address of function in entry table and get pointer in entry table
 addr = moduleFindFunc&#40;moduleFindLibrary&#40;modid,library&#41;,nid&#41;;

 // If not found
 if &#40;!&#40;addr&#41;&#41; return 2;

 // Copy address of function in structure
 modfunc->addr = *addr;

 // Find address of function in syscall table and get pointer in syscall table
 modfunc->sysaddr = moduleFindSyscallFunc&#40;modfunc->addr&#41;;

 // If not found
 if &#40;!&#40;modfunc->sysaddr&#41;&#41; return 3;

 // Hook function &#40;copy func address to syscall table, overwrite old func&#41;
 return moduleHookAddr&#40;modfunc->sysaddr,&#40;u32&#41; func&#41;;
&#125;


u32 moduleHookAddr &#40;u32 *addr, u32 func&#41;
&#123;
 int x;

 // Verify parameters
 if &#40;!&#40;addr&#41;&#41; return 1;

 // Disable interrupts
 x = pspSdkDisableInterrupts&#40;&#41;;

 // Patch address
 *addr = func;

 // Apply to cache
 sceKernelDcacheWritebackInvalidateRange&#40;addr,sizeof&#40;addr&#41;&#41;;
 sceKernelIcacheInvalidateRange&#40;addr,sizeof&#40;addr&#41;&#41;;

 // Enable interrupts
 pspSdkEnableInterrupts&#40;x&#41;;

 return 0;
&#125;


u32 *moduleFindSyscallFunc &#40;u32 func&#41;
&#123;
 u8 **syscall;
 ModuleSyscallHeader *sysheader;
 u32 *systable;
 int size, x;

 // Get syscall table
 asm&#40;"cfc0 %0, $12\n" &#58; "=r"&#40;syscall&#41;&#41;;

 // Exit if failed
 if &#40;!&#40;syscall&#41;&#41; return NULL;

 // Get syscall header
 sysheader = &#40;ModuleSyscallHeader *&#41; *syscall;

 // Get syscall table
 systable = &#40;u32 *&#41; &#40;&#40;*syscall&#41; + sizeof&#40;ModuleSyscallHeader&#41;&#41;;

 // Get syscall size
 size = &#40;sysheader->size - sizeof&#40;ModuleSyscallHeader&#41;&#41; / sizeof&#40;u32&#41;;

 // Search function
 for &#40;x=0;x<size;x++&#41;
 &#123;
  if &#40;systable&#91;x&#93; == func&#41; return &systable&#91;x&#93;;
 &#125;

 return NULL;
&#125;


u32 *moduleFindFunc &#40;SceLibraryEntryTable *entryTable, SceUID nid&#41;
&#123;
 u32 *entry;
 int x;

 // Verify parameters
 if &#40;!&#40;entryTable&#41;&#41; return NULL;

 // Find entry table
 entry = &#40;u32 *&#41; entryTable->entrytable;

 // NID loop
 for &#40;x=0;x<entryTable->stubcount;x++&#41;
 &#123;
  // Find function address
  if &#40;entry&#91;x&#93; == nid&#41; return &entry&#91;x + entryTable->stubcount + entryTable->vstubcount&#93;;
 &#125;

 return NULL;
&#125;


SceLibraryEntryTable *moduleFindLibrary &#40;SceUID modid, const char *library&#41;
&#123;
 SceModule *mod;
 SceLibraryEntryTable *entryTable, *entryEnd;


 // Find memory of module
 mod = sceKernelFindModuleByUID&#40;modid&#41;;

 // If bad module
 if &#40;&#40;&#40;&#40;long&#41; mod&#41; & 0xFF000000&#41; != 0x88000000&#41; return NULL;
 if &#40;&#40;mod->stub_top - mod->ent_top&#41; < 40&#41; return NULL;

 // Find entry table
 entryTable = &#40;SceLibraryEntryTable *&#41; &#40;&#40;u32 *&#41; mod->ent_top&#41;;
 entryEnd = &#40;SceLibraryEntryTable *&#41; &#40;&#40;&#40;u8 *&#41; mod->ent_top&#41; + mod->ent_size&#41;;

 // Entry table loop
 while &#40;entryTable < entryEnd&#41;
 &#123;
  // Find name
  if &#40;entryTable->libname&#41;				// first entry &#40;module info&#41; has name = NULL
  &#123;
   if &#40;!&#40;strcmp&#40;entryTable->libname,library&#41;&#41;&#41; return entryTable;
  &#125;

  // Next entry
  entryTable = &#40;SceLibraryEntryTable *&#41; &#40;&#40;&#40;u32 *&#41; entryTable&#41; + entryTable->len&#41;;
 &#125;

 // Not found
 return NULL;
&#125;


< main.c : alternative control functions >

Code: Select all


int sceCtrlPeekBufferPositiveFake&#40;SceCtrlData *pad_data, int count&#41;
&#123;
	u32 k1;
	k1 = pspSdkSetK1&#40;0&#41;;
	int res = &#40;&#40;FUNC_CTRL&#41; mainHookSave&#91;0&#93;.modfunc.addr&#41;&#40;pad_data, count&#41;;
	
	overrideControls&#40;pad_data&#41;;  # control signal overriding
	pspSdkSetK1&#40;k1&#41;;

	return res;
&#125;


int sceCtrlPeekBufferNegativeFake&#40;SceCtrlData *pad_data, int count&#41;
&#123;
	u32 k1;
	k1 = pspSdkSetK1&#40;0&#41;;
	int res = &#40;&#40;FUNC_CTRL&#41; mainHookSave&#91;1&#93;.modfunc.addr&#41;&#40;pad_data, count&#41;;
	
	overrideControls&#40;pad_data&#41;;
	pspSdkSetK1&#40;k1&#41;;
	
	return res;
&#125;


int sceCtrlReadBufferPositiveFake&#40;SceCtrlData *pad_data, int count&#41;
&#123;
	u32 k1;
	k1 = pspSdkSetK1&#40;0&#41;;
	int res = &#40;&#40;FUNC_CTRL&#41; mainHookSave&#91;2&#93;.modfunc.addr&#41;&#40;pad_data, count&#41;;

	overrideControls&#40;pad_data&#41;;
	pspSdkSetK1&#40;k1&#41;;
	
	return res;
&#125;


int sceCtrlReadBufferNegativeFake&#40;SceCtrlData *pad_data, int count&#41;
&#123;
	u32 k1;
	k1 = pspSdkSetK1&#40;0&#41;;
	int res = &#40;&#40;FUNC_CTRL&#41; mainHookSave&#91;3&#93;.modfunc.addr&#41;&#40;pad_data, count&#41;;
	
	overrideControls&#40;pad_data&#41;;
	pspSdkSetK1&#40;k1&#41;;
	
	return res;
&#125;


int sceCtrlPeekLatchFake&#40;SceCtrlLatch *latch_data&#41;
&#123;
	SceCtrlData pad;
	int res = sceCtrlPeekBufferPositiveFake&#40;&pad, 1&#41;;
	
	//Gen new Latch
	latch_data->uiMake  = &#40;previousPressed ^ pad.Buttons&#41; & pad.Buttons;
	latch_data->uiBreak = &#40;previousPressed ^ pad.Buttons&#41; & previousPressed;
	
	latch_data->uiPress   =  pad.Buttons;
	latch_data->uiRelease = ~pad.Buttons;
	
	previousPressed = pad.Buttons;
	return res;
&#125;


int sceCtrlReadLatchFake&#40;SceCtrlLatch *latch_data&#41;
&#123;
	SceCtrlData pad;
	int res = sceCtrlPeekBufferPositiveFake&#40;&pad, 1&#41;;
	//For one reason or another this is no good. Makes games run too slow
	//int res = sceCtrlReadBufferPositiveFake&#40;&pad, 1&#41;;
	
	//Gen new Latch
	latch_data->uiMake  = &#40;previousPressed ^ pad.Buttons&#41; & pad.Buttons;
	latch_data->uiBreak = &#40;previousPressed ^ pad.Buttons&#41; & previousPressed;
	
	latch_data->uiPress   =  pad.Buttons;
	latch_data->uiRelease = ~pad.Buttons;
	
	previousPressed = pad.Buttons;
	return res;
&#125;


4.

Is this makefile valid to achieve a prx file for PSP 4.01 M33 ?

---------------------------------------------------------------------------------

Code: Select all

TARGET = remapsp
OBJS = main.o Utils/module.o exports.o conf.o wifi.o menu.o multiselect.o blit.o launchmenu.o NKLIB.o

# Define to build this as a prx &#40;instead of a static elf&#41;
BUILD_PRX = 1

# Define the name of our custom exports &#40;minus the .exp extension&#41;
PRX_EXPORTS=exports.exp

USE_KERNEL_LIBC = 1
USE_KERNEL_LIBS = 1

INCDIR = 
CFLAGS = -Os -G0 -Wall -fno-strict-aliasing -fno-builtin-printf
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS = -mno-crt0 -nostartfiles
LIBS = -lpsphprm -lpsppower -lpspsdk -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpspge -lpsprtc -lpspumd

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