 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
racine_20
Joined: 19 Jul 2006 Posts: 19
|
Posted: Thu Jul 27, 2006 3:48 am Post subject: [RESOLVED] Who can explain how to load functions by NID ? |
|
|
Hi everybody,
all is in this title, Who can do it ?
I think iit's very important to know how to do it, because when I see the pspsdk and the number of function that appears in list of NID, I think it's very pity.
thx,
Last edited by racine_20 on Wed Aug 02, 2006 5:06 pm; edited 1 time in total |
|
| Back to top |
|
 |
jas0nuk
Joined: 27 Apr 2006 Posts: 137
|
Posted: Thu Jul 27, 2006 4:55 am Post subject: |
|
|
This should work. Thanks to moonlight for helping me with it a while back.
| Code: | // From PspPet's PSARDUMPER
static u32 FindProc(const char* szMod, const char* szLib, u32 nid)
{
SceModule* modP = sceKernelFindModuleByName(szMod);
if (modP == NULL)
{
printf("Failed to find mod '%s'\n", szMod);
return 0;
}
SceLibraryEntryTable* entP = (SceLibraryEntryTable*)modP->ent_top;
while ((u32)entP < ((u32)modP->ent_top + modP->ent_size))
{
if (entP->libname != NULL && strcmp(entP->libname, szLib) == 0)
{
// found lib
int i;
int count = entP->stubcount + entP->vstubcount;
u32* nidtable = (u32*)entP->entrytable;
for (i = 0; i < count; i++)
{
if (nidtable[i] == nid)
{
u32 procAddr = nidtable[count+i];
// printf("entry found: '%s' '%s' = $%x\n", szMod, szLib, (int)procAddr);
return procAddr;
}
}
printf("Found mod '%s' and lib '%s' but not nid=$%x\n", szMod, szLib, nid);
return 0;
}
entP++;
}
printf("Found mod '%s' but not lib '%s'\n", szMod, szLib);
return 0;
}
static void my_function(void)
{
int (* power) (int);
reboot = (void *)FindProc("scePower_Service", "scePower_driver", 0x0442D852);
if (!reboot)
{
sceKernelExitGame();
}
else
{
reboot(0);
}
} |
This is an example and uses the function scePower_0442D852
In this example, it is called asreboot(0) because the function only seems to work that way, but obviously you would change the contents of the brackets to whatever arguments you would be sending.
I think there is a more efficient way of doing this but for me it works :)
Regards |
|
| Back to top |
|
 |
racine_20
Joined: 19 Jul 2006 Posts: 19
|
Posted: Thu Jul 27, 2006 6:54 pm Post subject: |
|
|
Hi jas0nuk,
Thx for the answer, She look like great and easy.
But, when I look your example with "scePower_Service", I can see that
| Code: | | reboot = (void *)FindProc("scePower_Service", "scePower_driver", 0x0442D852); |
,appears 3 args, const char* szMod (scePower_Service), const char* szLib (scePower_driver) , u32 nid (0x0442D852).
I can understand 2nd and 3th args but not the 1st, where you can find this ?
So, for example, I need "sceUtilityDeleteNetParam" with NID 0x9ce50172.
I guess that function need 1 arg who's will the number of config to delete.
How to comunicate to this function this number ?? :) damn
If you can do it, you'll be the best ;)
thxxx |
|
| Back to top |
|
 |
jas0nuk
Joined: 27 Apr 2006 Posts: 137
|
Posted: Thu Jul 27, 2006 9:12 pm Post subject: |
|
|
| Code: | | reboot = (void *)FindProc("sceUtility_driver", "sceUtility_netparam_internal", 0x9CE50172); |
should work. |
|
| Back to top |
|
 |
danzel
Joined: 04 Nov 2005 Posts: 182
|
|
| Back to top |
|
 |
racine_20
Joined: 19 Jul 2006 Posts: 19
|
Posted: Thu Jul 27, 2006 11:10 pm Post subject: |
|
|
danzel>
| Quote: | | http://pspdev.ofcode.com/api2.0/index.php is another useful resource for this sort of thing. |
lol ! not for me .... nobody functions is explains, just the name, but also help in many case.
jas0nuk>
I suppose that the function can use as it :
| Code: | int ret;
int num_profil = 1;
ret = sceUtilityDeleteNetParam( num_profil );
fprint( "function return : %i",ret); |
How give "num_profil" to the function ?
I don't understand very much your line, sorry I'm bad ;)
Thx for all jas0nuk |
|
| Back to top |
|
 |
jas0nuk
Joined: 27 Apr 2006 Posts: 137
|
Posted: Fri Jul 28, 2006 12:02 am Post subject: |
|
|
I'm not sure what you're asking... but if you want to send an argument to the function, you could just call it as...
| Code: | | reboot(num_profil); |
after using the line I showed you before |
|
| Back to top |
|
 |
racine_20
Joined: 19 Jul 2006 Posts: 19
|
Posted: Fri Jul 28, 2006 12:44 am Post subject: |
|
|
oh .... hummm ... ok, I try this later and I'll back later after get results
thx a lot |
|
| Back to top |
|
 |
racine_20
Joined: 19 Jul 2006 Posts: 19
|
Posted: Sat Jul 29, 2006 10:24 pm Post subject: |
|
|
I'm back again :) !
I try your sample, it's appear correctly when I compile it, but when I execute it, he crash on line in FindProc :
| Code: | | SceModule* modP = sceKernelFindModuleByName(szMod); |
when I call it by :
| Code: | | DeleteNetParam = (void *)FindProc("sceUtility_driver", "sceUtility_netparam_internal", 0x9CE50172); |
And finish to black screen/shutdown.
Damn, I smelled come the end of it, but not.
Are you an idea about this problem ?
( PS : good luck for 0x89 Jas0nuk ) |
|
| Back to top |
|
 |
0okm0000

Joined: 13 Jan 2006 Posts: 116
|
Posted: Sat Jul 29, 2006 11:14 pm Post subject: |
|
|
what system you use ?
fw1.00, fw1.50, fw2.50, fw2.60 ? _________________ PSP hardware hack
http://0okm.blogspot.com/ |
|
| Back to top |
|
 |
racine_20
Joined: 19 Jul 2006 Posts: 19
|
Posted: Sun Jul 30, 2006 1:56 am Post subject: |
|
|
1.50, sorry
Anybody can explain me what want say parameters of Findproc funct please ? |
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Sun Jul 30, 2006 4:17 am Post subject: |
|
|
| Most likely looks like you are just not running in kernel mode. |
|
| Back to top |
|
 |
racine_20
Joined: 19 Jul 2006 Posts: 19
|
Posted: Sun Jul 30, 2006 5:53 pm Post subject: |
|
|
This is a sample of my code
| Code: | // *** MODULE INITIALISATION ***
PSP_MODULE_INFO("TestWifi",0x1000,1,1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(32);
//*** CallBack section *******
// ........
// ************************
static u32 FindProc(const char* szMod, const char* szLib, u32 nid)
{
//*********** BLACKSCREEN HERE *****************
SceModule* modP = sceKernelFindModuleByName(szMod);
if (modP == NULL)
{
pspDebugScreenPrintf("Failed to find mod '%i'\n", szMod);
return NULL;
}
SceLibraryEntryTable* entP = (SceLibraryEntryTable*)modP->ent_top;
while ((u32)entP < ((u32)modP->ent_top + modP->ent_size))
{
if (entP->libname != NULL && strcmp(entP->libname, szLib) == 0)
{
// found lib
int i;
int count = entP->stubcount + entP->vstubcount;
u32* nidtable = (u32*)entP->entrytable;
for (i = 0; i < count; i++)
{
if (nidtable[i] == nid)
{
u32 procAddr = nidtable[count+i];
// printf("entry found: '%s' '%s' = $%x\n", szMod, szLib, (int)procAddr);
return procAddr;
}
}
pspDebugScreenPrintf("Found mod '%s' and lib '%s' but not nid=$%x\n", szMod, szLib, nid);
return NULL;
}
entP++;
}
pspDebugScreenPrintf("Found mod '%s' but not lib '%s'\n", szMod, szLib);
return NULL;
}
int sceUtilityDeleteNetParam(int NetParam)
{
int (*DeleteNetParam) (int);
DeleteNetParam = (void *)FindProc("sceUtility_driver", "sceUtility_netparam_internal", 0x9CE50172);
if (DeleteNetParam <> NULL )
if(sceUtilityCheckNetParam(NetParam) != 0) pspDebugScreenPrintf("Profil %i inexistant\n",NetParam);
else return DeleteNetParam(NetParam);
return -1;
} |
I think I was in kernel mode, but I haven't enought knowledge about kernel mode, so ... . |
|
| Back to top |
|
 |
0okm0000

Joined: 13 Jan 2006 Posts: 116
|
Posted: Sun Jul 30, 2006 8:31 pm Post subject: |
|
|
maybe error on sceUtility_driver
try this :)
| Code: | ...
DeleteNetParam = (void *)FindProc("sceUtility_Driver", "sceUtility_netparam_internal", 0x9CE50172);
... |
_________________ PSP hardware hack
http://0okm.blogspot.com/ |
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Sun Jul 30, 2006 9:17 pm Post subject: |
|
|
| Also should if (DeleteNetParam <> NULL ) not be != :) |
|
| Back to top |
|
 |
racine_20
Joined: 19 Jul 2006 Posts: 19
|
Posted: Sun Jul 30, 2006 11:09 pm Post subject: |
|
|
Damn !! TyRaNiD have the good answer, I'm not running in kernel mode my thread ....
humm ... How could be it ?? Simply change the attribute of sceKernelCreateThread ? |
|
| Back to top |
|
 |
0okm0000

Joined: 13 Jan 2006 Posts: 116
|
Posted: Mon Jul 31, 2006 12:45 am Post subject: |
|
|
| racine_20 wrote: | Damn !! TyRaNiD have the good answer, I'm not running in kernel mode my thread ....
humm ... How could be it ?? Simply change the attribute of sceKernelCreateThread ? |
no
your code in kernel mode
but PrxName is wrong :P
try this to test :)
| Code: |
#include <pspkernel.h>
#include <pspsdk.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <string.h>
PSP_MODULE_INFO("FindProc", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
#define printf pspDebugScreenPrintf
/*** This function from PspPet PSARDUMPER ***/
static u32 FindProc(const char* szMod, const char* szLib, u32 nid)
{
SceModule* modP = sceKernelFindModuleByName(szMod);
if (modP == NULL)
{
printf("Failed to find mod '%s'\n", szMod);
return 0;
}
SceLibraryEntryTable* entP = (SceLibraryEntryTable*)modP->ent_top;
while ((u32)entP < ((u32)modP->ent_top + modP->ent_size))
{
if (entP->libname != NULL && strcmp(entP->libname, szLib) == 0)
{
// found lib
int i;
int count = entP->stubcount + entP->vstubcount;
u32* nidtable = (u32*)entP->entrytable;
for (i = 0; i < count; i++)
{
if (nidtable[i] == nid)
{
u32 procAddr = nidtable[count+i];
printf("entry found:\n '%s' '%s' = $%x\n", szMod, szLib, (int)procAddr);
return procAddr;
}
}
printf("Found mod '%s' and lib '%s' but not nid=$%x\n", szMod, szLib, nid);
return 0;
}
entP++;
}
printf("Found mod '%s' but not lib '%s'\n", szMod, szLib);
return 0;
}
int main(void)
{
pspDebugScreenInit();
pspDebugScreenPrintf("\n");
pspDebugScreenPrintf(" press [SQUARE] to Find sceUtility_driver_9CE50172\n");
pspDebugScreenPrintf(" press [CIRCLE] to Find sceUtility_Driver_9CE50172\n");
pspDebugScreenPrintf(" press [CROSS] to EXIT\n\n");
SceCtrlData pad;
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(0);
while (1)
{
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_SQUARE)
{
pspDebugScreenPrintf(" sceUtility_driver_9CE50172 : 0x%.8X\n\n", FindProc("sceUtility_driver", "sceUtility_netparam_internal", 0x9CE50172));
sceDisplayWaitVblankStart();
sceKernelDelayThread(500 * 1000);
}
if (pad.Buttons & PSP_CTRL_CIRCLE)
{
pspDebugScreenPrintf(" sceUtility_Driver_9CE50172 : 0x%.8X\n\n", FindProc("sceUtility_Driver", "sceUtility_netparam_internal", 0x9CE50172));
sceDisplayWaitVblankStart();
sceKernelDelayThread(500 * 1000);
}
if (pad.Buttons & PSP_CTRL_CROSS)
{
sceKernelExitGame();
}
}
return 0;
}
|
_________________ PSP hardware hack
http://0okm.blogspot.com/ |
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Mon Jul 31, 2006 12:46 am Post subject: |
|
|
Of course the real question is why dont you create a new file called something like netparam.S (note the capitalisation) and put into it:
| Code: | .set noreorder
#include "pspstub.s"
STUB_START "sceUtility_netparam_internal",0x40010000,0x00040005
STUB_FUNC 0x072DEBF2,sceUtilityCreateNetParam
STUB_FUNC 0x9CE50172,sceUtilityDeleteNetParam
STUB_FUNC 0xFB0C4840,sceUtilityCopyNetParam
STUB_FUNC 0xFC4516F3,sceUtilitySetNetParam
STUB_END
|
Link that with your code and jobs a good un... |
|
| Back to top |
|
 |
racine_20
Joined: 19 Jul 2006 Posts: 19
|
Posted: Mon Jul 31, 2006 4:38 am Post subject: |
|
|
I don't ask anymore, but, how to link this in your main.c ?
I tryed (note the capitalisation ;) ) :
| Code: |
#include "netparam.S"
..
int sceUtilityDeleteNetParam(int);
..
int main(void){
..
pspDebugScreenPrintf("Code retour : %i",sceUtilityDeleteNetParam(2));
..
}
|
and launch the makefile, he warm me about netparam.S and a lot of stuff invalid preprocessing directive.
Maybe my makefile is bad, maybe I mistake a line, I don't know anymore.
Can you give me a tips again :). I know I know, I bored you :)
thx a lot for all ;) |
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Mon Jul 31, 2006 5:59 am Post subject: |
|
|
| Well if you are using a standard Makefile from PSPSDK then just add to the 'OBJS =' line netparam.o, if you are not using a standard makefile then you are probably on your own. You only need to assemble the file with something like psp-gcc -I/usr/local/pspdev/psp/sdk/include -c -o netparam.o netparam.S and link in the object. |
|
| Back to top |
|
 |
racine_20
Joined: 19 Jul 2006 Posts: 19
|
Posted: Mon Jul 31, 2006 7:15 pm Post subject: |
|
|
Ohhh my god !!! TyRaNID you are sooo good !!
This code run correctly and I can delete a net parameters finally.
well, I post my sample for turn the post to [RESOLVE] and do it.
MAIN.C :
| Code: |
// *** MODULE INITIALISATION ***
PSP_MODULE_INFO("SampleSySCallNID",0x1000,1,1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(32); /* smaller stack for kernel thread */
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
pspSdkInetTerm();
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
pspDebugScreenInit();
return thid;
}
/*------------------------------------------------------------------------------*/
int sceUtilityDeleteNetParam(int);
int main(void)
{
SetupCallbacks();
int err = pspSdkLoadInetModules();
if (err != 0) {
pspDebugScreenPrintf("pspSdkLoadInetModules failed with %x\n", err);
sceKernelDelayThread(5*1000000); // 5 sec to read error
return 1;
}
// print available connections
pspDebugScreenPrintf("available connections:\n");
int i;
for (i = 1; i < 100; i++) // skip the 0th connection
{
if (sceUtilityCheckNetParam(i) != 0) break; // no more
char name[64];
sceUtilityGetNetParam(i, 0, (netData*) name);
pspDebugScreenPrintf("%i: %s\n", i, name);
}
pspDebugScreenPrintf("Test effacement derniere config de connection:\n");
pspDebugScreenPrintf("Code retour effacement : %i",sceUtilityDeleteNetParam(--i));
sceKernelExitGame();
return 0;
} |
NETPARAM.S :
| Code: | .set noreorder
#include "pspstub.s"
STUB_START "sceUtility_netparam_internal",0x40010000,0x00040005
STUB_FUNC 0x072DEBF2,sceUtilityCreateNetParam
STUB_FUNC 0x9CE50172,sceUtilityDeleteNetParam
STUB_FUNC 0xFB0C4840,sceUtilityCopyNetParam
STUB_FUNC 0xFC4516F3,sceUtilitySetNetParam
STUB_END
|
MAKEFILE :
| Code: | PSPSDK = $(shell psp-config --pspsdk-path)
PSPLIBSDIR = $(PSPSDK)/..
TARGET = SampleSySCallNID
OBJS = main.o netparam.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS = -lpspdebug -lpspsdk -lpspwlan -lpspnet_apctl -lpspnet_resolver -lc -lpspnet_inet -lpspnet
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = SampleSySCallNID
include $(PSPSDK)/lib/build.mak |
A little last question, where you got the values for STUB_START and what mean this 0x40010000 and 0x00040005
For continue, I search for use sceUtilitySetNetParam and other
Thx to TyRaNID and jas0nuk |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|