NO

Author Topic: Allocating Memory using VirtualAlloc  (Read 2505 times)

Jokaste

  • Guest
Allocating Memory using VirtualAlloc
« on: November 11, 2017, 09:50:17 AM »
Code: [Select]

                     .Const

                     INCLUDE   Win_AsmLibrary.inc

                     .Code

;   **********************************************************************************
;   *********************** MemoryAlloc **********************************************
;   **********************************************************************************

                     ALIGN   16

PUBLIC   MemoryAlloc

MemoryAlloc :

                     mov      rdx,rcx
                     and      rdx,00000000ffffffffh
                     jnz      @F

                     nop               ; If the only instruction after a label is RET
                     ret               ; Place a NOP or REP RET
@@ :

                     xor      rcx,rcx
                     shl      rdx,12
                     mov      r8,MEM_COMMIT or MEM_RESERVE
                     shr      rdx,12      ; Round to multiple of 4096

                     mov      r9,PAGE_EXECUTE_READWRITE
                     jmp      VirtualAlloc

;   **********************************************************************************
;   *********************** F I N I S H E D ******************************************
;   **********************************************************************************

                     END

Usualy it is a call VirtualAlloc, not a jump. After this call there would be a RET so it is not necessary to make a CALL. Just correct the stack and JUMP.
« Last Edit: November 11, 2017, 12:38:48 PM by Jokaste »