ir0nic
09-10-2009, 02:19 PM
Hi.
I'm currently trying new things on my hack and so I found the GD Detours Function. I want to use it, because MS Detours links against its .lib file and so the .DLL's size expands up to 300kb, so I want to use GD Detours.
Here's the function (anybody should know it):
void *CMemTools::detourFunction(BYTE *src, const BYTE *dst, const int len)
{
BYTE *jmp = (BYTE*)malloc(len + 5);
DWORD dwback;
VirtualProtect(src, len, PAGE_READWRITE, &dwback);
memcpy(jmp, src, len);
jmp += len;
jmp[0] = 0xE9;
*(DWORD*)(jmp + 1) = (DWORD)(src + len - jmp) - 5;
src[0] = 0xE9;
*(DWORD*)(src + 1) = (DWORD)(dst - src) - 5;
VirtualProtect(src, len, dwback, &dwback);
return (jmp - len);
}
Now - this actually works:
m_pEngineHooks->m_pInit = (int (__stdcall*)(CreateInterfaceFn, CreateInterfaceFn, CGlobalVarsBase*))DetourFunction((PBYTE)dwVTableClient[OFFSET_INIT], (PBYTE)CEngineHooks::Init);
And this does NOT:
m_pEngineHooks->m_pInit = (int (__stdcall*)(CreateInterfaceFn, CreateInterfaceFn, CGlobalVarsBase*))m_pMemTools->detourFunction((PBYTE)dwVTableClient[OFFSET_INIT], (PBYTE)CEngineHooks::Init, 5);
The CEngineHooks::Init doesn't contains any interesting, just default shit:
int __stdcall CEngineHooks::Init(CreateInterfaceFn appSystemFactory, CreateInterfaceFn physicsFactory, CGlobalVarsBase *pGlobals)
{
m_AAppSysFactory = appSystemFactory;
m_pGlobals = pGlobals;
return m_pEngineHooks->m_pInit(CEngineHooks::AppSysFactory, physicsFactory, pGlobals);
}
The point where it crashs is the call of m_pEngineHooks->m_pInit (only with GD Detours, MS Detours works well). Also I'm not sure about the "len" parameter on the GD Detours Function - what about that, and how I have to use it?
Thanks in advance!
I'm currently trying new things on my hack and so I found the GD Detours Function. I want to use it, because MS Detours links against its .lib file and so the .DLL's size expands up to 300kb, so I want to use GD Detours.
Here's the function (anybody should know it):
void *CMemTools::detourFunction(BYTE *src, const BYTE *dst, const int len)
{
BYTE *jmp = (BYTE*)malloc(len + 5);
DWORD dwback;
VirtualProtect(src, len, PAGE_READWRITE, &dwback);
memcpy(jmp, src, len);
jmp += len;
jmp[0] = 0xE9;
*(DWORD*)(jmp + 1) = (DWORD)(src + len - jmp) - 5;
src[0] = 0xE9;
*(DWORD*)(src + 1) = (DWORD)(dst - src) - 5;
VirtualProtect(src, len, dwback, &dwback);
return (jmp - len);
}
Now - this actually works:
m_pEngineHooks->m_pInit = (int (__stdcall*)(CreateInterfaceFn, CreateInterfaceFn, CGlobalVarsBase*))DetourFunction((PBYTE)dwVTableClient[OFFSET_INIT], (PBYTE)CEngineHooks::Init);
And this does NOT:
m_pEngineHooks->m_pInit = (int (__stdcall*)(CreateInterfaceFn, CreateInterfaceFn, CGlobalVarsBase*))m_pMemTools->detourFunction((PBYTE)dwVTableClient[OFFSET_INIT], (PBYTE)CEngineHooks::Init, 5);
The CEngineHooks::Init doesn't contains any interesting, just default shit:
int __stdcall CEngineHooks::Init(CreateInterfaceFn appSystemFactory, CreateInterfaceFn physicsFactory, CGlobalVarsBase *pGlobals)
{
m_AAppSysFactory = appSystemFactory;
m_pGlobals = pGlobals;
return m_pEngineHooks->m_pInit(CEngineHooks::AppSysFactory, physicsFactory, pGlobals);
}
The point where it crashs is the call of m_pEngineHooks->m_pInit (only with GD Detours, MS Detours works well). Also I'm not sure about the "len" parameter on the GD Detours Function - what about that, and how I have to use it?
Thanks in advance!