Advertisement
Guest User

InjectDll

a guest
Jan 13th, 2013
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. void InjectDll(unsigned int ProcessId, char *DllName)
  2. {
  3.     HANDLE hProcess;
  4.  
  5.     hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, ProcessId);
  6.  
  7.     unsigned int RemoteString;
  8.  
  9.     RemoteString = (unsigned int) VirtualAllocEx(hProcess, 0, strlen(DllName) + 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
  10.  
  11.     WriteProcessMemory(hProcess, (void*) RemoteString, DllName, strlen(DllName) + 1, 0);
  12.  
  13.     unsigned int RemoteThread;
  14.  
  15.     RemoteThread = (unsigned int) GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");
  16.  
  17.     HANDLE hThread;
  18.  
  19.     hThread = CreateRemoteThread(hProcess, 0, 0, (LPTHREAD_START_ROUTINE) RemoteThread, (void*) RemoteString, 0, 0);
  20.  
  21.     WaitForSingleObject(hThread, INFINITE);
  22.  
  23.     CloseHandle(hThread);
  24.  
  25.     VirtualFreeEx(hProcess, (void*) RemoteString, strlen(DllName) + 1, MEM_RELEASE);
  26.  
  27.     CloseHandle(hProcess);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement