CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2006
    Posts
    99

    Arrow <<<hook api with detours>>>

    hi people,

    i found a library called detours from microsoft web site (http://research.microsoft.com/sn/detours/). it is a library for hooking api. i checked out the samples it encloses, it can embed a piece of dll program which contain the "hook" function to an EXE at runtime.

    and then, it uses GetCurrentThread() function to get the current thread and inject the hook function.

    to hook the function, the dll's source looks like this:

    DetourTransactionBegin();
    //get current thread
    DetourUpdateThread(GetCurrentThread());
    //actually attach the hoop function to the current thread
    DetourAttach(&(PVOID&) hookpointer , originalpointer );
    DetourTransactionCommit();

    but i don't want to write the hook function in a dll, i want to implement the whole thing in an EXE, so that i can fully control the hook function with the outside EXE.

    i don't know how to get a thread of another process. is there any winapi to replace the GetCurrentThread()?

    why hook api programes like the detours samples are always written as DLLs? can i just write it in an EXE and control the hook function's behavior during the target applictation's runtime?

  2. #2
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: <<<hook api with detours>>>

    Simplified explanation: to create a hook, you have to inject some code into a process. To make injection possible, injected code has to be contained in some module, which can be loaded by target process. EXEs are not modules, which can be loaded by processes. Dynamic libraries are. So, you have to place injected code inside of dynamic library.

    Injecting code is quite complicated process, with lots of Windows mechanics involved, so complete explanation is much more complicated.

    Cheers
    B+!
    'There is no cat' - A. Einstein

    Use &#91;code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  3. #3

    Re: <<<hook api with detours>>>

    You need use a dll to inject the target process.
    Best Api Monitor tool.
    Trace the target program automatically and monitor the parameters of all API and COM interfaces.

    Auto Debug for Windows 4.0
    Auto Debug for .Net
    http://www.autodebug.com/

  4. #4
    Join Date
    Jan 2006
    Posts
    99

    Unhappy Re: <<<hook api with detours>>>

    thank you.

    then how to control the dll that is embeded into the exe with another process?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured