Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- LPCSTR windowName{ "AssaultCube" };
- LPCSTR fullDLLPath{ "C:\\Users\\SKOLZA\\source\\repos\\ActuallyWorkingACwallhack\\legitDLL\\legitDLL\\Debug\\legitDLL.dll" };
- SIZE_T dllPathSize{ strlen(fullDLLPath) };
- int main() {
- // Get the handle to the window. Needed in order to later get the id of the process of the window.
- HWND windowHandle{ FindWindowA(NULL, windowName) };
- if (!windowHandle) {
- std::cout << "Something went wrong with getting the window handle. Error Code: " << GetLastError() << "\n";
- return 1;
- }
- std::cout << "Successfully got the handle for the window.\n";
- // Get the process id of the window.
- DWORD pId{};
- GetWindowThreadProcessId(windowHandle, &pId);
- if (!pId) {
- std::cout << "Something went wrong with getting the process ID of the window.\n";
- return 1;
- }
- std::cout << "The process ID is: " << pId << ".\n";
- // Open a handle to the process.
- HANDLE hProc{ OpenProcess(PROCESS_ALL_ACCESS, false, pId) };
- if (!hProc) {
- std::cout << "Something went wrong with opening a handle to the process. Error Code: " << GetLastError() << "\n";
- return 1;
- }
- std::cout << "Successfully got the handle for the process.\n";
- // Allocate memory in the process.
- LPVOID vAlloc{ VirtualAllocEx(hProc, NULL, dllPathSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE) };
- if (!vAlloc) {
- std::cout << "Something went wrong with VirtualAllocEx. Error Code: " << GetLastError() << "\n";
- return 1;
- }
- std::cout << "Successfully allocated memory.\n";
- // Write our DLL path into allocated memory.
- BOOL wpMem{ WriteProcessMemory(hProc, vAlloc, fullDLLPath, dllPathSize, NULL) };
- if (!wpMem) {
- std::cout << "Something went wrong with WriteProcessMemory. Error Code: " << GetLastError() << "\n";
- return 1;
- }
- std::cout << "Successfully wrote dll path into allocated memory.\n";
- // Locate and save the LoadLibraryA function in the kernel32.dll module.
- FARPROC loadLibraryAddress{ GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA") };
- if (!loadLibraryAddress) {
- std::cout << "Something went wrong with GetProcAddress. Error Code: " << GetLastError() << "\n";
- return 1;
- }
- // Create a thread which runs LoadLibraryA using vAlloc as the parameter.
- HANDLE remoteThread{ CreateRemoteThread(hProc, NULL, NULL, (LPTHREAD_START_ROUTINE)loadLibraryAddress, vAlloc, NULL, NULL) };
- if (!remoteThread) {
- std::cout << "Something went wrong with CreateRemoteThread. Error Code: " << GetLastError() << "\n";
- return 1;
- }
- std::cout << "DLL Injection Successful!\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement