Search code examples
c#compiler-options

[c#]How to specify /GS, options to c# application?


As you know, /GS are Visual C++ Compiler or Linker Options.

  1. Can i Specify /GS in c# compiler or linker?

  2. Are these flags enabled by default in c# applications?

    [Edit]: change the question contents:

    2a. Are these features enabled (by these compiler options as in Visual C++) by default in c# applications?

  3. Is there a way to find out wheather a .exe/.dll file is build with these flags?

Thanks in advance.


Solution

  • I'm guessing your trying to do a code audit/run static analysis tools to ensure that security/SDL best practices are being followed. If you are keep reading...

    There is a tool called Binscope that can be used to check that your native/C++ binaries are compiled with the /GS, /SafeSEH, /NXCOMPAT, and /DYNAMICBASE. These are C++ specific options that make it harder for attackers to exploit buffer overruns. (Binscope also checks for a few other things)

    The only thing Binscope checks for in C#/managed binaries is if they are using strong names. The closest thing to binscope for C# is FxCop which will detail a bunch of potential issues in your managed .Net code. For security, fix any security warnings that FxCop produces and you are on your way.

    The /analyze flag causes Visual Studio to do some static analysis of your native code and lets you know if it finds anything suspicious. The C#/.Net equivalent is the security part of FxCop.