Guest User

Left4Dead 2 C++ Internal DLL Hack

a guest
Aug 4th, 2018
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <iostream>
  3. #include <tlhelp32.h>
  4. #include <Psapi.h>
  5.  
  6. using namespace std;
  7.  
  8. char module[] = "server.dll";
  9. char sig[] = "\x89\x37\x5F\xB8\x00\x00\x00\x00";
  10. char mask[] = "xxxx????";
  11. char nopOppCode[] = "\x90\x90\x90";
  12.  
  13. MODULEINFO GetModuleInfo(char *szModule)
  14. {
  15. MODULEINFO modinfo{ 0 };
  16. HMODULE hModule = GetModuleHandle(szModule);
  17. if (hModule == 0)
  18. return modinfo;
  19. GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO));
  20. return modinfo;
  21. }
  22.  
  23. void WriteToMemory(uintptr_t addressToWrite, char* valueToWrite, int byteNum)
  24. {
  25. unsigned long OldProtection;
  26. VirtualProtect((LPVOID)(addressToWrite), byteNum, PAGE_EXECUTE_READWRITE, &OldProtection);
  27. memcpy((LPVOID)addressToWrite, valueToWrite, byteNum);
  28. VirtualProtect((LPVOID)(addressToWrite), byteNum, OldProtection, NULL);
  29. }
  30.  
  31.  
  32. DWORD FindPattern(char *module, char *pattern, char *mask)
  33. {
  34. MODULEINFO mInfo = GetModuleInfo(module);
  35. DWORD base = (DWORD)mInfo.lpBaseOfDll;
  36. DWORD size = (DWORD)mInfo.SizeOfImage;
  37.  
  38. DWORD patternLength = (DWORD)strlen(mask);
  39.  
  40. for (DWORD i = 0; i < size - patternLength; i++)
  41. {
  42. bool found = true;
  43. for (DWORD j = 0; j < patternLength; j++)
  44. {
  45. found &= mask[j] == '?' || pattern[j] == *(char*)(base + i + j);
  46. }
  47. if (found)
  48. {
  49. return base + i;
  50. }
  51. }
  52.  
  53. return NULL;
  54. }
  55.  
  56.  
  57. void startDLL()
  58. {
  59. DWORD foundAddy = FindPattern(module, sig, mask);
  60. WriteToMemory(foundAddy, nopOppCode, 1);
  61. }
  62.  
  63. BOOL WINAPI DllMain(
  64. HINSTANCE hinstDLL,
  65. DWORD fwdReason,
  66. LPVOID lpReserved)
  67. {
  68. switch (fwdReason)
  69. {
  70. case DLL_PROCESS_ATTACH:
  71. MessageBoxA(NULL, "Good to Go", "", 0);
  72. startDLL();
  73. break;
  74. }
  75. return TRUE;
  76. }
Add Comment
Please, Sign In to add comment