110,534
社区成员
发帖
与我相关
我的任务
分享
DWORD StartInject(HANDLE hProcess, LPTHREAD_START_ROUTINE function, wchar_t * data)
{
auto buffLen = (wcslen(data) + 1) * sizeof(wchar_t);
void* remote = ::VirtualAllocEx(hProcess, NULL, buffLen, MEM_COMMIT, PAGE_READWRITE);
if (remote)
{
::WriteProcessMemory(hProcess, remote, data, buffLen, NULL);
auto hThread = ::CreateRemoteThread(hProcess, NULL, 0, function, remote, 0, NULL);
::WaitForSingleObject(hThread, INFINITE);
DWORD exitCode;
::GetExitCodeThread(hThread, &exitCode);
::CloseHandle(hThread);
::VirtualFreeEx(hProcess, remote, 0, MEM_RELEASE);
return exitCode;
}
return 0;
}