Advertisement
Guest User

Untitled

a guest
Apr 7th, 2013
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <stdio.h>
  3.  
  4. BOOL InjectDll(HANDLE hProcess, LPCSTR lpFileName, SIZE_T tSize);
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.     LPCSTR lpFileName = "C:\\TestDll.dll";
  9.  
  10.     PROCESS_INFORMATION ProcessInformation;
  11.     STARTUPINFO StartupInfo;
  12.     DWORD cb;
  13.  
  14.     cb = sizeof(STARTUPINFO);
  15.     ZeroMemory(&StartupInfo, cb);
  16.     StartupInfo.cb = cb;
  17.  
  18.     CreateProcess("TestApp.exe", NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &StartupInfo, &ProcessInformation);
  19.  
  20.     printf("Press [Return] to continue...");
  21.     getchar();
  22.  
  23.     InjectDll(ProcessInformation.hProcess, lpFileName, strlen(lpFileName)+1);
  24.  
  25.     ResumeThread(ProcessInformation.hThread);
  26.  
  27.     CloseHandle(ProcessInformation.hProcess);
  28.     CloseHandle(ProcessInformation.hThread);
  29.  
  30.     return 0;
  31. }
  32.  
  33. BOOL InjectDll(HANDLE hProcess, LPCSTR lpFileName, SIZE_T tSize)
  34. {
  35.     PVOID pAddress;
  36.     HANDLE hThread;
  37. //  DWORD ExitCode;
  38.  
  39.     pAddress = VirtualAllocEx(hProcess, NULL, tSize, MEM_COMMIT, PAGE_READWRITE);
  40.  
  41.     WriteProcessMemory(hProcess, pAddress, lpFileName, tSize, NULL);
  42.  
  43.     hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)LoadLibrary, pAddress, 0, NULL);
  44.  
  45.     WaitForSingleObject(hThread, 10000); // 10 seconds
  46.  
  47. //  GetExitCodeThread(hThread, &ExitCode);
  48.  
  49.     VirtualFreeEx(hProcess, pAddress, tSize, MEM_DECOMMIT);
  50.  
  51.     CloseHandle(hThread);
  52.  
  53.     return TRUE;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement