[RESOLVED] Who can explain how to load functions by NID ?

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

Moderators: cheriff, TyRaNiD

Post Reply
racine_20
Posts: 19
Joined: Wed Jul 19, 2006 6:47 pm

[RESOLVED] Who can explain how to load functions by NID ?

Post by racine_20 »

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.
jas0nuk
Posts: 137
Joined: Thu Apr 27, 2006 8:00 am

Post by jas0nuk »

This should work. Thanks to moonlight for helping me with it a while back.

Code: Select all

// 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 &#40;&#40;u32&#41;entP < &#40;&#40;u32&#41;modP->ent_top + modP->ent_size&#41;&#41;
    &#123;
        if &#40;entP->libname != NULL && strcmp&#40;entP->libname, szLib&#41; == 0&#41;
        &#123;
            // found lib
            int i;
            int count = entP->stubcount + entP->vstubcount;
            u32* nidtable = &#40;u32*&#41;entP->entrytable;
            for &#40;i = 0; i < count; i++&#41;
            &#123;
                if &#40;nidtable&#91;i&#93; == nid&#41;
                &#123;
                    u32 procAddr = nidtable&#91;count+i&#93;;
                    // printf&#40;"entry found&#58; '%s' '%s' = $%x\n", szMod, szLib, &#40;int&#41;procAddr&#41;;
                    return procAddr;
                &#125;
            &#125;
            printf&#40;"Found mod '%s' and lib '%s' but not nid=$%x\n", szMod, szLib, nid&#41;;
            return 0;
        &#125;
        entP++;
    &#125;
    printf&#40;"Found mod '%s' but not lib '%s'\n", szMod, szLib&#41;;
    return 0;
&#125;

static void my_function&#40;void&#41;
&#123;
	int &#40;* power&#41; &#40;int&#41;;
	reboot = &#40;void *&#41;FindProc&#40;"scePower_Service", "scePower_driver", 0x0442D852&#41;;
	if &#40;!reboot&#41;
	&#123; 
		sceKernelExitGame&#40;&#41;;
	&#125;
	else
	&#123; 
		reboot&#40;0&#41;;
	&#125;
&#125;
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
racine_20
Posts: 19
Joined: Wed Jul 19, 2006 6:47 pm

Post by racine_20 »

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: Select all

reboot = &#40;void *&#41;FindProc&#40;"scePower_Service", "scePower_driver", 0x0442D852&#41;;
,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
jas0nuk
Posts: 137
Joined: Thu Apr 27, 2006 8:00 am

Post by jas0nuk »

Code: Select all

reboot = &#40;void *&#41;FindProc&#40;"sceUtility_driver", "sceUtility_netparam_internal", 0x9CE50172&#41;;
should work.
danzel
Posts: 182
Joined: Fri Nov 04, 2005 11:03 pm

Post by danzel »

http://pspdev.ofcode.com/api2.0/index.php is another useful resource for this sort of thing.
racine_20
Posts: 19
Joined: Wed Jul 19, 2006 6:47 pm

Post by racine_20 »

danzel>
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: Select all

int ret;
int num_profil = 1;
ret = sceUtilityDeleteNetParam&#40; num_profil &#41;;
fprint&#40; "function return &#58; %i",ret&#41;;
How give "num_profil" to the function ?
I don't understand very much your line, sorry I'm bad ;)
Thx for all jas0nuk
jas0nuk
Posts: 137
Joined: Thu Apr 27, 2006 8:00 am

Post by jas0nuk »

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: Select all

reboot&#40;num_profil&#41;;
after using the line I showed you before
racine_20
Posts: 19
Joined: Wed Jul 19, 2006 6:47 pm

Post by racine_20 »

oh .... hummm ... ok, I try this later and I'll back later after get results

thx a lot
racine_20
Posts: 19
Joined: Wed Jul 19, 2006 6:47 pm

Post by racine_20 »

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: Select all

SceModule* modP = sceKernelFindModuleByName&#40;szMod&#41;;
when I call it by :

Code: Select all

DeleteNetParam = &#40;void *&#41;FindProc&#40;"sceUtility_driver", "sceUtility_netparam_internal", 0x9CE50172&#41;;
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 )
User avatar
0okm0000
Posts: 116
Joined: Fri Jan 13, 2006 9:51 am
Contact:

Post by 0okm0000 »

what system you use ?
fw1.00, fw1.50, fw2.50, fw2.60 ?
PSP hardware hack
http://0okm.blogspot.com/
racine_20
Posts: 19
Joined: Wed Jul 19, 2006 6:47 pm

Post by racine_20 »

1.50, sorry

Anybody can explain me what want say parameters of Findproc funct please ?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Most likely looks like you are just not running in kernel mode.
racine_20
Posts: 19
Joined: Wed Jul 19, 2006 6:47 pm

Post by racine_20 »

This is a sample of my code

Code: Select all

// *** MODULE INITIALISATION ***
PSP_MODULE_INFO&#40;"TestWifi",0x1000,1,1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;; 
PSP_MAIN_THREAD_STACK_SIZE_KB&#40;32&#41;; 

//*** CallBack section *******

//      ........

// ************************


static u32 FindProc&#40;const char* szMod, const char* szLib, u32 nid&#41; 
&#123; 
//*********** BLACKSCREEN HERE *****************
    SceModule* modP = sceKernelFindModuleByName&#40;szMod&#41;; 
    if &#40;modP == NULL&#41; 
    &#123; 
        pspDebugScreenPrintf&#40;"Failed to find mod '%i'\n", szMod&#41;; 
        return NULL; 
    &#125; 
    SceLibraryEntryTable* entP = &#40;SceLibraryEntryTable*&#41;modP->ent_top; 
    while &#40;&#40;u32&#41;entP < &#40;&#40;u32&#41;modP->ent_top + modP->ent_size&#41;&#41; 
    &#123; 
        if &#40;entP->libname != NULL && strcmp&#40;entP->libname, szLib&#41; == 0&#41; 
        &#123; 
            // found lib 
            int i; 
            int count = entP->stubcount + entP->vstubcount; 
            u32* nidtable = &#40;u32*&#41;entP->entrytable; 
            for &#40;i = 0; i < count; i++&#41; 
            &#123; 
                if &#40;nidtable&#91;i&#93; == nid&#41; 
                &#123; 
                    u32 procAddr = nidtable&#91;count+i&#93;; 
                    // printf&#40;"entry found&#58; '%s' '%s' = $%x\n", szMod, szLib, &#40;int&#41;procAddr&#41;; 
                    return procAddr; 
                &#125; 
            &#125; 
            pspDebugScreenPrintf&#40;"Found mod '%s' and lib '%s' but not nid=$%x\n", szMod, szLib, nid&#41;; 
            return NULL; 
        &#125; 
        entP++; 
    &#125; 
    pspDebugScreenPrintf&#40;"Found mod '%s' but not lib '%s'\n", szMod, szLib&#41;; 
    return NULL; 
&#125; 

int sceUtilityDeleteNetParam&#40;int NetParam&#41; 
&#123;  
   int &#40;*DeleteNetParam&#41; &#40;int&#41;;
   DeleteNetParam = &#40;void *&#41;FindProc&#40;"sceUtility_driver", "sceUtility_netparam_internal", 0x9CE50172&#41;;
   if &#40;DeleteNetParam <> NULL &#41; 
     if&#40;sceUtilityCheckNetParam&#40;NetParam&#41; != 0&#41; pspDebugScreenPrintf&#40;"Profil %i inexistant\n",NetParam&#41;;
     else return DeleteNetParam&#40;NetParam&#41;;
   return -1;
&#125;
I think I was in kernel mode, but I haven't enought knowledge about kernel mode, so ... .
User avatar
0okm0000
Posts: 116
Joined: Fri Jan 13, 2006 9:51 am
Contact:

Post by 0okm0000 »

maybe error on sceUtility_driver
try this :)

Code: Select all

...
   DeleteNetParam = &#40;void *&#41;FindProc&#40;"sceUtility_Driver", "sceUtility_netparam_internal", 0x9CE50172&#41;;
...
PSP hardware hack
http://0okm.blogspot.com/
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Also should if (DeleteNetParam <> NULL ) not be != :)
racine_20
Posts: 19
Joined: Wed Jul 19, 2006 6:47 pm

Post by racine_20 »

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 ?
User avatar
0okm0000
Posts: 116
Joined: Fri Jan 13, 2006 9:51 am
Contact:

Post by 0okm0000 »

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: Select all

#include <pspkernel.h>
#include <pspsdk.h>
#include <pspdisplay.h>
#include <pspctrl.h>

#include <stdlib.h>
#include <string.h>

PSP_MODULE_INFO&#40;"FindProc", 0x1000, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

#define printf	pspDebugScreenPrintf

/*** This function from PspPet PSARDUMPER ***/
static u32 FindProc&#40;const char* szMod, const char* szLib, u32 nid&#41;
&#123;
    SceModule* modP = sceKernelFindModuleByName&#40;szMod&#41;;
    if &#40;modP == NULL&#41;
    &#123;
        printf&#40;"Failed to find mod '%s'\n", szMod&#41;;
        return 0;
    &#125;
    SceLibraryEntryTable* entP = &#40;SceLibraryEntryTable*&#41;modP->ent_top;
    while &#40;&#40;u32&#41;entP < &#40;&#40;u32&#41;modP->ent_top + modP->ent_size&#41;&#41;
    &#123;
        if &#40;entP->libname != NULL && strcmp&#40;entP->libname, szLib&#41; == 0&#41;
        &#123;
            // found lib
            int i;
            int count = entP->stubcount + entP->vstubcount;
            u32* nidtable = &#40;u32*&#41;entP->entrytable;
            for &#40;i = 0; i < count; i++&#41;
            &#123;
                if &#40;nidtable&#91;i&#93; == nid&#41;
                &#123;
                    u32 procAddr = nidtable&#91;count+i&#93;;
                    printf&#40;"entry found&#58;\n '%s' '%s' = $%x\n", szMod, szLib, &#40;int&#41;procAddr&#41;;
                    return procAddr;
                &#125;
            &#125;
            printf&#40;"Found mod '%s' and lib '%s' but not nid=$%x\n", szMod, szLib, nid&#41;;
            return 0;
        &#125;
        entP++;
    &#125;
    printf&#40;"Found mod '%s' but not lib '%s'\n", szMod, szLib&#41;;
    return 0;
&#125;

int main&#40;void&#41;
&#123;
	pspDebugScreenInit&#40;&#41;;
	pspDebugScreenPrintf&#40;"\n"&#41;;
	pspDebugScreenPrintf&#40;" press &#91;SQUARE&#93; to Find sceUtility_driver_9CE50172\n"&#41;;
	pspDebugScreenPrintf&#40;" press &#91;CIRCLE&#93; to Find sceUtility_Driver_9CE50172\n"&#41;;
	pspDebugScreenPrintf&#40;" press &#91;CROSS&#93; to EXIT\n\n"&#41;;

	SceCtrlData pad;
	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;0&#41;;
	while &#40;1&#41;
	&#123;
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if &#40;pad.Buttons & PSP_CTRL_SQUARE&#41;
		&#123;
			pspDebugScreenPrintf&#40;" sceUtility_driver_9CE50172 &#58; 0x%.8X\n\n", FindProc&#40;"sceUtility_driver", "sceUtility_netparam_internal", 0x9CE50172&#41;&#41;;
			sceDisplayWaitVblankStart&#40;&#41;;
			sceKernelDelayThread&#40;500 * 1000&#41;;
		&#125;
		if &#40;pad.Buttons & PSP_CTRL_CIRCLE&#41;
		&#123;
			pspDebugScreenPrintf&#40;" sceUtility_Driver_9CE50172 &#58; 0x%.8X\n\n", FindProc&#40;"sceUtility_Driver", "sceUtility_netparam_internal", 0x9CE50172&#41;&#41;;
			sceDisplayWaitVblankStart&#40;&#41;;
			sceKernelDelayThread&#40;500 * 1000&#41;;
		&#125;
		if &#40;pad.Buttons & PSP_CTRL_CROSS&#41;
		&#123;
			sceKernelExitGame&#40;&#41;;
		&#125;
	&#125;

	return 0;
&#125;
PSP hardware hack
http://0okm.blogspot.com/
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

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: Select all

    .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...
racine_20
Posts: 19
Joined: Wed Jul 19, 2006 6:47 pm

Post by racine_20 »

I don't ask anymore, but, how to link this in your main.c ?
I tryed (note the capitalisation ;) ) :

Code: Select all

#include "netparam.S"
..
int sceUtilityDeleteNetParam&#40;int&#41;;
..
int main&#40;void&#41;&#123;
..
pspDebugScreenPrintf&#40;"Code retour &#58; %i",sceUtilityDeleteNetParam&#40;2&#41;&#41;;
..
&#125;
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 ;)
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

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.
racine_20
Posts: 19
Joined: Wed Jul 19, 2006 6:47 pm

Post by racine_20 »

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: Select all

// *** MODULE INITIALISATION ***
PSP_MODULE_INFO&#40;"SampleSySCallNID",0x1000,1,1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;; 
PSP_MAIN_THREAD_STACK_SIZE_KB&#40;32&#41;; /* smaller stack for kernel thread */


/* Exit callback */ 
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123; 
          pspSdkInetTerm&#40;&#41;;
          sceKernelExitGame&#40;&#41;; 
          return 0; 
&#125; 

/* Callback thread */ 
int CallbackThread&#40;SceSize args, void *argp&#41; &#123; 
          int cbid; 

          cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;; 
          sceKernelRegisterExitCallback&#40;cbid&#41;; 

          sceKernelSleepThreadCB&#40;&#41;; 

          return 0; 
&#125; 

/* Sets up the callback thread and returns its thread id */ 
int SetupCallbacks&#40;void&#41; &#123; 
          int thid = 0; 

          thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;; 
          if&#40;thid >= 0&#41; &#123; 
                    sceKernelStartThread&#40;thid, 0, 0&#41;; 
          &#125; 

          pspDebugScreenInit&#40;&#41;;
          return thid; 
&#125;

/*------------------------------------------------------------------------------*/

int sceUtilityDeleteNetParam&#40;int&#41;;

int main&#40;void&#41; 
&#123; 
   SetupCallbacks&#40;&#41;;  
   int err = pspSdkLoadInetModules&#40;&#41;; 

   if &#40;err != 0&#41; &#123; 
      pspDebugScreenPrintf&#40;"pspSdkLoadInetModules failed with %x\n", err&#41;; 
      sceKernelDelayThread&#40;5*1000000&#41;; // 5 sec to read error 
      return 1; 
   &#125; 

   // print available connections 
    pspDebugScreenPrintf&#40;"available connections&#58;\n"&#41;; 
    int i; 
    for &#40;i = 1; i < 100; i++&#41; // skip the 0th connection 
    &#123; 
        if &#40;sceUtilityCheckNetParam&#40;i&#41; != 0&#41; break;  // no more 
        char name&#91;64&#93;; 
        sceUtilityGetNetParam&#40;i, 0, &#40;netData*&#41; name&#41;; 
        pspDebugScreenPrintf&#40;"%i&#58; %s\n", i, name&#41;; 
    &#125;
    
    pspDebugScreenPrintf&#40;"Test effacement derniere config de connection&#58;\n"&#41;; 
    pspDebugScreenPrintf&#40;"Code retour effacement &#58; %i",sceUtilityDeleteNetParam&#40;--i&#41;&#41;;

   sceKernelExitGame&#40;&#41;; 

   return 0; 

&#125;
NETPARAM.S :

Code: Select all

   .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: Select all

PSPSDK = $&#40;shell psp-config --pspsdk-path&#41;
PSPLIBSDIR = $&#40;PSPSDK&#41;/..
TARGET = SampleSySCallNID
OBJS = main.o netparam.o

INCDIR = 
CFLAGS = -O2 -G0 -Wall 
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti 
ASFLAGS = $&#40;CFLAGS&#41; 

LIBDIR = 
LDFLAGS = 
LIBS = -lpspdebug -lpspsdk -lpspwlan -lpspnet_apctl -lpspnet_resolver -lc -lpspnet_inet -lpspnet 

EXTRA_TARGETS = EBOOT.PBP 
PSP_EBOOT_TITLE = SampleSySCallNID 
 
include $&#40;PSPSDK&#41;/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
Post Reply