Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2016
2,869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <windows.h> // Needed to use windows api calls
  3.  
  4. using namespace std;
  5.  
  6. // need to be global so our keyboard hook can clean up
  7. HANDLE hProc = NULL;
  8. HWND Window = NULL;
  9. HHOOK hHook = NULL;
  10. HANDLE hThread = NULL;
  11.  
  12. // haxx0r thread
  13. void haxxor (LPVOID Value)
  14. {
  15.     while (TRUE)
  16.     {
  17.         WriteProcessMemory(hProc,(BYTE*)0x28ff1c,(LPDWORD)Value,sizeof(DWORD),NULL);
  18.         Sleep (1000);
  19.     }
  20. }
  21.  
  22. // callback function for keyboard hook
  23. LRESULT CALLBACK KeyboardProc (int nCode, WPARAM wParam, LPARAM lParam)
  24. {
  25.     if (nCode >= 0)
  26.     {
  27.         // struct to get virtual key codes
  28.         KBDLLHOOKSTRUCT kbdStruct = *((KBDLLHOOKSTRUCT*)lParam);
  29.         // if F1 pressed
  30.         if (nCode == HC_ACTION && wParam == WM_KEYDOWN && kbdStruct.vkCode == VK_F1)
  31.         {
  32.             // kill haxx0r thread
  33.             TerminateThread (hThread, 0);
  34.  
  35.             cout << "Terminating haxxor thread" << endl;
  36.  
  37.             // clean up
  38.             CloseHandle (hThread);
  39.             UnhookWindowsHookEx (hHook);
  40.             CloseHandle(Window);
  41.             CloseHandle(hProc);
  42.  
  43.             // exit
  44.             ExitProcess (0);
  45.         }
  46.     }
  47.  
  48.     // if the message does not get processed
  49.     return CallNextHookEx (0, nCode, wParam, lParam);
  50. }
  51.  
  52. int main()
  53. {
  54.     int Value = 999; //New intended health Value
  55.     DWORD procID;
  56.  
  57.     Window = FindWindow(NULL,"Lose Health");
  58.  
  59.     if(!Window)
  60.     {
  61.         cout << "Window not found" << endl;
  62.         return 1;
  63.     }
  64.     else
  65.     {
  66.         if (!GetWindowThreadProcessId(Window,&procID))
  67.         {
  68.             cerr << "Get window process ID error: " << GetLastError() << endl;
  69.             return 1;
  70.         }
  71.     }
  72.  
  73.     if(procID != 0)
  74.     hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);
  75.  
  76.     if(!hProc)
  77.     {
  78.         cerr << "Can not open process: " << GetLastError() << endl;
  79.         return 2;
  80.     }
  81.     else
  82.     {
  83.         cout << "Process Found Ready to write" << endl;
  84.         cout << "Press F1 to terminate" << endl;
  85.     }
  86.  
  87.     // set global keyboard hook to capture F1 key press
  88.     hHook = SetWindowsHookEx (WH_KEYBOARD_LL, (HOOKPROC)KeyboardProc, GetModuleHandle (NULL), 0);
  89.  
  90.     // create threading function to haxx0r program
  91.     hThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)haxxor, &Value, 0, NULL);
  92.     if (hThread == NULL)
  93.     {
  94.         cerr << "Create thread error: " << GetLastError() << endl;
  95.  
  96.         // clean up
  97.         UnhookWindowsHookEx (hHook);
  98.         CloseHandle(Window);
  99.         CloseHandle(hProc);
  100.  
  101.         // exit
  102.         ExitProcess (1);
  103.     }
  104.  
  105.     // this is for the message queue to be able to capture key presses
  106.     MSG msg;
  107.     while (GetMessage (&msg, NULL, 0, 0 ) > 0)
  108.     {
  109.         TranslateMessage (&msg);
  110.         DispatchMessage (&msg);
  111.     }
  112.  
  113.     UnhookWindowsHookEx (hHook);
  114.     CloseHandle(Window);
  115.     CloseHandle(hProc);
  116.  
  117.     return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement