Creating a C function without compiler generated prologue/epilogue & RET instruction?

前端 未结 3 1481
野性不改
野性不改 2020-12-02 00:19

Consider this function:

void foo(){
    //do something
}

In assembly it would look something like this (not accurate):

push         


        
3条回答
  •  情深已故
    2020-12-02 00:55

    I found a neat workaround:

    Define the function in assembly but call a extern c function:

    bits 32
    
    global _bar
    extern _foo
    
    section .data
    
    section .text
    
    _bar:
        call _foo
        iret
    

    in C:

    void foo(){
        //do your stuff here
    }
    
    extern void bar();
    
    //bar is now your "naked" function
    

    compiled with nasm and gcc under windows

提交回复
热议问题