0

Hope this isn't an obvious issue. I've recently run in exceptions due to a lack of Data Execution Prevention (DEP) support in our 32-bit exe on a Windows 2008 R2 server. Adding the exe to the DEP exclusion list, solved the issue as a workaround.

I would like to compile with support for DEP, but can't find any indication on how to do this in Builder XE5 c++. Is this possible? I have found some vague suggestions for Delphi, but nothing definitive.

Any ideas?

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
Here'sWally
  • 61
  • 1
  • 6
  • http://stackoverflow.com/questions/8066266/how-can-i-enable-dep-nx-and-aslr-on-a-delphi-2006-or-earlier-executable – Ari0nhh Dec 11 '14 at 14:18
  • Why the downvote? I understand the problem, it is clearly stated and I did see to the Delphi fix. My problem is getting this done in C++ Builder, not Delphi. – Here'sWally Dec 12 '14 at 08:38
  • As to why DEP is kicking in - it is with recent changes to interact from our exe to a web service that this issue started. I have no control over the Builder libraries that we used to get that going. I would first like to recompile with the flags if possible, and then see if it is still an issue. – Here'sWally Dec 12 '14 at 08:40

1 Answers1

1

AFAIK, C++Builder doesn't have the same DEP options that Delphi has. You will have to either

  1. use an external PE editor to modify the PE flags of your compiled EXE file.

  2. call SetProcessDEPPolicy() at runtime, such as at the top of your main()/Winmain() function:

    void EnableDEP()
    {
        const DWORD PROCESS_DEP_ENABLE = 0x00000001;
        typedef BOOL WINAPI (*LP_SPDEPP)(DWORD);
    
        LP_SPDEPP SetProcessDEPPolicy = (LP_SPDEPP) GetProcAddress(GetModuleHandle(TEXT("kernel32")), "SetProcessDEPPolicy");
        if (SetProcessDEPPolicy != NULL)
            SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
    }
    
    
    int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        EnableDEP();
        ...
    }
    
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770