簡體   English   中英

通話未正確返回[X86_ASM]

[英]Call not returning properly [X86_ASM]

這是使用x86內聯匯編的C ++ [Intel語法]

功能:

     DWORD *Call ( size_t lArgs, ... ){

    DWORD *_ret = new DWORD[lArgs];

    __asm {
        xor edx, edx
        xor esi, esi
        xor edi, edi
        inc edx
start:
        cmp edx, lArgs
        je end
        push eax
        push edx
        push esi
        mov esi, 0x04
        imul esi, edx
        mov ecx, esi
        add ecx, _ret
        push ecx
        call dword ptr[ebp+esi] //Doesn't return to the next instruction, returns to the caller of the parent function.
        pop ecx
        mov [ecx], eax
        pop eax
        pop edx
        pop esi
        inc edx
        jmp start
end:
        mov eax, _ret
        ret
    }
}

此功能的目的是調用多個功能/地址,而無需單獨調用它們。

為什么我要調試它? 我白天必須上學,晚上需要上學。

非常感謝,iDomo

感謝您提供一個完整的可編譯示例,它使解決問題變得更加容易。

根據您的Call函數簽名,當設置了堆棧幀時, lArgs位於ebp+8 ,並且指針開始於ebp+C 還有其他一些問題。 這是經過修正的版本,具有一些推送/彈出優化和清理功能,已在MSVC 2010(16.00.40219.01)上進行了測試:

DWORD *Call ( size_t lArgs, ... ) {

    DWORD *_ret = new DWORD[lArgs];

    __asm {
        xor edx, edx
        xor esi, esi
        xor edi, edi
        inc edx
        push esi
start:
        cmp edx, lArgs
        ; since you started counting at 1 instead of 0
        ; you need to stop *after* reaching lArgs
        ja end
        push edx
        ; you're trying to call [ebp+0xC+edx*4-4]
        ; a simpler way of expressing that - 4*edx + 8
        ; (4*edx is the same as edx << 2)
        mov esi, edx
        shl esi, 2
        add esi, 0x8
        call dword ptr[ebp+esi]
        ; and here you want to write the return value
        ; (which, btw, your printfs don't produce, so you'll get garbage)
        ; into _ret[edx*4-4] , which equals ret[esi - 0xC]
        add esi, _ret
        sub esi, 0xC
        mov [esi], eax
        pop edx
        inc edx
        jmp start
end:
        pop esi
        mov eax, _ret
        ; ret ; let the compiler clean up, because it created a stack frame and allocated space for the _ret pointer
    }
}

完成后,別忘了delete[]從此函數返回的內存。

我注意到,在調用之前,您按順序按了EAX,EDX,ESI,ECX,但返回后不要以相反的順序彈出。 如果第一個CALL正確返回,但隨后的CALL沒有返回,則可能是問題所在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM