Removed IsBadReadPtr and BadReadHandler from CSourceHookImpl to fix Linux compile bug
1 /* ======== SourceHook ========
2 * Copyright (C) 2004-2005 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): Pavol "PM OnoTo" Marko
8 * ============================
11 #ifndef __SOURCEHOOK_IMPL_H__
12 #define __SOURCEHOOK_IMPL_H__
14 #include "sourcehook.h"
21 // Set this to 1 to enable runtime code generation (faster)
22 #define SH_RUNTIME_CODEGEN 1
27 * @brief The SourceHook implementation class
29 class CSourceHookImpl : public ISourceHook
32 * @brief A hook can be removed if you have this information
36 RemoveHookInfo(Plugin pplug, void *piface, int tpo, HookManagerPubFunc phookman,
37 ISHDelegate *phandler, bool ppost)
38 : plug(pplug), iface(piface), thisptr_offs(tpo),
39 hookman(phookman), handler(phandler), post(ppost)
46 HookManagerPubFunc hookman;
52 * @brief A list of HookManagerInfo structures
54 typedef std::list<HookManagerInfo> HookManInfoList;
60 bool operator==(void *other)
62 return cc.ptr == other;
66 * @brief A list of CallClass structures
68 typedef std::list<CallClassInfo> Impl_CallClassList;
70 Impl_CallClassList m_CallClasses; //!< A list of already generated callclasses
71 HookManInfoList m_HookMans; //!< A list of hook managers
74 * @brief Finds a hook manager for a function based on a text-prototype, a vtable offset and a vtable index
76 HookManInfoList::iterator FindHookMan(HookManInfoList::iterator begin, HookManInfoList::iterator end,
77 const char *proto, int vtblofs, int vtblidx);
79 void ApplyCallClassPatch(CallClassInfo &cc, int vtbl_offs, int vtbl_idx, void *orig_entry);
80 void ApplyCallClassPatches(CallClassInfo &cc);
81 void ApplyCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx, void *orig_entry);
82 void RemoveCallClassPatch(CallClassInfo &cc, int vtbl_offs, int vtbl_idx);
83 void RemoveCallClassPatches(void *ifaceptr, int vtbl_offs, int vtbl_idx);
85 META_RES m_Status, m_PrevRes, m_CurRes;
86 const void *m_OrigRet;
87 const void *m_OverrideRet;
94 * @brief Returns the interface version
96 int GetIfaceVersion();
99 * @brief Returns the implemnetation version
101 int GetImplVersion();
104 * @brief Make sure that a plugin is not used by any other plugins anymore, and unregister all its hook managers
106 void UnloadPlugin(Plugin plug);
109 * @brief Shut down the whole system, unregister all hook managers
111 void CompleteShutdown();
116 * @return True if the function succeeded, false otherwise
118 * @param plug The unique identifier of the plugin that calls this function
119 * @param iface The interface pointer
120 * @param ifacesize The size of the class iface points to
121 * @param myHookMan A hook manager function that should be capable of handling the function
122 * @param handler A pointer to a FastDelegate containing the hook handler
123 * @param post Set to true if you want a post handler
125 bool AddHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post);
128 * @brief Removes a hook.
130 * @return True if the function succeeded, false otherwise
132 * @param plug The unique identifier of the plugin that calls this function
133 * @param iface The interface pointer
134 * @param thisptr_offs This pointer adjuster
135 * @param myHookMan A hook manager function that should be capable of handling the function
136 * @param handler A pointer to a FastDelegate containing the hook handler
137 * @param post Set to true if you want a post handler
139 bool RemoveHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post);
142 * @brief Removes a hook.
144 * @ return True if the function succeeded, false otherwise
146 * @param info A RemoveHookInfo structure, describing the hook
148 bool RemoveHook(RemoveHookInfo info);
151 * @brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
153 * @param plug The unique identifier of the plugin in question
155 bool IsPluginInUse(Plugin plug);
158 * @brief Pauses all hooks of a plugin
160 * @param plug The unique identifier of the plugin
162 void PausePlugin(Plugin plug);
165 * @brief Unpauses all hooks of a plugin
167 * @param plug The unique identifier of the plugin
169 void UnpausePlugin(Plugin plug);
172 * @brief Return a pointer to a callclass. Generate a new one if required.
174 * @param iface The interface pointer
175 * @param size Size of the class instance
177 GenericCallClass *GetCallClass(void *iface, size_t size);
180 * @brief Release a callclass
182 * @param ptr Pointer to the callclass
184 virtual void ReleaseCallClass(GenericCallClass *ptr);
186 virtual void SetRes(META_RES res); //!< Sets the meta result
187 virtual META_RES GetPrevRes(); //!< Gets the meta result of the previously called handler
188 virtual META_RES GetStatus(); //!< Gets the highest meta result
189 virtual const void *GetOrigRet(); //!< Gets the original result. If not in post function, undefined
190 virtual const void *GetOverrideRet(); //!< Gets the override result. If none is specified, NULL
191 virtual void *GetIfacePtr(); //!< Gets the interface pointer
193 //////////////////////////////////////////////////////////////////////////
195 virtual META_RES &GetCurResRef(); //!< Gets the reference to the current meta result
196 virtual META_RES &GetPrevResRef(); //!< Gets the reference to the previous meta result
197 virtual META_RES &GetStatusRef(); //!< Gets the reference to the status variable
198 virtual void* &GetIfacePtrRef(); //!< Gets the reference to the iface ptr
199 virtual void SetOrigRet(const void *ptr); //!< Sets the original return pointer
200 virtual void SetOverrideRet(const void *ptr); //!< Sets the override result pointer
205 * @brief Checks to see if a memory value can be read from a given pointer.
207 * @return True if the value can be read and false if it cannot.
209 * @param ptr The pointer to the memory value.
210 * @param len The length of the memory value to be read from the pointer.
212 bool IsBadReadPtr(const void *ptr, size_t len);
213 void BadReadHandler(int sig);
215 bool g_BadReadCalled;
216 jmp_buf g_BadReadJmpBuf;