Hacking 5.5.0 progress

  • Thread starter Thread starter GOT4N
  • Start date Start date
  • Views Views 372,979
  • Replies Replies 1,267
  • Likes Likes 23
Speaking of programming issues, does anyone know how to get a random number without using a function that uses specific library, such as rand() or srand().
I can get a timestamp from OSGetTime in coreinit.rpl but I don't know how to write a function that will return a number in a specific range !?

Code:
int nextRand(int current, int min, int max) {
     return ((current * multiplier + addend) + min) % (max-min);
}

Something like this should work as a pseudo random number generator.

Ps:
send(rpc, buffer, 512, 0x20);
it freezes now here D: But recv works fine!

Edit: nvmd, had a typo somewhere lol
Edit 2: it was working once and now it does not work again @@
 
Last edited by Leanny,
Thanks this should work especially as I don't mind getting pseudo-random numbers and repetitions.

Ps:
send(rpc, buffer, 512, 0x20);
it freezes now here D: But recv works fine!

Edit: nvmd, had a typo somewhere lol

:yay:
 
it was working once and now it does not work again @@ Stupid thing xD. I really don't understand why it is not working.

Okay, I tracked the problem down a bit.

This works:
Code:
 while(1)
  {
      int bytes_read = recv(rpc, buffer, 512, 0x20);
      if(bytes_read == 0) continue;
      send(rpc, buffer, 512, 0x20);
      OSFatal("Done");
  }

This does not work:
Code:
 while(1)
  {
  /* Get data from the socket */
  int bytes_read = recv(rpc, buffer, 512, 0x20);
   if(bytes_read == 0) continue;
   /* Look at the command byte */
   switch (buffer[0])
   {
   /* Read memory */
   case 0: ;
     /* Copy them into the buffer */
     uint32_t *src = (uint32_t*) buffer[1];
     uint32_t *dest = &buffer[1];
     uint32_t num_words = buffer[2];

     for ( i = 0; i < num_words; i++) dest[i] = src[i];

     /* Send the buffer back */
     send(rpc, buffer, 512, 0x20);
     OSFatal("Done");
    break;
   case 1: ;
     OSFatal("Done");
    break;
   }
  }

It freezes at send
 
Last edited by Leanny,
it was working once and now it does not work again @@ Stupid thing xD. I really don't understand why it is not working.

Did you initialize the socket library with sock_lib_init ?

Don't know what is the problem but here is my code, maybe it can help:
Code:
void rpc()
{
    unsigned int nsysnet_handle;
    OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle);

    /* Cache, DMA, and socket functions */
    int (*socket)(int family, int type, int proto);
    int (*connect)(int fd, struct sockaddr *addr, int addrlen);
    int (*recv)(int fd, void *buffer, int len, int flags);
    int (*send)(int fd, const void *buffer, int len, int flags);
    int (*socket_lib_init)(void);
    int (*socket_lib_finish)(void);
    int (*setsockopt)(int fd, int level, int optname, void *optval, int optlen);
    int (*socketclose)(int fd);

    /* Read the addresses of the functions */
    OSDynLoad_FindExport(nsysnet_handle, 0, "socket_lib_init", &socket_lib_init);
    OSDynLoad_FindExport(nsysnet_handle, 0, "socket_lib_finish", &socket_lib_finish);
    OSDynLoad_FindExport(nsysnet_handle, 0, "socket", &socket);
    OSDynLoad_FindExport(nsysnet_handle, 0, "connect", &connect);
    OSDynLoad_FindExport(nsysnet_handle, 0, "recv", &recv);
    OSDynLoad_FindExport(nsysnet_handle, 0, "send", &send);
    OSDynLoad_FindExport(nsysnet_handle, 0, "setsockopt", &setsockopt);
    OSDynLoad_FindExport(nsysnet_handle, 0, "socketclose", &socketclose);

    // Initialize the library
    socket_lib_init();

    /* Set up our socket address structure */
    struct sockaddr sin;
    sin.sin_family = AF_INET;
    sin.sin_port = 12345;
    sin.sin_addr.s_addr = PC_IP;
    int i;
    for (i = 0; i < 8; i++)
    {
        sin.sin_zero[i] = 0;
    }

    // Create a socket
    int rpc = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    int optval=1;
    int optlen = sizeof(optval);

    // Set the KEEPALIVE option active
    setsockopt(rpc, -1, 0x00008, &optval, optlen);

    // Connect
    int status = connect(rpc, &sin, 0x10);
    if (status) {
        // Error
        return 0;
    }

    // RPC LOOP

    /* Block waiting for data */
    uint32_t buffer[128];
    while(1)
    {
        /* Get data from the socket */
        if(recv(rpc, buffer, 512, 0x20)>0) {

            /* Look at the command byte */
            switch (buffer[0])
            {
                /* [...]  */
            }
        }
    }
    socketclose(rpc);
    socket_lib_finish();
}

EDIT : Are you sure the connection was still open the moment you sent the data ? What does the python shell tells you ? I noticed that when you use a socket function whereas the server is down, it freezes the wii no matter how you try to catch the error....?
 
Last edited by eliboa,
How does your code compile?

Code:
    setsockopt(rpc, -1, 0x00008, &optval, optlen) < 0) {

This line should be wrong. Is this an if? What sould happen when the condition is true? I just try to ignore the line and see what happens xD
 
Yeah this is a bad copy/paste :P, it was in an if statement but the following code was a personnal debug function thaht would not compile for you.
The setsockopt function should work anyway but i'm not sure this will help for your problem
 
there who have the kernel exploit and loadiine for sale I buy remembering that let private and talk to me so that I buy!

OFW 5.5.0 U
 
tax where I live is so much that is not worth!
Unfortunately Nintendo is not support.


negotiate the price not lower ps4 games is cheap here. less than half of the nintendo
to the exclusive the ps4 are of great value.
is the nintendo has fought this area of business has not ps4.
 

Site & Scene News

Popular threads in this forum