我正在尝试编写一个汇编函数来分配内存并将地址存储在给定的指针中。但是,我无法弄清楚如何将地址存储在传递给函数的参数中。
我有以下内容:
struc SSLSocket sock, ssl, ctx, address, port, connected, type
{
.sock dd sock
.ssl dd ssl
.ctx dd ctx
.address dd address
.port dw port
.connected db connected
.type dd type
}
SockArray dd 0 //will allocate 5 of the above struct on the heap and store it in this pointer.
section '.code' code readable executable
main:
push ebp
mov ebp,esp
;push 5
;call [malloc]
;add esp, 0x04
;mov [SockArray], eax
push SockArray ;pointer that will hold allocated memory
push 23 ;size of struct
call ReAllocate_Memory
add esp, 0x08
push [SockArray] //print address of allocated memory.
push PrintPtr
call [printf]
add esp, 0x08
mov esp, ebp
pop ebx
call [getchar]
mov eax, 0x00
ret
ReAllocate_Memory:
push ebp
mov ebp, esp
mov eax, [ebp + 0x0C] ;Pointer that will hold address of allocation
mov edx, [ebp + 0x08] ;Size to allocate in bytes
push eax
call [free] ;Free any allocated memory
add esp, 0x04
push edx
call [malloc] ;Allocate n-size bytes
add esp, 0x04
;mov address into parameter pointer ([ebp + 0x0C]).
mov esp, ebp
pop ebp
ret
有任何想法吗?