Hi!
Right now, im programming something, so,
few seconds ago, i created a procedure that allocates dynamic (zero) buffer.
x64
; -----------------------------------------------------------;
;
; Procedure: sysAllocateMemory
;
; Usage:
; mov rcx,qword (2048)
; call sysAllocateMemory
; jc .quitError
;
; mov rcx,rax
; call free
;
;
; Returns a pointer to buffer into RAX.
; Set's carry flag on error.
; Clear's carry flag on success.
;
; -----------------------------------------------------------;
sysAllocateMemory:
; Check incoming argument
cmp rcx,qword (0)
jg .goodArg
stc
ret
.goodArg:
; Create stack
push rbp
mov rbp,rsp
push rbx
lea rsp,[rsp-(8*5)]
; Save "byte count" into RBX
mov rbx,rcx
; Allocate memory
; rcx remains set
call malloc
; Check for error
cmp rax,qword (0)
jne .gotMemory
stc
jmp .quit
.gotMemory:
; Restore "byte count" into r8
mov r8,rbx
; Save mem pointer into RBX
mov rbx,rax
; Init memory
mov rcx,rax
xor rdx,rdx
; r8 remains set
call memset
; Set return value, restore mem pointer from RBX
mov rax,rbx
; Set success
clc
; Clean stack n quit
.quit:
lea rsp,[rsp+(8*5)]
pop rbx
pop rbp
ret
Byte!
Encryptor256!!!