'http://msdn.microsoft.com/en-us/library/windows/desktop/aa366781(v=vs.85).aspx
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa366887(v=vs.85).aspx

extern lib "kernel32.dll"
! VirtualAlloc   (sys lpAddr,dwSize,flAllocationType,flProtect) as sys 'lpAddr
! VirtualProtect (sys lpAddr,dwSize,flNewProtect,*lpflOldProtect) as sys 'bool
! VirtualFree    (sys lpAddr,dwSize,dwFreeType) as sys 'bool
end extern

% MEM_COMMIT             0x1000
% MEM_RESERVE            0x2000


'Memory Protection Constants
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx

% PAGE_EXECUTE           0x10
% PAGE_EXECUTE_READ      0x20
% PAGE_EXECUTE_READWRITE 0x40

'http://msdn.microsoft.com/en-us/library/windows/desktop/aa366892(v=vs.85).aspx

% MEM_DECOMMIT           0x4000
% MEM_RELEASE            0x8000

sys p,size,prot

size=0x1000
p=VirtualAlloc 0,size,MEM_COMMIT,PAGE_EXECUTE_READWRITE

byte b at p

b={0xb8,1,2,3,4,0xc3} 'tiny function--> mov eax,0x04030201 : ret

VirtualProtect p,size,PAGE_EXECUTE_READ,prot

print hex call p

VirtualFree p,size,MEM_DECOMMIT


