Advertisement
Marionumber1

UhsQueryInterfaces()

Apr 10th, 2015
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.31 KB | None | 0 0
  1. #include "coreinit.h"
  2. #include "socket.h"
  3.  
  4. void start()
  5. {
  6.     /* Load a good stack */
  7.     asm(
  8.         "lis %r1, 0x1ab5 ;"
  9.         "ori %r1, %r1, 0xd138 ;"
  10.     );
  11.  
  12.     /* Get a handle to coreinit.rpl */
  13.     unsigned int coreinit_handle, nsysnet_handle;
  14.     OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
  15.     OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle);
  16.  
  17.     /* IOS functions */
  18.     int (*IOS_Open)(unsigned char *path, int mode);
  19.     int (*IOS_Ioctl)(int fd, int request, void *buffer1, int value, void *buffer2, int value2);
  20.     void* (*OSAllocFromSystem)(int size, int align);
  21.  
  22.     /* Socket functions */
  23.     int (*socket)(int family, int type, int proto);
  24.     int (*connect)(int fd, struct sockaddr *addr, int addrlen);
  25.     int (*recv)(int fd, void *buffer, int len, int flags);
  26.     int (*send)(int fd, const void *buffer, int len, int flags);
  27.    
  28.     /* Read the address of OSSetExceptionCallback() */
  29.     OSDynLoad_FindExport(coreinit_handle, 0, "IOS_Open", &IOS_Open);
  30.     OSDynLoad_FindExport(coreinit_handle, 0, "IOS_Ioctl", &IOS_Ioctl);
  31.     OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
  32.    
  33.     /* Read the addresses of socket(), connect(), and send() */
  34.     OSDynLoad_FindExport(nsysnet_handle, 0, "socket", &socket);
  35.     OSDynLoad_FindExport(nsysnet_handle, 0, "connect", &connect);
  36.     OSDynLoad_FindExport(nsysnet_handle, 0, "recv", &recv);
  37.     OSDynLoad_FindExport(nsysnet_handle, 0, "send", &send);
  38.  
  39.     /* Open /dev/uhs */
  40.     int uhs0 = IOS_Open("/dev/uhs/0",1);
  41.  
  42.     /* Allocate the buffers */
  43.     unsigned int *buffer1 = OSAllocFromSystem(0x10, 4);
  44.     unsigned int *buffer2 = OSAllocFromSystem(0x5b0, 4);
  45.     int i;
  46.     for (i = 0; i < 0x16c; i++)
  47.     {
  48.         buffer2[i] = 0;
  49.     }
  50.     buffer1[0] = 0;
  51.     buffer1[1] = 0;
  52.     buffer1[2] = 0;
  53.     buffer1[3] = 0;
  54.     int test = IOS_Ioctl(uhs0, 0x11, buffer1, 0x10, buffer2, 4);
  55.  
  56.     /* Set up our socket address structure */
  57.     struct sockaddr sin;
  58.     sin.sin_family = AF_INET;
  59.     sin.sin_port = 12345;
  60.     sin.sin_addr.s_addr = PC_IP;
  61.     for (j = 0; j < 8; j++)
  62.     {
  63.         sin.sin_zero[j] = 0;
  64.     }
  65.  
  66.     /* Connect to the PC */
  67.     int rpc = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  68.     int status = connect(rpc, &sin, 0x10);
  69.     if (status) OSFatal("Error connecting to RPC server");
  70.  
  71.     send(rpc, buffer1, 0x10, 0);
  72.     send(rpc, buffer2, 0x5b0, 0);
  73.    
  74.     char buffer[256];
  75.     __os_snprintf(buffer, 256, "IOS_Ioctl(): %d", test);
  76.     OSFatal(buffer);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement