0
메모리를 할당하고 주어진 포인터에 주소를 저장하는 어셈블리 함수를 작성하려고합니다. 그러나 함수에 전달 된 매개 변수에 주소를 저장하는 방법을 알 수 없습니다.참조/포인터로 FASM 전달
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
어떤 아이디어 :
나는 다음 있나요?
나는 아직 완전히 asm에 익숙하지 않기 때문에 그 모든 것을 이해하고있다. 내가 한 : http://pastebin.com/fYUXBkeW 그리고 그것은 작동하는 것. 나는 edx와 다른 레지스터를 저장해야했다. 그렇지 않으면 충돌이 일어날 것이기 때문이다. 그 말이 맞았 어. 나는 네가하는 말의 일부를 이해했지만 전부는 아니 었습니다. 특히 더 쉬운 방법. 대부분의 내용을 이해하고 저축 한 레지스터 파트가 나를 구했기 때문에이 대답을 받아들입니다. D – Brandon
'ReAllocate_Memory'에서 새 버퍼에 대해 'Reallocate_Memory'를 호출합니다. 'malloc'의 결과는'eax'에서 리턴됩니다. 아무 것도하지 않고 호출자에게 돌아 가면 값은'ReAllocate_Memory'가 리턴 할 때 여전히 호출 범위에있을 것이고, 원래의'malloc (와)과 같은 (주석 처리 되더라도) 동일한 값을 저장할 수 있습니다. '더 전화 해. –
오하이오 알겠습니다! 나는 그것에 대해 생각하지 않았다. 리턴 값에 대해 생각하기 위해 매개 변수로 작업하도록 내 마음을 고수했습니다. 아하하. 그것은 훨씬 더 나은 설명이었습니다. 고맙습니다! :디 – Brandon