Slexy.org is shutting down and stopped accepting new Pastes on May 4th, 2021.
Existing Pastes will stop being available on or after May 10th, 2021.
Author: Not specified Language: cpp
Description: Not specified Timestamp: 2017-06-19 04:22:45 +0000
View raw paste Reply
  1. static const unsigned int SendConsoleCommand_address = 0;
  2. static const unsigned int Com_Printf_address = 0;
  3. static const unsigned int SendServerCommand_address = 0;
  4. static const unsigned int Cmd_Argc_address = 0;
  5. static const unsigned int Cmd_Argv_address = 0;
  6.  
  7. static const unsigned int GVM_ClientConnect_address = 0;
  8. static const unsigned int GVM_ClientDisconnect_address = 0;
  9. static const unsigned int GVM_ClientCommand_address = 0;
  10. static const unsigned int GVM_ShutdownGame_address = 0;
  11.  
  12. void    (*Com_Printf)(const char *fmt, ...);
  13. int             (*Cmd_Argc)(void);
  14. void    (*Cmd_Argv)(int arg, char *buffer, int bufferLength);
  15. void    (*SendConsoleCommand)(int exec_when, const char *text);
  16. void    (*SendServerCommand)(int clientNum, const char *text);
  17.  
  18. void    (*GVM_ClientCommand)(int clientNum);
  19. char*   (*GVM_ClientConnect)(int clientNum, qboolean firstTime, qboolean isBot);
  20. void    (*GVM_ClientDisconnect)(int clientNum);
  21. void    (*GVM_ShutdownGame)(int restart);
  22.  
  23. void ClientConnect_Hook(int clientNum, qboolean firstTime, qboolean isBot);
  24. void ClientDisconnect_Hook(int clientNum);
  25. void ClientCommand_Hook(int clientNum);
  26. void ShutdownGame_Hook(int restart);
  27.  
  28. void hookInto(uint32_t *funcAddress, uint32_t *hookAddress) {
  29.         void *d = malloc(5);
  30.         memcpy(d, (void*)0xe9, 1);
  31.         memcpy(d + 1, hookAddress, 4);
  32.  
  33.         mprotect(funcAddress, 5, PROT_READ | PROT_WRITE);
  34.         memcpy(funcAddress, d, 5);
  35.         mprotect(funcAddress, 5, PROT_READ | PROT_EXEC ); // assume it is default protection
  36.  
  37.         free(d);
  38. }
  39.  
  40.  
  41. void Init_Hook(void) {
  42.         Com_Printf = Com_Printf_address;
  43.         Cmd_Argc = Cmd_Argc_address;
  44.         Cmd_Argv = Cmd_Argv_address;
  45.         SendConsoleCommand = SendConsoleCommand_address;
  46.         SendServerCommand = SendServerCommand_address;
  47.  
  48.         //Hook
  49.         hookInto(GVM_ClientCommand_address, (uint32_t*)ClientCommand_Hook);
  50.         hookInto(GVM_ClientConnect_address, (uint32_t*)ClientConnect_Hook);
  51.         hookInto(GVM_ClientDisconnect_address, (uint32_t*)ClientDisconnect_Hook);
  52.         hookInto(GVM_ShutdownGame_address, (uint32_t*)ShutdownGame_Hook);
  53. }
  54.  
  55. void GetPlayerInfo(int clientNum) {
  56.  
  57. }
  58.  
  59. void ClientCommand_Hook(int clientNum) {
  60.  
  61. }
  62.  
  63. void ClientConnect_Hook(int clientNum, qboolean firstTime, qboolean isBot) {
  64.  
  65. }
  66.  
  67. void ClientDisconnect_Hook(int clientNum) {
  68.  
  69. }
  70.  
  71. void ShutdownGame_Hook(int restart) {
  72.  
  73. }
  74.  
  75.  
  76. void UnHook(void) {
  77.  
  78. }
View raw paste Reply