I know that Linux supports the mmap
system command for being able to define a block of executable memory. How do you do the same thing in windows? I imagine there is some windows equivalent function that does the same thing, maybe?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Call CreateFileMapping
or VirtualProtect
or VirtualAlloc
passing one of the PAGE_EXECUTE_XXX
protection flags. The mmap
function is used for file mappings and so CreateFileMapping
is the closest Windows analogue.
回答2:
Google, one of the first hits. - use the VirtualAlloc
function with the protection flag being one of PAGE_EXECUTE
, PAGE_EXECUTE_READ
, PAGE_EXECUTE_READWRITE
, or PAGE_EXECUTE_WRITECOPY
.
Alternatively, use VirtualProtect()
to change the protection of an already existing memory region.