NtProcessMonitor.h
上传用户:jstlsd
上传日期:2007-01-13
资源大小:186k
文件大小:2k
源码类别:

钩子与API截获

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. //
  3. // NtProcessMonitor.h
  4. //
  5. // SUBSYSTEM: 
  6. // API Hooking system
  7. // MODULE:    
  8. // Implements a thread that uses an NT device driver
  9. //              for monitoring process creation
  10. //
  11. // DESCRIPTION:
  12. //
  13. // AUTHOR: Ivo Ivanov (ivopi@hotmail.com)
  14. //                                                                         
  15. //---------------------------------------------------------------------------
  16. #if !defined(_NTPROCESSMONITOR_H_)
  17. #define _NTPROCESSMONITOR_H_
  18. #if _MSC_VER > 1000
  19. #pragma once
  20. #endif // _MSC_VER > 1000
  21. #include "..CommonLockMgr.h"
  22. //---------------------------------------------------------------------------
  23. //
  24. // typedefs
  25. //
  26. //---------------------------------------------------------------------------
  27. // Structure for Process callback information
  28. typedef struct _CallbackInfo
  29. {
  30.     HANDLE  ParentId;
  31.     HANDLE  ProcessId;
  32.     BOOLEAN bCreate;
  33. } CALLBACK_INFO, *PCALLBACK_INFO;
  34. //---------------------------------------------------------------------------
  35. //
  36. // Forward declararion
  37. //
  38. //---------------------------------------------------------------------------
  39. class CNtDriverController;
  40. //---------------------------------------------------------------------------
  41. //
  42. // class CNtProcessMonitor
  43. //
  44. //---------------------------------------------------------------------------
  45. class CNtProcessMonitor  
  46. {
  47. public:
  48. CNtProcessMonitor();
  49. virtual ~CNtProcessMonitor();
  50. //
  51. // Activate / Stop the thread which gets the notification from the 
  52. // device driver
  53. //
  54. void SetActive(BOOL bVal);
  55. HANDLE Get_ShutdownEvent() const;
  56. HANDLE Get_ProcessEvent() const;
  57. //
  58. // Retrieves data from the driver after received notification 
  59. //
  60. void RetrieveProcessInfo(
  61. CALLBACK_INFO& callbackInfo,
  62. CALLBACK_INFO& callbackTemp
  63. );
  64. protected:
  65. virtual void OnCreateProcess(DWORD dwProcessId) = 0;
  66. virtual void OnTerminateProcess(DWORD dwProcessId) = 0;
  67. private:
  68. BOOL Get_ThreadActive();
  69. void Set_ThreadActive(BOOL val);
  70. static unsigned __stdcall ThreadFunc(void* pvParam);
  71. CNtDriverController* m_pDriverCtl;
  72. CCSWrapper           m_CritSec;
  73. HANDLE               m_hShutdownEvent;
  74. HANDLE               m_hProcessEvent; 
  75. BOOL                 m_bThreadActive;
  76. DWORD                m_dwThreadId;
  77. HANDLE               m_hDriver;
  78. };
  79. #endif // !defined(_NTPROCESSMONITOR_H_)
  80. //----------------------------End of the file -------------------------------