forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
racine_20



Joined: 19 Jul 2006
Posts: 19

PostPosted: Thu Jul 27, 2006 3:48 am    Post subject: [RESOLVED] Who can explain how to load functions by NID ? Reply with quote

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
View user's profile Send private message
jas0nuk



Joined: 27 Apr 2006
Posts: 137

PostPosted: Thu Jul 27, 2006 4:55 am    Post subject: Reply with quote

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
View user's profile Send private message
racine_20



Joined: 19 Jul 2006
Posts: 19

PostPosted: Thu Jul 27, 2006 6:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
jas0nuk



Joined: 27 Apr 2006
Posts: 137

PostPosted: Thu Jul 27, 2006 9:12 pm    Post subject: Reply with quote

Code:
reboot = (void *)FindProc("sceUtility_driver", "sceUtility_netparam_internal", 0x9CE50172);


should work.
Back to top
View user's profile Send private message
danzel



Joined: 04 Nov 2005
Posts: 182

PostPosted: Thu Jul 27, 2006 10:14 pm    Post subject: Reply with quote

http://pspdev.ofcode.com/api2.0/index.php is another useful resource for this sort of thing.
Back to top
View user's profile Send private message
racine_20



Joined: 19 Jul 2006
Posts: 19

PostPosted: Thu Jul 27, 2006 11:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
jas0nuk



Joined: 27 Apr 2006
Posts: 137

PostPosted: Fri Jul 28, 2006 12:02 am    Post subject: Reply with quote

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
View user's profile Send private message
racine_20



Joined: 19 Jul 2006
Posts: 19

PostPosted: Fri Jul 28, 2006 12:44 am    Post subject: Reply with quote

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

thx a lot
Back to top
View user's profile Send private message
racine_20



Joined: 19 Jul 2006
Posts: 19

PostPosted: Sat Jul 29, 2006 10:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
0okm0000



Joined: 13 Jan 2006
Posts: 116

PostPosted: Sat Jul 29, 2006 11:14 pm    Post subject: Reply with quote

what system you use ?
fw1.00, fw1.50, fw2.50, fw2.60 ?
_________________
PSP hardware hack
http://0okm.blogspot.com/
Back to top
View user's profile Send private message Visit poster's website
racine_20



Joined: 19 Jul 2006
Posts: 19

PostPosted: Sun Jul 30, 2006 1:56 am    Post subject: Reply with quote

1.50, sorry

Anybody can explain me what want say parameters of Findproc funct please ?
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sun Jul 30, 2006 4:17 am    Post subject: Reply with quote

Most likely looks like you are just not running in kernel mode.
Back to top
View user's profile Send private message
racine_20



Joined: 19 Jul 2006
Posts: 19

PostPosted: Sun Jul 30, 2006 5:53 pm    Post subject: Reply with quote

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
View user's profile Send private message
0okm0000



Joined: 13 Jan 2006
Posts: 116

PostPosted: Sun Jul 30, 2006 8:31 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sun Jul 30, 2006 9:17 pm    Post subject: Reply with quote

Also should if (DeleteNetParam <> NULL ) not be != :)
Back to top
View user's profile Send private message
racine_20



Joined: 19 Jul 2006
Posts: 19

PostPosted: Sun Jul 30, 2006 11:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
0okm0000



Joined: 13 Jan 2006
Posts: 116

PostPosted: Mon Jul 31, 2006 12:45 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Mon Jul 31, 2006 12:46 am    Post subject: Reply with quote

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
View user's profile Send private message
racine_20



Joined: 19 Jul 2006
Posts: 19

PostPosted: Mon Jul 31, 2006 4:38 am    Post subject: Reply with quote

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
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Mon Jul 31, 2006 5:59 am    Post subject: Reply with quote

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
View user's profile Send private message
racine_20



Joined: 19 Jul 2006
Posts: 19

PostPosted: Mon Jul 31, 2006 7:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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