Exemplo n.º 1
0
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
      struct sockaddr *src_addr, socklen_t *addrlen) {
   static ssize_t (*real_func)(int, void*, size_t, int,
         struct sockaddr*, socklen_t *) = NULL;
   static int i = -1;
   static int drop_every = 0;
   if (real_func == NULL) {
      real_func = dlsym(RTLD_NEXT, "recvfrom");
   }
     return real_func(sockfd, buf, len, flags, src_addr, addrlen);
   fprintf(stderr, "%d enter recvfrom %d i=%d f=%p %p\n", getpid(), sockfd, i, real_func, recvfrom);
   char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
   ssize_t r;
   do {
      r = real_func(sockfd, buf, len, flags, src_addr, addrlen);
      getnameinfo(src_addr, sizeof(struct sockaddr), hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), 0);
      fprintf(stderr, "addr=%s %s\n", hbuf, sbuf);
      if (drop_every > 0) {
         i = (i + 1) % drop_every;
         if (i == 0) {
            fprintf(stderr, "tester: drop packet %d %d\n", sockfd, len);
            fprintf(stderr, "%1024c\n", buf);
         }
      }
   } while (drop_every > 0 && i == 0);
   return r;
}
Exemplo n.º 2
0
SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode) {
  static SDL_GrabMode(*real_func)(SDL_GrabMode) = NULL;

  if (real_func == NULL) {
    real_func = dlsym(RTLD_NEXT, "SDL_WM_GrabInput");
    assert(real_func != NULL);
  }

  if (mode == SDL_GRAB_ON) {
    mode = SDL_GRAB_OFF;
  }

  return real_func(mode);
}
Exemplo n.º 3
0
void* SDL_SetVideoMode(int width, int height, int bitsperpixel, uint32_t flags) {
  static void*(*real_func)(int,int,int,uint32_t) = NULL;

  if (real_func == NULL) {
    real_func = dlsym(RTLD_NEXT, "SDL_SetVideoMode");
    assert(real_func != NULL);
  }

  if (flags & SDL_FULLSCREEN) {
    flags &= ~SDL_FULLSCREEN;
    flags |= SDL_NOFRAME;
  }

  return real_func(width, height, bitsperpixel, flags);
}
Exemplo n.º 4
0
int XNextEvent(Display *display, XEvent *outEvent) {
    // Code to pull the real function handle from X11 library.
    void *handle = NULL;
    //This will turn the function proto into a function pointer declaration
    int (*real_func)(Display *display, XEvent *outEvent) = NULL;
    char library[MAX_LIBRARY_PATH + 1];
    // If we're not emulating a 32 bit mode (which is either native 32 bit
    // or native 64 bit) - use the ordinary path for libX11
    if (is_emulated_32bit() == FALSE) {
        snprintf(library, MAX_LIBRARY_PATH, "/usr/lib/libX11.so.6");
    } else {
        // Use a path that usually contains the 32 bit libs in a 64 bit system.
        snprintf(library, MAX_LIBRARY_PATH, "/usr/lib32/libX11.so.6");
    }
    handle = dlopen(library, RTLD_LAZY);

    if (handle == NULL) {
        fprintf(stderr, "Failed to dlopen %s\n", library);
        fprintf(stderr, "dlerror says: %s\n", dlerror());
        return -1;
    }

    // The real event from XNextEvent
    XEvent realEvent;

    // Find the real function.
    real_func = dlsym(handle, "XNextEvent");
    // Invoke the real function.
    int rf_ret = real_func(display, &realEvent);

    if (should_discard_event(&realEvent))
    {
        // Fake an event!
        fake_visibility_event(outEvent, &realEvent);
    } else {
        *outEvent = realEvent;
    }
    return rf_ret;
}
Exemplo n.º 5
0
/* Log hook */
int _start(int arg0, int arg1, unsigned int arg2, void *addr, int len, int arg5)
{
    /* Kernel functions */
#if VER == 532
    void (*spinlock)(void *lock) = (void (*)(void*))0xFFF075BC;
    void (*spunlock)(void *lock) = (void (*)(void*))0xFFF075E0;
    int (*fd_to_handle)(unsigned int *ipcbuf, int rampid) = (int (*)(unsigned int*,int))0xFFF0C7F8;
    int (*IOS_IoctlvAsync)(int arg0, int fd, int cmd, int cnt_in, int cnt_out, struct iovec *vecs, void *cb, void *usrdata) = (int (*)(int,int,int,int,int,struct iovec*,void*,void*))0xFFF0BAF4;
    int (*IOS_WaitReply)(void *usrdata, int arg1, int arg2) = (int (*)(void*,int,int))0xFFF18150;
    void* (*memmove)(void *dst, void *src, int len) = (void* (*)(void*,void*,int))0xFFF09C7C;
#elif VER == 550
    void (*spinlock)(void *lock) = (void (*)(void*))0x0;
    void (*spunlock)(void *lock) = (void (*)(void*))0x0;
    int (*fd_to_handle)(unsigned int *ipcbuf, int rampid) = (int (*)(unsigned int*,int))0x0;
    int (*IOS_IoctlvAsync)(int arg0, int fd, int cmd, int cnt_in, int cnt_out, struct iovec *vecs, void *cb, void *usrdata) = (int (*)(int,int,int,int,int,struct iovec*,void*,void*))0x0;
    int (*IOS_WaitReply)(void *usrdata, int arg1, int arg2) = (int (*)(void*,int,int))0x0;
    void* (*memmove)(void *dst, void *src, int len) = (void* (*)(void*,void*,int))0x0;
#else
    void (*spinlock)(void *lock) = (void (*)(void*))0x0;
    void (*spunlock)(void *lock) = (void (*)(void*))0x0;
    int (*fd_to_handle)(unsigned int *ipcbuf, int rampid) = (int (*)(unsigned int*,int))0x0;
    int (*IOS_IoctlvAsync)(int arg0, int fd, int cmd, int cnt_in, int cnt_out, struct iovec *vecs, void *cb, void *usrdata) = (int (*)(int,int,int,int,int,struct iovec*,void*,void*))0x0;
    int (*IOS_WaitReply)(void *usrdata, int arg1, int arg2) = (int (*)(void*,int,int))0x0;
    void* (*memmove)(void *dst, void *src, int len) = (void* (*)(void*,void*,int))0x0;
#endif

    /* Only do this if socket open */
    int sockfd = *((int*)0xFFF00B48);
    if (sockfd != -1)
    {
        /* Lock a spinlock */
        spinlock((void*)(0xA0000000 + (0xFFF00B4C - 0xC0000000)));

        /* Get socket FD and convert to handle */
        unsigned int ipcbuf[3] = {0, 0, *((unsigned int*)0xFFF00B44)};
        fd_to_handle(ipcbuf, 4);

        /* Copy socket data to 0x40-aligned buffer */
        memmove((void*)0xDFF01500, addr, len);

        /* Execute send() request and wait for completion */
        unsigned int reqbuf[2] = {(unsigned int)sockfd, 0};
        int sendlen = ((len / 0x40) * 0x40) + ((len % 0x40 == 0) ? 0 : 0x40);
        struct iovec vecs[4];
        vecs[0].buffer = (void*)&reqbuf[0];
        vecs[0].len = 8;
        vecs[0].unknown8[0] = vecs[0].unknown8[1] = vecs[0].unknown8[2] = vecs[0].unknown8[3] = 0;
        vecs[1].buffer = (void*)0xDFF01500;
        vecs[1].len = sendlen;
        vecs[1].unknown8[0] = vecs[1].unknown8[1] = vecs[1].unknown8[2] = vecs[1].unknown8[3] = 0;
        vecs[2].buffer = (void*)0;
        vecs[2].len = 0;
        vecs[2].unknown8[0] = vecs[2].unknown8[1] = vecs[2].unknown8[2] = vecs[2].unknown8[3] = 0;
        vecs[3].buffer = (void*)0;
        vecs[3].len = 0;
        vecs[3].unknown8[0] = vecs[3].unknown8[1] = vecs[3].unknown8[2] = vecs[3].unknown8[3] = 0;
        IOS_IoctlvAsync(0, (int)ipcbuf[2], 0xE, 4, 0, vecs, (void*)0, (void*)0x1234ABC0);
        IOS_WaitReply((void*)0x1234ABC0, 0xF4240, 0);

        /* Release the spinlock */
        spunlock((void*)(0xA0000000 + (0xFFF00B4C - 0xC0000000)));
    }

    /* Pass through to real function */
#if VER == 532
    int (*real_func)(int arg0, int arg1, unsigned int arg2, void *addr, int len, int arg5) = (int (*)(int,int,unsigned int,void*,int,int))0xFFF1AB94;
#elif VER == 550
    int (*real_func)(int arg0, int arg1, unsigned int arg2, void *addr, int len, int arg5) = (int (*)(int,int,unsigned int,void*,int,int))0x0;
#else
    int (*real_func)(int arg0, int arg1, unsigned int arg2, void *addr, int len, int arg5) = (int (*)(int,int,unsigned int,void*,int,int))0x0;
#endif
    return real_func(arg0, arg1, arg2, addr, len, arg5);
}
Exemplo n.º 6
0
int XNextEvent(Display *display, XEvent *outEvent) {
  // Code to pull the real function handle from X11 library.
  void *handle = NULL;

  //This will turn the function proto into a function pointer declaration
  int (*real_func)(Display *display, XEvent *outEvent) = NULL;
  handle = get_xlib_handle();

  if (handle == NULL) {
    return -1;
  }

  // The real event from XNextEvent
  XEvent realEvent;

  // Find the real function.
  real_func = dlsym(handle, "XNextEvent");
  // Invoke the real function.
  int rf_ret = real_func(display, &realEvent);

  OPEN_LOGGING_FILE;

  if (g_library_inited == FALSE) {
    LOG("Library initialized.\n");
    g_library_inited = TRUE;
    init_cached_xquerytree();
    init_focus_keep_struct(&g_focus_status);
  }


  // This display object will be used to inquire X server
  // about inferior and parent windows.
  Display* dpy = display;
  //assert(dpy != NULL);

  print_event_to_log(dpy, &realEvent);

  // Is the event on a window other than the active one?
  // If so, update gActiveWindow on two cases:
  // 1. It's the first window known to the module.
  // 2. It's the second window known to the module. The second
  // window is the actual browser window (the first one is just a
  // set-up one).
  //
  if ((get_active_window(&g_focus_status) == 0) && (is_focus_in(&realEvent))) {
    set_active_window(&g_focus_status, &realEvent);
  } else {
    identify_switch_situation(&g_focus_status);
  }

  if (is_reparent_notify(&realEvent)) {
    identify_new_window_situation(&g_focus_status, &realEvent);
  }

  if (is_destroy_notify(&realEvent)) {
    identify_active_destroyed(&g_focus_status, &realEvent);
  }

  if ((g_focus_status.during_switch == TRUE) ||
      (get_active_window(&g_focus_status) == 0)) {
      LOG("During switch: %d Active win: %#lx during close: %d\n",
          g_focus_status.during_switch, get_active_window(&g_focus_status),
          g_focus_status.during_close);
    *outEvent = realEvent;
  } else if (should_discard_focus_out_event(&g_focus_status, dpy, &realEvent)) {
    // Fake an event!
    fake_keymap_notify_event(outEvent, &realEvent);
    LOG("Fake event for focus out.\n");
  }  else if (should_discard_focus_in_event(&g_focus_status, dpy, &realEvent)) {
    fake_keymap_notify_event(outEvent, &realEvent);
    LOG("Fake event for focus in.\n");
  } else {
    *outEvent = realEvent;
  }

  steal_focus_back_if_needed(&g_focus_status, dpy);

  dlclose(handle);
  CLOSE_LOGGING_FILE;
  return rf_ret;
}
// --------------------------------------------------
	// Fitness Rating
void Individual::fitness_rating(){
	fit_rating -= abs(real_func() - approx_func());
}