网上查阅GetExitCodeThread() 函数的作用是这个函数是获得线程的退出码,为何退出码恰好等于函数句柄?
相关代码如下:
// 请把代码文本粘贴到下方(请勿用图片代替代码)
【函数1:】
DWORD getMyBaseAddressGMH()
{
return (DWORD)GetModuleHandle(NULL);
}
【函数2:】
DWORD getRemoteBaseAddress(HANDLE process)
{
DWORD newBase;
// get the address of kernel32.dll
HMODULE k32 = GetModuleHandleA("kernel32.dll");
// get the address of GetModuleHandle()
LPVOID funcAdr = GetProcAddress(k32, "GetModuleHandleA");
if (!funcAdr) funcAdr = GetProcAddress(k32, "GetModuleHandleW");
// create the thread
HANDLE thread = CreateRemoteThread(process, NULL, NULL, (LPTHREAD_START_ROUTINE)funcAdr, NULL, NULL, NULL);
// let the thread finish
WaitForSingleObject(thread, INFINITE);
// get the exit code
GetExitCodeThread(thread, &newBase);
printf("ExitCode is : %d\n", newBase);
// clean up the thread handle
CloseHandle(thread);
return newBase;
}