Advertisement
encoree1996

Untitled

Apr 23rd, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 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. DWORD dwOldProtect;
  27. VirtualProtect(ppdwClassBase, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect);
  28. *ppdwClassBase = m_pdwNewVMT;
  29. VirtualProtect(ppdwClassBase, 4, dwOldProtect, &dwOldProtect);
  30. return true;
  31. }
  32. bool bInitialize(PDWORD** pppdwClassBase) // fix for pp
  33. {
  34. return bInitialize(*pppdwClassBase);
  35. }
  36.  
  37. void UnHook(void)
  38. {
  39. if(m_ppdwClassBase)
  40. {
  41. *m_ppdwClassBase = m_pdwOldVMT;
  42. }
  43. }
  44.  
  45. void ReHook(void)
  46. {
  47. if(m_ppdwClassBase)
  48. {
  49. *m_ppdwClassBase = m_pdwNewVMT;
  50. }
  51. }
  52.  
  53. int iGetFuncCount(void)
  54. {
  55. return (int)m_dwVMTSize;
  56. }
  57.  
  58. DWORD dwGetMethodAddress(int Index)
  59. {
  60. if(Index >= 0 && Index <= (int)m_dwVMTSize && m_pdwOldVMT != NULL)
  61. {
  62. return m_pdwOldVMT[Index];
  63. }
  64. return NULL;
  65. }
  66.  
  67. PDWORD pdwGetOldVMT(void)
  68. {
  69. return m_pdwOldVMT;
  70. }
  71.  
  72. DWORD dwHookMethod(DWORD dwNewFunc, unsigned int iIndex)
  73. {
  74. if(m_pdwNewVMT && m_pdwOldVMT && iIndex <= m_dwVMTSize && iIndex >= 0)
  75. {
  76. DWORD addr = m_pdwNewVMT[iIndex];
  77. DWORD lpflOldProtect;
  78. VirtualProtect((PVOID)addr, 4, PAGE_EXECUTE_READWRITE, &lpflOldProtect);
  79. *(DWORD *)addr = dwNewFunc;
  80. VirtualProtect((PVOID)addr, 4, lpflOldProtect, &lpflOldProtect);
  81. //m_pdwNewVMT[ iIndex ] = dwNewFunc;
  82. return m_pdwOldVMT[iIndex];
  83. }
  84.  
  85. return NULL;
  86. }
  87.  
  88. private:
  89. DWORD dwGetVMTCount(PDWORD pdwVMT)
  90. {
  91. DWORD dwIndex = 0;
  92.  
  93. for(dwIndex = 0; pdwVMT[dwIndex]; dwIndex++)
  94. {
  95. if(IsBadCodePtr((FARPROC)pdwVMT[dwIndex]))
  96. {
  97. break;
  98. }
  99. }
  100. return dwIndex;
  101. }
  102. PDWORD* m_ppdwClassBase;
  103. PDWORD m_pdwNewVMT, m_pdwOldVMT;
  104. DWORD m_dwVMTSize;
  105. };
  106. extern CVMTHookManager* pPanelHook;
  107. extern CVMTHookManager* pCreateMoveHook;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement