daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest Feb 12th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Windows.h>
  2.  
  3. void CUtils::unprotect(unsigned long address, unsigned int size)
  4. {
  5.     DWORD oldprot;
  6.     VirtualProtect((LPVOID)address, size, PAGE_EXECUTE_READWRITE, &oldprot);
  7. }
  8.  
  9. void CUtils::memSet(void *dst, int val, unsigned int size)
  10. {
  11.     unprotect((ULONG)dst, size);
  12.     memset(dst, val, size);
  13. }
  14.  
  15. void CUtils::memCpy(void *dst, const void *src, unsigned int size)
  16. {
  17.     unprotect((ULONG)dst, size);
  18.     memcpy(dst, src, size);
  19. }
  20.  
  21. void CUtils::strCpy(void *dst, const char *src, unsigned int size)
  22. {
  23.     unprotect((ULONG)dst, size);
  24.     strcpy((char*)dst, src);
  25. }
  26.  
  27. #define MAX_JUMPCODE_SIZE 50
  28.  
  29. template <class T, class U>
  30. void MemPutFast(U ptr, const T value)
  31. {
  32.     *(T*)ptr = value;
  33. }
  34.  
  35. BYTE* CreateJump(DWORD dwFrom, DWORD dwTo, BYTE* ByteArray)
  36. {
  37.     ByteArray[0] = 0xE9;
  38.     MemPutFast<DWORD>(&ByteArray[1], dwTo - (dwFrom + 5));
  39.     return ByteArray;
  40. }
  41.  
  42. BOOL CUtils::installHook(DWORD dwInstallAddress, DWORD dwHookHandler, int iJmpCodeSize)
  43. {
  44.     BYTE JumpBytes[MAX_JUMPCODE_SIZE];
  45.     CUtils::memSet(JumpBytes, 0x90, MAX_JUMPCODE_SIZE);
  46.     if (CreateJump(dwInstallAddress, dwHookHandler, JumpBytes))
  47.     {
  48.         CUtils::memCpy((PVOID)dwInstallAddress, JumpBytes, iJmpCodeSize);
  49.         return TRUE;
  50.     }
  51.     else
  52.         return FALSE;
  53. }
  54.  
  55. template < class T, class U >
  56. void CUtils::MemPut ( U ptr, const T value )
  57. {
  58.     if ( *(T*)ptr != value )
  59.         MemCpy ( (void*)ptr, &value, sizeof ( T ) );
  60. }
  61.  
  62. template < class T, class U >
  63. void CUtils::MemAdd ( U ptr, const T value )
  64. {
  65.     T current;
  66.     memcpy ( &current, (void*)ptr, sizeof ( T ) );
  67.     current += value;
  68.     MemCpy ( (void*)ptr, &current, sizeof ( T ) );
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top