mirror of
https://github.com/alliedmodders/sourcemod.git
synced 2025-12-07 10:28:34 +00:00
Strip sourcehook from bintools
This commit is contained in:
parent
f7b797e03b
commit
aaea454680
@ -663,7 +663,7 @@ else:
|
||||
'loader/AMBuilder',
|
||||
'core/AMBuilder',
|
||||
'core/logic/AMBuilder',
|
||||
#'extensions/bintools/AMBuilder',
|
||||
'extensions/bintools/AMBuilder',
|
||||
#'extensions/clientprefs/AMBuilder',
|
||||
#'extensions/curl/AMBuilder',
|
||||
#'extensions/cstrike/AMBuilder',
|
||||
|
||||
@ -30,53 +30,82 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include "CallMaker.h"
|
||||
#include "jit_compile.h"
|
||||
#include "extension.h"
|
||||
|
||||
/* SourceMod <==> SourceHook type conversion functions */
|
||||
|
||||
SourceHook::ProtoInfo::CallConvention GetSHCallConvention(SourceMod::CallConvention cv)
|
||||
class CProtoInfoBuilder
|
||||
{
|
||||
if (cv < SourceMod::CallConv_ThisCall || cv > SourceMod::CallConv_Cdecl)
|
||||
ProtoInfo m_PI;
|
||||
std::vector<PassInfo> m_Params;
|
||||
public:
|
||||
CProtoInfoBuilder(int cc)
|
||||
{
|
||||
return SourceHook::ProtoInfo::CallConv_Unknown;
|
||||
memset(reinterpret_cast<void*>(&m_PI), 0, sizeof(ProtoInfo));
|
||||
m_PI.convention = cc;
|
||||
|
||||
// dummy 0 params
|
||||
PassInfo dummy;
|
||||
memset(reinterpret_cast<void*>(&dummy), 0, sizeof(PassInfo));
|
||||
|
||||
dummy.size = 1; // Version1
|
||||
|
||||
m_Params.push_back(dummy);
|
||||
}
|
||||
|
||||
return (SourceHook::ProtoInfo::CallConvention)(cv + 1);
|
||||
}
|
||||
|
||||
SourceMod::CallConvention GetSMCallConvention(SourceHook::ProtoInfo::CallConvention cv)
|
||||
{
|
||||
assert(cv >= SourceHook::ProtoInfo::CallConv_ThisCall || cv <= SourceHook::ProtoInfo::CallConv_Cdecl);
|
||||
|
||||
return (SourceMod::CallConvention)(cv - 1);
|
||||
}
|
||||
|
||||
SourceHook::PassInfo::PassType GetSHPassType(SourceMod::PassType type)
|
||||
{
|
||||
if (type < SourceMod::PassType_Basic || type > SourceMod::PassType_Object)
|
||||
void SetReturnType(size_t size, PassType type, int flags,
|
||||
void *pNormalCtor, void *pCopyCtor, void *pDtor, void *pAssignOperator)
|
||||
{
|
||||
return SourceHook::PassInfo::PassType_Unknown;
|
||||
if (pNormalCtor)
|
||||
flags |= PASSFLAG_OCTOR;
|
||||
|
||||
//if (pCopyCtor)
|
||||
// flags |= PassInfo::PassFlag_CCtor;
|
||||
|
||||
if (pDtor)
|
||||
flags |= PASSFLAG_ODTOR;
|
||||
|
||||
if (pAssignOperator)
|
||||
flags |= PASSFLAG_OASSIGNOP;
|
||||
|
||||
m_PI.retPassInfo.size = size;
|
||||
m_PI.retPassInfo.type = type;
|
||||
m_PI.retPassInfo.flags = flags;
|
||||
}
|
||||
|
||||
return (SourceHook::PassInfo::PassType)(type + 1);
|
||||
}
|
||||
void AddParam(size_t size, PassType type, int flags,
|
||||
void *pNormalCtor, void *pCopyCtor, void *pDtor, void *pAssignOperator)
|
||||
{
|
||||
PassInfo pi;
|
||||
|
||||
SourceMod::PassType GetSMPassType(int type)
|
||||
{
|
||||
/* SourceMod doesn't provide an Unknown type so we it must be an error */
|
||||
assert(type >= SourceHook::PassInfo::PassType_Basic && type <= SourceHook::PassInfo::PassType_Object);
|
||||
if (pNormalCtor)
|
||||
flags |= PASSFLAG_OCTOR;
|
||||
|
||||
return (SourceMod::PassType)(type - 1);
|
||||
}
|
||||
//if (pCopyCtor)
|
||||
// flags |= PassInfo::PassFlag_CCtor;
|
||||
|
||||
void GetSMPassInfo(SourceMod::PassInfo *out, const SourceHook::PassInfo *in)
|
||||
{
|
||||
out->size = in->size;
|
||||
out->flags = in->flags;
|
||||
out->type = GetSMPassType(in->type);
|
||||
}
|
||||
if (pDtor)
|
||||
flags |= PASSFLAG_ODTOR;
|
||||
|
||||
if (pAssignOperator)
|
||||
flags |= PASSFLAG_OASSIGNOP;
|
||||
|
||||
|
||||
pi.size = size;
|
||||
pi.type = type;
|
||||
pi.flags = flags;
|
||||
|
||||
m_Params.push_back(pi);
|
||||
++m_PI.numOfParams;
|
||||
}
|
||||
|
||||
operator ProtoInfo*()
|
||||
{
|
||||
m_PI.paramsPassInfo = &(m_Params[0]);
|
||||
return &m_PI;
|
||||
}
|
||||
};
|
||||
|
||||
ICallWrapper *CallMaker::CreateCall(void *address,
|
||||
CallConvention cv,
|
||||
@ -85,22 +114,22 @@ ICallWrapper *CallMaker::CreateCall(void *address,
|
||||
unsigned int numParams,
|
||||
unsigned int fnFlags)
|
||||
{
|
||||
SourceHook::CProtoInfoBuilder protoInfo(GetSHCallConvention(cv));
|
||||
CProtoInfoBuilder protoInfo(cv);
|
||||
|
||||
for (unsigned int i=0; i<numParams; i++)
|
||||
{
|
||||
protoInfo.AddParam(paramInfo[i].size, GetSHPassType(paramInfo[i].type), paramInfo[i].flags,
|
||||
protoInfo.AddParam(paramInfo[i].size, paramInfo[i].type, paramInfo[i].flags,
|
||||
NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
if (retInfo)
|
||||
{
|
||||
protoInfo.SetReturnType(retInfo->size, GetSHPassType(retInfo->type), retInfo->flags,
|
||||
protoInfo.SetReturnType(retInfo->size, retInfo->type, retInfo->flags,
|
||||
NULL, NULL, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
protoInfo.SetReturnType(0, SourceHook::PassInfo::PassType_Unknown, 0,
|
||||
protoInfo.SetReturnType(0, PassType_Basic, 0,
|
||||
NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
@ -119,39 +148,34 @@ ICallWrapper *CallMaker::CreateVCall(unsigned int vtblIdx,
|
||||
unsigned int numParams,
|
||||
unsigned int fnFlags)
|
||||
{
|
||||
SourceHook::MemFuncInfo info;
|
||||
info.isVirtual = true;
|
||||
info.vtblindex = vtblIdx;
|
||||
info.vtbloffs = vtblOffs;
|
||||
info.thisptroffs = thisOffs;
|
||||
|
||||
SourceHook::CProtoInfoBuilder protoInfo(SourceHook::ProtoInfo::CallConv_ThisCall);
|
||||
CProtoInfoBuilder protoInfo(CallConv_ThisCall);
|
||||
|
||||
for (unsigned int i=0; i<numParams; i++)
|
||||
{
|
||||
protoInfo.AddParam(paramInfo[i].size, GetSHPassType(paramInfo[i].type), paramInfo[i].flags,
|
||||
protoInfo.AddParam(paramInfo[i].size, paramInfo[i].type, paramInfo[i].flags,
|
||||
NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
if (retInfo)
|
||||
{
|
||||
protoInfo.SetReturnType(retInfo->size, GetSHPassType(retInfo->type), retInfo->flags,
|
||||
protoInfo.SetReturnType(retInfo->size, retInfo->type, retInfo->flags,
|
||||
NULL, NULL, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
protoInfo.SetReturnType(0, SourceHook::PassInfo::PassType_Unknown, 0,
|
||||
protoInfo.SetReturnType(0, PassType::PassType_Basic, 0,
|
||||
NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
#if defined KE_ARCH_X64
|
||||
return g_CallMaker2.CreateVirtualCall(&(*protoInfo), &info, retInfo, paramInfo, fnFlags);
|
||||
return g_CallMaker2.CreateVirtualCall(&(*protoInfo), vtblIdx, retInfo, paramInfo, fnFlags);
|
||||
#else
|
||||
return g_CallMaker2.CreateVirtualCall(&(*protoInfo), &info);
|
||||
return g_CallMaker2.CreateVirtualCall(&(*protoInfo), vtblIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
ICallWrapper *CallMaker2::CreateCall(void *address, const SourceHook::ProtoInfo *protoInfo)
|
||||
ICallWrapper *CallMaker2::CreateCall(void *address, const ProtoInfo *protoInfo)
|
||||
{
|
||||
#ifdef KE_ARCH_X86
|
||||
CallWrapper *pWrapper = new CallWrapper(protoInfo);
|
||||
@ -166,12 +190,11 @@ ICallWrapper *CallMaker2::CreateCall(void *address, const SourceHook::ProtoInfo
|
||||
#endif
|
||||
}
|
||||
|
||||
ICallWrapper *CallMaker2::CreateVirtualCall(const SourceHook::ProtoInfo *protoInfo,
|
||||
const SourceHook::MemFuncInfo *info)
|
||||
ICallWrapper *CallMaker2::CreateVirtualCall(const ProtoInfo* protoInfo, uint32_t vtable_index)
|
||||
{
|
||||
#ifdef KE_ARCH_X86
|
||||
CallWrapper *pWrapper = new CallWrapper(protoInfo);
|
||||
pWrapper->SetMemFuncInfo(info);
|
||||
pWrapper->SetVtableIndex(vtable_index);
|
||||
|
||||
void *addr = JIT_CallCompile(pWrapper, FuncAddr_VTable);
|
||||
pWrapper->SetCodeBaseAddr(addr);
|
||||
@ -182,7 +205,7 @@ ICallWrapper *CallMaker2::CreateVirtualCall(const SourceHook::ProtoInfo *protoIn
|
||||
#endif
|
||||
}
|
||||
|
||||
ICallWrapper *CallMaker2::CreateCall(void *address, const SourceHook::ProtoInfo *protoInfo,
|
||||
ICallWrapper *CallMaker2::CreateCall(void *address, const ProtoInfo *protoInfo,
|
||||
const PassInfo *retInfo, const PassInfo paramInfo[],
|
||||
unsigned int fnFlags)
|
||||
{
|
||||
@ -199,15 +222,15 @@ ICallWrapper *CallMaker2::CreateCall(void *address, const SourceHook::ProtoInfo
|
||||
#endif
|
||||
}
|
||||
|
||||
ICallWrapper *CallMaker2::CreateVirtualCall(const SourceHook::ProtoInfo *protoInfo,
|
||||
const SourceHook::MemFuncInfo *info,
|
||||
ICallWrapper *CallMaker2::CreateVirtualCall(const ProtoInfo *protoInfo,
|
||||
uint32_t vtable_index,
|
||||
const PassInfo *retInfo,
|
||||
const PassInfo paramInfo[],
|
||||
unsigned int fnFlags)
|
||||
{
|
||||
#ifdef KE_ARCH_X64
|
||||
CallWrapper *pWrapper = new CallWrapper(protoInfo, retInfo, paramInfo, fnFlags);
|
||||
pWrapper->SetMemFuncInfo(info);
|
||||
pWrapper->SetVtableIndex(vtable_index);
|
||||
|
||||
void *addr = JIT_CallCompile(pWrapper, FuncAddr_VTable);
|
||||
pWrapper->SetCodeBaseAddr(addr);
|
||||
@ -216,23 +239,4 @@ ICallWrapper *CallMaker2::CreateVirtualCall(const SourceHook::ProtoInfo *protoIn
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
IHookWrapper *CallMaker2::CreateVirtualHook(SourceHook::ISourceHook *pSH,
|
||||
const SourceHook::ProtoInfo *protoInfo,
|
||||
const SourceHook::MemFuncInfo *info,
|
||||
VIRTUAL_HOOK_PROTO f)
|
||||
{
|
||||
HookWrapper *pWrapper = new HookWrapper(pSH, protoInfo, const_cast<SourceHook::MemFuncInfo *>(info), (void *)f);
|
||||
|
||||
void *addr = JIT_HookCompile(pWrapper);
|
||||
pWrapper->SetHookWrpAddr(addr);
|
||||
|
||||
ICallWrapper *callWrap = CreateVirtualCall(protoInfo, info);
|
||||
pWrapper->SetCallWrapperAddr(callWrap);
|
||||
|
||||
return pWrapper;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
@ -34,6 +34,7 @@
|
||||
|
||||
|
||||
#include "CallWrapper.h"
|
||||
#include "stdint.h"
|
||||
|
||||
using namespace SourceMod;
|
||||
|
||||
@ -59,30 +60,18 @@ class CallMaker2
|
||||
{
|
||||
public: //IBinTools2
|
||||
virtual ICallWrapper *CreateCall(void *address,
|
||||
const SourceHook::ProtoInfo *protoInfo);
|
||||
virtual ICallWrapper *CreateVirtualCall(const SourceHook::ProtoInfo *protoInfo,
|
||||
const SourceHook::MemFuncInfo *info);
|
||||
ICallWrapper *CreateCall(void *address, const SourceHook::ProtoInfo *protoInfo,
|
||||
const ProtoInfo *protoInfo);
|
||||
virtual ICallWrapper *CreateVirtualCall(const ProtoInfo *protoInfo,
|
||||
uint32_t vtable_index);
|
||||
ICallWrapper *CreateCall(void *address, const ProtoInfo *protoInfo,
|
||||
const PassInfo *retInfo, const PassInfo paramInfo[], unsigned int fnFlags);
|
||||
ICallWrapper *CreateVirtualCall(const SourceHook::ProtoInfo *protoInfo,
|
||||
const SourceHook::MemFuncInfo *info, const PassInfo *retInfo,
|
||||
ICallWrapper *CreateVirtualCall(const ProtoInfo *protoInfo,
|
||||
uint32_t vtable_index, const PassInfo *retInfo,
|
||||
const PassInfo paramInfo[], unsigned int fnFlags);
|
||||
#if 0
|
||||
virtual IHookWrapper *CreateVirtualHook(SourceHook::ISourceHook *pSH,
|
||||
const SourceHook::ProtoInfo *protoInfo,
|
||||
const SourceHook::MemFuncInfo *info,
|
||||
VIRTUAL_HOOK_PROTO f);
|
||||
#endif
|
||||
};
|
||||
|
||||
extern CallMaker2 g_CallMaker2;
|
||||
|
||||
SourceHook::ProtoInfo::CallConvention GetSHCallConvention(SourceMod::CallConvention cv);
|
||||
SourceMod::CallConvention GetSMCallConvention(SourceHook::ProtoInfo::CallConvention cv);
|
||||
SourceHook::PassInfo::PassType GetSHPassType(SourceMod::PassType type);
|
||||
SourceMod::PassType GetSMPassType(int type);
|
||||
void GetSMPassInfo(SourceMod::PassInfo *out, const SourceHook::PassInfo *in);
|
||||
|
||||
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_CALLMAKER_H_
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
#include "CallWrapper.h"
|
||||
#include "CallMaker.h"
|
||||
|
||||
CallWrapper::CallWrapper(const SourceHook::ProtoInfo *protoInfo) : m_FnFlags(0)
|
||||
CallWrapper::CallWrapper(const ProtoInfo *protoInfo) : m_FnFlags(0)
|
||||
{
|
||||
m_AddrCodeBase = NULL;
|
||||
m_AddrCallee = NULL;
|
||||
@ -41,15 +41,15 @@ CallWrapper::CallWrapper(const SourceHook::ProtoInfo *protoInfo) : m_FnFlags(0)
|
||||
unsigned int argnum = protoInfo->numOfParams;
|
||||
|
||||
m_Info = *protoInfo;
|
||||
m_Info.paramsPassInfo = new SourceHook::PassInfo[argnum + 1];
|
||||
memcpy((void *)m_Info.paramsPassInfo, protoInfo->paramsPassInfo, sizeof(SourceHook::PassInfo) * (argnum+1));
|
||||
m_Info.paramsPassInfo = new PassInfo[argnum + 1];
|
||||
memcpy((void *)m_Info.paramsPassInfo, protoInfo->paramsPassInfo, sizeof(PassInfo) * (argnum+1));
|
||||
|
||||
if (argnum)
|
||||
{
|
||||
m_Params = new PassEncode[argnum];
|
||||
for (size_t i=0; i<argnum; i++)
|
||||
{
|
||||
GetSMPassInfo(&(m_Params[i].info), &(m_Info.paramsPassInfo[i+1]));
|
||||
m_Params[i].info = m_Info.paramsPassInfo[i+1];
|
||||
}
|
||||
} else {
|
||||
m_Params = NULL;
|
||||
@ -57,8 +57,7 @@ CallWrapper::CallWrapper(const SourceHook::ProtoInfo *protoInfo) : m_FnFlags(0)
|
||||
|
||||
if (m_Info.retPassInfo.size != 0)
|
||||
{
|
||||
m_RetParam = new PassInfo;
|
||||
GetSMPassInfo(m_RetParam, &(m_Info.retPassInfo));
|
||||
m_RetParam = new PassInfo(m_Info.retPassInfo);
|
||||
} else {
|
||||
m_RetParam = NULL;
|
||||
}
|
||||
@ -66,7 +65,7 @@ CallWrapper::CallWrapper(const SourceHook::ProtoInfo *protoInfo) : m_FnFlags(0)
|
||||
/* Calculate virtual stack offsets for each parameter */
|
||||
size_t offs = 0;
|
||||
|
||||
if (m_Info.convention == SourceHook::ProtoInfo::CallConv_ThisCall)
|
||||
if (m_Info.convention == CallConvention::CallConv_ThisCall)
|
||||
{
|
||||
offs += sizeof(void *);
|
||||
}
|
||||
@ -77,7 +76,7 @@ CallWrapper::CallWrapper(const SourceHook::ProtoInfo *protoInfo) : m_FnFlags(0)
|
||||
}
|
||||
}
|
||||
|
||||
CallWrapper::CallWrapper(const SourceHook::ProtoInfo *protoInfo, const PassInfo *retInfo,
|
||||
CallWrapper::CallWrapper(const ProtoInfo *protoInfo, const PassInfo *retInfo,
|
||||
const PassInfo paramInfo[], unsigned int fnFlags) : CallWrapper(protoInfo)
|
||||
{
|
||||
if (retInfo)
|
||||
@ -121,7 +120,7 @@ void CallWrapper::Destroy()
|
||||
CallConvention CallWrapper::GetCallConvention()
|
||||
{
|
||||
/* Need to convert to a SourceMod convention for bcompat */
|
||||
return GetSMCallConvention((SourceHook::ProtoInfo::CallConvention)m_Info.convention);
|
||||
return (CallConvention)m_Info.convention;
|
||||
}
|
||||
|
||||
const PassEncode *CallWrapper::GetParamInfo(unsigned int num)
|
||||
@ -151,16 +150,6 @@ void CallWrapper::Execute(void *vParamStack, void *retBuffer)
|
||||
fn(vParamStack, retBuffer);
|
||||
}
|
||||
|
||||
void CallWrapper::SetMemFuncInfo(const SourceHook::MemFuncInfo *funcInfo)
|
||||
{
|
||||
m_FuncInfo = *funcInfo;
|
||||
}
|
||||
|
||||
SourceHook::MemFuncInfo *CallWrapper::GetMemFuncInfo()
|
||||
{
|
||||
return &m_FuncInfo;
|
||||
}
|
||||
|
||||
void CallWrapper::SetCalleeAddr(void *addr)
|
||||
{
|
||||
m_AddrCallee = addr;
|
||||
@ -181,26 +170,6 @@ void *CallWrapper::GetCodeBaseAddr()
|
||||
return m_AddrCodeBase;
|
||||
}
|
||||
|
||||
const SourceHook::PassInfo *CallWrapper::GetSHReturnInfo()
|
||||
{
|
||||
return &(m_Info.retPassInfo);
|
||||
}
|
||||
|
||||
SourceHook::ProtoInfo::CallConvention CallWrapper::GetSHCallConvention()
|
||||
{
|
||||
return (SourceHook::ProtoInfo::CallConvention)m_Info.convention;
|
||||
}
|
||||
|
||||
const SourceHook::PassInfo * CallWrapper::GetSHParamInfo(unsigned int num)
|
||||
{
|
||||
if (num + 1 > GetParamCount())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &(m_Info.paramsPassInfo[num+1]);
|
||||
}
|
||||
|
||||
unsigned int CallWrapper::GetParamOffset(unsigned int num)
|
||||
{
|
||||
assert(num < GetParamCount() && num >= 0);
|
||||
|
||||
@ -33,7 +33,6 @@
|
||||
#define _INCLUDE_SOURCEMOD_CALLWRAPPER_H_
|
||||
|
||||
#include <IBinTools.h>
|
||||
#include <sourcehook_pibuilder.h>
|
||||
|
||||
using namespace SourceMod;
|
||||
|
||||
@ -43,11 +42,24 @@ enum FuncAddrMethod
|
||||
FuncAddr_VTable
|
||||
};
|
||||
|
||||
struct ProtoInfo
|
||||
{
|
||||
int numOfParams; //!< number of parameters
|
||||
PassInfo retPassInfo; //!< PassInfo for the return value. size=0 -> no retval
|
||||
const PassInfo *paramsPassInfo; //!< PassInfos for the parameters
|
||||
|
||||
// paramsPassInfo[0] is basically a dummy parameter.
|
||||
// However, paramsPassInfo[0].size stores the version of the ProtoInfo structure.
|
||||
|
||||
// Extra info:
|
||||
int convention;
|
||||
};
|
||||
|
||||
class CallWrapper : public ICallWrapper
|
||||
{
|
||||
public:
|
||||
CallWrapper(const SourceHook::ProtoInfo *protoInfo);
|
||||
CallWrapper(const SourceHook::ProtoInfo *protoInfo, const PassInfo *retInfo,
|
||||
CallWrapper(const ProtoInfo *protoInfo);
|
||||
CallWrapper(const ProtoInfo *protoInfo, const PassInfo *retInfo,
|
||||
const PassInfo paramInfo[], unsigned int fnFlags);
|
||||
~CallWrapper();
|
||||
public: //ICallWrapper
|
||||
@ -57,26 +69,21 @@ public: //ICallWrapper
|
||||
unsigned int GetParamCount();
|
||||
void Execute(void *vParamStack, void *retBuffer);
|
||||
void Destroy();
|
||||
const SourceHook::PassInfo *GetSHReturnInfo();
|
||||
SourceHook::ProtoInfo::CallConvention GetSHCallConvention();
|
||||
const SourceHook::PassInfo *GetSHParamInfo(unsigned int num);
|
||||
unsigned int GetParamOffset(unsigned int num);
|
||||
unsigned int GetFunctionFlags();
|
||||
void SetVtableIndex(unsigned int);
|
||||
unsigned int GetVtableIndex();
|
||||
public:
|
||||
void SetCalleeAddr(void *addr);
|
||||
void SetCodeBaseAddr(void *addr);
|
||||
void *GetCalleeAddr();
|
||||
void *GetCodeBaseAddr();
|
||||
|
||||
void SetMemFuncInfo(const SourceHook::MemFuncInfo *funcInfo);
|
||||
SourceHook::MemFuncInfo *GetMemFuncInfo();
|
||||
private:
|
||||
PassEncode *m_Params;
|
||||
SourceHook::ProtoInfo m_Info;
|
||||
ProtoInfo m_Info;
|
||||
PassInfo *m_RetParam;
|
||||
void *m_AddrCallee;
|
||||
void *m_AddrCodeBase;
|
||||
SourceHook::MemFuncInfo m_FuncInfo;
|
||||
unsigned int m_FnFlags;
|
||||
};
|
||||
|
||||
|
||||
@ -111,13 +111,13 @@ inline void Write_Function_Epilogue(JitWriter *jit, bool is_void, bool has_param
|
||||
IA32_Return(jit);
|
||||
}
|
||||
|
||||
inline void Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *info, unsigned int offset)
|
||||
inline void Write_PushPOD(JitWriter *jit, const PassInfo& info, unsigned int offset)
|
||||
{
|
||||
jit_uint8_t reg = _DecodeRegister3(g_RegDecoder++);
|
||||
|
||||
if (info->flags & PASSFLAG_BYVAL)
|
||||
if (info.flags & PASSFLAG_BYVAL)
|
||||
{
|
||||
switch (info->size)
|
||||
switch (info.size)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
@ -200,7 +200,7 @@ inline void Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *info, unsi
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (info->flags & PASSFLAG_BYREF) {
|
||||
} else if (info.flags & PASSFLAG_BYREF) {
|
||||
//lea reg, [ebx+<offset>]
|
||||
//push reg
|
||||
if (!offset)
|
||||
@ -221,11 +221,11 @@ inline void Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *info, unsi
|
||||
}
|
||||
}
|
||||
|
||||
inline void Write_PushFloat(JitWriter *jit, const SourceHook::PassInfo *info, unsigned int offset)
|
||||
inline void Write_PushFloat(JitWriter *jit, const PassInfo& info, unsigned int offset)
|
||||
{
|
||||
if (info->flags & PASSFLAG_BYVAL)
|
||||
if (info.flags & PASSFLAG_BYVAL)
|
||||
{
|
||||
switch (info->size)
|
||||
switch (info.size)
|
||||
{
|
||||
case 4:
|
||||
{
|
||||
@ -264,7 +264,7 @@ inline void Write_PushFloat(JitWriter *jit, const SourceHook::PassInfo *info, un
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (info->flags & PASSFLAG_BYREF) {
|
||||
} else if (info.flags & PASSFLAG_BYREF) {
|
||||
//lea reg, [ebx+<offset>]
|
||||
//push reg
|
||||
if (!offset)
|
||||
@ -287,18 +287,18 @@ inline void Write_PushFloat(JitWriter *jit, const SourceHook::PassInfo *info, un
|
||||
}
|
||||
}
|
||||
|
||||
inline void Write_PushObject(JitWriter *jit, const SourceHook::PassInfo *info, unsigned int offset)
|
||||
inline void Write_PushObject(JitWriter *jit, const PassInfo& info, unsigned int offset)
|
||||
{
|
||||
if (info->flags & PASSFLAG_BYVAL)
|
||||
if (info.flags & PASSFLAG_BYVAL)
|
||||
{
|
||||
#ifdef PLATFORM_POSIX
|
||||
if (info->flags & PASSFLAG_ODTOR)
|
||||
if (info.flags & PASSFLAG_ODTOR)
|
||||
{
|
||||
goto push_byref;
|
||||
}
|
||||
#endif
|
||||
jit_uint32_t dwords = info->size >> 2;
|
||||
jit_uint32_t bytes = info->size & 0x3;
|
||||
jit_uint32_t dwords = info.size >> 2;
|
||||
jit_uint32_t bytes = info.size & 0x3;
|
||||
|
||||
//sub esp, <size>
|
||||
//cld
|
||||
@ -314,11 +314,11 @@ inline void Write_PushObject(JitWriter *jit, const SourceHook::PassInfo *info, u
|
||||
// rep movsb
|
||||
//pop esi
|
||||
//pop edi
|
||||
if (info->size < SCHAR_MAX)
|
||||
if (info.size < SCHAR_MAX)
|
||||
{
|
||||
IA32_Sub_Rm_Imm8(jit, kREG_ESP, (jit_int8_t)info->size, MOD_REG);
|
||||
IA32_Sub_Rm_Imm8(jit, kREG_ESP, (jit_int8_t)info.size, MOD_REG);
|
||||
} else {
|
||||
IA32_Sub_Rm_Imm32(jit, kREG_ESP, info->size, MOD_REG);
|
||||
IA32_Sub_Rm_Imm32(jit, kREG_ESP, info.size, MOD_REG);
|
||||
}
|
||||
IA32_Cld(jit);
|
||||
IA32_Push_Reg(jit, kREG_EDI);
|
||||
@ -347,8 +347,8 @@ inline void Write_PushObject(JitWriter *jit, const SourceHook::PassInfo *info, u
|
||||
IA32_Pop_Reg(jit, kREG_ESI);
|
||||
IA32_Pop_Reg(jit, kREG_EDI);
|
||||
|
||||
g_StackUsage += info->size;
|
||||
} else if (info->flags & PASSFLAG_BYREF) {
|
||||
g_StackUsage += info.size;
|
||||
} else if (info.flags & PASSFLAG_BYREF) {
|
||||
#ifdef PLATFORM_POSIX
|
||||
push_byref:
|
||||
#endif
|
||||
@ -410,9 +410,9 @@ inline void Write_CallFunction(JitWriter *jit, FuncAddrMethod method, CallWrappe
|
||||
//mov eax, [edx+<thisOffs>+<vtblOffs>]
|
||||
//mov edx, [eax+<vtblIdx>*4]
|
||||
//call edx
|
||||
SourceHook::MemFuncInfo *funcInfo = pWrapper->GetMemFuncInfo();
|
||||
jit_uint32_t total_offs = funcInfo->thisptroffs + funcInfo->vtbloffs;
|
||||
jit_uint32_t vfunc_pos = funcInfo->vtblindex * 4;
|
||||
//SourceHook::MemFuncInfo *funcInfo = pWrapper->GetMemFuncInfo();
|
||||
jit_uint32_t total_offs = 0; /*funcInfo->thisptroffs + funcInfo->vtbloffs;*/
|
||||
jit_uint32_t vfunc_pos = pWrapper->GetVtableIndex(); /*funcInfo->vtblindex * 4;*/
|
||||
|
||||
IA32_Mov_Reg_Rm(jit, kREG_EDX, kREG_EBX, MOD_MEM_REG);
|
||||
if (total_offs < SCHAR_MAX)
|
||||
@ -529,24 +529,24 @@ jit_rewind:
|
||||
for (jit_int32_t i=ParamCount-1; i>=0; i--)
|
||||
{
|
||||
unsigned int offset = pWrapper->GetParamOffset(i);
|
||||
const SourceHook::PassInfo *info = pWrapper->GetSHParamInfo(i);
|
||||
auto info = pWrapper->GetParamInfo(i);
|
||||
assert(info != NULL);
|
||||
|
||||
switch (info->type)
|
||||
switch (info->info.type)
|
||||
{
|
||||
case SourceHook::PassInfo::PassType_Basic:
|
||||
case PassType::PassType_Basic:
|
||||
{
|
||||
Write_PushPOD(jit, info, offset);
|
||||
Write_PushPOD(jit, info->info, offset);
|
||||
break;
|
||||
}
|
||||
case SourceHook::PassInfo::PassType_Float:
|
||||
case PassType::PassType_Float:
|
||||
{
|
||||
Write_PushFloat(jit, info, offset);
|
||||
Write_PushFloat(jit, info->info, offset);
|
||||
break;
|
||||
}
|
||||
case SourceHook::PassInfo::PassType_Object:
|
||||
case PassType::PassType_Object:
|
||||
{
|
||||
Write_PushObject(jit, info, offset);
|
||||
Write_PushObject(jit, info->info, offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,10 +273,10 @@ inline void Write_Function_Epilogue(JitWriter *jit, bool is_void, bool has_param
|
||||
X64_Return(jit);
|
||||
}
|
||||
|
||||
inline jit_uint8_t Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *info, unsigned int offset)
|
||||
inline jit_uint8_t Write_PushPOD(JitWriter *jit, const PassInfo& info, unsigned int offset)
|
||||
{
|
||||
bool needStack = false;
|
||||
jit_uint8_t reg = NextPODReg(info->size);
|
||||
jit_uint8_t reg = NextPODReg(info.size);
|
||||
jit_uint8_t reg2;
|
||||
|
||||
if (reg == STACK_PARAM)
|
||||
@ -285,9 +285,9 @@ inline jit_uint8_t Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *inf
|
||||
needStack = true;
|
||||
}
|
||||
|
||||
if (info->flags & PASSFLAG_BYVAL)
|
||||
if (info.flags & PASSFLAG_BYVAL)
|
||||
{
|
||||
switch (info->size)
|
||||
switch (info.size)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
@ -358,7 +358,7 @@ inline jit_uint8_t Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *inf
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (info->flags & PASSFLAG_BYREF) {
|
||||
} else if (info.flags & PASSFLAG_BYREF) {
|
||||
//lea reg, [ebx+<offset>]
|
||||
if (!offset)
|
||||
X64_Mov_Reg_Rm(jit, reg, kREG_RBX, MOD_REG);
|
||||
@ -384,7 +384,7 @@ inline jit_uint8_t Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *inf
|
||||
else
|
||||
X64_Mov_RmRSP_Disp32_Reg(jit, reg, g_StackUsage);
|
||||
|
||||
if (info->size == 16)
|
||||
if (info.size == 16)
|
||||
{
|
||||
if (g_StackUsage + 8 < SCHAR_MAX)
|
||||
X64_Mov_RmRSP_Disp8_Reg(jit, reg2, (jit_int8_t)g_StackUsage + 8);
|
||||
@ -399,10 +399,10 @@ inline jit_uint8_t Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *inf
|
||||
return reg;
|
||||
}
|
||||
|
||||
inline void Write_PushFloat(JitWriter *jit, const SourceHook::PassInfo *info, unsigned int offset, uint8_t *floatRegs)
|
||||
inline void Write_PushFloat(JitWriter *jit, const PassInfo& info, unsigned int offset, uint8_t *floatRegs)
|
||||
{
|
||||
bool needStack = false;
|
||||
jit_uint8_t floatReg = NextFloatReg(info->size);
|
||||
jit_uint8_t floatReg = NextFloatReg(info.size);
|
||||
jit_uint8_t floatReg2;
|
||||
|
||||
if (floatReg == STACK_PARAM)
|
||||
@ -411,9 +411,9 @@ inline void Write_PushFloat(JitWriter *jit, const SourceHook::PassInfo *info, un
|
||||
needStack = true;
|
||||
}
|
||||
|
||||
if (info->flags & PASSFLAG_BYVAL)
|
||||
if (info.flags & PASSFLAG_BYVAL)
|
||||
{
|
||||
switch (info->size)
|
||||
switch (info.size)
|
||||
{
|
||||
case 4:
|
||||
{
|
||||
@ -491,7 +491,7 @@ inline void Write_PushFloat(JitWriter *jit, const SourceHook::PassInfo *info, un
|
||||
X64_Movups_Rm_Disp32(jit, floatReg2, kREG_EBX, offset+8);
|
||||
}
|
||||
}
|
||||
} else if (info->flags & PASSFLAG_BYREF) {
|
||||
} else if (info.flags & PASSFLAG_BYREF) {
|
||||
//lea reg, [ebx+<offset>]
|
||||
Write_PushPOD(jit, info, offset);
|
||||
return;
|
||||
@ -520,7 +520,7 @@ inline void Write_PushFloat(JitWriter *jit, const SourceHook::PassInfo *info, un
|
||||
X64_Movups_Rm_Disp32_Reg(jit, kREG_RSP, floatReg, g_StackUsage);
|
||||
}
|
||||
|
||||
if (info->size == 16)
|
||||
if (info.size == 16)
|
||||
{
|
||||
if (g_StackUsage + 8 < SCHAR_MAX) {
|
||||
if ((g_StackUsage + 8) % 16 == 0)
|
||||
@ -542,7 +542,7 @@ inline void Write_PushFloat(JitWriter *jit, const SourceHook::PassInfo *info, un
|
||||
if (floatRegs)
|
||||
{
|
||||
floatRegs[0] = floatReg;
|
||||
floatRegs[1] = info->size == 16 ? floatReg2 : INVALID_REG;
|
||||
floatRegs[1] = info.size == 16 ? floatReg2 : INVALID_REG;
|
||||
}
|
||||
}
|
||||
|
||||
@ -716,10 +716,10 @@ inline int ClassifyObject(const PassInfo *info, ObjectClass *classes)
|
||||
return numWords;
|
||||
}
|
||||
|
||||
inline void Write_PushObject(JitWriter *jit, const SourceHook::PassInfo *info, unsigned int offset,
|
||||
inline void Write_PushObject(JitWriter *jit, const PassInfo& info, unsigned int offset,
|
||||
const PassInfo *smInfo)
|
||||
{
|
||||
if (info->flags & PASSFLAG_BYVAL)
|
||||
if (info.flags & PASSFLAG_BYVAL)
|
||||
{
|
||||
#ifdef PLATFORM_POSIX
|
||||
ObjectClass classes[MAX_CLASSES];
|
||||
@ -752,27 +752,27 @@ inline void Write_PushObject(JitWriter *jit, const SourceHook::PassInfo *info, u
|
||||
|
||||
if (classes[0] != ObjectClass::Memory)
|
||||
{
|
||||
size_t sizeLeft = info->size;
|
||||
size_t sizeLeft = info.size;
|
||||
for (int i = 0; i < numWords; i++)
|
||||
{
|
||||
switch (classes[i])
|
||||
{
|
||||
case ObjectClass::Integer:
|
||||
{
|
||||
SourceHook::PassInfo podInfo;
|
||||
PassInfo podInfo;
|
||||
podInfo.size = (sizeLeft > 8) ? 8 : sizeLeft;
|
||||
podInfo.type = SourceHook::PassInfo::PassType_Basic;
|
||||
podInfo.flags = SourceHook::PassInfo::PassFlag_ByVal;
|
||||
Write_PushPOD(jit, &podInfo, offset + (i * 8));
|
||||
podInfo.type = PassType_Basic;
|
||||
podInfo.flags = PASSFLAG_BYVAL;
|
||||
Write_PushPOD(jit, podInfo, offset + (i * 8));
|
||||
break;
|
||||
}
|
||||
case ObjectClass::SSE:
|
||||
{
|
||||
SourceHook::PassInfo floatInfo;
|
||||
PassInfo floatInfo;
|
||||
floatInfo.size = (sizeLeft > 8) ? 8 : sizeLeft;
|
||||
floatInfo.type = SourceHook::PassInfo::PassType_Float;
|
||||
floatInfo.flags = SourceHook::PassInfo::PassFlag_ByVal;
|
||||
Write_PushFloat(jit, &floatInfo, offset + (i * 8), nullptr);
|
||||
floatInfo.type = PassType_Float;
|
||||
floatInfo.flags = PASSFLAG_BYVAL;
|
||||
Write_PushFloat(jit, floatInfo, offset + (i * 8), nullptr);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -800,8 +800,8 @@ inline void Write_PushObject(JitWriter *jit, const SourceHook::PassInfo *info, u
|
||||
return;
|
||||
#endif
|
||||
|
||||
jit_uint32_t qwords = info->size >> 3;
|
||||
jit_uint32_t bytes = info->size & 0x7;
|
||||
jit_uint32_t qwords = info.size >> 3;
|
||||
jit_uint32_t bytes = info.size & 0x7;
|
||||
|
||||
//sub rsp, <size>
|
||||
//cld
|
||||
@ -854,25 +854,25 @@ inline void Write_PushObject(JitWriter *jit, const SourceHook::PassInfo *info, u
|
||||
X64_Pop_Reg(jit, kREG_RSI);
|
||||
X64_Pop_Reg(jit, kREG_RDI);
|
||||
|
||||
g_StackUsage += info->size;
|
||||
} else if (info->flags & PASSFLAG_BYREF) {
|
||||
g_StackUsage += info.size;
|
||||
} else if (info.flags & PASSFLAG_BYREF) {
|
||||
push_byref:
|
||||
//lea reg, [ebx+<offset>]
|
||||
SourceHook::PassInfo podInfo;
|
||||
PassInfo podInfo;
|
||||
podInfo.size = sizeof(void *);
|
||||
podInfo.type = SourceHook::PassInfo::PassType_Basic;
|
||||
podInfo.flags = SourceHook::PassInfo::PassFlag_ByRef;
|
||||
Write_PushPOD(jit, &podInfo, offset);
|
||||
podInfo.type = PassType_Basic;
|
||||
podInfo.flags = PASSFLAG_BYREF;
|
||||
Write_PushPOD(jit, podInfo, offset);
|
||||
}
|
||||
}
|
||||
|
||||
inline void Write_PushThisPtr(JitWriter *jit)
|
||||
{
|
||||
SourceHook::PassInfo podInfo;
|
||||
PassInfo podInfo;
|
||||
podInfo.size = 8;
|
||||
podInfo.type = SourceHook::PassInfo::PassType_Basic;
|
||||
podInfo.flags = SourceHook::PassInfo::PassFlag_ByVal;
|
||||
g_ThisPtrReg = Write_PushPOD(jit, &podInfo, 0);
|
||||
podInfo.type = PassType_Basic;
|
||||
podInfo.flags = PASSFLAG_BYVAL;
|
||||
g_ThisPtrReg = Write_PushPOD(jit, podInfo, 0);
|
||||
}
|
||||
|
||||
inline void Write_PushRetBuffer(JitWriter *jit)
|
||||
@ -904,9 +904,9 @@ inline void Write_CallFunction(JitWriter *jit, FuncAddrMethod method, CallWrappe
|
||||
// mov r10, [g_ThisPtrReg+<thisOffs>+<vtblOffs>]
|
||||
// mov r11, [r10+<vtablIdx>*8]
|
||||
// call r11
|
||||
SourceHook::MemFuncInfo *funcInfo = pWrapper->GetMemFuncInfo();
|
||||
jit_uint32_t total_offs = funcInfo->thisptroffs + funcInfo->vtbloffs;
|
||||
jit_uint32_t vfunc_pos = funcInfo->vtblindex * 8;
|
||||
//SourceHook::MemFuncInfo *funcInfo = pWrapper->GetMemFuncInfo();
|
||||
jit_uint32_t total_offs = 0;/*funcInfo->thisptroffs + funcInfo->vtbloffs;*/
|
||||
jit_uint32_t vfunc_pos = pWrapper->GetVtableIndex();/*funcInfo->vtblindex * 8;*/
|
||||
|
||||
//X64_Mov_Reg_Rm(jit, kREG_RAX, kREG_RBX, MOD_MEM_REG);
|
||||
if (total_offs < SCHAR_MAX)
|
||||
@ -1115,17 +1115,17 @@ skip_retbuffer:
|
||||
for (jit_uint32_t i = 0; i < ParamCount; i++)
|
||||
{
|
||||
unsigned int offset = pWrapper->GetParamOffset(i);
|
||||
const SourceHook::PassInfo *info = pWrapper->GetSHParamInfo(i);
|
||||
auto info = pWrapper->GetParamInfo(i);
|
||||
assert(info != NULL);
|
||||
|
||||
switch (info->type)
|
||||
switch (info->info.type)
|
||||
{
|
||||
case SourceHook::PassInfo::PassType_Basic:
|
||||
case PassType::PassType_Basic:
|
||||
{
|
||||
Write_PushPOD(jit, info, offset);
|
||||
Write_PushPOD(jit, info->info, offset);
|
||||
break;
|
||||
}
|
||||
case SourceHook::PassInfo::PassType_Float:
|
||||
case PassType::PassType_Float:
|
||||
{
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
if ((info->flags & PASSFLAG_BYVAL) && (pWrapper->GetFunctionFlags() & FNFLAG_VARARGS))
|
||||
@ -1137,14 +1137,14 @@ skip_retbuffer:
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Write_PushFloat(jit, info, offset, nullptr);
|
||||
Write_PushFloat(jit, info->info, offset, nullptr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SourceHook::PassInfo::PassType_Object:
|
||||
case PassType::PassType_Object:
|
||||
{
|
||||
const PassEncode *paramInfo = pWrapper->GetParamInfo(i);
|
||||
Write_PushObject(jit, info, offset, ¶mInfo->info);
|
||||
Write_PushObject(jit, info->info, offset, ¶mInfo->info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user