x86 - Hooking a _userpurge function c++ -


i want hook function x86 executeable. that's functions prototype decompiled hex-rays plugin ida:

int __userpurge sub_43ce70<eax>(int a1<eax>, int a2, char a3, int a4, int a5, int a6) 

so function acception eax first parameter , returns same register.

i tried following function wrapper:

int the_wrapper(int a2, unsigned a3, int a4, int a5, int a6) {     int a1;     _asm     {         mov [a1], eax     };     char bstring[50];     sprintf(bstring,"a1: %u, a2: %u, a3: %d, a4: %d, a5: %d, a6: %d",a1,a2,a3,a4,a5,a6);     logs(bstring);     int rtn;     _asm{         push a6         push a5         push a4         push a3         push a2         mov eax, [a1]         call the_function         mov [rtn], eax     };     return rtn; } 

for reason it's not working , crashed everytime function gets called.

you need declare wrapper same calling convention function trying wrap.

depending on convention (the common being cdecl , stdcall depends on compiler of wrapped code) either caller or callee cleans stack. if not use correct convention prone stack corruption , crash.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -