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
Post a Comment