Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <Windows.h>
  2.  
  3. typedef BOOL (__stdcall * FlushInstructionCache_t)(HANDLE hProcess,LPCVOID lpBaseAddress,SIZE_T dwSize);
  4. FlushInstructionCache_t pFlushInstructionCache;
  5.  
  6. void* detourFunc(BYTE *src, const BYTE *dst, const int len)
  7. {
  8.     BYTE *jmp = (BYTE*)malloc(len+5);
  9.     DWORD dwback;
  10.  
  11.     VirtualProtect(src, len, PAGE_READWRITE, &dwback);
  12.  
  13.     memcpy(jmp, src, len);  jmp += len;
  14.  
  15.     jmp[0] = 0xE9;
  16.     *(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
  17.  
  18.     src[0] = 0xE9;
  19.     *(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
  20.  
  21.     VirtualProtect(src, len, dwback, &dwback);
  22.  
  23.     return (jmp-len);
  24. }
  25.  
  26. BOOL __stdcall hkFlushInstructionCache(HANDLE hProcess, LPCVOID lpBaseAddress, SIZE_T dwSize)
  27. {
  28.      ExitProcess(0);
  29.      return pFlushInstructionCache(hProcess,lpBaseAddress,dwSize);
  30. }
  31.  
  32.  
  33. BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
  34. {
  35.       if(dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH)
  36.       {
  37.         MessageBox(NULL, "Injected!", "123", NULL);
  38.         DWORD dwFlushInstructionCache = (DWORD)GetProcAddress(GetModuleHandleA("kernel32.dll"), "ExitProcess");
  39.         pFlushInstructionCache = (FlushInstructionCache_t)detourFunc((BYTE*)dwFlushInstructionCache, (BYTE*)&hkFlushInstructionCache, 5);
  40.         MessageBox(NULL, "Hook set!", "223", NULL);
  41.       }
  42.  
  43.     return TRUE;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement