injector
#include <Windows.h> #include <iostream> #include <string> #include <psapi.h> #include <VersionHelpers.h> #include <atlstr.h> #define CREATE_THREAD_ACCESS (PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ) BOOL InjectDLL(DWORD ProcessID) { LPCWSTR DLL_PATH = L"C:\\Users\\Lenovo\\Desktop\\robloxinjector\\Dll1.dll"; LPVOID LoadLibAddy, RemoteString; if (!ProcessID) return FALSE; HANDLE Proc = OpenProcess(CREATE_THREAD_ACCESS, FALSE, ProcessID); if (!Proc) { std::cerr << "OpenProcess() failed: " << GetLastError() << std::endl; return FALSE; } HMODULE hKernel32 = GetModuleHandleW(L"kernel32.dll"); if (!hKernel32) { std::cerr << "GetModuleHandleW() failed: " << GetLastError() << std::endl; CloseHandle(Proc); return FALSE; } LoadLibAddy = (LPVOID)GetProcAddress(hKernel32, "LoadLibraryW"); if (!LoadLibAddy) { std::cerr << "GetProcAddress() failed: " << GetLastError() << std::endl; CloseHandle(Proc); return FALSE; } SIZE_T dllPathSize = (wcslen(DLL_PATH) + 1) * sizeof(WCHAR); RemoteString = VirtualAllocEx(Proc, NULL, dllPathSize, MEM_COMMIT, PAGE_READWRITE); if (!RemoteString) { std::cerr << "VirtualAllocEx() failed: " << GetLastError() << std::endl; CloseHandle(Proc); return FALSE; } if (!WriteProcessMemory(Proc, RemoteString, (LPVOID)DLL_PATH, dllPathSize, NULL)) { std::cerr << "WriteProcessMemory() failed: " << GetLastError() << std::endl; VirtualFreeEx(Proc, RemoteString, 0, MEM_RELEASE); CloseHandle(Proc); return FALSE; } HANDLE hThread = CreateRemoteThread(Proc, NULL, 0, (LPTHREAD_START_ROUTINE)LoadLibAddy, RemoteString, 0, NULL); if (!hThread) { std::cerr << "CreateRemoteThread() failed: " << GetLastError() << std::endl; VirtualFreeEx(Proc, RemoteString, 0, MEM_RELEASE); CloseHandle(Proc); return FALSE; } WaitForSingleObject(hThread, INFINITE); // Wait for the thread to finish VirtualFreeEx(Proc, RemoteString, 0, MEM_RELEASE); CloseHandle(hThread); CloseHandle(Proc); std::cout << "DLL Injection succeeded." << std::endl; return TRUE; } BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) { DWORD dwThreadId, dwProcessId; WCHAR String[255]; if (!hWnd) return TRUE; // Not a window if (!::IsWindowVisible(hWnd)) return TRUE; // Not visible if (!SendMessageW(hWnd, WM_GETTEXT, sizeof(String) / sizeof(WCHAR), (LPARAM)String)) return TRUE; // No window title dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId); std::wcout << L"PID: " << dwProcessId << L'\t' << String << L'\t' << std::endl; return TRUE; } int main() { if (IsWindowsXPOrGreater()) { std::wcout << L"Available Targets:\n\n" << std::endl; EnumWindows(EnumWindowsProc, NULL); std::wcout << L"\nPick Target ProcessID" << std::endl; DWORD PID; std::cin >> PID; InjectDLL(PID); } else { std::wcout << L"Method not supported by OS. Terminating" << std::endl; return 0; } return 0; }
Leave a Comment