c - can VirtualAlloc replace VirtualProtect -


virtualalloc function

reserves, commits, or changes state of region of pages in virtual address space of calling process. memory allocated function automatically initialized zero.

virtualprotect function

changes protection on region of committed pages in virtual address space of calling process. change access protection of process, use virtualprotectex function.

as above(from msdn) says, virtualalloc can change protection state of committed pages virtualprotect. wondering whether virtualprotect can replaced virtualalloc.thanks.

the following example of using virtualalloc change protection type of committed pages.

lpvoid lpaddress = null; size_t dwsize = 0x40000; dword flallocationtype = mem_commit; dword flprotect = page_readwrite; lpvoid newaddress; newaddress = virtualalloc(lpaddress, dwsize, flallocationtype, flprotect); if(newaddress == null) {      printf("error %d occurs\n", getlasterror());     return -1; } printf("allocation address %p\n", newaddress); lpaddress = (lpvoid)((int)newaddress + 0x8000); newaddress = virtualalloc(lpaddress, dwsize, flallocationtype, page_execute_readwrite); if(newaddress == null) {      printf("error %d occurs\n", getlasterror());     return -1; } printf("allocation address %p\n", newaddress); return 0; 


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -