Advertisement
CHEAT_THE_GAME

Untitled

Oct 24th, 2022
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.24 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <string>
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <tlhelp32.h>
  6. #include <process.h>
  7. #include <processthreadsapi.h>
  8. #include <cstdio>
  9. using namespace std;
  10.  
  11. LPDWORD pid ;
  12.  
  13. struct Enum_windows_data
  14. {
  15.     DWORD process_id;
  16.     const char* window_title;
  17.     HWND hwnd;
  18. };
  19.  
  20. BOOL CALLBACK enum_windows_proc(HWND hwnd, LPARAM lparam)
  21. {
  22.     auto data = reinterpret_cast<Enum_windows_data*>(lparam);
  23.  
  24.     DWORD process_id = 0;
  25.  
  26.     GetWindowThreadProcessId(hwnd, &process_id);
  27.  
  28.     if (process_id == data->process_id)
  29.     {
  30.         if (!data->window_title)
  31.         {
  32.             data->hwnd = hwnd;
  33.  
  34.             return FALSE;
  35.         }
  36.  
  37.         char window_title[64 + 1];
  38.  
  39.         if (!GetWindowTextA(hwnd, window_title, sizeof(window_title)))
  40.             return TRUE; // No title or error
  41.  
  42.         if (_stricmp(window_title, data->window_title) == 0)
  43.         {
  44.             data->hwnd = hwnd;
  45.  
  46.             return FALSE;
  47.         }
  48.     }
  49.  
  50.     return TRUE;
  51. }
  52.  
  53. FORCEINLINE DWORD get_thread_id_by_hwnd(HWND hwnd)
  54. {
  55.     return GetWindowThreadProcessId(hwnd, pid);
  56. }
  57.  
  58.  
  59.  
  60. HWND find_window(DWORD pid, const std::string& window_title)
  61. {
  62.     Enum_windows_data data;
  63.     data.process_id = pid;
  64.     data.window_title
  65.         = window_title.empty()
  66.         ? nullptr
  67.         : window_title.c_str();
  68.     data.hwnd = nullptr;
  69.  
  70.     // MSDN: If EnumWindowsProc returns zero, the return value is also zero.
  71.     if (!EnumWindows(enum_windows_proc, reinterpret_cast<LPARAM>(&data)) && !data.hwnd)
  72.     {
  73.         return nullptr;
  74.     }
  75.  
  76.     if (!data.hwnd)
  77.     {
  78.         return nullptr;
  79.     }
  80.     return data.hwnd;
  81. }
  82.  
  83.  
  84. struct GetCurrentProcessWindowParameters
  85. {
  86.     HWND hWnd;
  87.     LPCSTR ClassName;
  88.     LPCSTR Title;
  89. };
  90.  
  91.  
  92.  
  93. HWND FindWindowX(LPCSTR className, LPCSTR title)
  94. {
  95.     GetCurrentProcessWindowParameters parameters;
  96.     parameters.hWnd = nullptr;
  97.     parameters.ClassName = className;
  98.     parameters.Title = title;
  99.  
  100.     EnumWindows(enum_windows_proc, reinterpret_cast<LPARAM>(&parameters));
  101.  
  102.     return parameters.hWnd;
  103. }
  104.  
  105.  
  106. int main(int argc, wchar_t* argv[])
  107. {
  108.  
  109.  
  110.  
  111.     //Load library in which we’ll be hooking our functions.
  112.     HMODULE dll = LoadLibraryW(L"xinput1_3.dll");
  113.     if (dll == NULL)
  114.     {
  115.         cout << "[ FAILED ] Could not find target window." << endl;
  116.         system("pause");
  117.         return EXIT_FAILURE;
  118.     }
  119.  
  120.    
  121.     HWND target = FindWindowX("LaunchUnrealUWindowsClient", "Alliance of Valiant Arms");
  122.     if (target == NULL)
  123.     {
  124.         cout << "target = 0." << endl;
  125.         system("pause");
  126.         return EXIT_FAILURE;
  127.     }
  128.     cout << "window Found " << target << std::hex << std::endl;
  129.     DWORD tid = GetWindowThreadProcessId(target,pid);
  130.     if (tid == NULL)
  131.     {
  132.         cout << "tid = 0." << endl;
  133.         system("pause");
  134.         return EXIT_FAILURE;
  135.     }
  136.     cout << "pid = " << pid << endl;
  137.     cout << "tid = " << tid << endl;
  138.  
  139.     //Get the address of the function inside the DLL.  
  140.     HOOKPROC addr = (HOOKPROC)GetProcAddress(dll, "NextHook");
  141.     if (addr == NULL)
  142.     {
  143.         cout << "dll = 0" << endl;
  144.         system("pause");
  145.         return EXIT_FAILURE;
  146.     }
  147.  
  148.     //Hook the function.
  149.     HHOOK handle = SetWindowsHookEx(WH_GETMESSAGE, addr, dll, tid);
  150.     if (handle == NULL)
  151.     {
  152.         cout << "MDFK Success injected" << endl;
  153.         system("pause");
  154.         return EXIT_FAILURE;
  155.     }
  156.     cout << "injection successfull Handle = " << handle << std::hex << endl;
  157.  
  158.     //   Unhook the function.  
  159.     system("pause");
  160.     return EXIT_FAILURE;
  161.  
  162.     UnhookWindowsHookEx(handle);
  163.  
  164.     return 0;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement