Advertisement
Guest User

Untitled

a guest
May 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <iostream>
  3.  
  4. LPCSTR windowName{ "AssaultCube" };
  5. LPCSTR fullDLLPath{ "C:\\Users\\SKOLZA\\source\\repos\\ActuallyWorkingACwallhack\\legitDLL\\legitDLL\\Debug\\legitDLL.dll" };
  6. SIZE_T dllPathSize{ strlen(fullDLLPath) };
  7.  
  8. int main() {
  9.     // Get the handle to the window. Needed in order to later get the id of the process of the window.
  10.     HWND windowHandle{ FindWindowA(NULL, windowName) };
  11.     if (!windowHandle) {
  12.         std::cout << "Something went wrong with getting the window handle. Error Code: " << GetLastError() << "\n";
  13.         return 1;
  14.     }
  15.     std::cout << "Successfully got the handle for the window.\n";
  16.  
  17.     // Get the process id of the window.
  18.     DWORD pId{};
  19.     GetWindowThreadProcessId(windowHandle, &pId);
  20.     if (!pId) {
  21.         std::cout << "Something went wrong with getting the process ID of the window.\n";
  22.         return 1;
  23.     }
  24.     std::cout << "The process ID is: " << pId << ".\n";
  25.  
  26.     // Open a handle to the process.
  27.     HANDLE hProc{ OpenProcess(PROCESS_ALL_ACCESS, false, pId) };
  28.     if (!hProc) {
  29.         std::cout << "Something went wrong with opening a handle to the process. Error Code: " << GetLastError() << "\n";
  30.         return 1;
  31.     }
  32.     std::cout << "Successfully got the handle for the process.\n";
  33.  
  34.     // Allocate memory in the process.
  35.     LPVOID vAlloc{ VirtualAllocEx(hProc, NULL, dllPathSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE) };
  36.     if (!vAlloc) {
  37.         std::cout << "Something went wrong with VirtualAllocEx. Error Code: " << GetLastError() << "\n";
  38.         return 1;
  39.     }
  40.     std::cout << "Successfully allocated memory.\n";
  41.  
  42.     // Write our DLL path into allocated memory.
  43.     BOOL wpMem{ WriteProcessMemory(hProc, vAlloc, fullDLLPath, dllPathSize, NULL) };
  44.     if (!wpMem) {
  45.         std::cout << "Something went wrong with WriteProcessMemory. Error Code: " << GetLastError() << "\n";
  46.         return 1;
  47.     }
  48.     std::cout << "Successfully wrote dll path into allocated memory.\n";
  49.  
  50.     // Locate and save the LoadLibraryA function in the kernel32.dll module.
  51.     FARPROC loadLibraryAddress{ GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA") };
  52.     if (!loadLibraryAddress) {
  53.         std::cout << "Something went wrong with GetProcAddress. Error Code: " << GetLastError() << "\n";
  54.         return 1;
  55.     }
  56.  
  57.     // Create a thread which runs LoadLibraryA using vAlloc as the parameter.
  58.     HANDLE remoteThread{ CreateRemoteThread(hProc, NULL, NULL, (LPTHREAD_START_ROUTINE)loadLibraryAddress, vAlloc, NULL, NULL) };
  59.     if (!remoteThread) {
  60.         std::cout << "Something went wrong with CreateRemoteThread. Error Code: " << GetLastError() << "\n";
  61.         return 1;
  62.     }
  63.  
  64.     std::cout << "DLL Injection Successful!\n";
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement