#Alloc memory with custom protection.

1 messages · Page 1 of 1 (latest)

stiff eagle
#

I'm working at windows 11 and i need to alloc memory for shellcode (raw function bytes).
Is there way to alloc memory using some of zig builtin allocators with execution allowance by default? Like for example here:

void* exec = VirtualAlloc(NULL, sizeof(sc), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);

Where PAGE_EXECUTE_READWRITE means that memory region can be executed as code.

restive kettle
iron gazelle
#

The only allocator it would make sense for is std.heap.PageAllocator, and even then I think making executable the default is a security footgun.

desert radish
echo nebula
desert radish
#

you could probably just make an allocator that wraps any other allocator and changes the permissions on the memory

#

well

#

you'd need to always allocate page-aligned memory from the underlying allocator even when the request to this custom allocator isn't aligned

stiff eagle
#

Looks like the best way to achieve what i need will be is to use VirtualProtect WInAPI function with usage of page_allocator