1.1 --- a/sourcehook/sourcehook_impl_cvfnptr.h Sat Oct 13 20:15:58 2007 +0000
1.2 +++ b/sourcehook/sourcehook_impl_cvfnptr.h Sun Oct 14 11:59:13 2007 +0000
1.3 @@ -12,6 +12,7 @@
1.4 #define __SOURCEHOOK_IMPL_CVFNPTR_H__
1.5
1.6 #include "sh_list.h"
1.7 +#include "sh_memory.h"
1.8
1.9 namespace SourceHook
1.10 {
1.11 @@ -23,6 +24,7 @@
1.12 void *m_Ptr;
1.13 void *m_OrigEntry;
1.14
1.15 + List<CHookManager*> m_HookMans;
1.16 List<CIface> m_IfaceList;
1.17 public:
1.18 // *** Descriptor ***
1.19 @@ -30,6 +32,7 @@
1.20
1.21 // *** Interface ***
1.22 inline CVfnPtr(void *ptr);
1.23 + inline ~CVfnPtr();
1.24 inline bool operator==(const Descriptor &other);
1.25 inline void *GetPtr() const;
1.26 inline void *GetOrigEntry() const;
1.27 @@ -39,6 +42,11 @@
1.28 CIface &GetIface(void *iface);
1.29 bool Patch(void *newValue);
1.30 inline bool Revert();
1.31 +
1.32 + void AddHookMan(CHookManager *pHookMan);
1.33 + // If this returns false, it means that there is no hook manager left
1.34 + // to use and that this vfnptr should be removed.
1.35 + bool HookManRemoved(CHookManager *pHookMan);
1.36 };
1.37
1.38 // *** Implementation ***
1.39 @@ -47,6 +55,12 @@
1.40 {
1.41 }
1.42
1.43 + inline CVfnPtr::~CVfnPtr()
1.44 + {
1.45 + if (!m_HookMans.empty())
1.46 + m_HookMans.front()->DecrRef(this);
1.47 + }
1.48 +
1.49 inline bool CVfnPtr::operator==(const Descriptor &other)
1.50 {
1.51 return m_Ptr == other;
1.52 @@ -74,7 +88,18 @@
1.53
1.54 inline bool CVfnPtr::Revert()
1.55 {
1.56 - return Patch(m_OrigEntry);
1.57 + // Only patch the vfnptr back if the module is still in memory
1.58 + // If it's not, do not remove stuff like we did before
1.59 + // First off we did it wrong (shutdown the whole hookman, uh..) and secondly applications may be
1.60 + // confused by RemoveHook returning false then (yeah, I know, I made this one up, no one checks for RemoveHook error)
1.61 + if (ModuleInMemory(reinterpret_cast<char*>(m_Ptr), SH_PTRSIZE))
1.62 + {
1.63 + return Patch(m_OrigEntry);
1.64 + }
1.65 + else
1.66 + {
1.67 + return true;
1.68 + }
1.69 }
1.70
1.71 inline CIface *CVfnPtr::FindIface(void *iface)