Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void InjectDll(unsigned int ProcessId, char *DllName)
- {
- HANDLE hProcess;
- hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, ProcessId);
- unsigned int RemoteString;
- RemoteString = (unsigned int) VirtualAllocEx(hProcess, 0, strlen(DllName) + 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
- WriteProcessMemory(hProcess, (void*) RemoteString, DllName, strlen(DllName) + 1, 0);
- unsigned int RemoteThread;
- RemoteThread = (unsigned int) GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");
- HANDLE hThread;
- hThread = CreateRemoteThread(hProcess, 0, 0, (LPTHREAD_START_ROUTINE) RemoteThread, (void*) RemoteString, 0, 0);
- WaitForSingleObject(hThread, INFINITE);
- CloseHandle(hThread);
- VirtualFreeEx(hProcess, (void*) RemoteString, strlen(DllName) + 1, MEM_RELEASE);
- CloseHandle(hProcess);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement