Detours中的函数,是正确实施HOOK的基础,需要详细了解其意义。在这里对基本的挂钩操作函数稍作小结。

 1、DetourTransactionBegin()

    开始一次挂钩或者解除挂钩。

 

     备注:DetourTransactionBegin begins a new transaction for attaching or detaching detours.(此函数开始一个新的转换的开始或者已有转换的结束)

    After beginning a transaction, a program calls the DetourAttach or DetourAttachEx API to attach a detour to a target function, calls the DetourDetach API to detach a detour from a target function, or calls the DetourUpdateThread API to include include a thread in the transaction update.(调用此函数之后,可以使用DetourAttach和DetourAttachEx函数挂钩目标函数,使用DetourDetch函数解除函数的挂钩行为,使用DetourUpdateThread函数去加入待HOOK的线程)

    The attach, detach, and thread operations do not take effect until the program commits the transaction using the DetourTransactionCommit or DetourTransactionCommitEx API. Alternatively, the program can abort the transaction using the DetourTransactionAbort API.(但所有的操作,只有到程序提交DetourTransactionCommit或者DetourTransactionCommitEx函数之后才能生效)

2、LONG DetourUpdateThread(HANDLE hThread );

   加入待HOOK的线程,包含一个参数,就是待HOOK的线程的线程号。

   备注:这个函数在DetourTransactionBegin之后调用,且必须。

3、LONG DetourAttach( PVOID * ppPointer, PVOID pDetour );

   对一个API进行HOOK,前一个参数是目标函数,后一个函数为新函数。

 4、LONG DetourDetach(PVOID * ppPointer, PVOID pDetour );

    基础对API函数的挂钩操作,参数的顺序及内容同HOOK函数。

5、LONG DetourTransactionCommit();

   提交由DetourTransactionBegin()开启的挂钩行为。