Advertisement
Guest User

Jail.c script for Majesty on Linux

a guest
Sep 25th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #define _GNU_SOURCE
  2. #include <dlfcn.h>
  3. #include <SDL/SDL.h>
  4.  
  5. // pointer to the real function
  6. Uint8* (*real_SDL_GetKeyState) (int *numkeys) = NULL;
  7.  
  8. void __attribute__ ((constructor)) jail_init(void)
  9. {
  10.     // match the library name loaded by our binary target
  11.     dlopen("libSDL-1.2.so.0", RTLD_LAZY);
  12.     real_SDL_GetKeyState = dlsym(RTLD_NEXT, "SDL_GetKeyState");
  13. }
  14.  
  15. // the wrapper
  16. Uint8* SDL_GetKeyState (int *numkeys)
  17. {
  18.     Uint8* keys;
  19.     SDL_GrabMode mode;
  20.  
  21.     keys = (*real_SDL_GetKeyState)(numkeys);
  22.  
  23.     if ((keys[SDLK_LCTRL] && keys[SDLK_SPACE])|| keys[SDLK_RCTRL])
  24.     {
  25.         keys[SDLK_SPACE] = 0;
  26.         mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
  27.         SDL_WM_GrabInput(mode == SDL_GRAB_OFF ? SDL_GRAB_ON : SDL_GRAB_OFF);
  28.     }
  29.  
  30.     return keys;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement