What is wrong with this __usercall wrapper?

与世无争的帅哥 提交于 2020-01-16 13:13:12

问题


/*
 * Wrapper from
 * int func(int a, int b, int c, unsigned int d, signed int e);
 * to
 * int __usercall func<eax>(int a<eax>, int b<ecx>, int c, unsigned int d, signed int e);
 */
int func(int a, int b, int c, unsigned int d, signed int e)
{
    __asm
    {       
        push e
        push d
        push c
        mov ecx, b
        mov eax, a
        call __usercall_func // access violation somewhere inside here
        add esp, 12
    }
}

回答1:


You cannot perform ret yourself from within an inline asm block, because you don't know what the outer function has done with the stack pointer. Instead you need to arrange for the assembly code to leave the return value in a local variable, which the wrapper function can return with the normal C return statement.

You also probably need to fix the stack pointer after the return from __usercall_func, unless it uses a perverse calling convention where it pops its own parameters off the stack.



来源:https://stackoverflow.com/questions/4102981/what-is-wrong-with-this-usercall-wrapper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!