我对Microsoft Detours图书馆有几个简单的问题。我已经使用过它(成功),但我只是想过这个功能:Microsoft Detours - DetourUpdateThread?
LONG DetourUpdateThread(HANDLE hThread);
我在别处读到这个函数实际上会挂起线程直到事务完成。这似乎很奇怪,因为大多数示例代码调用:
DetourUpdateThread(GetCurrentThread());无论如何,显然这个函数“登记”了线程,以便当事务提交(和绕行)时,如果它们位于目标函数或蹦床函数的重写代码内,它们的指令指针就会被修改“。
我的问题是:
当事务提交时,是当前线程的指令指针将成为DetourTransactionCommit函数内?如果是这样,我们为什么要打扰它更新?另外,如果入伍线程被挂起,当前线程如何继续执行(假定大多数示例代码调用DetourUpdateThread(GetCurrentThread());)?
最后,您可以暂停当前进程的所有线程,避免竞争条件(考虑到线程可能随时被创建和销毁)?也许这是在交易开始时完成的?这将允许我们更安全地枚举线程(因为看起来不太可能创建新线程),但CreateRemoteThread()如何?
感谢,
保罗
仅供参考,下面是摘录从简单的示例:
// DllMain function attaches and detaches the TimedSleep detour to the
// Sleep target function. The Sleep target function is referred to
// through the TrueSleep target pointer.
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
if (dwReason == DLL_PROCESS_ATTACH) {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)TrueSleep, TimedSleep);
DetourTransactionCommit();
}
else if (dwReason == DLL_PROCESS_DETACH) {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)TrueSleep, TimedSleep);
DetourTransactionCommit();
}
return TRUE;
}
感谢分享! – Danra 2012-08-01 11:30:23