Advertisement
Guest User

Untitled

a guest
May 5th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Hooking DLL loader\injector GUI by Mikhail Remizov aka keng
  4. // 2012-2013
  5. //
  6. ///////////////////////////////////////////////////////////////////////////////
  7.  
  8. #include <d3d9.h>
  9. #include <tlhelp32.h>
  10. #include "resource.h"
  11.  
  12. #pragma comment(lib, "d3d9.lib")
  13.  
  14. ///////////////////////////////////////////////////////////////////////////////
  15.  
  16. unsigned long GetTargetThreadIDFromProcName(const char *);
  17. int Inject(const unsigned long, const char *);
  18.  
  19. ///////////////////////////////////////////////////////////////////////////////
  20.  
  21. int __stdcall WinMain(HINSTANCE hInstance,
  22. HINSTANCE hPrevInstance,
  23. LPSTR lpCmdLine,
  24. int nCmdShow)
  25. {
  26.  
  27. HRSRC hRes = FindResource(0, MAKEINTRESOURCE(IDR_DLL2), "DLL");
  28. if (hRes == NULL)
  29. {
  30. Beep(500, 1000);
  31. }
  32. HGLOBAL hMem = LoadResource(0, hRes);
  33. void* pMem = LockResource(hMem);
  34. DWORD size = SizeofResource(0, hRes);
  35.  
  36. WNDCLASSEX wc;
  37. HWND hWnd;
  38. MSG msg;
  39. unsigned long pID;
  40.  
  41. pID = GetTargetThreadIDFromProcName("csgo.exe");
  42. if (pID == 0)
  43. {
  44. MessageBox(0, "CS:GO not found. Please start ur game.",
  45. "Start", MB_OK);
  46. return 0;
  47. }
  48. else
  49. {
  50. char buf[MAX_PATH] = { 0 };
  51. Beep(1000, 100);
  52. GetFullPathName("ezhook.dll", MAX_PATH, buf, 0);
  53. Inject(pID, buf);
  54. return 0;
  55. }
  56.  
  57. return msg.wParam;
  58. }
  59.  
  60. ///////////////////////////////////////////////////////////////////////////////
  61.  
  62. char* Customstrstr(const char *in, const char *str)
  63. {
  64. char c;
  65. size_t len;
  66. c = *str++;
  67. if (!c)
  68. return (char *)in;
  69. len = strlen(str);
  70. do {
  71. char sc;
  72. do {
  73. sc = *in++;
  74. if (!sc)
  75. return (char *)0;
  76. } while (sc != c);
  77. } while (strncmp(in, str, len) != 0);
  78. return (char *)(in - 1);
  79. }
  80.  
  81. ///////////////////////////////////////////////////////////////////////////////
  82.  
  83. //
  84. // Game process ID searching function
  85. //
  86. unsigned long GetTargetThreadIDFromProcName(const char *procName)
  87. {
  88. PROCESSENTRY32 pe; // process snapshot
  89. int retval;
  90. // getting the whole system processes snapshot
  91. HANDLE thSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  92. pe.dwSize = sizeof(PROCESSENTRY32);
  93.  
  94. retval = Process32First(thSnapShot, &pe); // get the 1-st process
  95. while (retval) { // while there are any processes left
  96. // if process name == our needed name, then return the pid and quit
  97. if (Customstrstr(pe.szExeFile, procName))
  98. return pe.th32ProcessID;
  99. // if not - get the next process
  100. retval = Process32Next(thSnapShot, &pe);
  101. }
  102. return 0; //if nothing was found - return 0 and quit
  103. }
  104.  
  105. ///////////////////////////////////////////////////////////////////////////////
  106.  
  107. int Inject(const unsigned long pID, const char* dllName)
  108. {
  109. HANDLE pHandle;
  110. unsigned long loadLibAddr;
  111. LPVOID rString;
  112. //HANDLE hThread;
  113.  
  114. if (!pID)
  115. return 1;
  116. pHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pID);
  117. // get the LoadLibraryA() address from kernel32.dll
  118. loadLibAddr =
  119. (unsigned long)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
  120. rString = (LPVOID)VirtualAllocEx(pHandle, 0, strlen(dllName),
  121. MEM_RESERVE | MEM_COMMIT,
  122. PAGE_READWRITE);
  123. WriteProcessMemory(pHandle, (LPVOID)rString, dllName, strlen(dllName), 0);
  124. CreateRemoteThread(pHandle, 0, 0,
  125. (LPTHREAD_START_ROUTINE)loadLibAddr,
  126. (LPVOID)rString, 0, 0);
  127. CloseHandle(pHandle); // close the opened handle
  128. return 0; // everything is done, so quit
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement