Advertisement
encoree1996

Untitled

Nov 2nd, 2015
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #pragma once
  2. class CVMTHookManager
  3. {
  4. public:
  5. CVMTHookManager( void )
  6. {
  7. memset( this, 0, sizeof( CVMTHookManager ) );
  8. }
  9.  
  10. CVMTHookManager( PDWORD* ppdwClassBase )
  11. {
  12. bInitialize( ppdwClassBase );
  13. }
  14.  
  15. ~CVMTHookManager( void )
  16. {
  17. UnHook( );
  18. }
  19. bool bInitialize( PDWORD* ppdwClassBase )
  20. {
  21. m_ppdwClassBase = ppdwClassBase;
  22. m_pdwOldVMT = *ppdwClassBase;
  23. m_dwVMTSize = dwGetVMTCount( *ppdwClassBase );
  24. m_pdwNewVMT = new DWORD[ m_dwVMTSize ];
  25. memcpy( m_pdwNewVMT, m_pdwOldVMT, sizeof( DWORD ) * m_dwVMTSize );
  26. *ppdwClassBase = m_pdwNewVMT;
  27. return true;
  28. }
  29. bool bInitialize( PDWORD** pppdwClassBase ) // fix for pp
  30. {
  31. return bInitialize( *pppdwClassBase );
  32. }
  33.  
  34. void UnHook( void )
  35. {
  36. if ( m_ppdwClassBase )
  37. {
  38. *m_ppdwClassBase = m_pdwOldVMT;
  39. }
  40. }
  41.  
  42. void ReHook( void )
  43. {
  44. if ( m_ppdwClassBase )
  45. {
  46. *m_ppdwClassBase = m_pdwNewVMT;
  47. }
  48. }
  49.  
  50. int iGetFuncCount( void )
  51. {
  52. return (int)m_dwVMTSize;
  53. }
  54.  
  55. DWORD dwGetMethodAddress( int Index )
  56. {
  57. if ( Index >= 0 && Index <= (int)m_dwVMTSize && m_pdwOldVMT != NULL )
  58. {
  59. return m_pdwOldVMT[ Index ];
  60. }
  61. return NULL;
  62. }
  63.  
  64. PDWORD pdwGetOldVMT( void )
  65. {
  66. return m_pdwOldVMT;
  67. }
  68.  
  69. DWORD dwHookMethod( DWORD dwNewFunc, unsigned int iIndex )
  70. {
  71. if ( m_pdwNewVMT && m_pdwOldVMT && iIndex <= m_dwVMTSize && iIndex >= 0 )
  72. {
  73. m_pdwNewVMT[ iIndex ] = dwNewFunc;
  74. return m_pdwOldVMT[ iIndex ];
  75. }
  76.  
  77. return NULL;
  78. }
  79.  
  80. private:
  81. DWORD dwGetVMTCount( PDWORD pdwVMT )
  82. {
  83. DWORD dwIndex = 0;
  84.  
  85. for ( dwIndex = 0; pdwVMT[ dwIndex ]; dwIndex++ )
  86. {
  87. if ( IsBadCodePtr( (FARPROC)pdwVMT[ dwIndex ] ) )
  88. {
  89. break;
  90. }
  91. }
  92. return dwIndex;
  93. }
  94. PDWORD* m_ppdwClassBase;
  95. PDWORD m_pdwNewVMT, m_pdwOldVMT;
  96. DWORD m_dwVMTSize;
  97. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement