Does ALLOCMEM allow us to allocate memory with read/write/execute flag or only read/write?
I have a software that needs to load a resource into a memoryarea with read/write/execute and it just keeps failing. If I would change this to inline asm (and read the file in using incbin), it would be either segment .text (rx) or segment .data (rw), but can I combine these somehow? Both the resources method and the inline asm method would be nice to get a solution for, but at least one of them is critical.
The reason for this is that I need to load the encrypted code (stored in a resource for now, but I would like to have it optional as an incbin-statement) into an area which I can then decrypt and jmp/call to execute.
Thanks.
Peter, try with VirtualProtect api:
$include "windowssdk.inc"
...
pointer code
int size
if decrypt(..., &code, &size)
if (VirtualProtect(code, size, PAGE_EXECUTE_READ, 0)) /*or PAGE_EXECUTE, or PAGE_EXECUTE_READWRITE*/
execute it here
endif
free the memory
endif
If VirtualProtect fails, then use VirtualAlloc instead allocmem, and VirtualFree instead freemem.
Will do as soon as I get home. Thanks sapero!