Add util source and header with functions used in multiple locations.
This commit is contained in:
parent
3f62ff4faf
commit
c3bc30ece3
48
util.cpp
Normal file
48
util.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
void * GetObjectAddr(HookParamType type, unsigned int flags, void **params, size_t offset)
|
||||||
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
if (type == HookParamType_Object)
|
||||||
|
return (void *)((intptr_t)params + offset);
|
||||||
|
#elif POSIX
|
||||||
|
if (type == HookParamType_Object && !(flags & PASSFLAG_ODTOR)) //Objects are passed by rrefrence if they contain destructors.
|
||||||
|
return (void *)((intptr_t)params + offset);
|
||||||
|
#endif
|
||||||
|
return *(void **)((intptr_t)params + offset);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t GetParamOffset(HookParamsStruct *paramStruct, unsigned int index)
|
||||||
|
{
|
||||||
|
size_t offset = 0;
|
||||||
|
for (unsigned int i = 0; i < index; i++)
|
||||||
|
{
|
||||||
|
#ifndef WIN32
|
||||||
|
if (paramStruct->dg->params.at(i).type == HookParamType_Object && (paramStruct->dg->params.at(i).flags & PASSFLAG_ODTOR)) //Passed by refrence
|
||||||
|
{
|
||||||
|
offset += sizeof(void *);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
offset += paramStruct->dg->params.at(i).size;
|
||||||
|
}
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t GetParamTypeSize(HookParamType type)
|
||||||
|
{
|
||||||
|
return sizeof(void *);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t GetParamsSize(DHooksCallback *dg)
|
||||||
|
{
|
||||||
|
size_t res = 0;
|
||||||
|
|
||||||
|
for (int i = dg->params.size() - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
res += dg->params.at(i).size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
10
util.h
Normal file
10
util.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef _INCLUDE_UTIL_FUNCTIONS_H_
|
||||||
|
#define _INCLUDE_UTIL_FUNCTIONS_H_
|
||||||
|
|
||||||
|
#include "vhook.h"
|
||||||
|
|
||||||
|
size_t GetParamOffset(HookParamsStruct *params, unsigned int index);
|
||||||
|
void * GetObjectAddr(HookParamType type, unsigned int flags, void **params, size_t offset);
|
||||||
|
size_t GetParamTypeSize(HookParamType type);
|
||||||
|
size_t GetParamsSize(DHooksCallback *dg);
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user