Advertisement
Guest User

Untitled

a guest
May 27th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <TlHelp32.h>
  3. #include <iostream>
  4. #include <io.h>
  5.  
  6. DWORD GetProcessByName(char* process_name)
  7. {
  8. HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  9. PROCESSENTRY32 process;
  10. DWORD proc_id = 0;
  11. if (Process32First(snapshot, &process))
  12. {
  13. while (Process32Next(snapshot, &process))
  14. {
  15. if (_stricmp(process.szExeFile, process_name) == 0)
  16. {
  17. proc_id = process.th32ProcessID;
  18. break;
  19. }
  20. }
  21. }
  22. CloseHandle(snapshot);
  23. return proc_id;
  24. }
  25.  
  26. bool FileExist(char* name)
  27. {
  28. return _access(name, 0) != -1;
  29. }
  30.  
  31. bool Inject(DWORD pID, char*path)
  32. {
  33. HANDLE proc_handle;
  34. LPVOID RemoteString;
  35. LPCVOID LoadLibAddy;
  36. if (pID == 0)
  37. return false;
  38. proc_handle = OpenProcess(PROCESS_ALL_ACCESS, false, pID);
  39. if (proc_handle == 0)
  40. return false;
  41. LoadLibAddy = GetProcAddress(GetModuleHandle("kernel32.dll")), "LoadLibraryA";
  42. RemoteString = VirtualAllocEx(proc_handle, NULL, strlen(path), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
  43. WriteProcessMemory(proc_handle, RemoteString, path, strlen(path), NULL);
  44. CreateRemoteThread(proc_handle, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddy, RemoteString, NULL, NULL);
  45. CloseHandle(proc_handle);
  46. return true;
  47. }
  48. int main()
  49. {
  50. char process_name[32];
  51. char dll_name[32];
  52. char path[256];
  53. printf("enter process name: ");
  54. scanf_s("%s", process_name);
  55. DWORD pID = GetProcessByName(process_name);
  56. printf("Waiting %s for start...\n", process_name);
  57. for (;; Sleep(50))
  58. {
  59. if (pID == 0)
  60. pID = GetProcessByName(process_name);
  61. if (pID != 0) break;
  62. }
  63. printf("%s found (pid = %X)!\n", process_name, pID);
  64. while (FileExist(path) == false)
  65. {
  66. printf("Enter DLL name: ");
  67. scanf_s("%s", dll_name);
  68. GetFullPathName(dll_name, sizeof(path), path, NULL);
  69. if (FileExist(path))
  70. {
  71. printf("DLL found!\n");
  72. break;
  73. }
  74. else
  75. printf("DLL not found!\n");
  76. }
  77. printf("Preparing DLL for injection...\n");
  78. if (Inject(pID, path))
  79. {
  80. printf("DLL successfully injected!\n");
  81. system("pause");
  82. }
  83. else
  84. {
  85. printf("CRITICAL ERROR! \nDestroying window...\n");
  86. Sleep(500);
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement