WriteProcessMemory fails and crashes because of DEP (Data Execution Prevention)

Posted on 2008-11-08
Last Modified: 2013-12-14

I have a piece of code similar to

It's function injection (code injection) into another process using WriteProcessMemory and VirtualAllocEx etc.

But it fails because DEP is enabled in my PC and I get a message about DEP error.

How I can solve it without disabling DEP? or disabling DEP but without needing for PC or app restart or it's because of DEP or it's wrong message?

Thanks from now!
Question by:CSecurity
    LVL 86

    Expert Comment

    You cannot do that without disabling DEP in general. One attempt that could work would be to use 'VirtualProtectEx()' to set the 'execute' flag for the memory you are writing to, but I am not sure whether DEP prevents that also.
    LVL 17

    Author Comment

    Thank you so much, I tried VirtualProtectEx, again no luck!

    First I get a message about DEP, then I get Sending Report Crash window.
    LVL 17

    Accepted Solution

    Here is 2 screen I see

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now