April 26, 2024, 02:35:00 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


ALLOCMEM

Started by Peter, December 25, 2009, 02:00:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Peter

December 25, 2009, 02:00:59 PM Last Edit: December 25, 2009, 02:02:44 PM by Peter
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.

sapero

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.

Peter

Will do as soon as I get home. Thanks sapero!