Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string injectDLL(std::string dllPath, std::string windowName){
- if (dllPath.empty() || windowName.empty())
- return "[*] Input Box Empty";
- HWND window = FindWindowA(NULL, windowName.c_str());
- if (window == NULL)
- return "[*] Failed To Find Window";
- DWORD pid = 0;
- GetWindowThreadProcessId(window, &pid);
- if (pid == NULL)
- return "[*] Failed To Get The PID";
- HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
- if (handle == NULL)
- return "[*] Failed To Open The Process";
- LPVOID allocedMem = VirtualAllocEx(handle, NULL, dllPath.length(), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
- if (allocedMem == NULL)
- return "[*] Failed To Allocate Memory";
- bool wroteFine = WriteProcessMemory(handle, allocedMem, dllPath.c_str(), dllPath.length(), NULL);
- if (wroteFine == NULL)
- return "[*] Failed To Write To Memory";
- HMODULE k32dll = GetModuleHandleA("kernel32");
- if (k32dll == NULL)
- return "[*] Failed To Grab A Handle To Kernel32";
- FARPROC loadLibraryFunct = GetProcAddress(k32dll, "LoadLibraryA");
- if (loadLibraryFunct == NULL)
- return "[*] Failed To Get The LoadLibraryA Address";
- if (!CreateRemoteThread(handle, NULL, NULL, (LPTHREAD_START_ROUTINE)loadLibraryFunct, allocedMem, NULL, NULL)){
- VirtualFreeEx(handle, allocedMem, dllPath.length(), MEM_RELEASE);
- CloseHandle(handle);
- return "[*] Injection Failed";
- }
- else{
- VirtualFreeEx(handle, allocedMem, dllPath.length(), MEM_RELEASE);
- CloseHandle(handle);
- return "[*] Injection Successful";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement