Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to hook windows'socket functions using SetWindowsHookEx function

How to hook windows'socket functions using SetWindowsHookEx function

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vietth2004
    wrote on last edited by
    #1

    Please help me! I am writing a small program that I want to uses the Hook function for windows'socket functions like recv, send,... I have tried to uses the function SetWindowsHookEx: HHOOK SetWindowsHookEx( int idHook, HOOKPROC lpfn, HINSTANCE hMod, DWORD dwThreadId ); But it seems to have too fews argument.It has only 4 arguments: one for the type of hook, one for the address of the function to be hooked, one for the instance that contain the function, one for the thread that the function is running in. I cannot find out where to put the address of the new function that I want to put into the hook chain. Please show me where to put the new function's address, how to uses the SetWindowsHookEx function and how its argument work. Thank you very much!

    S H P 3 Replies Last reply
    0
    • V vietth2004

      Please help me! I am writing a small program that I want to uses the Hook function for windows'socket functions like recv, send,... I have tried to uses the function SetWindowsHookEx: HHOOK SetWindowsHookEx( int idHook, HOOKPROC lpfn, HINSTANCE hMod, DWORD dwThreadId ); But it seems to have too fews argument.It has only 4 arguments: one for the type of hook, one for the address of the function to be hooked, one for the instance that contain the function, one for the thread that the function is running in. I cannot find out where to put the address of the new function that I want to put into the hook chain. Please show me where to put the new function's address, how to uses the SetWindowsHookEx function and how its argument work. Thank you very much!

      S Offline
      S Offline
      Sarath C
      wrote on last edited by
      #2

      lpfn parameter is the HOOKPROC. you can pass the function handle there. But i think you are trying to do something like sniffing right? Search codeproject for "Sniffer" you will get plenty of tools with source code. SetWindowsHookEx allows us to HOOK these types

      WH_CALLWNDPROC Thread or global
      WH_CALLWNDPROCRET Thread or global
      WH_CBT Thread or global
      WH_DEBUG Thread or global
      WH_FOREGROUNDIDLE Thread or global
      WH_GETMESSAGE Thread or global
      WH_JOURNALPLAYBACK Global only
      WH_JOURNALRECORD Global only
      WH_KEYBOARD Thread or global
      WH_KEYBOARD_LL Global only
      WH_MOUSE Thread or global
      WH_MOUSE_LL Global only
      WH_MSGFILTER Thread or global
      WH_SHELL Thread or global
      WH_SYSMSGFILTER Global only

      AFAIK it is not possible to hook socket using this API. SaRath.
      _"It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar."


      My Blog | Understanding State Pattern in C++_

      1 Reply Last reply
      0
      • V vietth2004

        Please help me! I am writing a small program that I want to uses the Hook function for windows'socket functions like recv, send,... I have tried to uses the function SetWindowsHookEx: HHOOK SetWindowsHookEx( int idHook, HOOKPROC lpfn, HINSTANCE hMod, DWORD dwThreadId ); But it seems to have too fews argument.It has only 4 arguments: one for the type of hook, one for the address of the function to be hooked, one for the instance that contain the function, one for the thread that the function is running in. I cannot find out where to put the address of the new function that I want to put into the hook chain. Please show me where to put the new function's address, how to uses the SetWindowsHookEx function and how its argument work. Thank you very much!

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        vietth2004 wrote:

        how to uses the SetWindowsHookEx function and how its argument work.

        See API Hooking Revealed [^]and Hooking the Keyboard [^] maybe it is some helpful to you_**


        **_

        whitesky


        1 Reply Last reply
        0
        • V vietth2004

          Please help me! I am writing a small program that I want to uses the Hook function for windows'socket functions like recv, send,... I have tried to uses the function SetWindowsHookEx: HHOOK SetWindowsHookEx( int idHook, HOOKPROC lpfn, HINSTANCE hMod, DWORD dwThreadId ); But it seems to have too fews argument.It has only 4 arguments: one for the type of hook, one for the address of the function to be hooked, one for the instance that contain the function, one for the thread that the function is running in. I cannot find out where to put the address of the new function that I want to put into the hook chain. Please show me where to put the new function's address, how to uses the SetWindowsHookEx function and how its argument work. Thank you very much!

          P Offline
          P Offline
          pgibson007700
          wrote on last edited by
          #4

          You could look at the following http://www.codeproject.com/dll/apihijack.asp[^] which has a simple example showing how to hook API's.

          V 1 Reply Last reply
          0
          • P pgibson007700

            You could look at the following http://www.codeproject.com/dll/apihijack.asp[^] which has a simple example showing how to hook API's.

            V Offline
            V Offline
            vietth2004
            wrote on last edited by
            #5

            Thank you very much!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups