How to alloc a executable memory buffer?

后端 未结 4 1712
时光取名叫无心
时光取名叫无心 2020-11-30 07:19

I would like to alloc a buffer that I can execute on Win32 but I have an exception in visual studio cuz the malloc function returns a non executable memory zone. I read that

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 07:50

    As stated in documentation for VirtualAlloc

    flProtect [in]

    The memory protection for the region of pages to be allocated. If the pages are being committed, you can specify any one of the memory protection constants.

    one of them is:

    PAGE_EXECUTE 0x10 Enables execute access to the committed region of pages. An attempt to write to the committed region results in an access violation. This flag is not supported by the CreateFileMapping function.

    PAGE_EXECUTE_READ 0x20 Enables execute or read-only access to the committed region of pages. An attempt to write to the committed region results in an access violation. Windows Server 2003 and Windows XP: This attribute is not supported by the CreateFileMapping function until Windows XP with SP2 and Windows Server 2003 with SP1.

    PAGE_EXECUTE_READWRITE 0x40 Enables execute, read-only, or read/write access to the committed region of pages. Windows Server 2003 and Windows XP: This attribute is not supported by the CreateFileMapping function until Windows XP with SP2 and Windows Server 2003 with SP1.

    and so on from here

提交回复
热议问题