TransWikia.com

Function pointer reference

Reverse Engineering Asked on May 3, 2021

I need to hook 10/20 functions like these:

static void* __cdecl HookFunction1(char *FileName, int a2, int a3, int a4);


 __declspec(naked)  void HookFunction2(char  *Src, int pedx, int 
    
    a3, int a4, int a5, int a6);
    
 static BOOL HookFunction3(int a1, DWORD *a2, DWORD *a3, int a4, char a5, int a6);

and I use this code:

switch (int iD)
{
case 1

    DetourAttach(&(LPVOID&)AddressOfHook, &HookFunction1);

case 2
   DetourAttach(&(LPVOID&)AddressOfHook, &HookFunction2);

case 3
   DetourAttach(&(LPVOID&)AddressOfHook, &HookFunction3);
.....
}

but I like to not repeat x times "DetourAttach" and I like do to something like this:

switch (int iD)
{
case 1

    HookFunction = &HookFunction1;

case 2
    HookFunction = &HookFunction2;

case 3
   HookFunction = &HookFunction3;
.....
}

DetourAttach(&(LPVOID&)AddressOfHook, &HookFunction);

I ask if there is a easy way to do this becouse is more flexible.

Thanks !!

One Answer

I have solved myself.

PVOID HookFunction;

HookFunction = (PVOID)HookFunction1;

and

DetourAttach(&(LPVOID&)AddressOfHook, HookFunction);

Answered by user3449922 on May 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP