00001 /** 00002 * vim: set ts=4 : 00003 * ============================================================================= 00004 * SourceMod BinTools Extension 00005 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. 00006 * ============================================================================= 00007 * 00008 * This program is free software; you can redistribute it and/or modify it under 00009 * the terms of the GNU General Public License, version 3.0, as published by the 00010 * Free Software Foundation. 00011 * 00012 * This program is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00014 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00015 * details. 00016 * 00017 * You should have received a copy of the GNU General Public License along with 00018 * this program. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 * As a special exception, AlliedModders LLC gives you permission to link the 00021 * code of this program (as well as its derivative works) to "Half-Life 2," the 00022 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software 00023 * by the Valve Corporation. You must obey the GNU General Public License in 00024 * all respects for all other code used. Additionally, AlliedModders LLC grants 00025 * this exception to all derivative works. AlliedModders LLC defines further 00026 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), 00027 * or <http://www.sourcemod.net/license.php>. 00028 * 00029 * Version: $Id: IBinTools.h 1964 2008-03-27 04:54:56Z damagedsoul $ 00030 */ 00031 00032 #ifndef _INCLUDE_SMEXT_BINTOOLS_H_ 00033 #define _INCLUDE_SMEXT_BINTOOLS_H_ 00034 00035 #include <IShareSys.h> 00036 00037 #define SMINTERFACE_BINTOOLS_NAME "IBinTools" 00038 #define SMINTERFACE_BINTOOLS_VERSION 2 00039 00040 /** 00041 * @brief Function calling encoding utilities 00042 * @file IBinTools.h 00043 */ 00044 00045 namespace SourceMod 00046 { 00047 /** 00048 * @brief Supported calling conventions 00049 */ 00050 enum CallConvention 00051 { 00052 CallConv_ThisCall, /**< This call (object pointer required) */ 00053 CallConv_Cdecl, /**< Standard C call */ 00054 }; 00055 00056 /** 00057 * @brief Describes how a parameter should be passed 00058 */ 00059 enum PassType 00060 { 00061 PassType_Basic, /**< Plain old register data (pointers, integers) */ 00062 PassType_Float, /**< Floating point data */ 00063 PassType_Object, /**< Object or structure */ 00064 }; 00065 00066 #define PASSFLAG_BYVAL (1<<0) /**< Passing by value */ 00067 #define PASSFLAG_BYREF (1<<1) /**< Passing by reference */ 00068 #define PASSFLAG_ODTOR (1<<2) /**< Object has a destructor */ 00069 #define PASSFLAG_OCTOR (1<<3) /**< Object has a constructor */ 00070 #define PASSFLAG_OASSIGNOP (1<<4) /**< Object has an assignment operator */ 00071 00072 /** 00073 * @brief Parameter passing information 00074 */ 00075 struct PassInfo 00076 { 00077 PassType type; /**< PassType value */ 00078 unsigned int flags; /**< Pass/return flags */ 00079 size_t size; /**< Size of the data being passed */ 00080 }; 00081 00082 /** 00083 * @brief Parameter encoding information 00084 */ 00085 struct PassEncode 00086 { 00087 PassInfo info; /**< Parameter information */ 00088 size_t offset; /**< Offset into the virtual stack */ 00089 }; 00090 00091 /** 00092 * @brief Wraps a C/C++ call. 00093 */ 00094 class ICallWrapper 00095 { 00096 public: 00097 /** 00098 * @brief Returns the calling convention. 00099 * 00100 * @return CallConvention value. 00101 */ 00102 virtual CallConvention GetCallConvention() =0; 00103 00104 /** 00105 * @brief Returns parameter info. 00106 * 00107 * @param num Parameter number to get (starting from 0). 00108 * @return A PassInfo pointer. 00109 */ 00110 virtual const PassEncode *GetParamInfo(unsigned int num) =0; 00111 00112 /** 00113 * @brief Returns return type info. 00114 * 00115 * @return A PassInfo pointer. 00116 */ 00117 virtual const PassInfo *GetReturnInfo() =0; 00118 00119 /** 00120 * @brief Returns the number of parameters. 00121 * 00122 * @return Number of parameters. 00123 */ 00124 virtual unsigned int GetParamCount() =0; 00125 00126 /** 00127 * @brief Execute the contained function. 00128 * 00129 * @param vParamStack A blob of memory containing stack data. 00130 * @param retBuffer Buffer to store return value. 00131 */ 00132 virtual void Execute(void *vParamStack, void *retBuffer) =0; 00133 00134 /** 00135 * @brief Destroys all resources used by this object. 00136 */ 00137 virtual void Destroy() =0; 00138 }; 00139 00140 /** 00141 * @brief Binary tools interface. 00142 */ 00143 class IBinTools : public SMInterface 00144 { 00145 public: 00146 virtual const char *GetInterfaceName() 00147 { 00148 return SMINTERFACE_BINTOOLS_NAME; 00149 } 00150 virtual unsigned int GetInterfaceVersion() 00151 { 00152 return SMINTERFACE_BINTOOLS_VERSION; 00153 } 00154 public: 00155 /** 00156 * @brief Creates a call decoder. 00157 * 00158 * Note: CallConv_ThisCall requires an implicit first parameter 00159 * of PassType_Basic / PASSFLAG_BYVAL / sizeof(void *). However, 00160 * this should only be given to the Execute() function, and never 00161 * listed in the paramInfo array. 00162 * 00163 * @param address Address to use as a call. 00164 * @param cv Calling convention. 00165 * @param retInfo Return type information, or NULL for void. 00166 * @param paramInfo Array of parameters. 00167 * @param numParams Number of parameters in the array. 00168 * @return A new ICallWrapper function. 00169 */ 00170 virtual ICallWrapper *CreateCall(void *address, 00171 CallConvention cv, 00172 const PassInfo *retInfo, 00173 const PassInfo paramInfo[], 00174 unsigned int numParams) =0; 00175 00176 /** 00177 * @brief Creates a vtable call decoder. 00178 * 00179 * Note: CallConv_ThisCall requires an implicit first parameter 00180 * of PassType_Basic / PASSFLAG_BYVAL / sizeof(void *). However, 00181 * this should only be given to the Execute() function, and never 00182 * listed in the paramInfo array. 00183 * 00184 * @param vtblIdx Index into the virtual table. 00185 * @param vtblOffs Offset of the virtual table. 00186 * @param thisOffs Offset of the this pointer of the virtual table. 00187 * @param retInfo Return type information, or NULL for void. 00188 * @param paramInfo Array of parameters. 00189 * @param numParams Number of parameters in the array. 00190 * @return A new ICallWrapper function. 00191 */ 00192 virtual ICallWrapper *CreateVCall(unsigned int vtblIdx, 00193 unsigned int vtblOffs, 00194 unsigned int thisOffs, 00195 const PassInfo *retInfo, 00196 const PassInfo paramInfo[], 00197 unsigned int numParams) =0; 00198 }; 00199 } 00200 00201 #endif //_INCLUDE_SMEXT_BINTOOLS_H_
1.5.1