PDA

View Full Version : Question Crash using GD Detour Function



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!

bobbysing
09-10-2009, 02:42 PM
Attach a debugger to see why you are crashing, search on the forums for the length-parameter(it might be the cause of your crashes).

okidoki
09-11-2009, 08:46 AM
Hi,

Could you paste the disassembly of Init (call and function)? Could help a bit to understand your problem ;)

Regards.

ir0nic
10-06-2009, 06:13 AM
I tried everything but can't get it work (not experienced enough with olly and IDA). I think it's best if I use MS Detours, works well but it boosts dll size :/

Thanks anyway and sorry for my late answer :)