问下各位大佬C++handle方面的问题
现在我想要通过进程和线程handle对一个程序注入dll,我现在能获取到的信息只有该程序的PID。现在的场景是在游戏运行中获取handle然后进行注入。
我尝试过用OpenProcess()获得进程handle,然后进行注入,但是并不能注入成功。能注入成功的只有通过CreateProcess()获得的handle。求问下各位大佬,如何在游戏运行中获得与CreateProcess一样的handle。
以下为注入代码
void KInject::InjectDll(HANDLE hProcess, HANDLE hThread, ULONG_PTR param){
QueueUserAPC(
(PAPCFUNC)GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA"),
hThread,
(ULONG_PTR)param
);
}
void KInject::Inject2(HANDLE hProcess, HANDLE hThread, const char* szDLL ){
SIZE_T len = strlen(szDLL) + 1;
PVOID param = VirtualAllocEx(hProcess, NULL, len, MEM_COMMIT | MEM_TOP_DOWN /*MEM_RESERVE*/, PAGE_READWRITE);
if (param != NULL)
{
SIZE_T ret;
if (WriteProcessMemory(hProcess, param, szDLL, len, &ret)) {
InjectDll(hProcess, hThread, (ULONG_PTR)param );
}
}
}#C/C++#
我尝试过用OpenProcess()获得进程handle,然后进行注入,但是并不能注入成功。能注入成功的只有通过CreateProcess()获得的handle。求问下各位大佬,如何在游戏运行中获得与CreateProcess一样的handle。
以下为注入代码
void KInject::InjectDll(HANDLE hProcess, HANDLE hThread, ULONG_PTR param){
QueueUserAPC(
(PAPCFUNC)GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA"),
hThread,
(ULONG_PTR)param
);
}
void KInject::Inject2(HANDLE hProcess, HANDLE hThread, const char* szDLL ){
SIZE_T len = strlen(szDLL) + 1;
PVOID param = VirtualAllocEx(hProcess, NULL, len, MEM_COMMIT | MEM_TOP_DOWN /*MEM_RESERVE*/, PAGE_READWRITE);
if (param != NULL)
{
SIZE_T ret;
if (WriteProcessMemory(hProcess, param, szDLL, len, &ret)) {
InjectDll(hProcess, hThread, (ULONG_PTR)param );
}
}
}#C/C++#