Advertisement
CasualGamer

DLLInjector - 1

Dec 25th, 2019
9,889
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. #include<Windows.h> //DWORD
  2. #include <iostream>
  3. #include <string>
  4. #include <psapi.h> //EnumProcessModules
  5. #include <VersionHelpers.h>
  6. #include <atlstr.h> // CString
  7.  
  8. #define CREATE_THREAD_ACCESS (PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ)
  9.  
  10. BOOL InjectDLL(DWORD ProcessID)
  11. {
  12.     LPCSTR DLL_PATH = "E:\\Videos\\11 dll injector\\vs Project\\DllInjector\\Debug\\Terraria_dll.dll";
  13.     LPVOID LoadLibAddy, RemoteString;
  14.  
  15.     if (!ProcessID)
  16.         return false;
  17.  
  18.     HANDLE Proc = OpenProcess(CREATE_THREAD_ACCESS, FALSE, ProcessID);
  19.  
  20.     if (!Proc)
  21.     {
  22.         std::cout << "OpenProcess() failed: " << GetLastError() << std::endl;
  23.         return false;
  24.     }
  25.  
  26.     LoadLibAddy = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
  27.  
  28.     RemoteString = (LPVOID)VirtualAllocEx(Proc, NULL, strlen(DLL_PATH) + 1, MEM_COMMIT, PAGE_READWRITE);
  29.     WriteProcessMemory(Proc, RemoteString, (LPVOID)DLL_PATH, strlen(DLL_PATH)+1, NULL);
  30.     CreateRemoteThread(Proc, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddy, RemoteString, NULL, NULL);
  31.  
  32.     CloseHandle(Proc);
  33.  
  34.     return true;
  35. }
  36.  
  37. //BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
  38.  
  39. BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) {
  40.     DWORD dwThreadId, dwProcessId;
  41.     HINSTANCE hInstance;
  42.     char String[255];
  43.     if (!hWnd)
  44.         return TRUE;        // Not a window
  45.     if (!::IsWindowVisible(hWnd))
  46.         return TRUE;        // Not visible
  47.     if (!SendMessage(hWnd, WM_GETTEXT, sizeof(String), (LPARAM)String))
  48.         return TRUE;        // No window title
  49.     hInstance = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
  50.     dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
  51.     std::cout << "PID: " << dwProcessId << '\t' << String << '\t' << std::endl;
  52.     return TRUE;
  53. }
  54.  
  55. int main() {
  56.     if (IsWindowsXPOrGreater()) {
  57.         std::cout << "Available Targets:\n\n" <<std::endl;
  58.         EnumWindows(EnumWindowsProc, NULL);
  59.         std::cout << "\nPick Target ProcessID" << std::endl;
  60.         DWORD PID;
  61.         std::cin >> PID;
  62.         InjectDLL(PID);
  63.     }
  64.     else {
  65.         std::cout << "Method not supported by OS. Terminating" << std::endl;
  66.         return 0;
  67.     }
  68.  
  69.     return 0;
  70. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement