3 * ===============================================================
4 * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC.
6 * ===============================================================
8 * This file is part of the SourceMod/SourcePawn SDK. This file may only be
9 * used or modified under the Terms and Conditions of its License Agreement,
10 * which is found in public/licenses/LICENSE.txt. As of this notice, derivative
11 * works must be licensed under the GNU General Public License (version 2 or
12 * greater). A copy of the GPL is included under public/licenses/GPL.txt.
14 * To view the latest information, see: http://www.sourcemod.net/license.php
19 #ifndef _INCLUDE_SMEXT_BINTOOLS_H_
20 #define _INCLUDE_SMEXT_BINTOOLS_H_
22 #include <IShareSys.h>
24 #define SMINTERFACE_BINTOOLS_NAME "IBinTools"
25 #define SMINTERFACE_BINTOOLS_VERSION 2
28 * @brief Function calling encoding utilities
35 * @brief Supported calling conventions
39 CallConv_ThisCall, /**< This call (object pointer required) */
40 CallConv_Cdecl, /**< Standard C call */
44 * @brief Describes how a parameter should be passed
48 PassType_Basic, /**< Plain old register data (pointers, integers) */
49 PassType_Float, /**< Floating point data */
50 PassType_Object, /**< Object or structure */
53 #define PASSFLAG_BYVAL (1<<0) /**< Passing by value */
54 #define PASSFLAG_BYREF (1<<1) /**< Passing by reference */
55 #define PASSFLAG_ODTOR (1<<2) /**< Object has a destructor */
56 #define PASSFLAG_OCTOR (1<<3) /**< Object has a constructor */
57 #define PASSFLAG_OASSIGNOP (1<<4) /**< Object has an assignment operator */
60 * @brief Parameter passing information
64 PassType type; /**< PassType value */
65 unsigned int flags; /**< Pass/return flags */
66 size_t size; /**< Size of the data being passed */
70 * @brief Parameter encoding information
74 PassInfo info; /**< Parameter information */
75 size_t offset; /**< Offset into the virtual stack */
79 * @brief Wraps a C/C++ call.
85 * @brief Returns the calling convention.
87 * @return CallConvention value.
89 virtual CallConvention GetCallConvention() =0;
92 * @brief Returns parameter info.
94 * @param num Parameter number to get (starting from 0).
95 * @return A PassInfo pointer.
97 virtual const PassEncode *GetParamInfo(unsigned int num) =0;
100 * @brief Returns return type info.
102 * @return A PassInfo pointer.
104 virtual const PassInfo *GetReturnInfo() =0;
107 * @brief Returns the number of parameters.
109 * @return Number of parameters.
111 virtual unsigned int GetParamCount() =0;
114 * @brief Execute the contained function.
116 * @param vParamStack A blob of memory containing stack data.
117 * @param retBuffer Buffer to store return value.
119 virtual void Execute(void *vParamStack, void *retBuffer) =0;
122 * @brief Destroys all resources used by this object.
124 virtual void Destroy() =0;
128 * @brief Binary tools interface.
130 class IBinTools : public SMInterface
133 virtual const char *GetInterfaceName()
135 return SMINTERFACE_BINTOOLS_NAME;
137 virtual unsigned int GetInterfaceVersion()
139 return SMINTERFACE_BINTOOLS_VERSION;
143 * @brief Creates a call decoder.
145 * Note: CallConv_ThisCall requires an implicit first parameter
146 * of PassType_Basic / PASSFLAG_BYVAL / sizeof(void *). However,
147 * this should only be given to the Execute() function, and never
148 * listed in the paramInfo array.
150 * @param address Address to use as a call.
151 * @param cv Calling convention.
152 * @param retInfo Return type information, or NULL for void.
153 * @param paramInfo Array of parameters.
154 * @param numParams Number of parameters in the array.
155 * @return A new ICallWrapper function.
157 virtual ICallWrapper *CreateCall(void *address,
159 const PassInfo *retInfo,
160 const PassInfo paramInfo[],
161 unsigned int numParams) =0;
164 * @brief Creates a vtable call decoder.
166 * Note: CallConv_ThisCall requires an implicit first parameter
167 * of PassType_Basic / PASSFLAG_BYVAL / sizeof(void *). However,
168 * this should only be given to the Execute() function, and never
169 * listed in the paramInfo array.
171 * @param vtblIdx Index into the virtual table.
172 * @param vtblOffs Offset of the virtual table.
173 * @param thisOffs Offset of the this pointer of the virtual table.
174 * @param retInfo Return type information, or NULL for void.
175 * @param paramInfo Array of parameters.
176 * @param numParams Number of parameters in the array.
177 * @return A new ICallWrapper function.
179 virtual ICallWrapper *CreateVCall(unsigned int vtblIdx,
180 unsigned int vtblOffs,
181 unsigned int thisOffs,
182 const PassInfo *retInfo,
183 const PassInfo paramInfo[],
184 unsigned int numParams) =0;
188 #endif //_INCLUDE_SMEXT_BINTOOLS_H_