We have an app where some parts of the heap are executed as assembly instructions / for testing purposes - we download programs to PLCs but allow users to simulate running their applications by executing their code before downloading to the PLC. Before we always executed these programs from the heap where the instructions are stored and this worked fine but we have now converted to VS2012 and now it seems that turning off DEP is not so easy. I was wondering if it is somehow possible to turn off the DEP regardless of what GetProcessDEPPolicy
returns or if there is some other technique to execute assembly instructions from heap without involving DEP?
Asked
Active
Viewed 1,928 times
4
-
and no, this is not a virus :-) – AndersK Mar 22 '13 at 23:51
-
2This hasn't been possible for a very long time. What did you upgrade from? Note the HEAP_CREATE_ENABLE_EXECUTE option for the HeapCreate() winapi function. And no, you can't change this in VS2012, it now allocates from the default process heap. You'll need to use VirtualAlloc() to allocate memory with the right protection flags. Sounds like an old project I worked btw ;) – Hans Passant Mar 23 '13 at 01:19
1 Answers
6
You don't want to disable DEP; you want to modify your app to work within it.
Per http://msdn.microsoft.com/en-us/library/windows/desktop/aa366553%28v=vs.85%29.aspx
If your application must run code from a memory page, it must allocate and set the proper
virtual memory protection attributes. The allocated memory must be marked PAGE_EXECUTE,
PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE, or PAGE_EXECUTE_WRITECOPY when allocating memory.
Follow these simple directions and your code can coexist with DEP.

j__m
- 9,392
- 1
- 32
- 56