2015-02-07 62 views
0
Function CallFunc(Address: PtrUInt; Arg: Array of PtrUInt; isCDecl: Boolean = True): PtrUInt; 
{$ASMMODE INTEL} 
begin 
    if (isCDecl) then 
    asm 
    mov ecx, 3 //loop 3 times. 
    mov edx, Arg 
    @@start: 
     dec ecx 
     push dword ptr[edx + ecx * 4] //push 3 pointers onto the stack. 
    jnz @@start 
    call [Address] 

    //Do cleanup 
    mov ecx, 3 
    @@end: 
     dec ecx 
     pop dword ptr[edx + ecx * 4] //pop each pointer off the stack. 
    jnz @@end 

    mov @Result, eax 
    end; 
end; 

但是,清理時出現段錯誤。如果我不彈出堆棧中的參數,它不會出現段錯誤。CDECL中的組件清理堆棧導致崩潰

在這種情況下,我是否需要將參數從堆棧中彈出或者是否安全?

我試圖做「ret 12」,但也失敗了。

+0

但是你失去了我。這個函數是調用者。它「打電話給[地址]」,那麼它必須正確清理它? – Brandon 2015-02-07 20:56:06

回答

1
  1. 你的edx在呼叫[地址]返回後包含垃圾,所以誰知道你在彈出什麼。

  2. 您不需要彈出任何內存。只需要彈出edx三次。

+0

啊!沒有注意到。試圖弄清楚我做錯了什麼,正在破壞我的大腦。 Ahaha。謝謝一堆! – Brandon 2015-02-07 21:07:50

+0

很高興能有所幫助,但請告訴我,這是否確實解決了問題? – 2015-02-07 21:09:43

+1

是的,它的工作原理。它修復了它。 – Brandon 2015-02-07 21:31:34