Weird behaviour with SceModule struct

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

Moderators: cheriff, TyRaNiD

Post Reply
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

Weird behaviour with SceModule struct

Post by m0skit0 »

I'm working on a PSP 2000 TA85v1 with 5.00 M33-4, using PSPSDK.

Here's my code:

Code: Select all

fileio_module = sceKernelFindModuleByName("sceIOFileManager");
[...]
sceIoWrite(fd, &(fileio_module->text_addr), sizeof(u32));
I check the value written in the file, and found it is 0x8805EFC0. But psplink, on the same run, gives me this:

Code: Select all

ms0:/> modinfo 0x00943901
UID: 0x00943901 Attr: 0007 - Name: sceIOFileManager
Entry: 0x880540F8 - GP: 0x8805EFC0 - TextAddr: 0x88050800
So text_addr is 0x88050800 (which is the correct value), not 0x8805EFC0, which is in fact the GP. But if I change my code to

Code: Select all

sceIoWrite(fd, &(fileio_module->text_size), sizeof(u32));
Now in fact I'm writing the text_addr struct member. So obviously there's a 4 byte shift missing there.

Any clues why is this happening?
The Incredible Bill Gates wrote:The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
Davee
Posts: 43
Joined: Mon Jun 22, 2009 3:58 am

Post by Davee »

SceModule structure has always been incorrect.

Code: Select all

typedef struct
{
	SceModule *	next; //0, 0x00
	u16 		attribute; //4, 0x04
	u8 			version[2]; //6, 0x06
	char 		modname[27]; //8, 0x08
	char 		terminal; //35, 0x23
	u16 		status; //36, 0x24 (AND 0x100 ? (usermodule) | (kernelmodule))
	u16 		padding; //38, 0x26
	u32 		unk_28; //40, 0x28
	SceUID 		modid; //44, 0x2C
	SceUID 		usermod_thid; //48, 0x30
	SceUID 		memid; //52, 0x34
	SceUID 		mpidtext; //56, 0x38
	SceUID 		mpiddata; //60, 0x3C
	void *		ent_top; //64, 0x40
	u32 		ent_size; //68, 0x44
	void *		stub_top; //72, 0x48
	u32 		stub_size; //76, 0x4C
	int 		(* module_start)(SceSize, void *); //80, 0x50
	int 		(* module_stop)(SceSize, void *); //84, 0x54
	int 		(* module_bootstart)(SceSize, void *); //88, 0x58
	int 		(* module_reboot_before)(SceSize, void *); //92, 0x5C
	int 		(* module_reboot_phase)(SceSize, void *); //96, 0x60
	u32 		entry_addr; //100, 0x64(seems to be repeated)
	u32 		gp_value; //104, 0x68
	u32 		text_addr; //108, 0x6C
	u32 		text_size; //112, 0x70
	u32 		data_size; //116, 0x74
	u32 		bss_size; //120, 0x78
	u8 			nsegment; //124, 0x7C
	u8			padding[3]; //125, 0x7D
	u32 		segmentaddr[4]; //128, 0x80
	u32 		segmentsize[4]; //144, 0x90
	int 		module_start_thread_priority; //160, 0xA0
	SceSize 	module_start_thread_stacksize; //164, 0xA4
	SceUInt 	module_start_thread_attr; //168, 0xA8
	int 		module_stop_thread_priority; //172, 0xAC
	SceSize 	module_stop_thread_stacksize; //176, 0xB0
	SceUInt 	module_stop_thread_attr; //180, 0xB4
	int 		module_reboot_before_thread_priority; //184, 0xB8
	SceSize 	module_reboot_before_thread_stacksize; //188, 0xBC
	SceUInt 	module_reboot_before_thread_attr; //192, 0xC0
} SceModule;
Thats the one I reversed from 1.50. It's changed a little recently adding new things, but thats the most upto date version.
User avatar
Coldbird
Posts: 97
Joined: Thu Feb 08, 2007 7:22 am

Post by Coldbird »

SDK submit - nao!
Been gone for some time. Now I'm back. Someone mind getting me up-2-date?
Post Reply