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

钩子与API截获

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. //
  3. // ApplicationScope.h
  4. //
  5. // SUBSYSTEM:   Hook system
  6. //
  7. // MODULE:      Hook server
  8. //
  9. // DESCRIPTION: Implementation of the CApplicationScope class.
  10. //              This class is designed to provide single interface for 
  11. //              all hook related activities.
  12. // 
  13. //             
  14. // AUTHOR: Ivo Ivanov (ivopi@hotmail.com)
  15. // DATE: 2001 December v1.00
  16. //
  17. //---------------------------------------------------------------------------
  18. #include "stdafx.h"
  19. #include "HookSrv.h"
  20. #include "ApplicationScope.h"
  21. //---------------------------------------------------------------------------
  22. //
  23. // class CApplicationScope 
  24. //
  25. //---------------------------------------------------------------------------
  26. //---------------------------------------------------------------------------
  27. //
  28. // Static memeber declarations
  29. //
  30. //---------------------------------------------------------------------------
  31. CApplicationScope* CApplicationScope::sm_pInstance = NULL;
  32. //---------------------------------------------------------------------------
  33. //
  34. // Constructor
  35. //
  36. //---------------------------------------------------------------------------
  37. CApplicationScope::CApplicationScope():
  38. m_hmodHookTool(NULL),
  39. m_pfnInstallHook(NULL)
  40. {
  41. }
  42. //---------------------------------------------------------------------------
  43. //
  44. // Destructor 
  45. //
  46. //---------------------------------------------------------------------------
  47. CApplicationScope::~CApplicationScope()
  48. {
  49. if (m_hmodHookTool)
  50. ::FreeLibrary( m_hmodHookTool );
  51. }
  52. //---------------------------------------------------------------------------
  53. //
  54. // Copy constructor
  55. //
  56. //---------------------------------------------------------------------------
  57. CApplicationScope::CApplicationScope(const CApplicationScope& rhs)
  58. {
  59. }
  60. //---------------------------------------------------------------------------
  61. //
  62. // Assignment operator
  63. //
  64. //---------------------------------------------------------------------------
  65. CApplicationScope& CApplicationScope::operator=(const CApplicationScope& rhs)
  66. {
  67. if (this == &rhs) 
  68. return *this;
  69. return *this; // return reference to left-hand object
  70. }
  71. //---------------------------------------------------------------------------
  72. // GetInstance
  73. //
  74. // Implements the "double-checking" locking pattern combined with 
  75. // Scott Meyers single instance
  76. // For more details see - 
  77. // 1. "Modern C++ Design" by Andrei Alexandrescu - 6.9 Living in a 
  78. //     Multithreaded World
  79. // 2. "More Effective C++" by Scott Meyers - Item 26
  80. //---------------------------------------------------------------------------
  81. CApplicationScope& CApplicationScope::GetInstance()
  82. {
  83. if (!sm_pInstance)
  84. {
  85. CLockMgr<CCSWrapper> guard(g_AppSingeltonLock, TRUE);
  86. if (!sm_pInstance)
  87. {
  88. static CApplicationScope instance;
  89. sm_pInstance = &instance;
  90. }
  91. } // if
  92. return *sm_pInstance;
  93. }
  94. //---------------------------------------------------------------------------
  95. // InstallHook
  96. //
  97. // Delegates the call to the DLL InstallHook function
  98. //---------------------------------------------------------------------------
  99. void CApplicationScope::InstallHook(BOOL bActivate, HWND hwndServer)
  100. {
  101. if (NULL == m_hmodHookTool)
  102. {
  103. m_hmodHookTool = ::LoadLibrary( "HookTool.Dll" );
  104. if (NULL != m_hmodHookTool)
  105. m_pfnInstallHook = (PFN_INSTALLHOOK)::GetProcAddress(
  106. m_hmodHookTool, 
  107. "InstallHook"
  108. );
  109. } // if
  110. if (m_pfnInstallHook)
  111. m_pfnInstallHook(bActivate, hwndServer);
  112. }
  113. //---------------------------------------------------------------------------
  114. // OnDllLoaded
  115. //
  116. // Fired when a process loads hooktool dll
  117. //---------------------------------------------------------------------------
  118. void CApplicationScope::OnDllLoaded(DWORD dwProcessId)
  119. {
  120. }
  121. //---------------------------------------------------------------------------
  122. // OnDllUnLoaded
  123. //
  124. // Fired when a process unloads hooktool dll
  125. //---------------------------------------------------------------------------
  126. void CApplicationScope::OnDllUnLoaded(DWORD dwProcessId)
  127. {
  128. }
  129. //----------------------------End of the file -------------------------------